Single channel PWM with complimentary outputs for the STM32L432 Nucleo
Dependencies: mbed
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 00012 // Using the MBED libraries to configure the PWM outputs (its easier than 00013 // calculating all of the register contents by hand) 00014 DigitalOut myled(LED1); 00015 PwmOut PhaATop(PA_8); 00016 PwmOut PhaABottom(PA_7); 00017 void initTimer1() 00018 { 00019 00020 TIM1->CR1 = 0; // make sure Counter is disabled before changing configuration 00021 TIM1->CR2 = 0; 00022 TIM1->PSC = 1; 00023 TIM1->ARR = PWM_PERIOD_COUNT; 00024 TIM1->CCR1 = PWM_PERIOD_COUNT/4; // 25% duty 00025 // Enable channel 1 and its complimentary output 00026 TIM1->CCER = (1 << 0) + (1 << 2); 00027 TIM1->SR = 0; // Clear flags. 00028 TIM1->CR1 |= 1; // enable counter 00029 00030 } 00031 00032 int main() { 00033 00034 initTimer1(); 00035 while(1) { 00036 00037 } 00038 }
Generated on Mon Jul 18 2022 08:40:29 by
1.7.2