cancel
Showing results for 
Search instead for 
Did you mean: 

Final State of PWM

blue_dolphin1987
Associate II
Posted on February 04, 2013 at 10:17

Hi ,

I am trying to drive a LED Driver IC with a PWM signal on button press. However , it seems that at the end of a PWM cycle the LED final state is not determinable (maybe on/off). It seem that it is dependent of the final state of the pulse. Is is possible to ensure a low state at the end of a pwm cycle ? I am using stm32f4 and mic4812 My code is as follows,

RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM12, ENABLE);
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOH, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN;
GPIO_Init(GPIOH, &GPIO_InitStructure);
GPIO_PinAFConfig(GPIOH, GPIO_PinSource9, GPIO_AF_TIM12);
PrescalerValue = (uint16_t)((SystemCoreClock) / 100000) - 1;
/* Time base configuration */
TIM_TimeBaseStructure.TIM_Period = 49;
TIM_TimeBaseStructure.TIM_Prescaler = PrescalerValue;
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM12, &TIM_TimeBaseStructure);
/* PWM2 Mode configuration: Channel2 */
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_Pulse = CCR1_Val;
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low;
TIM_OC2Init(TIM12, &TIM_OCInitStructure);
TIM_OC2PreloadConfig(TIM12, TIM_OCPreload_Enable);
TIM_ARRPreloadConfig(TIM12, ENABLE);

Thank you.
4 REPLIES 4
Posted on February 04, 2013 at 13:14

Is is possible to ensure a low state at the end of a pwm cycle ?

Yes, do you just stop it randomly, or is there some method to it now? Have you tried TIM12->CCR1 = 0 during the Update interrupt?

Tip : If you're complaining about stopping something don't just show the code that starts it.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
jj2
Associate II
Posted on February 04, 2013 at 16:48

Clive1: ''Tip : If you're complaining about stopping something don't just show the code that starts it.''

Absolutely classic!  Posters so into their discomfort - fail to consider that which is necessary to, ''enhance their rescue...''

Posted on February 04, 2013 at 17:30

It's Monday morning, and I'm feeling punchy...

Probably would be TIM12->CCR2, missed the CH2 thing with the undefined value for CCR1_Val

It's important to provide a relatively complete context. If the brakes don't work a picture of the accelerator pedal or fuel gauge aren't helpful.
Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
blue_dolphin1987
Associate II
Posted on February 05, 2013 at 02:24

Hi Clive , 

I used  TIM_Cmd(TIM12, DISABLE); to simply disable the LED. Or is that a better way ?

Your solution works perfectly . Thank you for your help.