Page 1 of 1

Problem with PWM Complementry signal

Posted: Wed Feb 15, 2017 4:42 pm
by arun_1990
Hi Giovani,

I successfully generated PWM with complementry singnal on STM32 disco board for a Motor control application.

I used palSetPadMode(GPIOC,7, PAL_MODE_ALTERNATE(3)) for actual PWM signal and palSetPadMode(GPIOB,0, PAL_MODE_ALTERNATE(3)) for its complementry signal using timer 8. Its working fine on stm32 disco board.

But when I executed the same program on custom made board with STM32F437 only by changing the complementy pin to PB0 to PH14 I am facing a problem which i have explained below.

Following is the configuration on custom made board.

palSetPadMode(PHASE_B_HIGH_PORT,PHASE_B_HIGH_PIN,PAL_MODE_ALTERNATE(3)) - this is PC7 pin as actual PWM signal and palSetPadMode(PHASE_B_LOW_PORT,PHASE_B_LOW_PIN,PAL_MODE_ALTERNATE(3)) - this is PH14 pin as its complementry signal.

The problem is when I congiure the PWM channel mode like this, PWM_OUTPUT_ACTIVE_HIGH |PWM_COMPLEMENTARY_OUTPUT_DISABLED,
I expected the pin PH14 to be disabled and there will be no output, but it is ON and I got PWM signal at PC7 as expected. This will cause problem since FETs will on at the same time. This problem did not arise when i used the stm32 disco board.

I am using the board.h and board.c file same as stm32 demo. I also noticed, PH14 was configured as input pullup in GPIOH setup in board.h file of stm32 demo. I believe PH14 is ON because it is configured as input pullup initially and I have just configured it as PAL_MODE_ALTERNATE(3) in main.c file.

Could you please let me know how to configure PH14 and all PWM output pins as PAL_MODE_ALTERNATE(3) and also as pushpull?

I tried like following to configure all PWM pins and also as pushpull.

1. palSetPadMode(PHASE_B_HIGH_PORT,PHASE_B_HIGH_PIN,PAL_MODE_OUTPUT_PUSHPULL|PAL_MODE_ALTERNATE(3) )in this case there is no error and also no output from PWM even though the channel mode is PWM_OUTPUT_ACTIVE_HIGH.

2.palSetPadMode(PHASE_B_HIGH_PORT,PHASE_B_HIGH_PIN,PAL_MODE_STM32_ALTERNATE_PUSHPULL) in this case there is a following error

'main.c:384:27: error: 'PAL_MODE_STM32_ALTERNATE_PUSHPULL' undeclared (first use in this function)
palSetPadMode(GPIOC,6,PAL_MODE_STM32_ALTERNATE_PUSHPULL);

Please let me know how i can resolve this issue. Also please tell me know what i have to keep in mind when using board.c and board.h of stm32 disco for custom made board.

Kind regards,
Arun

Re: Problem with PWM Complementry signal

Posted: Wed Feb 15, 2017 7:06 pm
by Giovanni
Hi,

PAL_MODE_ALTERNATE(n) sets both the alternate and the pushpull mode.

Make sure to not program multiple pins to the same peripheral, only one pin must be made alternate on a peripheral.

Details are on the GPIO section of the Reference Manual.

The macros you can combine with PAL_MODE_ALTERNATE(n) are the following:

Code: Select all

#define PAL_STM32_OTYPE_MASK            (1U << 2U)
#define PAL_STM32_OTYPE_PUSHPULL        (0U << 2U)
#define PAL_STM32_OTYPE_OPENDRAIN       (1U << 2U)

#define PAL_STM32_OSPEED_MASK           (3U << 3U)
#define PAL_STM32_OSPEED_LOWEST         (0U << 3U)
#if defined(STM32F0XX) || defined(STM32F30X) || defined(STM32F37X)
#define PAL_STM32_OSPEED_MID            (1U << 3U)
#else
#define PAL_STM32_OSPEED_MID1           (1U << 3U)
#define PAL_STM32_OSPEED_MID2           (2U << 3U)
#endif
#define PAL_STM32_OSPEED_HIGHEST        (3U << 3U)

#define PAL_STM32_PUPDR_MASK            (3U << 5U)
#define PAL_STM32_PUPDR_FLOATING        (0U << 5U)
#define PAL_STM32_PUPDR_PULLUP          (1U << 5U)
#define PAL_STM32_PUPDR_PULLDOWN        (2U << 5U)

Giovanni