Skip to main content
Alexmouse
Associate III
May 28, 2019
Solved

PWM output on Timer3 Ch1

  • May 28, 2019
  • 11 replies
  • 6677 views

I've my LCD backlight control on STM32F429 pin PB4, and as a digital output it was fine. I chose this pin because it can be configured as a PWM output.

I've set up TIM3 Ch1 in CubeMX. I just want a free-running PWM with a dynamically configurable duty cycle, so I can set my backlight to 'bright', 'medium' or 'dim' settings.

I'm getting no signal on PB4, it is just sitting high.

Did I miss something? Is there an 'enable' or 'start' instruction I need to add?

This topic has been closed for replies.
Best answer by Alexmouse

OK, I now have PWM on PB4, thanks to Uncle Google and this page

https://electronics.stackexchange.com/questions/179546/getting-pwm-to-work-on-stm32f4-using-sts-hal-libraries

I needed to add

 HAL_TIM_Base_Start(&htim3);

 HAL_TIM_PWM_Start(&htim3,TIM_CHANNEL_1);

Microchip's Code Configurator tool gives you a header listing all the functions to initialise, start, stop and control your configured peripheral, why can't CubeMX be as helpful?

11 replies

S.Ma
Principal
May 28, 2019

Activate the gpio alternate function, configure the timer channel and activate the channel in the timer. Go debug mode, view gpio and timer registers, manually inspect and tweak until things get better, then fix the sw. LED dimming is similar. Remember that yout eye perceive the log so don t do a linear duty cycle.... You will need more steps than you think....

Alexmouse
AlexmouseAuthor
Associate III
May 28, 2019

The pin is set to the alternate function, timer output. I'd assumed CubeMX would set things up ready to roll.

I've driven the backlight from a sig generator so have a good idea of requirements.​

waclawek.jan
Super User
May 28, 2019

Read out and check/post content of timer and relevant GPIO registers.

JW

Alexmouse
AlexmouseAuthor
Associate III
May 29, 2019

..

Alexmouse
AlexmouseAuthor
Associate III
May 29, 2019

..

Alexmouse
AlexmouseAuthor
Associate III
May 29, 2019

If this were a PIC micro, I'd go through the registers bit by bit, but here there are too many and descriptions are cryptic. In any case, isn't that why I'm using CubeMX?

Alexmouse
AlexmouseAuthor
Associate III
May 29, 2019

OK, I've manually the TIM3_CR1 "CEN" bit, and now I can see the CNT register incrementing between breakpoiints. Still no activity on the PB4 pin assigned to TIM3 Ch1.

Alexmouse
AlexmouseAuthor
Associate III
May 29, 2019

How do I find the AFIO_MAPR register in the debug SFR listing, so I can check the alternate function mapping?

Alexmouse
AlexmouseAuthorBest answer
Associate III
May 29, 2019

OK, I now have PWM on PB4, thanks to Uncle Google and this page

https://electronics.stackexchange.com/questions/179546/getting-pwm-to-work-on-stm32f4-using-sts-hal-libraries

I needed to add

 HAL_TIM_Base_Start(&htim3);

 HAL_TIM_PWM_Start(&htim3,TIM_CHANNEL_1);

Microchip's Code Configurator tool gives you a header listing all the functions to initialise, start, stop and control your configured peripheral, why can't CubeMX be as helpful?

Alexmouse
AlexmouseAuthor
Associate III
May 29, 2019

How do I flag this thread as "answered"?

Amel NASRI
ST Technical Moderator
May 30, 2019

Click on "Select as Best" on the comment that you consider the more helpful one.

To give better visibility on the answered topics, please click on "Best Answer" on the reply which solved your issue or answered your question.