other

Dependents:   qonly_controller foc-ed_in_the_bot_compact foc-ed_in_the_bot_compact CurrentModeSine ... more

Fork of FastPWM by Erik -

Files at this revision

API Documentation at this revision

Comitter:
Sissors
Date:
Sun Jul 20 19:49:43 2014 +0000
Parent:
12:4600daab8a83
Child:
14:b30038fbba51
Commit message:
Added NUCLEO support (F030 + F401, but others should be easily added).

Changed in this revision

Device/FastPWM_STM_TIM.cpp Show annotated file Show diff for this revision Revisions of this file
Device/FastPWM_STM_TIM_PinOut.cpp Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Device/FastPWM_STM_TIM.cpp	Sun Jul 20 19:49:43 2014 +0000
@@ -0,0 +1,42 @@
+//This should (hopefully) work on all STM targets which use TIM timers for PWM
+
+#ifdef TARGET_STM
+
+#include "FastPWM.h"
+
+#define PWM_CHANNEL     (**(__IO uint32_t**)fast_obj)
+#define PWM_TIMER       ((TIM_TypeDef*)_pwm.pwm)
+
+extern __IO uint32_t* getChannel(TIM_TypeDef* pwm, PinName pin);
+
+void FastPWM::initFastPWM( void ) {
+    fast_obj = new (__IO uint32_t*);
+    *(__IO uint32_t**)fast_obj = getChannel(PWM_TIMER, _pwm.pin);
+    bits = 16;
+}
+
+void FastPWM::pulsewidth_ticks( uint32_t ticks ) {
+    PWM_CHANNEL = ticks;    
+}
+
+void FastPWM::period_ticks( uint32_t ticks ) {
+    PWM_TIMER->ARR = ticks - 1;
+}
+
+uint32_t FastPWM::getPeriod( void ) {
+    return PWM_TIMER->ARR + 1;
+}
+
+uint32_t FastPWM::setPrescaler(uint32_t reqScale) {
+    if (reqScale == 0)
+        //Return prescaler
+        return PWM_TIMER->PSC + 1;
+    if (reqScale > (uint32_t)(1<<16))
+        reqScale = 1<<16;
+    //Else set prescaler, we have to substract one from reqScale since a 0 in PCVAL is prescaler of 1
+    PWM_TIMER->PSC = reqScale - 1;
+
+    return reqScale;
+}
+
+#endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Device/FastPWM_STM_TIM_PinOut.cpp	Sun Jul 20 19:49:43 2014 +0000
@@ -0,0 +1,47 @@
+#include "mbed.h"
+
+#ifdef TARGET_NUCLEO_F030R8
+__IO uint32_t* getChannel(TIM_TypeDef* pwm, PinName pin) {
+    switch (pin) {
+        // Channels 1
+        case PA_4: case PA_6: case PB_1: case PB_4: case PB_8: case PB_9: case PB_14: case PC_6: case PB_6: case PB_7:
+            return &pwm->CCR1;
+            
+        // Channels 2
+        case PA_7: case PB_5: case PC_7:
+            return &pwm->CCR2;
+            
+        // Channels 3
+        case PB_0: case PC_8:
+            return &pwm->CCR3;
+            
+        // Channels 4
+        case PC_9:
+            return &pwm->CCR4;
+    }        
+    return NULL;
+}
+#endif
+
+#ifdef TARGET_NUCLEO_F401RE
+__IO uint32_t* getChannel(TIM_TypeDef* pwm, PinName pin) {
+    switch (pin) {
+        // Channels 1
+        case PA_0: case PA_5: case PA_6: case PA_8: case PA_15: case PB_4: case PB_6: case PC_6: case PA_7: case PB_13:
+            return &pwm->CCR1;
+        
+        // Channels 2
+        case PA_1: case PA_9: case PB_3: case PB_5: case PB_7: case PC_7: case PB_0: case PB_14:
+            return &pwm->CCR2;
+            
+        // Channels 3
+        case PA_2: case PA_10: case PB_8: case PB_10: case PC_8: case PB_1: case PB_15:
+            return &pwm->CCR3;
+ 
+        // Channels 4
+        case PA_3: case PA_11: case PB_9: case PC_9: 
+            return &pwm->CCR4;
+    }
+    return NULL;
+}
+#endif
\ No newline at end of file