MC9S12DG256B Timer Interrupt

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

MC9S12DG256B Timer Interrupt

867件の閲覧回数
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

ラベル(1)
0 件の賞賛
2 返答(返信)

343件の閲覧回数
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 件の賞賛

343件の閲覧回数
kef
Specialist I

65536 of what? Timer ticks or count variable increments?

 

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

0 件の賞賛