Page 1 of 1
PWM use negative channels
Posted: Sun Jan 22, 2017 4:29 pm
by HDKLog
Hello !
I want to drive BLDC motor, which require 3 positive and 3 negative PWMs to driving 6 mosfets (3 High side and 3 Low side). I saw example of PWM with ICU on stm32f4xx and already have read documentation of ChibisOS but cant figure out how to use positive and negative channels together. How I can accomplish this?
for exemple If I want to use A8, A9, A10 with their negative channels B13, B14, B15 with Timer1 how should I configure driver1?
Re: PWM use negative channels
Posted: Sun Jan 22, 2017 7:34 pm
by Giovanni
Hi,
You need to use TIM1 or TIM8 for this, note that in the PWMConfig structure there are some fields that have the same name of TIM registers, look into the STM32 Reference Manual how to enable negative channels in those registers, the driver does nothing except initialize the timer and handle interrupts.
Giovanni
Re: PWM use negative channels
Posted: Sun Jan 22, 2017 9:09 pm
by HDKLog
Thank you Giovanni!
I thought driver can do it and I'm missing something.
So do I need to do something like this:
Code: Select all
pwmStart(&PWMD1, &pwmPcfg);
PWMD1.tim->CCER |= TIM_OutputNState_Enable | TIM_OCNPolarity_High;
PWMD1.tim->CR2 |= TIM_OCNIdleState_Set;
Re: PWM use negative channels
Posted: Sun Jan 22, 2017 9:28 pm
by Giovanni
Hi,
I forgot that the driver received enhancements for this.
See the file pwm_lld.h, there are the following macros to be ORed to the PWM mode field:
Code: Select all
/**
* @brief Complementary output, active is logic level one.
* @note This is an STM32-specific setting.
* @note This setting is only available if the configuration option
* @p STM32_PWM_USE_ADVANCED is set to TRUE and only for advanced
* timers TIM1 and TIM8.
*/
#define PWM_COMPLEMENTARY_OUTPUT_ACTIVE_HIGH 0x10
/**
* @brief Complementary output, active is logic level zero.
* @note This is an STM32-specific setting.
* @note This setting is only available if the configuration option
* @p STM32_PWM_USE_ADVANCED is set to TRUE and only for advanced
* timers TIM1 and TIM8.
*/
#define PWM_COMPLEMENTARY_OUTPUT_ACTIVE_LOW 0x20
I think it is what you need, if so then no need to touch registers.
Giovanni
Re: PWM use negative channels
Posted: Sun Jan 22, 2017 10:01 pm
by HDKLog
Thank you for great support Giovanni!!
You saved me from few hours of reading manual.
I set STM32_PWM_USE_ADVANCED TRUE in mcuconf.h to able to use PWM_COMPLEMENTARY_OUTPUT_ACTIVE_HIGH.
and yes that is sufficient for my project as I need only positive and negative outputs from channels, synchronised with TIM1
Re: PWM use negative channels
Posted: Tue Jan 31, 2017 1:50 pm
by chrystal
Is there any possibilities to shift the phase of Ch2 and Ch3 at 120 Degree with the configuration "STM32_PWM_USE_ADVANCED" ?
Thanks.
Re: PWM use negative channels
Posted: Tue Jan 31, 2017 3:32 pm
by Giovanni
Hi,
Would that be the "Combined 3-phase PWM mode" described in the reference manual? the PWM driver is not designed to use that mode.
Giovanni
Re: PWM use negative channels
Posted: Tue Jan 31, 2017 5:15 pm
by chrystal
Giovanni wrote:Hi,
Would that be the "Combined 3-phase PWM mode" described in the reference manual? the PWM driver is not designed to use that mode.
Giovanni
Yes, I would like to control a BLDC Motor. My generated 3 PWMs are not 120 phase shifted.

Re: PWM use negative channels
Posted: Tue Jan 31, 2017 5:20 pm
by Giovanni
It is an interesting use case but I cannot guarantee an implementation in any reasonable time, there are way too many things waiting in queue.
You may consider accessing the timer at register level and implement your driver, it is not forbidden by the general architecture.
Giovanni
Re: PWM use negative channels
Posted: Sun Feb 19, 2017 12:49 pm
by rew
chrystal wrote:Yes, I would like to control a BLDC Motor. My generated 3 PWMs are not 120 phase shifted.

Why would you want to have the PWM signals 120 degrees phase shifted? It sounds as if you think that running the timer will cause the motor to spin? This is not the way things work. If you manged to get that to work, you would always be running at the maximum possible current for the motor, even when that is not necessary for the current load on the motor. Similarly you're always running at the maximum possible voltage, which is only required at the maximum RPM for the voltage of your power supply system.