dominicbeesley
New member
Hello,
I've just got a Teensy 3.2 and am trying to port a project from a Due where I do PWM that changes from an interrupt routine. I'd like this to be as quick as possible as it updates frequently so I'd like to access the registers direct.
So far I'm trying to get pin 6 to do PWM but I can't get it to work. The pin just goes high after a reset. I'm probably missing something obvious...
I've just got a Teensy 3.2 and am trying to port a project from a Due where I do PWM that changes from an interrupt routine. I'd like this to be as quick as possible as it updates frequently so I'd like to access the registers direct.
So far I'm trying to get pin 6 to do PWM but I can't get it to work. The pin just goes high after a reset. I'm probably missing something obvious...
Code:
void setup() {
// put your setup code here, to run once:
SIM_SCGC6 |= SIM_SCGC6_FTM0;
PORTD_PCR4 = PORT_PCR_MUX(4) | PORT_PCR_DSE | PORT_PCR_SRE;
//WRITE ENABLE
FTM0_MODE |= FTM_MODE_WPDIS;
FTM0_MODE |= FTM_MODE_FTMEN;
FTM0_MOD = 300;
FTM0_CNTIN = 0;
FTM0_C4V = 100;
//Edge aligned PWM neg
FTM0_C4SC = FTM_CSC_MSB | FTM_CSC_ELSA;
//System clock, prescaler 128
FTM0_SC = FTM_SC_CLKS(1) | FTM_SC_PS(7);
//NOT SURE IF NEEDED?
FTM0_OUTINIT = 0;
//allow all outputs
FTM0_OUTMASK = 0;
// no combine
FTM0_COMBINE = 0;
FTM0_SYNC |= FTM_SYNC_SWSYNC;
FTM0_CNT = 0;
FTM0_PWMLOAD = 0x2F;
}