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?
PWM use negative channels Topic is solved
Moderators: RoccoMarco, barthess
- 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
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
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
Thank you Giovanni!
I thought driver can do it and I'm missing something.
So do I need to do something like this:
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;
- 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
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:
I think it is what you need, if so then no need to touch registers.
Giovanni
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
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
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
Is there any possibilities to shift the phase of Ch2 and Ch3 at 120 Degree with the configuration "STM32_PWM_USE_ADVANCED" ?
Thanks.
Thanks.
- 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
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
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
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.
- 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
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
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
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.
Who is online
Users browsing this forum: No registered users and 41 guests