AnsweredAssumed Answered

Trouble getting PIT to work

Question asked by Ian Campbell on Apr 11, 2010
Latest reply on Apr 12, 2010 by Ian Campbell



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;
  for(;:smileywink: {
 interrupt 0x7A void timer_int() {

    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.