MC9S12DG256B Timer Interrupt

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

MC9S12DG256B Timer Interrupt

992 Views
Josrodmar
Contributor I

Hi, I'm a learning student currently working with the MC9S12DG256B in codewarrior, and I have a few questions in regards of interrupts in C.

 Down below there is a program I found out that basically use the timer overflow to interrupt and increment count everytime it sees an overflow. The main problem is the program hangs up after 65536, I wanna know if there is something else that I need to configure to get this working.

THX

 

#include <hidef.h>      /* common defines and macros */
#include <mc9s12dg256.h>     /* derivative information */


#pragma LINK_INFO DERIVATIVE "mc9s12dg256b"


volatile unsigned int count;
void main(void) {
  /* put your own code here */
 
  TSCR1=0X80;//enable timer
  TSCR2=0x80;  //select prescler bus
  TFLG2=0x80;// clear timer flag
 
  EnableInterrupts;
 
  for(;:smileywink:
  {
 
  } /* wait forever */
}

#pragma CODE_SEG NON_BANKED

interrupt void _Timerovf(void)
{


 TFLG2 = 0x80;// clear the interrupt flag
 
 count++; //increment counter
   
}   
#pragma CODE_SEG DEFAULT

Labels (1)
0 Kudos
Reply
2 Replies

468 Views
vishaka_maithil
Contributor I

Hi dear,

 

Firstly, try to understand the module properly by going through the datasheet for timer system.

There are vector numbers associated with every interrupt and it  is 16 for timeroverflow.You can write it in the fashion below,

 interrupt 16 void ISR_TIMOVF(void)

Also keep in mind that hexadecimal system 0x00 shall be followed while configuring the registers, However, individual bits can be set .

One more thing, it is not just enough to include a word EnableInterrupts but set the timer interrupt bit.

For more on this timing system, refer Embedded Systems-Design and Application for 68HC12 and HCS12 book by Steven F Barret and Daniel J Pack.

ALL THE BEST ! 

0 Kudos
Reply

468 Views
kef
Specialist I

65536 of what? Timer ticks or count variable increments?

 

Did you set up vector table entry for timer overflow interrupt?

0 Kudos
Reply