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
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
27
27
28
28
// Arduino digital pinout
29
29
{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
34
34
35
35
{NC , NC , 0 }
36
36
};
@@ -54,10 +54,9 @@ void pwmout_init(pwmout_t* obj, PinName pin) {
54
54
ftm -> MODE |= FTM_MODE_WPDIS_MASK ; //write protection disabled
55
55
ftm -> CONF |= FTM_CONF_BDMMODE (3 );
56
56
ftm -> SC = FTM_SC_CLKS (1 ) | FTM_SC_PS (6 ); // (48)MHz / 64 = (0.75)MHz
57
+ ftm -> PWMLOAD |= FTM_PWMLOAD_LDOK_MASK ;
57
58
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
61
60
62
61
obj -> CnV = & ftm -> CONTROLS [ch_n ].CnV ;
63
62
obj -> MOD = & ftm -> MOD ;
@@ -66,7 +65,7 @@ void pwmout_init(pwmout_t* obj, PinName pin) {
66
65
67
66
// default to 20ms: standard for servos, and fine for e.g. brightness control
68
67
pwmout_period_ms (obj , 20 );
69
- pwmout_write (obj , 0 );
68
+ pwmout_write (obj , 0 );
70
69
71
70
// Wire pinout
72
71
pinmap_pinout (pin , PinMap_PWM );
@@ -83,7 +82,7 @@ void pwmout_write(pwmout_t* obj, float value) {
83
82
84
83
* obj -> CnV = (uint32_t )((float )(* obj -> MOD ) * value );
85
84
* obj -> CNT = 0 ;
86
- // *obj->SYNC |= FTM_SYNC_SWSYNC_MASK;
85
+ * obj -> SYNC |= FTM_SYNC_SWSYNC_MASK ;
87
86
}
88
87
89
88
float pwmout_read (pwmout_t * obj ) {
@@ -116,4 +115,5 @@ void pwmout_pulsewidth_ms(pwmout_t* obj, int ms) {
116
115
117
116
void pwmout_pulsewidth_us (pwmout_t * obj , int us ) {
118
117
* obj -> CnV = PWM_CLOCK_MHZ * us ;
118
+ * obj -> SYNC |= FTM_SYNC_SWSYNC_MASK ;
119
119
}
0 commit comments