MC9S12NE64 timers

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

MC9S12NE64 timers

2,211 Views
Mampaey
Contributor I

Hi everyone,

 

I have many problems with timers.

 

could someone tell me what I have to do to have a timer wich reset and works forever, with interrupts.

 

 

Thanks.

Labels (1)
0 Kudos
Reply
5 Replies

1,028 Views
Mampaey
Contributor I

Hi

 

 

This code should make a LED twinkle.

 

In fact, the LED isn't.

 

Thanks.

0 Kudos
Reply

1,028 Views
Mampaey
Contributor I
#include <MC9S12NE64.h>     /* derivative information */#include "lib.h"#include "Cpu.h"static long absoluteTime = 0;static long absoluteTimeUp = 0;static long msDelai = 0;static int b=1;static void startTimeBase(void){  absoluteTime = 0;  msDelai=500;  absoluteTimeUp=absoluteTime+msDelai;  }volatile unsigned int count;#pragma CODE_SEG NON_BANKEDinterrupt void _Vtimovf (void) { int i =0; absoluteTime++;                  //i=setPortPinValue('g', 0, ON); TFLG2 = 0x80;// clear the interrupt flag   count++; //increment counter   }   #pragma CODE_SEG DEFAULTvoid main(void) {int i =0;  /* put your own code here */   TSCR1=0X80;//enable timer   TSCR2=0x85;  //select prescler bus clock/32  TFLG2=0x80;// clear timer flag    i=setPortPinDirection('g', 0, OUTPUT);  i=setPortPinDirection('h', 0, INPUT);  PTG_PTG0 =1;  //i=setPortPinValue('g', 0, OFF);  startTimeBase();  EnableInterrupts;   while(1)   {    while(absoluteTimeUp>absoluteTime)    {   }         absoluteTime=0;      if(b==0)       {        b=1;                i=setPortPinValue('g', 0, OFF);      }      else       {        b=0;                i=setPortPinValue('g', 0, ON);      }               } /* wait forever */}

 

here is my code

0 Kudos
Reply

1,028 Views
kef
Specialist I

Why then i=setPortPinValue('g', 0, ON); line is commented out?

 

 

Did you initialize interrupt vectors table properly? Is there some dedicated *.c module with interrupts table defined? Maybe set interrupt vectors in *.prm file? If not then you should change timer overflow ISR like this:

 

interrupt VectorNumber_Vtimovf void _Vtimovf (void)

{

...

}

 

 

0 Kudos
Reply

1,028 Views
isionous
Contributor III

What do you want the code to do and what does the code actually do?

 

One suggestion so far, make your global variables volatile since they are being used by more than one thread.

0 Kudos
Reply

1,028 Views
isionous
Contributor III

You should probably post your code in order for us to help you.  Also, you might want to look at http://users.ece.utexas.edu/~valvano/Starterfiles/ which has plenty of starter code for timers if you search for "output compare" on the page.

0 Kudos
Reply