完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
void tiM3_PWM4_Init3(u16 state)//一号舵机
{ static u16 i=200; GPIO_InitTypeDef GPIO_InitStructure; TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; TIM_OCInitTypeDef TIM_OCInitStructure; RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE); //ê1Äü¶¨ê±Æ÷3ê±Öó RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB | RCC_APB2Periph_AFIO, ENABLE); //ê1ÄüGPIOíaéèoíAFIO¸′óÃ1|ÄüÄ£¿éê±Öó GPIO_PinRemapConfig(GPIO_PartialRemap_TIM3, ENABLE); //Timer32¿íêè«ÖØó3éä TIM3_CH4->B1 //éèÖøÃòy½ÅÎa¸′óÃêä3ö1|Äü,êä3öTIM3 CH4μÄWMÂö3å2¨DÎ GPIOB.0 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1; //TIM_CH3 {GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; } //¸′óÃíÆíìêä3ö GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOB, &GPIO_InitStructure);//3õê¼»ˉGPIO //3õê¼»ˉTIM3 TIM_TimeBaseStructure.TIM_Period = 1999; //éèÖÃÔúÏÂò»¸ö¸üDÂê¼t×°èë»î¶ˉμÄ×Ô¶ˉÖØ×°ÔؼÄ′æÆ÷ÖüÆúμÄÖμ TIM_TimeBaseStructure.TIM_Prescaler = 719; //éèÖÃóÃà′×÷ÎaTIMxê±ÖóÆμÂê3yêyμÄÔ¤·ÖÆμÖμ TIM_TimeBaseStructure.TIM_ClockDivision = 0; //éèÖÃê±Öó·Ö¸î:TDTS = Tck_tim TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; //TIMÏòéϼÆêyÄ£ê½ TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure); //¸ù¾YTIM_TimeBaseInitStructÖDÖ¸¶¨μÄ2Îêy3õê¼»ˉTIMxμÄê±¼ä»ùêyμ¥λ //3õê¼»ˉTIM3 Channel 3 PWMÄ£ê½ TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1; //Ñ¡Ôñ¶¨ê±Æ÷Ä£ê½:TIMÂö3å¿í¶èμ÷ÖÆÄ£ê½2 TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; //±è½Ïêä3öê1Äü TIM_OCInitStructure.TIM_Pulse = 18; TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High; //êä3ö¼«DÔ:TIMêä3ö±è½Ï¼«DÔ¸ß TIM_OC4Init(TIM3, &TIM_OCInitStructure); //¸ù¾YTÖ¸¶¨μÄ2Îêy3õê¼»ˉíaéèTIM3 OC4 TIM_OC4PreloadConfig(TIM3, TIM_OCPreload_Enable); //ê1ÄüTIM3ÔúCCR2éÏμÄԤװÔؼÄ′æÆ÷ TIM_Cmd(TIM3, ENABLE); //ê1ÄüTIM3 if(state == 1) //Æe { for(;i>140;i--) { TIM_SetCompare4(TIM3,i); delay_ms(20); } } else { for(;i<200;i++) { TIM_SetCompare4(TIM3,i); delay_ms(20); } } //Âä } void TIM3_PWM3_Init2(u16 state)//二号舵机 { static u16 i=160; GPIO_InitTypeDef GPIO_InitStructure; TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; TIM_OCInitTypeDef TIM_OCInitStructure; RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE); //ê1Äü¶¨ê±Æ÷3ê±Öó RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB | RCC_APB2Periph_AFIO, ENABLE); //ê1ÄüGPIOíaéèoíAFIO¸′óÃ1|ÄüÄ£¿éê±Öó GPIO_PinRemapConfig(GPIO_PartialRemap_TIM3, ENABLE); //Timer22¿íêè«ÖØó3éä TIM3_CH3->B0 //éèÖøÃòy½ÅÎa¸′óÃêä3ö1|Äü,êä3öTIM3 CH4μÄWMÂö3å2¨DÎ GPIOB.0 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; //TIM_CH3 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //¸′óÃíÆíìêä3ö GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOB, &GPIO_InitStructure);//3õê¼»ˉGPIO //3õê¼»ˉTIM3 TIM_TimeBaseStructure.TIM_Period = 1999; //éèÖÃÔúÏÂò»¸ö¸üDÂê¼t×°èë»î¶ˉμÄ×Ô¶ˉÖØ×°ÔؼÄ′æÆ÷ÖüÆúμÄÖμ TIM_TimeBaseStructure.TIM_Prescaler = 719; //éèÖÃóÃà′×÷ÎaTIMxê±ÖóÆμÂê3yêyμÄÔ¤·ÖÆμÖμ TIM_TimeBaseStructure.TIM_ClockDivision = 0; //éèÖÃê±Öó·Ö¸î:TDTS = Tck_tim TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; //TIMÏòéϼÆêyÄ£ê½ TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure); //¸ù¾YTIM_TimeBaseInitStructÖDÖ¸¶¨μÄ2Îêy3õê¼»ˉTIMxμÄê±¼ä»ùêyμ¥λ //3õê¼»ˉTIM3 Channel3 PWMÄ£ê½ TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1; //Ñ¡Ôñ¶¨ê±Æ÷Ä£ê½:TIMÂö3å¿í¶èμ÷ÖÆÄ£ê½2 TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; //±è½Ïêä3öê1Äü TIM_OCInitStructure.TIM_Pulse = 180; TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High; //êä3ö¼«DÔ:TIMêä3ö±è½Ï¼«DÔ¸ß TIM_OC3Init(TIM3, &TIM_OCInitStructure); //¸ù¾YTÖ¸¶¨μÄ2Îêy3õê¼»ˉíaéèTIM3 OC3 TIM_OC3PreloadConfig(TIM3, TIM_OCPreload_Enable); //ê1ÄüTIM3ÔúCCR2éÏμÄԤװÔؼÄ′æÆ÷ TIM_Cmd(TIM3, ENABLE); //ê1ÄüTIM3 if(state == 1) //Æe { for(;i>130;i--) { TIM_SetCompare3(TIM3,i); delay_ms(30); } } else { for(;i<190;i++) { TIM_SetCompare3(TIM3,i); delay_ms(30); } } } int main(void) { RCC_Configuration(); delay_init(); uart_init(115200); TIM3_PWM3_Init2(1);//二号舵机 delay_ms(1000); TIM3_PWM4_Init3(1);//一号舵机 while(1); } |
|
相关推荐
4个回答
|
|
|
|
|
|
看波形分析问题。
|
|
|
|
666656666
|
|
|
|
很有可能是输出电流不够 ,舵机的电流需要比较大
|
|
|
|
只有小组成员才能发言,加入小组>>
请问下图大疆lightbridge2遥控器主板电源芯片型号是什么?
4481 浏览 1 评论
使用常见的二极管、三极管和mos做MCU和模组的电平转换电路,但是模组和MCU无法正常通信,为什么?
352浏览 2评论
为了提高USIM卡电路的可靠性和稳定性,在电路设计中须注意的点有哪些?
359浏览 2评论
381浏览 2评论
376浏览 2评论
435浏览 2评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-29 05:26 , Processed in 1.024423 second(s), Total 88, Slave 70 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号