PWM use negative channels Topic is solved

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

Moderators: RoccoMarco, barthess

User avatar
HDKLog
Posts: 41
Joined: Thu Aug 18, 2016 12:36 am
Been thanked: 2 times

PWM use negative channels

Postby HDKLog » Sun Jan 22, 2017 4:29 pm

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?

User avatar
Giovanni
Site Admin
Posts: 14457
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1076 times
Been thanked: 922 times
Contact:

Re: PWM use negative channels

Postby Giovanni » Sun Jan 22, 2017 7:34 pm

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

User avatar
HDKLog
Posts: 41
Joined: Thu Aug 18, 2016 12:36 am
Been thanked: 2 times

Re: PWM use negative channels

Postby HDKLog » Sun Jan 22, 2017 9:09 pm

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;

User avatar
Giovanni
Site Admin
Posts: 14457
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1076 times
Been thanked: 922 times
Contact:

Re: PWM use negative channels  Topic is solved

Postby Giovanni » Sun Jan 22, 2017 9:28 pm

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

User avatar
HDKLog
Posts: 41
Joined: Thu Aug 18, 2016 12:36 am
Been thanked: 2 times

Re: PWM use negative channels

Postby HDKLog » Sun Jan 22, 2017 10:01 pm

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

chrystal
Posts: 7
Joined: Sat Jan 28, 2017 3:52 pm

Re: PWM use negative channels

Postby chrystal » Tue Jan 31, 2017 1:50 pm

Is there any possibilities to shift the phase of Ch2 and Ch3 at 120 Degree with the configuration "STM32_PWM_USE_ADVANCED" ?

Thanks.

User avatar
Giovanni
Site Admin
Posts: 14457
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1076 times
Been thanked: 922 times
Contact:

Re: PWM use negative channels

Postby Giovanni » Tue Jan 31, 2017 3:32 pm

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

chrystal
Posts: 7
Joined: Sat Jan 28, 2017 3:52 pm

Re: PWM use negative channels

Postby chrystal » Tue Jan 31, 2017 5:15 pm

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. :(

User avatar
Giovanni
Site Admin
Posts: 14457
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1076 times
Been thanked: 922 times
Contact:

Re: PWM use negative channels

Postby Giovanni » Tue Jan 31, 2017 5:20 pm

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

rew
Posts: 380
Joined: Sat Jul 19, 2014 12:59 pm
Has thanked: 2 times
Been thanked: 13 times

Re: PWM use negative channels

Postby rew » Sun Feb 19, 2017 12:49 pm

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.


Return to “STM32 Support”

Who is online

Users browsing this forum: No registered users and 41 guests