I am using a MC9S08LH64 microcontroller's timer module to generate an internal timer for synchronization. bus clock is at 4.3 MHz, modulo is set at 4309 (TPM1MODH and TPM1MODL) and I am expecting pulse every 1.25 ms but the result is about every 3.75ms. Is there any setting I am missing here? Thank you very much
From the reference manual:
/*
* TPM1SC: pg 358
bit
7 TOF need to check for this flag
6 not used since no interrupt being used
5 1 not used
4 0 selecting bus clock
3 1
2 0 not dividing clock down
1 0
0 0
*/
TPM1SC = 0x08;
*Update: I have just realized that changing the TPM1MOD has no effect on the result pulse width. TPM1SC is the only register I used to set up the module. Is there any other register I need to set up for this?
Here are the source code to set up the timer:
//to set up the modulo register:
void set_base_pulse(float time_ms)
{
int modulo_value;
modulo_value = (int) time_ms*1000/233;
TPM1MODH = modulo_value >>8;
TPM1MODL = modulo_value;
}
to generate the pulses, I checked the TOF flag, every 40 times the flag goes off, I toggle the output:
for (counter = 0; counter<40; counter++) {
while (!TPM1SC_TOF) {}
if (counter == 39) output ~= output;
}