22
22
static const PinMap PinMap_PWM [] = {
23
23
// LEDs
24
24
{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
26
26
{LED_BLUE , PWM_9 , 3 }, // PTA2 , FTM0 CH7
27
27
28
28
// Arduino digital pinout
29
- {D3 , PWM_5 , 3 }, // PTA12 , FTM0 CH4
29
+ {D3 , PWM_5 , 3 }, // PTD4 , FTM0 CH4
30
30
{D5 , PWM_7 , 3 }, // PTA1 , FTM0 CH6
31
31
{D6 , PWM_3 , 3 }, // PTC3 , FTM0 CH2
32
32
{D9 , PWM_8 , 4 }, // PTD2 , FTM0 CH7
@@ -51,12 +51,18 @@ void pwmout_init(pwmout_t* obj, PinName pin) {
51
51
SIM -> SCGC6 |= 1 << (SIM_SCGC6_FTM0_SHIFT + ftm_n );
52
52
53
53
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 );
54
56
ftm -> SC = FTM_SC_CLKS (1 ) | FTM_SC_PS (6 ); // (48)MHz / 64 = (0.75)MHz
55
57
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 ;
56
61
57
62
obj -> CnV = & ftm -> CONTROLS [ch_n ].CnV ;
58
63
obj -> MOD = & ftm -> MOD ;
59
64
obj -> CNT = & ftm -> CNT ;
65
+ obj -> SYNC = & ftm -> SYNC ;
60
66
61
67
// default to 20ms: standard for servos, and fine for e.g. brightness control
62
68
pwmout_period_ms (obj , 20 );
@@ -77,6 +83,7 @@ void pwmout_write(pwmout_t* obj, float value) {
77
83
78
84
* obj -> CnV = (uint32_t )((float )(* obj -> MOD ) * value );
79
85
* obj -> CNT = 0 ;
86
+ //*obj->SYNC |= FTM_SYNC_SWSYNC_MASK;
80
87
}
81
88
82
89
float pwmout_read (pwmout_t * obj ) {
0 commit comments