Skip to content

Commit a384d1d

Browse files
committed
pwm channel 7 correction, enhanced mode
1 parent 8d7c3da commit a384d1d

File tree

1 file changed

+11
-11
lines changed
  • libraries/mbed/targets/hal/TARGET_Freescale/TARGET_K20D5M

1 file changed

+11
-11
lines changed

libraries/mbed/targets/hal/TARGET_Freescale/TARGET_K20D5M/pwmout_api.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@
2222
static const PinMap PinMap_PWM[] = {
2323
// LEDs
2424
{LED_RED , PWM_3 , 3}, // PTC3, FTM0 CH2
25-
{LED_GREEN, PWM_5, 3}, // PTD4, FTM0 CH4
26-
{LED_BLUE , PWM_9 , 3}, // PTA2 , FTM0 CH7
25+
{LED_GREEN, PWM_5, 3}, // PTD4, FTM0 CH4
26+
{LED_BLUE , PWM_8 , 3}, // PTA2, FTM0 CH7
2727

2828
// Arduino digital pinout
2929
{D3, PWM_5 , 3}, // PTD4, FTM0 CH4
30-
{D5, PWM_7 , 3}, // PTA1 , FTM0 CH6
31-
{D6, PWM_3 , 3}, // PTC3 , FTM0 CH2
32-
{D9, PWM_8 , 4}, // PTD2 , FTM0 CH7
33-
{D10, PWM_2 , 4}, // PTC2 , FTM0 CH1
30+
{D5, PWM_7 , 3}, // PTA1, FTM0 CH6
31+
{D6, PWM_3 , 3}, // PTC3, FTM0 CH2
32+
{D9, PWM_8 , 4}, // PTD2, FTM0 CH7
33+
{D10, PWM_2 , 4}, // PTC2, FTM0 CH1
3434

3535
{NC , NC , 0}
3636
};
@@ -54,10 +54,9 @@ void pwmout_init(pwmout_t* obj, PinName pin) {
5454
ftm->MODE |= FTM_MODE_WPDIS_MASK; //write protection disabled
5555
ftm->CONF |= FTM_CONF_BDMMODE(3);
5656
ftm->SC = FTM_SC_CLKS(1) | FTM_SC_PS(6); // (48)MHz / 64 = (0.75)MHz
57+
ftm->PWMLOAD |= FTM_PWMLOAD_LDOK_MASK;
5758
ftm->CONTROLS[ch_n].CnSC = (FTM_CnSC_MSB_MASK | FTM_CnSC_ELSB_MASK); /* No Interrupts; High True pulses on Edge Aligned PWM */
58-
ftm->PWMLOAD |= FTM_PWMLOAD_LDOK_MASK; //loading updated values enabled
59-
//ftm->SYNCONF |= FTM_SYNCONF_SWRSTCNT_MASK;
60-
ftm->MODE |= FTM_MODE_INIT_MASK;
59+
ftm->SYNCONF |= FTM_SYNCONF_SYNCMODE_MASK | FTM_SYNCONF_SWWRBUF_MASK; //enhanced
6160

6261
obj->CnV = &ftm->CONTROLS[ch_n].CnV;
6362
obj->MOD = &ftm->MOD;
@@ -66,7 +65,7 @@ void pwmout_init(pwmout_t* obj, PinName pin) {
6665

6766
// default to 20ms: standard for servos, and fine for e.g. brightness control
6867
pwmout_period_ms(obj, 20);
69-
pwmout_write (obj, 0);
68+
pwmout_write(obj, 0);
7069

7170
// Wire pinout
7271
pinmap_pinout(pin, PinMap_PWM);
@@ -83,7 +82,7 @@ void pwmout_write(pwmout_t* obj, float value) {
8382

8483
*obj->CnV = (uint32_t)((float)(*obj->MOD) * value);
8584
*obj->CNT = 0;
86-
//*obj->SYNC |= FTM_SYNC_SWSYNC_MASK;
85+
*obj->SYNC |= FTM_SYNC_SWSYNC_MASK;
8786
}
8887

8988
float pwmout_read(pwmout_t* obj) {
@@ -116,4 +115,5 @@ void pwmout_pulsewidth_ms(pwmout_t* obj, int ms) {
116115

117116
void pwmout_pulsewidth_us(pwmout_t* obj, int us) {
118117
*obj->CnV = PWM_CLOCK_MHZ * us;
118+
*obj->SYNC |= FTM_SYNC_SWSYNC_MASK;
119119
}

0 commit comments

Comments
 (0)