Trouble getting PIT to work

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

Trouble getting PIT to work

跳至解决方案
1,843 次查看
campbellig
Contributor I

Hello,

 

I'm new to codewarrior and microcontrollers in general.  I'm currently trying to get a periodic interrupt with on a DEMO9S12XDT512 board (which has the MC9S12XDT512CAA chip).  I'm writing the program in C using codewarrior IDE version 5.7.0.

 

The code I'm using is as follows:

 

#include <hidef.h>      
#include <mc9s12xdt512.h>
#include <stdio.h>
#include <math.h>
#pragma LINK_INFO DERIVATIVE "mc9s12xdt512"

int count = 0;

void main (void) {
          
  PITCE    = 0x01;
  PITINTE  = 0x01;
  PITMTLD0 = 0xFF;
  PITMTLD1 = 0xFF;
  PITLD0 = 0x00;
  PITLD1 = 0x00;
 
  PITCFLMT = 0x80;
  EnableInterrupts;         
 
  for(;:smileywink: {
 
  }
}
 
 interrupt 0x7A void timer_int() {
    count++;

    PITTF = 0x01;
  }

 

The problem I'm having is that whenever I run the code the de-bugger will stop and I'll be told I have an illegal breakpoint.  As far as I'm aware this means that my interrupt is either not being called at all or is not being reset properly.

 

I'm confident it is PITTF that will reset the interrupt flag, however I'm not sure of the interrupt number (I believe its refered to as a vector?) is correct.

 

Looking in the manual I noticed the accociated vector address for PIT0 is "vector base + 0x7A", which is why I chose 0x7A although this is largely just a guess.  I have read through a number of threads which suggest that the vector table might not be set up correctly, however I have used some example code with an almost identical interrupt which does not do this and functions correctly(although if this were the problem however, I would I go about setting it up correctly in C?).

 

Thank you for any help.

 

Ian

标签 (1)
标记 (1)
0 项奖励
回复
1 解答
1,126 次查看
kef
Specialist I

Here

 

interrupt N void timer_int() {

 

N is interrupt vector number, counting from the top address vector. N=0 is reset vector, N=1 is CME vector etc.

 

You speciefied 0x7A. That's lower byte of PIT0 vector address, not vector number. PIT0 vector number is 66. But better use vector number define from the header file.

 

interrupt VectorNumber_Vpit0 void timer_int(void) {

...

在原帖中查看解决方案

0 项奖励
回复
2 回复数
1,127 次查看
kef
Specialist I

Here

 

interrupt N void timer_int() {

 

N is interrupt vector number, counting from the top address vector. N=0 is reset vector, N=1 is CME vector etc.

 

You speciefied 0x7A. That's lower byte of PIT0 vector address, not vector number. PIT0 vector number is 66. But better use vector number define from the header file.

 

interrupt VectorNumber_Vpit0 void timer_int(void) {

...

0 项奖励
回复
1,126 次查看
campbellig
Contributor I

Ah, excellent, that sorted everything.  Thank you very much for your help.

 

Ian

 

 

0 项奖励
回复