Forked FastPWM

Dependents:   Berekenen_motorhoek Encoder System_Identification Motor_PID_set_parameters ... more

Fork of FastPWM by Erik -

Files at this revision

API Documentation at this revision

Comitter:
Sissors
Date:
Fri Feb 28 18:18:52 2014 +0000
Parent:
4:a7b9f778c4b4
Child:
6:0f57969697b6
Commit message:
KL25Z renamed to KLXX, should work fine for all KLXX devices.

Changed in this revision

Device/FastPWM_KL25Z.cpp Show diff for this revision Revisions of this file
Device/FastPWM_KLXX.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/Device/FastPWM_KL25Z.cpp	Tue Aug 13 16:54:06 2013 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,56 +0,0 @@
-#ifdef TARGET_KL25Z
-
-#include "FastPWM.h"
-
-volatile uint32_t *TPM_SC;
-
-void FastPWM::initFastPWM( void ) {
-    bits = 16;
-    
-    //Yes this is ugly, yes I should feel bad about it
-    TPM_SC = _pwm.MOD - 2;
-}
-
-void FastPWM::pulsewidth_ticks( uint32_t ticks ) {
-    *(_pwm.CnV) = ticks;
-    *_pwm.CNT = 0;  //Not yet sure why this is needed!
-}
-
-void FastPWM::period_ticks( uint32_t ticks ) {
-    *(_pwm.MOD) = ticks;
-    *_pwm.CNT = 0;
-}
-
-uint32_t FastPWM::getPeriod( void ) {
-    return *(_pwm.MOD);
-}
-
-uint32_t FastPWM::setPrescaler(uint32_t reqScale) {
-    const char prescalers[] = {1, 2, 4, 8, 16, 32, 64, 128};
-    
-    //If prescaler is 0, return current one
-    if (reqScale == 0)
-        return (prescalers[(*TPM_SC) & 0x07]);
-    
-    uint32_t retval = 0;
-    char bin;
-    
-    for (bin = 0; bin<8; bin++) {
-        retval = prescalers[bin];
-        if (retval >= reqScale)
-            break;
-    }
-    
-    //Clear lower 5 bits, write new value:
-    char clockbits = *TPM_SC & (3<<3);
-    
-    //For some reason clearing them takes some effort
-    while ((*TPM_SC & 0x1F) != 0)
-        *TPM_SC &= ~0x1F;
-        
-    
-    *TPM_SC |= bin + clockbits;
-    
-    return retval;   
-}
-#endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Device/FastPWM_KLXX.cpp	Fri Feb 28 18:18:52 2014 +0000
@@ -0,0 +1,56 @@
+#ifdef TARGET_KLXX
+
+#include "FastPWM.h"
+
+volatile uint32_t *TPM_SC;
+
+void FastPWM::initFastPWM( void ) {
+    bits = 16;
+    
+    //Yes this is ugly, yes I should feel bad about it
+    TPM_SC = _pwm.MOD - 2;
+}
+
+void FastPWM::pulsewidth_ticks( uint32_t ticks ) {
+    *(_pwm.CnV) = ticks;
+    *_pwm.CNT = 0;  //Not yet sure why this is needed!
+}
+
+void FastPWM::period_ticks( uint32_t ticks ) {
+    *(_pwm.MOD) = ticks;
+    *_pwm.CNT = 0;
+}
+
+uint32_t FastPWM::getPeriod( void ) {
+    return *(_pwm.MOD);
+}
+
+uint32_t FastPWM::setPrescaler(uint32_t reqScale) {
+    const char prescalers[] = {1, 2, 4, 8, 16, 32, 64, 128};
+    
+    //If prescaler is 0, return current one
+    if (reqScale == 0)
+        return (prescalers[(*TPM_SC) & 0x07]);
+    
+    uint32_t retval = 0;
+    char bin;
+    
+    for (bin = 0; bin<8; bin++) {
+        retval = prescalers[bin];
+        if (retval >= reqScale)
+            break;
+    }
+    
+    //Clear lower 5 bits, write new value:
+    char clockbits = *TPM_SC & (3<<3);
+    
+    //For some reason clearing them takes some effort
+    while ((*TPM_SC & 0x1F) != 0)
+        *TPM_SC &= ~0x1F;
+        
+    
+    *TPM_SC |= bin + clockbits;
+    
+    return retval;   
+}
+#endif
\ No newline at end of file