Martin Dusek

MCF51QE128 timer module

Discussion created by Martin Dusek on Feb 6, 2009
Latest reply on Feb 11, 2009 by Martin Dusek
Hi all,
in the MAIN part of my program, I have this init code for TPM1:
SCGC1_TPM1 = 1;TPM1MOD = 0x3F;TPM1SC = 0b01001111;

(mod value = 0x3F, bus clock divided by 128, overflow interrupt enabled)
Interrupt service rutine is here:
void interrupt VectorNumber_Vtpm1ovf commutationTime(void) {  TPM1SC_TOF = 0;  SCGC1_TPM1 = 0; // stop clock  TPM1SC = 0b01000111; // stop clock  TPM1CNT = 0; // reset timer  TPM1MOD = 0x2; // change mod value  TPM1SC = 0b01001111; // start clock   SCGC1_TPM1 = 1; // start clock      PTGD_PTGD7 ^= 1; // here I toggle one pin to see what timer does

Output signal should be first toggled after timer reaches 0x3F, in the interrupt service routine the mod value is changed to 0x02, so then the signal should have higher frequency. 
My problem is, that the mod value never changes to 0x02, I don't know why. Any advice?
And is there any manual how to operate TPM modules? I think there is not said all in the datasheet of MCF51QE128, because this is not my only problem with TPM modules, they just don't work as they should.