FastPWM clone
Diff: Device/FastPWM_KSDK.cpp
- Revision:
- 33:2ca2e47f9650
- Parent:
- 31:10e2e171f430
- Child:
- 35:d6c2b73d71f5
--- a/Device/FastPWM_KSDK.cpp Sun Jan 01 14:37:55 2017 +0000 +++ b/Device/FastPWM_KSDK.cpp Sun Sep 03 16:26:07 2017 +0000 @@ -7,11 +7,13 @@ #define PWM_CNV (*(((fastpwm_struct*)fast_obj)->CnV)) #define PWM_MOD (*(((fastpwm_struct*)fast_obj)->MOD)) #define PWM_SC (*(((fastpwm_struct*)fast_obj)->SC)) +#define PWM_SYNC (*(((fastpwm_struct*)fast_obj)->SYNC)) typedef struct { __IO uint32_t *CnV; __IO uint32_t *MOD; __IO uint32_t *SC; + __IO uint32_t *SYNC; } fastpwm_struct; static uint32_t pwm_prescaler; @@ -29,18 +31,21 @@ ((fastpwm_struct*)fast_obj)->CnV = &ftm->CONTROLS[ch_n].CnV; ((fastpwm_struct*)fast_obj)->MOD = &ftm->MOD; ((fastpwm_struct*)fast_obj)->SC = &ftm->SC; + ((fastpwm_struct*)fast_obj)->SYNC = &ftm->SYNC; + + //Do not clear counter when writing new value, set end of period as loading value + ftm->SYNCONF &= ~FTM_SYNCONF_SWRSTCNT_MASK; + ftm->SYNC |= FTM_SYNC_CNTMAX_MASK; } 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); + PWM_SYNC |= FTM_SYNC_SWSYNC_MASK; } void FastPWM::period_ticks( uint32_t ticks ) { PWM_MOD = ticks - 1; + PWM_SYNC |= FTM_SYNC_SWSYNC_MASK; } uint32_t FastPWM::getPeriod( void ) { @@ -78,7 +83,6 @@ PWM_SC = bin + clockbits; - return retval; } #endif \ No newline at end of file