cancel
Showing results for 
Search instead for 
Did you mean: 

Disabling PWM at logic high

blue_dolphin1987
Associate II
Posted on March 12, 2014 at 12:05

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 ?
6 REPLIES 6
chen
Associate II
Posted on March 12, 2014 at 12:47

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.

blue_dolphin1987
Associate II
Posted on March 13, 2014 at 02:33

Hi sung,

Can you elaborate on  TIMx_CNT relative to the TIMx_CCMRx register.

Can you provide an example ?

Thanks

chen
Associate II
Posted on March 13, 2014 at 11:05

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)

blue_dolphin1987
Associate II
Posted on March 17, 2014 at 02:58 Hi Sung , From your suggestion i tried the following

TIM_Cmd(TIM3, DISABLE);
TIM3->CNT = 0x0;

However , it stills output at high after the disabling . Did i missed a step ?
chen
Associate II
Posted on March 17, 2014 at 13:14

''However , it stills output at high after the disabling .''

Try

TIM3->CNT =

TIM3->CCMRx + 1;
dark_killer_1796
Associate II
Posted on July 22, 2015 at 10:09

Thank you for your answer, I have tried your code and I can disable my PWM.