Sorry, I didn't read the datasheet carefully...
I have another problem with TPM. What happens, when I write to TPMxCNT register? Datasheet says that it simply resets TPMxCNT... But I have this code:
Code:
void interrupt VectorNumber_Vtpm1ch0 zeroCrossing(void) { // TPM1CH0 interrupt service // another code here TPM1CNT = 0;
TPM1SC = (unsigned char) (TPM1SC & 0b00000111); // stop counter, but keep clock divider if(TPM2CNT == 0) { // here I test TPM2CNT for 0, and it is 0 } TPM2CNT = 0; // this is THE line TPM2MOD = (unsigned short) (someVar); // set new modulo value for TPM2 TPM2SC = (unsigned char) (0b01001000 | TPM1SC); // set TPM2 clock divider the same as TPM1 clock divider, start timer
// another code here
TPM1SC = (unsigned char) (TPM1SC | 0b01001000); start timer
// another code here
TPM2SC;
TPM2SC_TOF;
TPM1C0SC;
TPM1C0SC_CH0F = 0;}
void interrupt VectorNumber_Vtpm2ovf commutationTime(void) { // TPM2 overflow interrupt service
TPM2SC = 0b00000111; // stop counter
// another code here
TPM2SC;
TPM2SC_TOF = 0;}
TPM1CH0 is configured as input capture, TPM2 is modulo counter which generates overflow interrupt.
When I delete the line "TPM2CNT = 0;" in TPM1CH0 interrupt service, program does something different than when the line is there (it doesn't matter what the difference is). I test if TPM2CNT is zero right before the line "TPM2CNT = 0;" and it is, so the "TPM2CNT = 0;" line should not have any effect, as it resets already reseted counter. TPM2 counter is also stopped as you can see from the code.
So in fact, what "TPM2CNT = 0;" does?
Thanks
Message Edited by gaminn on
2009-02-08 12:41 PMMessage Edited by gaminn on
2009-02-08 01:27 PM