cancel
Showing results for 
Search instead for 
Did you mean: 

Advanced Timers not working in PWM in all channels.

anthony239955
Associate II
Posted on August 01, 2014 at 02:25

Greetings,

I'm attempting to use stm32cubemx to configure the timers of a stm32f427ig to control a few rgb leds as open-drain, pwm outputs.  I'm using timers 1,3,4,5, and 8.  All of them are using channels 1 thru 3, except timers 1 and 3, which are using a 4th channel attached to a single-color auxiliary LED.

The ''regular'' timers are working as-expected.  However, the advanced timers, 1 and 8 aren't putting a signal out on their configured pins. So far, I've only gotten Ch 4 working on timer 1.  Channels 1-3 on timers 1 and 8 simply aren't working, even through their configuration is identical to that of Ch 4 on Tim1.

(As an added-bonus, STM32CubeMX seems to hang/crash often while generating code. Often losing custom code sections in main.c)

I'm starting the PWM units after initialization using the following commands:

HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_1);

HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_2);

HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_3);

HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_4);

HAL_TIM_PWM_Start(&htim4, TIM_CHANNEL_1);

HAL_TIM_PWM_Start(&htim4, TIM_CHANNEL_2);

HAL_TIM_PWM_Start(&htim4, TIM_CHANNEL_3);

HAL_TIM_PWM_Start(&htim5, TIM_CHANNEL_1);

HAL_TIM_PWM_Start(&htim5, TIM_CHANNEL_2);

HAL_TIM_PWM_Start(&htim5, TIM_CHANNEL_3);

HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_1);

HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_2);

HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_3);

HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_4);

HAL_TIM_PWM_Start(&htim8, TIM_CHANNEL_1);

HAL_TIM_PWM_Start(&htim8, TIM_CHANNEL_2);

HAL_TIM_PWM_Start(&htim8, TIM_CHANNEL_3);

I've attached the .ioc used.  Any advice as to why the advanced timers aren't working as expected would be appreciated. 🙂

3 REPLIES 3
Posted on August 01, 2014 at 03:04

Any advice as to why the advanced timers aren't working as expected would be appreciated.

Probably a broken code generator, or other bug. TIM1 and TIM8 would need to have PWM Output enabled explicitly.

In the old firmware library TIM_CtrlPWMOutputs(TIM1, ENABLE);

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
anthony239955
Associate II
Posted on August 01, 2014 at 11:23

The outputs get enabled as part of of the HAL_TIM_PWM_Start().  But, I think I've (mostly) figured it out...

The one thing channel 4 doesn't have in common with the others is that it has no complimentary output.  It would seem that the TIM_CR2_CCPC bit is on by default.  (In effect, a feature apparently meant for hall-sensors is holding channels 1-3 in an off state.)  Disabling the feature with:

  htim1.Instance->CR2 &= ~(TIM_CR2_CCPC);

  htim8.Instance->CR2 &= ~(TIM_CR2_CCPC);

makes the timers behave as-expected.  Why that bit is enabled by default, I do not know. This is probably more of a HAL driver issue than an STM32CubeMX issue.

 

stm32cube-t
Senior III
Posted on September 16, 2014 at 11:40

Hello,

There is an issue with current STM32CubeMX 4.3.1 and earlier versions. This will be fixed in next release.

As a workaround, please add the following code highlighted in red below to ensure that optional fields are initialized as well.

sConfigOC.OCMode = TIM_OCMODE_PWM1;

 

sConfigOC.Pulse = 0; 

sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;

 

sConfigOC.OCNPolarity = TIM_OCNPOLARITY_HIGH;

 

sConfigOC.OCFastMode = TIM_OCFAST_DISABLE; 

sConfigOC.OCIdleState = TIM_OCIDLESTATE_RESET;

 

sConfigOC.OCNIdleState = TIM_OCNIDLESTATE_RESET;

 

HAL_TIM_PWM_ConfigChannel(&htim1, &sConfigOC, TIM_CHANNEL_1);

Best Regards