HI,
I am trying to toggle the red led using TPM0 _interrupt on FRDM-KL43Z board. I selected MCGIRCLK(8MHZ) as TPM clock source.
Since the prescaler is 2, the TPM clock period is 0.25microseconds.I am loading the TPM_MOD register with 8000 so that the ON and OFF period of led is 2ms .
But the problem is irrespective of the value loaded in the TPM_MOD register the ON and OFF periods are 16.80ms and 16ms respectively. The following is the code .
SIM_SCGC6 |= SIM_SCGC6_TPM0_MASK ; //enable the clock for TPM0 module
SIM_SOPT2 |= SIM_SOPT2_TPMSRC_MASK ; //MCGIRCLK as clock source
TPM0_CONF |= TPM_CONF_DBGMODE_MASK ; // increment the counter in debug mode
TPM0_SC |= TPM_SC_PS(1); //PRESCALER IS 2
TPM0_SC |= TPM_SC_CPWMS_upcounting ; //up counting is selected(0x08u)
TPM0_CNT |= TPM_CNT_COUNT_MASK ; //clear the counter value
TPM0_MOD |= TPM_MOD_MOD(8000); // to get a delay of 2msec
TPM0_SC |= TPM_SC_TOF_MASK ; // clear the interrupt flag
TPM0_SC |= TPM_SC_TOIE_MASK; //enable the interrupt
TPM0_SC |= TPM_SC_CMOD(2); //TPM counter increments on every TPM counter clock