各个大哥好,stm8s003的tim1一直发不了脉冲,程序如下: void TIM1_init(void) { TIM1_DeInit(); TIM1_TimeBaseInit(0,TIM1_COUNTERMODE_UP,200,0); // TIM1_CCxCmd(TIM1_CHANNEL_1, ENABLE); TIM1_OC1Init(TIM1_OCMODE_PWM2, TIM1_OUTPUTSTATE_DISABLE, TIM1_OUTPUTNSTATE_DISABLE, 100, TIM1_OCPOLARITY_HIGH, TIM1_OCNPOLARITY_HIGH, TIM1_OCIDLESTATE_RESET, TIM1_OCNIDLESTATE_SET); TIM1_ARRPreloadConfig(ENABLE); TIM1_OC1PreloadConfig(ENABLE); TIM1_CtrlPWMOutputs(ENABLE); TIM1_Cmd(ENABLE); } 请问有哪里需要改动的,另外,直接写寄存器的也不行 void TIM1_init(void) { TIM1->PSCRH=0;//分频系数为0,定时器时钟为8M/(1+0)=8M TIM1->PSCRL=0; TIM1->ARRH=0x00; TIM1->ARRL=0xC8;//频率调为40k TIM1->CCMR1 =0x78;//通道1配置成比较输出模式,PWM2模式 // TIM1->CCER1 |=0x03;//开启通道1引脚,低电平有效 TIM1->CCER1=0x03; //初始化CCR1,占空比为50%; TIM1->CCR1H=0x00; TIM1->CCR1L=0x64; TIM1->RCR|=0x01; TIM1->EGR=0x01; // TIM1->CNTRH=0; // TIM1->CNTRL=0; TIM1->BKR =0x80; TIM1->CR1 =0x01;//启动定时器1 } 谢谢! |
哦,已解决,这里disable写错了。下面寄存器的程序可以用,只是stm8s003 用tim1的pwm得写选项字。谢谢了!
用tim1的pwm得写选项字
用tim1的pwm得写选项字