问答

汇集网友智慧,解决技术难题

shilut

TA的家园币:924  

  • 使用三个定时器输出PWM卡死

    请教各位大牛一个问题,卡住我几天了。我使用如下定时器配置PWM,如下示:PA6->PWM0tim1_cha(4)PA7->PWM1tim2_cha(5)PB0->PWM2tim3_ch1b(2)在应行如下初始化代码后,直接卡死了,请问是什么原因呢voidpwm_init(){Sysctrl_SetPeripheralGate(SysctrlPeripheralGpio,TRUE);//端口外设时钟使能TimerPortCfg(PWM0);TimerPortCfg(PWM1);TimerPortCfg(PWM2);Timer1Cfg(100,PWM_DUTY);Bt_M23_EnPWM_Output(TIM1,TRUE,FALSE);//端口输出使能Timer2Cfg(100,PWM_DUTY);Bt_M23_EnPWM_Output(TIM2,TRUE,FALSE);//端口输出使能Timer3Cfg(100,PWM_DUTY);Tim3_M23_EnPWM_Output(TRUE,FALSE);//端口输出使能Bt_M23_Run(TIM2);//运行。Bt_M23_Run(TIM1);//运行。Tim3_M23_Run();//运行。}完整模块代码发下:#include"pwm.h"#include"timer3.h"#include"bt.h"#include"gpio.h"#include"motor.h"volatilecharpwm_duty=95;//PA6->PWM0tim1_cha(4)//PA7->PWM1tim2_cha(5)或tim3_ch0b(4)//PB0->PWM2tim3_ch1b(2)typedefenum{PWM0=0u,PWM1,PWM2,}pwm_index_t;/********************************************************************************中断服务函数******************************************************************************/voidTim1_IRQHandler(void){//Timer1模式23更新中断if(TRUE==Bt_GetIntFlag(TIM1,BtUevIrq)){Bt_M23_CCR_Set(TIM1,BtCCR0A,100-pwm_duty);//设置通道A比较值Bt_ClearIntFlag(TIM1,BtUevIrq);//清中断标志}}voidTim2_IRQHandler(void){//Timer2模式23更新中断if(TRUE==Bt_GetIntFlag(TIM2,BtUevIrq)){Bt_M23_CCR_Set(TIM2,BtCCR0A,100-pwm_duty);//设置通道A比较值Bt_ClearIntFlag(TIM2,BtUevIrq);//清中断标志}}voidTim3_IRQHandler(void){//Timer3模式23更新中断if(TRUE==Tim3_GetIntFlag(Tim3UevIrq)){Tim3_M23_CCR_Set(Tim3CCR1B,100-pwm_duty);//设置CH1通道B比较值Tim3_ClearIntFlag(Tim3UevIrq);/

  • 使用两个定时器输出PWM卡死

    请教各位大牛一个问题,卡住我几天了。我使用如下定时器配置PWM,如下示:PA6->PWM0tim1_cha(4)PA7->PWM1tim2_cha(5)PB0->PWM2tim3_ch1b(2)在应行如下初始化代码后,直接卡死了,请问是什么原因呢voidpwm_init(){Sysctrl_SetPeripheralGate(SysctrlPeripheralGpio,TRUE);//端口外设时钟使能TimerPortCfg(PWM0);TimerPortCfg(PWM1);TimerPortCfg(PWM2);Timer1Cfg(100,PWM_DUTY);Bt_M23_EnPWM_Output(TIM1,TRUE,FALSE);//端口输出使能Timer2Cfg(100,PWM_DUTY);Bt_M23_EnPWM_Output(TIM2,TRUE,FALSE);//端口输出使能Timer3Cfg(100,PWM_DUTY);Tim3_M23_EnPWM_Output(TRUE,FALSE);//端口输出使能Bt_M23_Run(TIM2);//运行。Bt_M23_Run(TIM1);//运行。Tim3_M23_Run();//运行。}完整模块代码发下:#include"pwm.h"#include"timer3.h"#include"bt.h"#include"gpio.h"#include"motor.h"volatilecharpwm_duty=95;//PA6->PWM0tim1_cha(4)//PA7->PWM1tim2_cha(5)或tim3_ch0b(4)//PB0->PWM2tim3_ch1b(2)typedefenum{PWM0=0u,PWM1,PWM2,}pwm_index_t;/********************************************************************************中断服务函数******************************************************************************/voidTim1_IRQHandler(void){//Timer1模式23更新中断if(TRUE==Bt_GetIntFlag(TIM1,BtUevIrq)){Bt_M23_CCR_Set(TIM1,BtCCR0A,100-pwm_duty);//设置通道A比较值Bt_ClearIntFlag(TIM1,BtUevIrq);//清中断标志}}voidTim2_IRQHandler(void){//Timer2模式23更新中断if(TRUE==Bt_GetIntFlag(TIM2,BtUevIrq)){Bt_M23_CCR_Set(TIM2,BtCCR0A,100-pwm_duty);//设置通道A比较值Bt_ClearIntFlag(TIM2,BtUevIrq);//清中断标志}}voidTim3_IRQHandler(void){//Timer3模式23更新中断if(TRUE==Tim3_GetIntFlag(Tim3UevIrq)){Tim3_M23_CCR_Set(Tim3CCR1B,100-pwm_duty);//设置CH1通道B比较值Tim3_ClearIntFlag(Tim3UevIrq);/