MC9S12NE64 timers

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

MC9S12NE64 timers

2,188 次查看
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.

标签 (1)
0 项奖励
回复
5 回复数

1,005 次查看
Mampaey
Contributor I

Hi

 

 

This code should make a LED twinkle.

 

In fact, the LED isn't.

 

Thanks.

0 项奖励
回复

1,005 次查看
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 项奖励
回复

1,005 次查看
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 项奖励
回复

1,005 次查看
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 项奖励
回复

1,005 次查看
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 项奖励
回复