ArmfulKST / Mbed 2 deprecated STM32L432PWM2

Dependencies:   mbed

Committer:
f3d
Date:
Tue Mar 26 12:41:30 2019 +0000
Revision:
1:af207f38ed4a
Parent:
0:18d54d648967
Complimentary single channel PWM (no deadtime)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
f3d 0:18d54d648967 1 #include "mbed.h"
f3d 0:18d54d648967 2 #include <stm32l432xx.h>
f3d 0:18d54d648967 3
f3d 0:18d54d648967 4
f3d 0:18d54d648967 5 #define PWM_PERIOD_COUNT 1000
f3d 0:18d54d648967 6
f3d 0:18d54d648967 7 /*
f3d 0:18d54d648967 8 For register definitions see here:
f3d 0:18d54d648967 9 https://github.com/ARMmbed/mbed-os/blob/master/targets/TARGET_STM/TARGET_STM32L4/TARGET_STM32L432xC/device/stm32l432xx.h
f3d 0:18d54d648967 10 */
f3d 0:18d54d648967 11
f3d 0:18d54d648967 12 // Using the MBED libraries to configure the PWM outputs (its easier than
f3d 0:18d54d648967 13 // calculating all of the register contents by hand)
f3d 0:18d54d648967 14 DigitalOut myled(LED1);
f3d 0:18d54d648967 15 PwmOut PhaATop(PA_8);
f3d 1:af207f38ed4a 16 PwmOut PhaABottom(PA_7);
f3d 0:18d54d648967 17 void initTimer1()
f3d 0:18d54d648967 18 {
f3d 0:18d54d648967 19
f3d 0:18d54d648967 20 TIM1->CR1 = 0; // make sure Counter is disabled before changing configuration
f3d 0:18d54d648967 21 TIM1->CR2 = 0;
f3d 0:18d54d648967 22 TIM1->PSC = 1;
f3d 0:18d54d648967 23 TIM1->ARR = PWM_PERIOD_COUNT;
f3d 0:18d54d648967 24 TIM1->CCR1 = PWM_PERIOD_COUNT/4; // 25% duty
f3d 1:af207f38ed4a 25 // Enable channel 1 and its complimentary output
f3d 1:af207f38ed4a 26 TIM1->CCER = (1 << 0) + (1 << 2);
f3d 0:18d54d648967 27 TIM1->SR = 0; // Clear flags.
f3d 0:18d54d648967 28 TIM1->CR1 |= 1; // enable counter
f3d 0:18d54d648967 29
f3d 0:18d54d648967 30 }
f3d 0:18d54d648967 31
f3d 0:18d54d648967 32 int main() {
f3d 0:18d54d648967 33
f3d 0:18d54d648967 34 initTimer1();
f3d 0:18d54d648967 35 while(1) {
f3d 0:18d54d648967 36
f3d 0:18d54d648967 37 }
f3d 0:18d54d648967 38 }