当前位置:网站首页>Steering gear control (stm32f103c8t6)
Steering gear control (stm32f103c8t6)
2022-06-24 19:24:00 【Me-Space】
Preface
This article is based on STM32F103C8T6 As the main control chip , adopt PB6 Port output PWM, Achieve control 180° The steering gear .
One 、 Steering control principle
( One ) summary
The steering gear is a position servo driver , It is a small device with an output shaft . When we send a control signal to the server , The output shaft can be turned to a specific position . Only when the control signal remains constant , The servo mechanism will keep the relative angular position unchanged . If the control signal changes , The position of the output shaft will change accordingly . The control of the steering gear is mostly through PWM Signal controlled .
notes : The steering gear is divided into 90°、180°、270°、360° The steering gear , among 360° The steering gear can only control the rotation speed and cannot be fixed at a certain angle .
( Two )PWM
PWM, English name Pulse Width Modulation, Short for pulse width modulation , It is by modulating the width of a series of pulses , Equivalent to the required waveform ( Including shape and amplitude ), Digitally code the analog signal level , That is to say, adjust the signal by adjusting the change of duty cycle 、 Changes in energy, etc , Duty cycle means in a cycle , The time the signal is at the high level as a percentage of the entire signal cycle . Here's the picture
( 3、 ... and ) Control principle
Through the signal line to the steering gear PWM The signal controls the output of the steering gear , Generally speaking ,PWM The cycle and duty cycle of , Programmable .
When we send a pulse width of 1.5ms when , The output shaft of the steering gear will move to the middle position 0°;
When the pulse width is 1ms when , The output shaft of the steering gear will move to the middle position -45°;
The pulse width is 2ms when , The output shaft of the steering gear will move to the middle position 45°.
notes : The angle between the maximum position and the minimum position may be different between different types and brands of servo motors . Many servers only rotate about 170 degree ( Or just 90 degree ), But the width is 1.5 ms The servo pulse will usually set the servo to the middle position ( It's usually half of the specified full range ); Refer to the following figure for details.

Duty cycle = t / T The relevant parameters are as follows :
t = 0.5ms —————— The rudder will turn to -90 °
t = 1.0ms —————— The rudder will turn to -45°
t = 1.5ms —————— The rudder will turn to 0°
t = 2.0ms —————— The rudder will turn to 45°
t = 2.5ms —————— The rudder will turn to 90°
PWM The period is 20ms = (2000*720)/72000000 = 0.2, Programmed TIM_Period = 719,TIM_Prescaler = 1999( In this paper, the program )
Two 、 Hardware connection
( One ) Description of steering gear line

( Two ) Pin connection
| master control | The steering gear |
| 5V | +5V |
| GND | GND |
| PB6 | PWM |
3、 ... and 、 Reference code
1、 initialization
void TIM4_CH1_PWM_Init(u16 arr,u16 psc)
{
GPIO_InitTypeDef GPIO_InitStruct;
TIM_TimeBaseInitTypeDef TIM_TimeBaseStruct;
TIM_OCInitTypeDef TIM_OCInitTypeStruct;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4,ENABLE);
// Only when the multiplexing function is enabled can the clock be remapped
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB ,ENABLE);
//TIM3 Partial remapping
/*
* Check the data book , The timer channel of the pin is fully mapped , Or partial mapping
* The two call parameters are different
* Complete mapping :GPIO_FullRemap_TIM4
* Partial mapping :GPIO_PartialRemap_TIM4
*/
// Set this pin to multiplex output function
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_6;
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB,&GPIO_InitStruct);
// initialization TIM4
TIM_TimeBaseStruct.TIM_Period = arr;// Reload value
TIM_TimeBaseStruct.TIM_Prescaler = psc;// Prescaled value
TIM_TimeBaseStruct.TIM_ClockDivision = 0; // The clock frequency division 1、2、4 frequency division
TIM_TimeBaseStruct.TIM_CounterMode = TIM_CounterMode_Up;// Set counting mode
TIM_TimeBaseInit(TIM4,&TIM_TimeBaseStruct);
// Initialize the output comparison parameters
TIM_OCInitTypeStruct.TIM_OCMode = TIM_OCMode_PWM2; // Select timer mode
TIM_OCInitTypeStruct.TIM_OutputState = TIM_OutputState_Enable;// Compare output enable
TIM_OCInitTypeStruct.TIM_OCPolarity = TIM_OCPolarity_High;// Output polarity
TIM_OC1Init(TIM4,&TIM_OCInitTypeStruct); // Select timer output channel TIM4_CH1
// Enable preload register
TIM_OC1PreloadConfig(TIM4,TIM_OCPreload_Enable);
// Enable timer
TIM_Cmd(TIM4,ENABLE);
}2、 The main function
int main(void)
{
TIM4_CH1_PWM_Init(1999,719);//PWM frequency =72000000/(719+1)/(1999+1)=50hz=20ms
while(1)
{
//-90 degree
TIM_SetCompare1(TIM4,1750);// Duty cycle (2000-1750)/2000*20ms=2.5ms
//45 degree
//TIM_SetCompare1(TIM4,1800);// Duty cycle (2000-1800)/2000*20ms=2ms
//0 degree
//TIM_SetCompare1(TIM4,1850);// Duty cycle (2000-1850)/2000*20ms=1.5ms
//-45 degree
//TIM_SetCompare1(TIM4,1900);// Duty cycle (2000-1900)/2000*20ms=1ms
//-90 degree
//TIM_SetCompare1(TIM4,1945);// Duty cycle (2000-1945)/2000*20ms=0.5ms
}
} Related codes , If necessary, you can download it yourself ( It can only send control rotation through the string )
Network disk link :
link :https://pan.baidu.com/s/1p-lAXJ4pS6-Tw3DFqxdQhQ
Extraction code :ml04
If you have any questions, please point them out , What modules can you contact bloggers , Bloggers will inquire and share information .
边栏推荐
- 建立自己的网站(8)
- 一次 MySQL 误操作导致的事故,高可用都不顶不住!
- Fabric 账本数据块结构解析(一):如何解析账本中的智能合约交易数据
- ls 常用参数
- Unityshader world coordinates do not change with the model
- Multi cloud mode is not a "master key"
- 論文解讀(SR-GNN)《Shift-Robust GNNs: Overcoming the Limitations of Localized Graph Training Data》
- Sr-gnn shift robot gnns: overlapping the limitations of localized graph training data
- Programmers spend most of their time not writing code, but...
- Freeswitch使用originate转dialplan
猜你喜欢

starring V6平台开发接出点流程

Kubernetes集群部署

Understanding openstack network

Geoscience remote sensing data collection online

A detailed explanation of the implementation principle of go Distributed Link Tracking

Do you have all the basic embedded knowledge points that novices often ignore?

试驾 Citus 11.0 beta(官方博客)

工作6年,月薪3W,1名PM的奋斗史

How to use R package ggtreeextra to draw evolution tree

Northwestern Polytechnic University attacked by hackers? Two factor authentication changes the situation!
随机推荐
Introduction and download of nine npp\gpp datasets
网络安全审查办公室对知网启动网络安全审查
一次 MySQL 误操作导致的事故,高可用都不顶不住!
Make track map
Development of NFT dual currency pledge liquidity mining system
Apifox与其他接口开发工具的博弈
Freeswitch使用originate转dialplan
Ask a question. Adbhi supports the retention of 100 databases with the latest IDs. Is this an operation like this
Working for 6 years with a monthly salary of 3W and a history of striving for one PM
What other data besides SHP data
What do I mean when I link Mysql to report this error?
flink cdc全量读mysql老是报这个错怎么处理
通过SCCM SQL生成计算机上一次登录用户账户报告
优维低代码:构件渲染子构件
Vs2017 setting function Chinese Notes
Server lease error in Hong Kong may lead to serious consequences
Would you like to ask whether the same multiple tasks of the PgSQL CDC account will have an impact? I now have only one of the three tasks
Mqtt protocol usage of LabVIEW
Experience of MDM master data project implementation for manufacturing projects
Several ways of connecting upper computer and MES