Skip to content

Commit 5e9e53f

Browse files
committed
PWM - changes to start the channel
1 parent d8d526f commit 5e9e53f

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

libraries/mbed/targets/hal/TARGET_Freescale/TARGET_K20D5M/objects.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ struct pwmout_s {
4343
__IO uint32_t *MOD;
4444
__IO uint32_t *CNT;
4545
__IO uint32_t *CnV;
46+
__IO uint32_t *SYNC;
4647
};
4748

4849
struct serial_s {

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@
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
25+
{LED_GREEN, PWM_5, 3}, // PTD4, FTM0 CH4
2626
{LED_BLUE , PWM_9 , 3}, // PTA2 , FTM0 CH7
2727

2828
// Arduino digital pinout
29-
{D3, PWM_5 , 3}, // PTA12, FTM0 CH4
29+
{D3, PWM_5 , 3}, // PTD4, FTM0 CH4
3030
{D5, PWM_7 , 3}, // PTA1 , FTM0 CH6
3131
{D6, PWM_3 , 3}, // PTC3 , FTM0 CH2
3232
{D9, PWM_8 , 4}, // PTD2 , FTM0 CH7
@@ -51,12 +51,18 @@ void pwmout_init(pwmout_t* obj, PinName pin) {
5151
SIM->SCGC6 |= 1 << (SIM_SCGC6_FTM0_SHIFT + ftm_n);
5252

5353
FTM_Type *ftm = (FTM_Type *)(FTM0_BASE + 0x1000 * ftm_n);
54+
ftm->MODE |= FTM_MODE_WPDIS_MASK; //write protection disabled
55+
ftm->CONF |= FTM_CONF_BDMMODE(3);
5456
ftm->SC = FTM_SC_CLKS(1) | FTM_SC_PS(6); // (48)MHz / 64 = (0.75)MHz
5557
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;
5661

5762
obj->CnV = &ftm->CONTROLS[ch_n].CnV;
5863
obj->MOD = &ftm->MOD;
5964
obj->CNT = &ftm->CNT;
65+
obj->SYNC = &ftm->SYNC;
6066

6167
// default to 20ms: standard for servos, and fine for e.g. brightness control
6268
pwmout_period_ms(obj, 20);
@@ -77,6 +83,7 @@ void pwmout_write(pwmout_t* obj, float value) {
7783

7884
*obj->CnV = (uint32_t)((float)(*obj->MOD) * value);
7985
*obj->CNT = 0;
86+
//*obj->SYNC |= FTM_SYNC_SWSYNC_MASK;
8087
}
8188

8289
float pwmout_read(pwmout_t* obj) {

0 commit comments

Comments
 (0)