File tree Expand file tree Collapse file tree 1 file changed +19
-2
lines changed
targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K64F Expand file tree Collapse file tree 1 file changed +19
-2
lines changed Original file line number Diff line number Diff line change @@ -124,8 +124,25 @@ void pwmout_period_us(pwmout_t* obj, int us)
124
124
FTM_Type * base = ftm_addrs [obj -> pwm_name >> TPM_SHIFT ];
125
125
float dc = pwmout_read (obj );
126
126
127
- // Stop FTM clock to ensure instant update of MOD register
128
- base -> MOD = FTM_MOD_MOD ((pwm_clock_mhz * (float )us ) - 1 );
127
+ uint32_t pwm_base_clock ;
128
+ uint32_t clkdiv = 0 ;
129
+ pwm_base_clock = CLOCK_GetFreq (kCLOCK_BusClk );
130
+ pwm_clock_mhz = (float ) pwm_base_clock / 1000000.0f ;
131
+ uint32_t mod = (pwm_clock_mhz * (float ) us ) - 1 ;
132
+ while (mod > 0xFFFF ) {
133
+ ++ clkdiv ;
134
+ pwm_clock_mhz /= 2.0f ;
135
+ mod = (pwm_clock_mhz * (float ) us ) - 1 ;
136
+ if (clkdiv == 7 ) {
137
+ break ;
138
+ }
139
+ }
140
+ uint32_t SC = base -> SC & ~FTM_SC_PS_MASK ;
141
+ SC |= FTM_SC_PS ((ftm_clock_prescale_t ) clkdiv );
142
+ base -> SC = SC ;
143
+
144
+ //Stop FTM clock to ensure instant update of MOD register
145
+ base -> MOD = FTM_MOD_MOD (mod );
129
146
pwmout_write (obj , dc );
130
147
}
131
148
You can’t perform that action at this time.
0 commit comments