Coldfire : timer reset every 256 ms.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Coldfire : timer reset every 256 ms.

736 Views
adrien_segura12
Contributor I

Hi,

I use Codewarrior 10.6 with a coldifre MCF51CN128 and a multilink universal , and, when i use my 100 ms timer (defined well), it resets at 256 ms : here i toggle a led every 100 ms using that timer :

pastedImage_2.png

as you can see , it stays 150 ms high instead of 100ms.The problem seems to come from a reset of the module after 256 ms.

my code looks like this :

TPM2CNT = 0 ;        
TPM2SC_TOF = 0 ;
TPM2SC_CLKSx = 0x2;     //start 100 ms timer

LedBusy = 1 ;   // led set to high

while (TPM2SC_TOF != 1 ){}   // wait for the timer to end

TPM2SC_TOF = 0 ;   //clear flag

TPM2SC_CLKSx = 0 ;   //stop timer

LedBusy = 0 ;    // led set to low

TPM2CNT = 0 ; 
TPM2SC_TOF = 0 ; 
TPM2SC_CLKSx = 0x2;     //start 100 ms timer

while (TPM2SC_TOF != 1 ){}      // wait for the timer to end

TPM2SC_TOF = 0 ;    //clear flag

TPM2SC_CLKSx = 0 ;

any ideas of what could be the problem? thanks for your help !

Adrien Segura

0 Kudos
2 Replies

661 Views
TomE
Specialist II

Everything is wrong with your code. It has at least one bug per line of code. You should read the Reference Manual carefully as this timer does not work the way you think it does.

> TPM2CNT = 0 ;            This register is *READ ONLY*. You can't write to it.
> TPM2SC_TOF = 0 ;        This bit is *READ ONLY* You can't write to it. It clears when you READ TPM2SC
> TPM2SC_CLKSx = 0x2;  This does not reset-and-start the timer. It stops-and-restarts

Keep re-reading the chapter until you understand how this timer works. It is far more powerful and useful than the older ones that "count and reset". Otherwise, use the "Modulo Timer" which probably works the way you expect.


Tom

0 Kudos

661 Views
adrien_segura12
Contributor I

Ops ! i forgot something ! , if we do not see the timer reset a second time on the screenshot after 256 ms, it's due to my scope which is kinda bad. The timer does reset a second time on the second high state :

pastedImage_1.png

thanks for your help

0 Kudos