STM32L4xx PWM Combined Mode

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderator: RoccoMarco

Post Reply
choowf
Posts: 9
Joined: Tue Oct 10, 2017 8:31 am
Has thanked: 3 times
Been thanked: 3 times

STM32L4xx PWM Combined Mode

Post by choowf »

Hi,

I need to generate 5-6 PWM output (all synchronized with each other) with a STM32L476 and some of these PWMs are run time adjustable on their frequency, duty cycle and phase shift.

To achieve this, i need to utilize the master and slave timer mode (one timer to trigger start the other timer) and also the combined pwm output (combined two PWM output) to get the duty cycle and phase shift change done. For these i need to set some of the registers (CCMR1, CCMR2, SMCR, CR1) that not available in the hal_pwm_lld.h PWMConfig structure.

Currently, I'm modifying the PWMConfig structure for me to pass in those registers value and set them in pwm_lld_start(). Also put some flags to enable/disable the changes so it doesn't affect the legacy pwm lld hal.

I'm not sure if this the best way to do it, would like to hear your opinions. Thanks.
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: STM32L4xx PWM Combined Mode

Post by Giovanni »

Hi,

I think you need a custom driver for this. You may reuse parts of the existing driver but it is not designed for such a scenario.

Giovanni
faisal
Posts: 382
Joined: Wed Jul 19, 2017 12:44 am
Has thanked: 45 times
Been thanked: 62 times

Re: STM32L4xx PWM Combined Mode

Post by faisal »

Giovanni wrote:Hi,

I think you need a custom driver for this. You may reuse parts of the existing driver but it is not designed for such a scenario.

Giovanni


If he can modify the stm32L4xx low level driver in such a way that doesn't require upper level hal_pwm changes, wouldn't that be okay? You would just be adding to the configuration structure in lld some custom registers. Could that be included in ChibiOS? Having chained/linked timers is a useful feature .. Something similar is essentially done with stm32 can filters.
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: STM32L4xx PWM Combined Mode

Post by Giovanni »

He can also change the high level if he wishes so, the Apache license is permissive.

Giovanni
faisal
Posts: 382
Joined: Wed Jul 19, 2017 12:44 am
Has thanked: 45 times
Been thanked: 62 times

Re: STM32L4xx PWM Combined Mode

Post by faisal »

Giovanni wrote:He can also change the high level if he wishes so, the Apache license is permissive.

Giovanni


I wss thinking more along the lines off getting it included in the official trunk.
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: STM32L4xx PWM Combined Mode

Post by Giovanni »

Not likely, I am striving for stability more than completeness, this kind of changes are a nightmare for testing and support.

At most it could go in the community repository, which is unmaintained by definition.

Giovanni
rew
Posts: 383
Joined: Sat Jul 19, 2014 12:59 pm
Has thanked: 2 times
Been thanked: 14 times

Re: STM32L4xx PWM Combined Mode

Post by rew »

FYI, in such cases I have started the PWM driver the normal way in my application and then I tweak the hardware registers to my liking.
Post Reply