HI,
I have been trying to flash an LED in a TPM interrupt at 5HZ using a 48MHZ MCGFLLCLK. I cannot seem to set the TPM0 prescaler to divide down the MCGFLLCLK. I'm clearly doing something wrong and maybe not figured out the TPM fully yet.
My code is below. Note I have not set the prescaler and TPM0_C0V value to the correct values for 5HZ operation yet. Any help or pointwers greatly appreciated, as its driving me mad.
int timerInit()
{
NVIC_ICER = 1 << (17%32);
SIM_SOPT2 &= ~(SIM_SOPT2_TPMSRC_MASK);
SIM_SOPT2 |= SIM_SOPT2_TPMSRC(1); // MCGFLLCLK is source
SIM_SCGC6 = SIM_SCGC6_TPM0_MASK; // enable clock for Uart0
TPM0_SC = 0;
TPM0_SC = TPM_SC_PS(7);
TPM0_MOD = 0xFFFF;
TPM0_CNT = 0;
TPM0_SC = TPM_SC_TOIE_MASK|TPM_SC_CMOD(1); // NB Default to 'up-counting' mode.
TPM0_C0SC = TPM_CnSC_MSB_MASK| TPM_CnSC_ELSB_MASK; // MSB:MSA 1:0 Edge Aligned mode (A defaults to 0)
//TPM0_C0SC |= TPM_CnSC_CHIE_MASK; //channel interrupt enable
TPM0_C0V = 0x00;
NVIC_ICPR |= 1 << (17%32);
}
void FTM0_IRQHandler (void)
{
tick = TPM0_CNT;
TPM0_SC |= TPM_SC_TOF_MASK;
TPM0_C0V = 0x1FFF
TPM0_C0SC |= TPM_STATUS_CH0F_MASK;
NegLED();
}