求助:如何在停止pwm后,置输出为0

2019-07-21 07:09发布

求助:如何在停止pwm后,置输出为0 原子哥,我有一个问题,我想在用停止pwm以后,想置输出电平为0,即pwm=0%. 但是在我的程序中,停止pwm以后,输出电平时而为0,时而为1,即pwm=0%pwm=100%. 请问如果解决呢? 谢谢   我的程序如下,用的是STM32F105中的PA2作为PWMTIM5_Ch3)的输出脚 /******初始化程序,这里和原子哥的程序基本一致PWM_Init(900,0);          ******/   void Scrubber_PWW_Init(u16 arr,u16 psc) {                                                                                                                               RCC->APB1ENR|=1<<3;       // enable TIM5 clock                                GPIOA->CRL&=0XFFFFF0FF;//PA2 output               GPIOA->CRL|=0X00000B00;//alternater function push-pull 50Mhz                         GPIOA->ODR|=1<<2; //PA2        pull up                 TIM5->ARR=arr; // set auto-Reload Register                TIM5->SC=psc;//          PWM_Init(900,0);          //non prescaler, PWM frequency=72000KHz/900=80Khz                               TIM5->CCMR2|=7<<4;  //CH3 mode PWM CCMR2 bit6:4(commence à bit12) OC3M[2:0]=111;                             TIM5->CCMR2|=1<<3; //channel 3 Output Compare   preload enable              OC3PE               TIM5->CCER|=1<<8;  //channel 3 Capture/Compare  output enable    CC3E               TIM5->CR1=0x0080;   //enalbe ARPE     Auto-reload preload enable               TIM5->CR1|=0x01;    //enable Time5                                                                                                                       }                 /******如果收到信息sMessTexte 的第8(sMessTexte[8])0:停止计数器Tim5 如果sMessTexte 的第8(sMessTexte[8])1:置Pwm=20%,开计数器Tim5 如果sMessTexte 的第8(sMessTexte[8])2:置Pwm=40%,开计数器Tim5******/   void scrubber(u8* sMessTexte)               {                             switch(sMessTexte[8])                                            {                                                          case '0':                                                                                                    TIM5->CR1&=0x00;    //disable Time5                                                                                                    break;                                                          case '1':                                                                                                    SCRUBBER_PWM=40; //Pwm=20%                                                                                                         TIM5->CR1|=0x01;    //enable Time5                                                                                                    break;                                                          case '2':                                                                                                    SCRUBBER_PWM=80;//20%                                                                                                    TIM5->CR1|=0x01;    //enable Time5                                                                                                    break;                                                                                                     }                             }          谢谢大家帮助!!  
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。