当前位置:网站首页>PWM controlled steering gear
PWM controlled steering gear
2022-07-02 16:43:00 【Let everything burn】
Mission requirements
Use PWM Control the steering gear to rotate at any angle within the steering gear angle range . matters needing attention : Try not to use external force to prevent the steering gear from rotating , Avoid damage to the single chip . Acceptance requirements :
initial position 0°, Press the button ( You can customize any key ) rotate 30°, If you end up turning , Turn into pressing the button to turn in the opposite direction 30°
Press a key repeatedly , From 0 Change to the maximum angle and return to 0
Ideas

Need to use 30°
So use the original
0° 1500 0.5ms
45° 3000 1ms
……
Calculate the proportion
You can estimate
30.06 2502 0.834 1002
The whole cycle is 20ms, Overflow value is 60000
0 0.5ms 1500
180 2.5ms 7500
Overflow time =(arr+1)(psc+1)/Tclk
20MS = (59999+1)*(23+1)/72000000
Finished code
int main (void){
// Defining variables must be placed first
u16 t = 1500;
u8 dir = 1;
delay_ms(500);
RCC_Configuration();
RELAY_Init();
I2C_Configuration();
TOUCH_KEY_Init();// Initialize touch button
TIM3_PWM_Init(59999,23);
// Make the initial situation 0°
TIM_SetCompare3(TIM3,1500);
while(1){
delay_ms(10);
// Positive direction , Press the key every time 30°
if(dir){
for(t=1500;t<7500;){
if(!GPIO_ReadInputDataBit(TOUCH_KEYPORT,TOUCH_KEY_B)){
if(!GPIO_ReadInputDataBit(TOUCH_KEYPORT,TOUCH_KEY_B)){
t=t+1002;// It needs to be done first ++ Then execute, so write the code here
TIM_SetCompare3(TIM3,t);
while(!GPIO_ReadInputDataBit(TOUCH_KEYPORT,TOUCH_KEY_B));
}
}
}
}
if(t==7500)dir=0;
// Negative direction , Press the key every time 30°
else{
for(t=7500;t>1500;){
if(!GPIO_ReadInputDataBit(TOUCH_KEYPORT,TOUCH_KEY_B)){
if(!GPIO_ReadInputDataBit(TOUCH_KEYPORT,TOUCH_KEY_B)){
t=t-1002;
TIM_SetCompare3(TIM3,t);
while(!GPIO_ReadInputDataBit(TOUCH_KEYPORT,TOUCH_KEY_B));
}
}
}
}
if(t==1500)dir=1;// Corresponding to the previous one if The statement needs to be written in if(dir) Outside , Otherwise, the loop cannot jump out
}
}
Because you need to go every time you press the key 30° So the key should be locked , The principle is the same as the previous mechanical key locking . But touching the button does not need to delay to eliminate jitter .
边栏推荐
- 大厂面试总结大全
- OSPF - route aggregation [(summary) including configuration commands] | address summary calculation method - detailed explanation
- False summer vacation
- 渗透工具-内网权限维持-Cobalt strike
- Seal Library - installation and introduction
- LeetCode 4. Find the median (hard) of two positive arrays
- LeetCode 2. Add two numbers
- Yyds dry goods inventory has not revealed the artifact? Valentine's Day is coming. Please send her a special gift~
- PyC file decompile
- 忆当年高考|成为程序员的你,后悔了吗?
猜你喜欢

Unity使用UGUI设置一个简单多级水平方向下拉菜单(不需要代码)

What is normal distribution? What is the 28 law?

大厂面试总结大全

Remove the underline in router link

Yyds dry goods inventory # look up at the sky | talk about the way and principle of capturing packets on the mobile terminal and how to prevent mitm

OSPF - detailed explanation of NSSA area and full NSSA area (including configuration command), LSA type 7 lsa-7

大廠面試總結大全

⌈ 2022 ⌋ how to use webp gracefully in projects

分析超700万个研发需求发现,这8门编程语言才是行业最需要的!

路由模式:hash和history模式
随机推荐
ROW_NUMBER()、RANK()、DENSE_RANK区别
Analysis of how to prevent virus in industrial computer
LeetCode 4. 寻找两个正序数组的中位数(hard)
Yyds dry goods inventory student attendance system based on QT design
LeetCode 5. Longest Palindromic Substring
Today in history: Alipay launched barcode payment; The father of time-sharing system was born; The first TV advertisement in the world
Classic quotations
历史上的今天:支付宝推出条码支付;分时系统之父诞生;世界上第一支电视广告...
Yyds dry inventory executor package (parameter processing function)
Seal Library - installation and introduction
Student course selection system (curriculum design of Shandong Agricultural University)
Where can I open computer administrator permissions
隐私计算技术创新及产业实践研讨会:学习
台积电全球员工薪酬中位数约46万,CEO约899万;苹果上调日本的 iPhone 售价 ;Vim 9.0 发布|极客头条...
Original God 2.6 server download and installation tutorial
Rock PI Development Notes (II): start with rock PI 4B plus (based on Ruixing micro rk3399) board and make system operation
Rock PI Development Notes (II): start with rock PI 4B plus (based on Ruixing micro rk3399) board and make system operation
The median salary of TSMC's global employees is about 460000, and the CEO is about 8.99 million; Apple raised the price of iPhone in Japan; VIM 9.0 releases | geek headlines
学生选课系统(山东农业大学课程设计)
Yyds dry goods inventory has not revealed the artifact? Valentine's Day is coming. Please send her a special gift~