Page 1 of 1

STM32L4xx PWM Combined Mode

Posted: Wed Oct 11, 2017 1:23 am
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.

Re: STM32L4xx PWM Combined Mode

Posted: Wed Oct 11, 2017 8:48 am
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

Re: STM32L4xx PWM Combined Mode

Posted: Wed Oct 11, 2017 1:33 pm
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.

Re: STM32L4xx PWM Combined Mode

Posted: Wed Oct 11, 2017 2:32 pm
by Giovanni
He can also change the high level if he wishes so, the Apache license is permissive.

Giovanni

Re: STM32L4xx PWM Combined Mode

Posted: Wed Oct 11, 2017 2:59 pm
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.

Re: STM32L4xx PWM Combined Mode

Posted: Wed Oct 11, 2017 3:08 pm
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

Re: STM32L4xx PWM Combined Mode

Posted: Sun Nov 05, 2017 8:18 am
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.