Trouble getting PIT to work

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

Trouble getting PIT to work

Jump to solution
1,875 Views
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

Labels (1)
Tags (1)
0 Kudos
Reply
1 Solution
1,158 Views
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) {

...

View solution in original post

0 Kudos
Reply
2 Replies
1,159 Views
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 Kudos
Reply
1,158 Views
campbellig
Contributor I

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

 

Ian

 

 

0 Kudos
Reply