Uses NucleoL432
Dependencies: mbed
Revision 0:b98f50bdfcd4, committed 2018-06-05
- Comitter:
- f3d
- Date:
- Tue Jun 05 09:17:33 2018 +0000
- Commit message:
- PWM Example for 3 phase bridge (fixed duty);
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
| mbed.bld | Show annotated file Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Tue Jun 05 09:17:33 2018 +0000
@@ -0,0 +1,54 @@
+#include "mbed.h"
+#define PWM_PERIOD_COUNT 20000
+/*
+For register definitions see here:
+https://github.com/ARMmbed/mbed-os/blob/master/targets/TARGET_STM/TARGET_STM32L4/TARGET_STM32L432xC/device/stm32l432xx.h
+*/
+// Using the MBED libraries to configure the PWM outputs (its easier than
+// calculating all of the register contents by hand)
+
+PwmOut PhaATop(PA_8);
+PwmOut PhaBTop(PA_9);
+PwmOut PhaCTop(PA_10);
+PwmOut PhaABottom(PA_7);
+PwmOut PhaBBottom(PB_0);
+PwmOut PhaCBottom(PB_1);
+
+void TimerISR(void)
+{
+
+
+ TIM1->CCR1 = PWM_PERIOD_COUNT/2;
+ TIM1->CCR2 = PWM_PERIOD_COUNT/2;
+ TIM1->CCR3 = PWM_PERIOD_COUNT/2;
+
+ TIM1->SR &= ~0x3f; // ack the interrupt
+}
+void initTimer1()
+{
+
+ TIM1->CR1 = 0; // make sure Counter is disabled before changing configuration
+ TIM1->CR2 = 0;
+ TIM1->ARR = PWM_PERIOD_COUNT;
+ TIM1->CCR1 = 0; // 0% duty
+ TIM1->CCR2 = 0; // 0% duty
+ TIM1->CCR3 = 0; // 0% duty
+ // Enable complimentary outputs on channels 1 to 3
+ TIM1->CCER = (1 << 0) + (1 << 2) + (1 << 4) + (1 << 6) + (1 << 8) + (1<<10);
+ TIM1->SR = 0; // Clear flags.
+ TIM1->BDTR &= ~(0xff);
+ TIM1->BDTR |= (127); // set dead time to 127 clock cycles
+ // Set up the interrupt handler
+ TIM1->DIER = 1; // Want update interrupt
+ NVIC_SetVector(TIM1_UP_TIM16_IRQn,(uint32_t) TimerISR);
+ NVIC_EnableIRQ(TIM1_UP_TIM16_IRQn);
+ __enable_irq(); // enable interrupts */
+ TIM1->CR1 |= 1; // enable counter
+
+}
+int main() {
+ initTimer1();
+ while(1) {
+
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Tue Jun 05 09:17:33 2018 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/5aab5a7997ee \ No newline at end of file