stm32舵机驱动程序

2019-07-20 23:13发布

舵机驱动程序不对,舵机只往一个方向转,而且不能控制角度,调了好几天了,原子大神帮我看看行吗

[mw_shl_code=c,true]/* ************???ú???????ò *************????PB-0 */ #include "bsp_duo.h" void duo_GPIO_Config(void) { GPIO_InitTypeDef GPIO_InitStructure; TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; TIM_OCInitTypeDef TIM_OCInitStructure; RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE); //?????3?? RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOB |RCC_APB2Periph_AFIO, ENABLE); //??GPIO???AFIO???????? GPIO_PinRemapConfig(GPIO_PartialRemap_TIM3, ENABLE); //Timer3????? TIM3_CH2->B5 //????????????,??TIM3 CH2?PWM???? GPIOB.5 GPIOB.4 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5|GPIO_Pin_0; //TIM_CH2|TIM_CH1 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //?????? GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOB, &GPIO_InitStructure);//???GPIO //???TIM3 TIM_TimeBaseStructure.TIM_Period = 19999; //??????????????????????????? TIM_TimeBaseStructure.TIM_Prescaler =71; //??????TIMx??????????? TIM_TimeBaseStructure.TIM_ClockDivision = 0; //??????:TDTS = Tck_tim TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; //TIM?????? TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure); //??TIM_TimeBaseInitStruct?????????TIMx??????? //???TIM3 Channel2 PWM?? TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM2; //???????:TIM????????2 TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; //?????? TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High; //????:TIM??????? TIM_OC2Init(TIM3, &TIM_OCInitStructure); //??T??????????TIM3 OC2 TIM_OC3Init(TIM3, &TIM_OCInitStructure); TIM_OC2PreloadConfig(TIM3, TIM_OCPreload_Enable); //??TIM3?CCR2???????? TIM_OC3PreloadConfig(TIM3, TIM_OCPreload_Enable); TIM_Cmd(TIM3, ENABLE); //??TIM3 } void SetJointAngle(float angle) { //angle=angle+90.0; // angle=(u16)(50.0*angle/9.0+249.0); //angle=(u16)(4.175*angle+409.25); angle=(u16)(20000-(500+angle*7.8125)); TIM_SetCompare3(TIM3,angle); }[/mw_shl_code]


主函数为

[mw_shl_code=c,true]int main(void) { SystemInit(); Key_GPIO_Config(); //???????¤?? duo_GPIO_Config(); Delay_ms(10); while(1) { SetJointAngle(10); Delay_ms(30); SetJointAngle(20); Delay_ms(30); SetJointAngle(200); Delay_ms(30); } }[/mw_shl_code]
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
该问题目前已经被作者或者管理员关闭, 无法添加新回复
4条回答
384172253
1楼-- · 2019-07-21 04:23
 精彩回答 2  元偷偷看……
正点原子
2楼-- · 2019-07-21 07:42
帮顶....
我为电子狂
3楼-- · 2019-07-21 09:13
我也有同样的疑问,帮顶
zds晴天依旧
4楼-- · 2019-07-21 13:16
楼主后来发现了是什么问题啊?

一周热门 更多>