cancel
Showing results for 
Search instead for 
Did you mean: 

PWM output on Timer3 Ch1

Alexmouse
Senior

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?

1 ACCEPTED SOLUTION

Accepted Solutions
Alexmouse
Senior

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?

View solution in original post

11 REPLIES 11
S.Ma
Principal

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
Senior

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.​

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

JW

Alexmouse
Senior
 
Alexmouse
Senior
 
Alexmouse
Senior

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
Senior

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
Senior

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

Alexmouse
Senior

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?