当前位置:网站首页>Stm32f103c8t6 PWM drive steering gear (sg90)
Stm32f103c8t6 PWM drive steering gear (sg90)
2022-07-07 15:06:00 【Related to the sun_】
Little knowledge : Same timer , Different channel outputs different outputs PWM Characteristics .
For different channel outputs of the same timer PWM, Because they share a counter , therefore frequency It has to be the same , and Duty cycle By their own CCR decision , It can be set separately . also , phase Due to counter update , all PWM Will jump at the same time , So the phase is synchronous .
If you use 1 A timer controls multiple steering gears or DC motors , Use different channels of the same timer PWM, That's fine .
TIM_OC1Init(TIM2,&TIM_OCInitStructure);
TIM_OC2Init(TIM2,&TIM_OCInitStructure);
TIM_OC3Init(TIM2,&TIM_OCInitStructure);
TIM_OC4Init(TIM2,&TIM_OCInitStructure);
Code :
PWM.h
#ifndef __PWM_H
#define __PWM_H
void PWM_Init();
void PWM_SetCompare2(uint16_t Compare);
#endif
PWM.c
#include "stm32f10x.h" // Device header
void PWM_Init()
{
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2,ENABLE); // Turn on timer 2
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);// passageway 2 Clock enable function
GPIO_InitTypeDef GPIO_InitStructure; // Definition GPIO Initializing structure variables
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; // Set up GPIO For push-pull output mode
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; // The speed is set to 50MHz
GPIO_Init(GPIOA, &GPIO_InitStructure); // Proceed according to the above parameters GPIO The initialization
TIM_InternalClockConfig(TIM2);//TIM The time base unit of is controlled by the internal clock
TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStructure;
TIM_TimeBaseInitStructure.TIM_ClockDivision = TIM_CKD_DIV1;
TIM_TimeBaseInitStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInitStructure.TIM_Period = 20000 - 1; //ARR The value of the automatic reloader
TIM_TimeBaseInitStructure.TIM_Prescaler = 72 - 1; //PSC Prescaler value Yes 72M(720000000) Conduct 7200 frequency division namely 10K At different frequencies meter 10000 Number 1s Time for
TIM_TimeBaseInitStructure.TIM_RepetitionCounter = 0;// Repeat counter value
TIM_TimeBaseInit(TIM2,&TIM_TimeBaseInitStructure);
TIM_OCInitTypeDef TIM_OCInitStructure;
TIM_OCStructInit(&TIM_OCInitStructure);
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;// Output polarity selection
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;// Output status enable
TIM_OCInitStructure.TIM_Pulse = 0;//CCR, That is, the duty cycle is 10%
TIM_OC2Init(TIM2,&TIM_OCInitStructure);
TIM_Cmd(TIM2,ENABLE);
}
void PWM_SetCompare2(uint16_t Compare)
{
TIM_SetCompare2(TIM2, Compare);
}
Serco.h
#ifndef __Servo_H
#define __Servo_H
void Servo_Init(void);
void Servo_SetAngle(float Angle);
#endif
Servo.c
#include "stm32f10x.h" // Device header
#include "PWM.H"
void Servo_Init(void)
{
PWM_Init();
}
void Servo_SetAngle(float Angle)
{
PWM_SetCompare2(Angle / 180 * 2000 +500);
}
main.c
#include "stm32f10x.h" // Device header
#include "Delay.h"
#include "LED.h"
#include "Key.h"
#include "OLED.H"
#include "Servo.H"
uint8_t KeyNum;
float Angle; // Steering angle
int main(void)
{
OLED_Init();
Servo_Init();
Key_Init();
OLED_ShowString(1,1,"Angle:");
while (1)
{
KeyNum = Key_GetNum();
if(KeyNum == 1)
{
Angle +=30;
if(Angle > 180)
{
Angle = 0;
}
}
Servo_SetAngle(Angle);
OLED_ShowNum(1,7,Angle,3);// Show the angle on the screen
}
}
What happened :
Changed a steering gear , Then use the oscilloscope to measure that the pin is
WaveOf , But the steering gear isImmobility. Later it was found thatvoltageNot enough .
Work hard , Grow slowly
边栏推荐
- 最安全的证券交易app都有哪些
- Promoted to P8 successfully in the first half of the year, and bought a villa!
- 时空可变形卷积用于压缩视频质量增强(STDF)
- CTFshow,信息搜集:web1
- [server data recovery] a case of RAID data recovery of a brand StorageWorks server
- Stm32cubemx, 68 sets of components, following 10 open source protocols
- CTFshow,信息搜集:web9
- leetcode 241. Different Ways to Add Parentheses 为运算表达式设计优先级(中等)
- Pinduoduo lost the lawsuit, and the case of bargain price difference of 0.9% was sentenced; Wechat internal test, the same mobile phone number can register two account functions; 2022 fields Awards an
- CTFshow,信息搜集:web12
猜你喜欢

Ctfshow, information collection: Web3

安恒堡垒机如何启用Radius双因素/双因子(2FA)身份认证

【深度学习】语义分割实验:Unet网络/MSRC2数据集

Ctfshow, information collection: web5

Spatiotemporal deformable convolution for compressed video quality enhancement (STDF)

Niuke real problem programming - day15

Pandora IOT development board learning (HAL Library) - Experiment 12 RTC real-time clock experiment (learning notes)
![[Yugong series] go teaching course 005 variables in July 2022](/img/66/4265a06a98412bd2c88d8281caf06e.png)
[Yugong series] go teaching course 005 variables in July 2022

Change win10 Screensaver

【服务器数据恢复】某品牌StorageWorks服务器raid数据恢复案例
随机推荐
TypeScript 发布 4.8 beta 版本
#yyds干货盘点# 解决名企真题:交叉线
Unity之ASE实现卡通火焰
Apache multiple component vulnerability disclosure (cve-2022-32533/cve-2022-33980/cve-2021-37839)
CTFshow,信息搜集:web10
什么是数据泄露
Find your own value
Apache多个组件漏洞公开(CVE-2022-32533/CVE-2022-33980/CVE-2021-37839)
Bye, Dachang! I'm going to the factory today
JSON parsing instance (QT including source code)
Niuke real problem programming - Day9
Guangzhou Development Zone enables geographical indication products to help rural revitalization
Deformable convolutional dense network for enhancing compressed video quality
Today's sleep quality record 78 points
Es log error appreciation -trying to create too many buckets
Read PG in data warehouse in one article_ stat
Promoted to P8 successfully in the first half of the year, and bought a villa!
PD virtual machine tutorial: how to set the available shortcut keys in the parallelsdesktop virtual machine?
Discussion on CPU and chiplet Technology
Protection strategy of server area based on Firewall