Hello,
I am currently trying to generate triphased PWM on a STM32 using Timer 1. I sucessfully generated the signals on the positive outputs. Now I'm trying to find out if the complementary output feature is implemented in ChibiOS. I've been searching for some time now and I can't seem to find it. Can someone help me out?
Thanks,
Olivier
STM32: Timer 1 PWM complementary outputs
Moderators: RoccoMarco, lbednarz, tfAteba
- Giovanni
- Site Admin
- Posts: 14891
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 996 times
Re: STM32: Timer 1 PWM complementary outputs
Hi,
It is supported in 2.3.3 but not in the stable branch 2.2.x.
You have to activate the option STM32_PWM_USE_ADVANCED in mcuconf.h and then configure the output mode using the extra modes:
PWM_COMPLEMENTARY_OUTPUT_DISABLED
PWM_COMPLEMENTARY_OUTPUT_ACTIVE_HIGH
PWM_COMPLEMENTARY_OUTPUT_ACTIVE_LOW
Please see the online documentation of the PWM driver for details. The code is new, please report any problem you may find.
Giovanni
It is supported in 2.3.3 but not in the stable branch 2.2.x.
You have to activate the option STM32_PWM_USE_ADVANCED in mcuconf.h and then configure the output mode using the extra modes:
PWM_COMPLEMENTARY_OUTPUT_DISABLED
PWM_COMPLEMENTARY_OUTPUT_ACTIVE_HIGH
PWM_COMPLEMENTARY_OUTPUT_ACTIVE_LOW
Please see the online documentation of the PWM driver for details. The code is new, please report any problem you may find.
Giovanni
Re: STM32: Timer 1 PWM complementary outputs
Well I was using the stable branch, sorry for that I never saw it in the documentation. I'll try it out!
Re: STM32: Timer 1 PWM complementary outputs
Okay I made the upgrade to the unstable branch. Unfortunately I won't have access to an oscilloscope for some time now, can you tell me if the syntax I used to configure the complementary output mode correct?
...
Code: Select all
static PWMConfig pwm1cfg = {
8000000, /* 8MHz PWM clock frequency. */
US2ST(20), /* PWM period 20us. */
NULL,
{
{PWM_OUTPUT_ACTIVE_HIGH | PWM_COMPLEMENTARY_OUTPUT_ACTIVE_LOW, NULL}, /* PWM4, CH1 */
{PWM_OUTPUT_ACTIVE_HIGH | PWM_COMPLEMENTARY_OUTPUT_ACTIVE_LOW, NULL}, /* PWM4, CH2 */
{PWM_OUTPUT_ACTIVE_HIGH | PWM_COMPLEMENTARY_OUTPUT_ACTIVE_LOW, NULL}, /* PWM4, CH3 */
{PWM_OUTPUT_DISABLED, NULL}
},
0,
0
};
...
Code: Select all
palSetPadMode(GPIOA, 8, PAL_MODE_STM32_ALTERNATE_PUSHPULL);
palSetPadMode(GPIOA, 9, PAL_MODE_STM32_ALTERNATE_PUSHPULL);
palSetPadMode(GPIOA, 10, PAL_MODE_STM32_ALTERNATE_PUSHPULL);
palSetPadMode(GPIOB, 13, PAL_MODE_STM32_ALTERNATE_PUSHPULL);
palSetPadMode(GPIOB, 14, PAL_MODE_STM32_ALTERNATE_PUSHPULL);
palSetPadMode(GPIOB, 15, PAL_MODE_STM32_ALTERNATE_PUSHPULL);
pwmStart(&PWMD1, &pwm1cfg);
pwmEnableChannel(&PWMD1, 0, PWM_PERCENTAGE_TO_WIDTH (&PWMD1, 1000));
pwmEnableChannel(&PWMD1, 1, PWM_PERCENTAGE_TO_WIDTH (&PWMD1, 7000));
pwmEnableChannel(&PWMD1, 2, PWM_PERCENTAGE_TO_WIDTH (&PWMD1, 7000));
- Giovanni
- Site Admin
- Posts: 14891
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 996 times
Re: STM32: Timer 1 PWM complementary outputs
I think it is correct but you will know for sure after trying.
Giovanni
Giovanni
Re: STM32: Timer 1 PWM complementary outputs
hi OlivierD
i am facing same kind of problem
did you get 3 phase out put?
am using chibios on STM32F4-Discovery board
trying to generate 3 phase using 6 PWM channel
but i can't get phase shift in each pair of CHx and CHxN (complementary)
if i configure 2 PWMConfig and put some delay in two respective pwmStart()
then i got phase shift between channels respected to 2 different PWMConfig
but don't understand how to get another phase shift . .
please help me . . .it's critical situation on my side . .
is it possible solution by change in TIMx_CCRx . ..
give me some idea phase shifting
i am facing same kind of problem
did you get 3 phase out put?
am using chibios on STM32F4-Discovery board
trying to generate 3 phase using 6 PWM channel
but i can't get phase shift in each pair of CHx and CHxN (complementary)
if i configure 2 PWMConfig and put some delay in two respective pwmStart()
then i got phase shift between channels respected to 2 different PWMConfig
but don't understand how to get another phase shift . .
please help me . . .it's critical situation on my side . .
Code: Select all
#include "ch.h"
#include "hal.h"
static PWMConfig pwmcfg1 = {
10000, // 10Khz PWM clock frequency
20000, // PWM period 1 second 200,* 50 Hz (20.0 ms) initial frequency
NULL, // No callback
{
{PWM_COMPLEMENTARY_OUTPUT_ACTIVE_LOW, NULL},
{PWM_COMPLEMENTARY_OUTPUT_ACTIVE_LOW, NULL},
{PWM_COMPLEMENTARY_OUTPUT_ACTIVE_LOW, NULL},
{PWM_OUTPUT_DISABLED, NULL},
},
0,
0
};
static PWMConfig pwmcfg2 = {
10000, /* 10Khz PWM clock frequency */
20000, /* PWM period 1 second */
NULL, /* No call back */
{
{PWM_OUTPUT_ACTIVE_HIGH, NULL},
{PWM_OUTPUT_ACTIVE_HIGH, NULL},
{PWM_OUTPUT_ACTIVE_HIGH, NULL},
{PWM_OUTPUT_DISABLED, NULL},
},
0,
0
};
int main(void)
{
halInit();
chSysInit();
/*for TIM1/2 PAL_MODE_ALTERNATE(n) = 1 */
palSetPadMode(GPIOE, 8, PAL_MODE_ALTERNATE(1));//TIM1, channel 1N
palSetPadMode(GPIOE, 10, PAL_MODE_ALTERNATE(1));//TIM1, channel 2N
palSetPadMode(GPIOE, 12, PAL_MODE_ALTERNATE(1));//TIM1, channel 3N
/* TIM8
* for TIM8/9/10/11 PAL_MODE_ALTERNATE(n) = 3 */
palSetPadMode(GPIOC, 6, PAL_MODE_ALTERNATE(3));//TIM8, channel 1
palSetPadMode(GPIOC, 7, PAL_MODE_ALTERNATE(3));//TIM8, channel 2
palSetPadMode(GPIOC, 8, PAL_MODE_ALTERNATE(3));//TIM8, channel 3
pwmStart(&PWMD1, &pwmcfg1);
pwmEnableChannel(&PWMD1, 0, 10000));
pwmEnableChannel(&PWMD1, 1, 10000);
pwmEnableChannel(&PWMD1, 2, 10000);
chThdSleepMilliseconds(500);
pwmStart(&PWMD8, &pwmcfg2);
pwmEnableChannel(&PWMD8, 0, 10000);
pwmEnableChannel(&PWMD8, 1, 10000);
pwmEnableChannel(&PWMD8, 2, 10000);
while (TRUE)
{
chThdSleepMilliseconds(5000);
}
}
is it possible solution by change in TIMx_CCRx . ..
give me some idea phase shifting
Re: STM32: Timer 1 PWM complementary outputs
I checked the documentation but could not find anything about what I need to put in "static PWMConfig pwmcfg". It complained about a missing "DIER", and I added an extra zero at the end which removed the warning, and seems to work, but it'd be nice to be able to verify things like this against the documentation.Giovanni wrote:Please see the online documentation of the PWM driver for details. The code is new, please report any problem you may find.
Another reason I'm looking at the documentation is that I need "dead time". Is there an interface for that?
- Giovanni
- Site Admin
- Posts: 14891
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 996 times
Re: STM32: Timer 1 PWM complementary outputs
Those are features specific of the device so there is not an API, everything is configured into the PWMConfig structure.
Giovanni
Giovanni