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:
Fri Jun 27 06:18:23 2014 +0000
Parent:
9:c50f688cad07
Child:
11:e0a8f0fcb1c9
Commit message:
Same error as for the KLxx removed when multiple FastPWMs are used. Contrary to KLxx this gives a bit more overhead, but not much I can do about it while keeping the lib tidy

Changed in this revision

Device/FastPWM_LPC11U24.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/Device/FastPWM_LPC11U24.cpp	Fri Jun 27 06:02:37 2014 +0000
+++ b/Device/FastPWM_LPC11U24.cpp	Fri Jun 27 06:18:23 2014 +0000
@@ -2,14 +2,13 @@
 
 #include "FastPWM.h"
 
-
-volatile uint32_t *PWM_MR;
-LPC_CTxxBx_Type *pwm_obj;
-
 typedef struct {
     uint8_t timer;
     uint8_t mr;
 } timer_mr;
+
+LPC_CTxxBx_Type *pwm_obj;
+timer_mr tid;
  
 static timer_mr pwm_timer_map[11] = {
     {0, 0}, {0, 1}, {0, 2},
@@ -25,11 +24,8 @@
 
 
 void FastPWM::initFastPWM( void ) {
-    //Sadly the 11u24 pwm object does not store match register/pwm object for some reason
-    //It recalculates it everytime, we just do it once because we are awesome
-    timer_mr tid = pwm_timer_map[_pwm.pwm];
+    tid = pwm_timer_map[_pwm.pwm];
     pwm_obj = Timers[tid.timer];
-    PWM_MR = &pwm_obj->MR[tid.mr];
     
     if (tid.timer < 2)
         //16-bit timer
@@ -40,23 +36,35 @@
 }
 
 void FastPWM::pulsewidth_ticks( uint32_t ticks ) {
+    tid = pwm_timer_map[_pwm.pwm];
+    pwm_obj = Timers[tid.timer];
+    
     if (ticks)
-        *PWM_MR = pwm_obj->MR3 - ticks;  //They inverted PWM on the 11u24
+        pwm_obj->MR[tid.mr] = pwm_obj->MR3 - ticks;  //They inverted PWM on the 11u24
     else
-        *PWM_MR = 0xFFFFFFFF;           //If MR3 = ticks 1 clock cycle wide errors appear, this prevents that (unless MR3 = max).
+        pwm_obj->MR[tid.mr] = 0xFFFFFFFF;           //If MR3 = ticks 1 clock cycle wide errors appear, this prevents that (unless MR3 = max).
 }
 
 void FastPWM::period_ticks( uint32_t ticks ) {
+    tid = pwm_timer_map[_pwm.pwm];
+    pwm_obj = Timers[tid.timer];
+    
     pwm_obj->TCR = 0x02;
     pwm_obj->MR3 = ticks;
     pwm_obj->TCR = 0x01;   
 }
 
 uint32_t FastPWM::getPeriod( void ) {
+    tid = pwm_timer_map[_pwm.pwm];
+    pwm_obj = Timers[tid.timer];
+    
     return pwm_obj->MR3;
 }
 
 uint32_t FastPWM::setPrescaler(uint32_t reqScale) {
+    tid = pwm_timer_map[_pwm.pwm];
+    pwm_obj = Timers[tid.timer];
+    
     //If 32-bit, disable auto-scaling, return 1
     if (bits == 32) {
         dynamicPrescaler = false;