2014-03-12 04:05 AM
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 ?
2014-03-12 04:47 AM
Hi
Thw PWM level is controlled by three registers : TIMx_CNT - the counter register TIMx_CCMRx - the threshold for the PWM TIMx_ARR - the PWM period (value at which count is going to be reset) You can control the output level by setting the TIMx_CNT relative to the TIMx_CCMRx register.2014-03-12 06:33 PM
2014-03-13 03:05 AM
Hi
''Can you elaborate on TIMx_CNT relative to the TIMx_CCMRx register.'' If the TIMx_CNT is less than TIMx_CCMRx then the output is inactive. If the TIMx_CNT is greaterthan TIMx_CCMRx then the output is active. ''inactive'' and ''active'' are further modified by ''CCxP'' bit in TIMx_CCER register. This sets the polarity as 'active high' or 'active low' ''Can you provide an example ?'' All you have to do is to 1) stop the timer (stops the count incrementing/decrementing) 2) write to TIMx_CNT register with value ( less/greater than depending on what you want the output to be)2014-03-16 06:58 PM
TIM_Cmd(TIM3, DISABLE);
TIM3->CNT = 0x0;
However , it stills output at high after the disabling .
Did i missed a step ?
2014-03-17 05:14 AM
''However , it stills output at high after the disabling .''
TryTIM3->CNT =
TIM3->CCMRx + 1;
2015-07-22 01:09 AM
Thank you for your answer, I have tried your code and I can disable my PWM.