AnsweredAssumed Answered

Disabling PWM at logic high

Question asked by asl.sean on Mar 12, 2014
Latest reply on Jul 22, 2015 by duc.le
Hi , 

I am trying to disable my PWM with the pin at LOW when disabled however it seems to be always at HIGH.

RCC_APB1PeriphClockCmd(TIM3, ENABLE);
 
TIM_TimeBaseInitTypeDef  TIM_TimeBaseStructure;
TIM_OCInitTypeDef  TIM_OCInitStructure;
 
 
uint16_t PrescalerValue = (uint16_t) ((SystemCoreClock /2) / 10000) - 1;
 
    /* Time base configuration */
TIM_TimeBaseStructure.TIM_Period = laser_timer_count - 1;
TIM_TimeBaseStructure.TIM_Prescaler = PrescalerValue;
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
 
TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);
 
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_Pulse = 200;
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
 
TIM_OC1Init(TIM3, &TIM_OCInitStructure);
 
TIM_OC1PreloadConfig(TIM3, TIM_OCPreload_Enable);
 
TIM_ARRPreloadConfig(TIM3, ENABLE);
 
/* TIM3 enable counter */
TIM_Cmd(TIM3, DISABLE);


It seems that , it requires a delay between setting CCR to 0 and disabling the clock as follows :
TIM3->CCR1 = 0;
int x = 0;
for(x = 0 ; x < 499 ; x++);
TIM_Cmd(TIM3, DISABLE);

Without the delay the PWM will be stopped at HIGH.

May i know why is the delay necessary ?

Outcomes