当前位置:网站首页>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 .
边栏推荐
- IBPS开源表单设计器有什么功能?
- NFT双币质押流动性挖矿系统开发
- Internet of things? Come and see Arduino on the cloud
- 实时渲染:实时、离线、云渲染、混合渲染的区别
- 应用实践 | 海量数据,秒级分析!Flink+Doris 构建实时数仓方案
- Several ways of connecting upper computer and MES
- Dataworks development ODPs SQL development production environment automatic completion of ProjectName
- Pingcap was selected as the "voice of customers" of Gartner cloud database in 2022, and won the highest score of "outstanding performer"
- Zadig + 洞态 IAST:让安全溶于持续交付
- Programmers spend most of their time not writing code, but...
猜你喜欢

Apifox与其他接口开发工具的博弈

Necessary fault handling system for enterprise network administrator

60 个神级 VS Code 插件!!

How to use R package ggtreeextra to draw evolution tree

Zadig + 洞态 IAST:让安全溶于持续交付

Make track map

建立自己的网站(8)
![[leetcode] rotation series (array, matrix, linked list, function, string)](/img/9e/079311df16fa8e28708f4e050e531f.png)
[leetcode] rotation series (array, matrix, linked list, function, string)

PHP OSS file reads and writes files, and workman generates temporary files and outputs them to the browser for download

网络安全审查办公室对知网启动网络安全审查
随机推荐
一文详解|Go 分布式链路追踪实现原理
High dimension low code: component rendering sub component
STM32 uses time delay to realize breathing lamp register version
System design idea of time traceability
Make track map
Drawing DEM with GEE gracefully
cdc sql表里面的datetime要用什么类型替换
NFT双币质押流动性挖矿系统开发
Starring develops httpjson access point + Database
Apifox与其他接口开发工具的博弈
使用阿里云RDS for SQL Server性能洞察优化数据库负载-初识性能洞察
Tkde2022: Dialogue recommendation system based on knowledge enhanced sampling
Volcano成Spark默認batch調度器
Game between apifox and other interface development tools
Vs2017 add header file path method
试驾 Citus 11.0 beta(官方博客)
Introduction to smart contract security audit delegatecall (2)
NOKOV动作捕捉系统使多场协同无人机自主建造成为可能
If the programmer tells the truth during the interview
At present, only CDC monitors Mysql to get the data of new columns. Sqlserver can't, can it