Problem with m9s12ne64 timer

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

Problem with m9s12ne64 timer

1,255 Views
Mahmoud
Contributor I
I can't understand how can i make o/p compare , I wrote a function which make time delay
 
void delay(void){
 TIOS_IOS4 = 1;   // timer 4 output compare
    TSCR2_PR = 7;    // prescaler 0 : 25Mhz
    TIE_C4I = 0;     // interrupt 4 enable
    TSCR1_TSFRZ = 1; // disable timer in freeze mode
    TC4 = 0xfffc;
    TSCR1_TEN = 1;   // enable timer
   while(TFLG1_C4F =0 );
   TSCR1_TEN = 0;  //disable timer
}
 
 
but it didn't and i don't know why , please if any one read this and find the problem reply to me
Labels (1)
0 Kudos
Reply
1 Reply

645 Views
JimDon
Senior Contributor III
TIE_C4I = 0;
You set this to 1 to enable the interrupt.
"The bits in TIE correspond bit-for-bit with the bits in the TFLG1 status register. If cleared, the corresponding flag is disabled from causing a hardware interrupt. If set, the corresponding flag is enabled to cause a interrupt"

while(TFLG1_C4F =0 );  You mean '=='

if  you learn to write:
while(  0 == TFLG1_C4F  ); Then the compiler will flag this common error.

 TC4 = 0xfffc;  I think you want TC4 = TCNT + mydelay;
Otherwise you will get a random delay depending upon the value of TCNT.

TSCR2_PR = 7;    // prescaler 0 : 25Mhz (7= Divide by 128)
You should set the prescaler before you need to use the delay:
"The newly selected prescale factor will not take effect until the next synchronized edge where all prescale counter stages equal zero."




Message Edited by JimDon on 2008-01-27 09:50 AM
0 Kudos
Reply