
This program demonstrates how you might use the complimentary PWM outputs with deadtime for an STM32F103 nucleo board
Dependencies: mbed
main.cpp@0:badd8991240d, 2015-10-19 (annotated)
- Committer:
- f3d
- Date:
- Mon Oct 19 15:02:23 2015 +0000
- Revision:
- 0:badd8991240d
Complimentary output PWM with deadtime for the STM32F103 Nucleo
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
f3d | 0:badd8991240d | 1 | #include "mbed.h" |
f3d | 0:badd8991240d | 2 | DigitalOut my_led(LED1); |
f3d | 0:badd8991240d | 3 | |
f3d | 0:badd8991240d | 4 | /* |
f3d | 0:badd8991240d | 5 | Pin mappings for Timer 1 (the advanced timer with deadtime) |
f3d | 0:badd8991240d | 6 | From: https://developer.mbed.org/users/mbed_official/code/mbed-src/file/a11c0372f0ba/targets/hal/TARGET_STM/TARGET_STM32F1/TARGET_NUCLEO_F103RB/PeripheralPins.c |
f3d | 0:badd8991240d | 7 | {PA_8, PWM_1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, // TIM1_CH1 - Default |
f3d | 0:badd8991240d | 8 | {PA_9, PWM_1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, // TIM1_CH2 - Default |
f3d | 0:badd8991240d | 9 | {PA_10, PWM_1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, // TIM1_CH3 - Default |
f3d | 0:badd8991240d | 10 | {PB_13, PWM_1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, // TIM1_CH1N - Default |
f3d | 0:badd8991240d | 11 | {PB_14, PWM_1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, // TIM1_CH2N - Default |
f3d | 0:badd8991240d | 12 | {PB_15, PWM_1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0)}, // TIM1_CH3N - Default |
f3d | 0:badd8991240d | 13 | |
f3d | 0:badd8991240d | 14 | */ |
f3d | 0:badd8991240d | 15 | |
f3d | 0:badd8991240d | 16 | int main() |
f3d | 0:badd8991240d | 17 | { |
f3d | 0:badd8991240d | 18 | |
f3d | 0:badd8991240d | 19 | PwmOut PhaATop(PA_8); |
f3d | 0:badd8991240d | 20 | PwmOut PhaABtm(PB_13); // This should be the complement of PA_8 |
f3d | 0:badd8991240d | 21 | PhaATop.period_ms(1); |
f3d | 0:badd8991240d | 22 | PhaATop = 0.8; |
f3d | 0:badd8991240d | 23 | TIM1->CCER |= 4; //enable complimentary output |
f3d | 0:badd8991240d | 24 | TIM1->BDTR |= 0xff; // specify the maximum amount of deadtime required approx 13.5us - see page 356 of reference manual |
f3d | 0:badd8991240d | 25 | while (1) { |
f3d | 0:badd8991240d | 26 | my_led = !my_led; |
f3d | 0:badd8991240d | 27 | wait(0.2); // 500 ms |
f3d | 0:badd8991240d | 28 | } |
f3d | 0:badd8991240d | 29 | } |