ArmfulKST / Mbed 2 deprecated STM32L4323PhasePWM1

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include <stm32l432xx.h>
00003 
00004 
00005 #define PWM_PERIOD_COUNT 1000
00006 
00007 /*
00008 For register definitions see here:
00009 https://github.com/ARMmbed/mbed-os/blob/master/targets/TARGET_STM/TARGET_STM32L4/TARGET_STM32L432xC/device/stm32l432xx.h
00010 */
00011 // Using the MBED libraries to configure the PWM outputs (its easier than 
00012 // calculating all of the register contents by hand)
00013 DigitalOut myled(LED1);
00014 PwmOut  PhaATop(PA_8); 
00015 PwmOut  PhaBTop(PA_9); 
00016 PwmOut  PhaCTop(PA_10); 
00017 PwmOut  PhaABottom(PA_7); 
00018 PwmOut  PhaBBottom(PB_0); 
00019 PwmOut  PhaCBottom(PB_1); 
00020 
00021 void initTimer1()
00022 {    
00023     
00024     TIM1->CR1 = 0; // make sure Counter is disabled before changing configuration
00025     TIM1->CR2 = 0;
00026     TIM1->PSC = 1;
00027     TIM1->ARR = PWM_PERIOD_COUNT;
00028     TIM1->CCR1 = PWM_PERIOD_COUNT/4; // 25% duty
00029     TIM1->CCR2 = PWM_PERIOD_COUNT/2; // 50% duty
00030     TIM1->CCR3 = 3*PWM_PERIOD_COUNT/4; // 75% duty
00031     // Enable complimentary outputs on channels 1 to 3
00032     TIM1->CCER = (1 << 0) + (1 << 2) + (1 << 4) + (1 << 6) + (1 << 8) + (1<<10);
00033     TIM1->SR = 0;      // Clear flags.    
00034     TIM1->BDTR &= ~(0xff);
00035     TIM1->BDTR |= (127); // set dead time to 127 clock cycles
00036     
00037 
00038 }
00039 
00040 int main() {    
00041    
00042     initTimer1();
00043     while(1) {
00044        
00045     }
00046 }