Pinscape fork (KL25Z)

Dependents:   Pinscape_Controller_V2_arnoz Pinscape_Controller_V2

Fork of FastPWM by Erik -

Revision:
35:25e9500598ae
Parent:
32:10e2e171f430
--- a/Device/FastPWM_KSDK.cpp	Fri Mar 24 05:32:57 2017 +0000
+++ b/Device/FastPWM_KSDK.cpp	Fri Mar 24 05:39:58 2017 +0000
@@ -1,7 +1,7 @@
 #if defined(TARGET_KPSDK_MCUS)
 
 #include "FastPWM.h"
-#include "fsl_clock_manager.h"
+#include "fsl_ftm.h"
 
 
 #define PWM_CNV              (*(((fastpwm_struct*)fast_obj)->CnV))  
@@ -15,18 +15,16 @@
 } fastpwm_struct;
 
 static uint32_t pwm_prescaler;
+static FTM_Type *const ftm_addrs[] = FTM_BASE_PTRS;
 
 void FastPWM::initFastPWM( void ) {
     fast_obj = new fastpwm_struct;
     bits = 16;
-    
-    uint32_t pwm_base_clock;
-    CLOCK_SYS_GetFreq(kBusClock, &pwm_base_clock);
-    pwm_prescaler = SystemCoreClock / pwm_base_clock;
+
+    pwm_prescaler = SystemCoreClock / CLOCK_GetFreq(kCLOCK_BusClk);;
 
-    uint32_t ftms[] = FTM_BASE_ADDRS;
-    unsigned int ch_n = (_pwm.pwm_name & 0xFF);
-    FTM_Type *ftm = (FTM_Type *)ftms[_pwm.pwm_name >> TPM_SHIFT];
+    unsigned int ch_n = (_pwm.pwm_name & 0xF);
+    FTM_Type *ftm = ftm_addrs[_pwm.pwm_name >> TPM_SHIFT];
     
     ((fastpwm_struct*)fast_obj)->CnV = &ftm->CONTROLS[ch_n].CnV;
     ((fastpwm_struct*)fast_obj)->MOD = &ftm->MOD;
@@ -35,6 +33,10 @@
 
 void FastPWM::pulsewidth_ticks( uint32_t ticks ) {
     PWM_CNV = ticks;
+    
+    //Temporary work around until I figure out which settings mbed screwed up in this update
+    FTM_Type *ftm = ftm_addrs[_pwm.pwm_name >> TPM_SHIFT];
+    FTM_SetSoftwareTrigger(ftm, true);
 }
 
 void FastPWM::period_ticks( uint32_t ticks ) {