tom fire

TPM interrupts

Discussion created by tom fire on Nov 6, 2006
Latest reply on Nov 15, 2006 by tom fire
Hi,
I am using MC9S08RD16. I want to use TPM interrupts. I was unable to get them. I send my written code.
What is problem in my code?
thank you.

#include <hidef.h> /* for EnableInterrupts macro */
#include "derivative.h" /* include peripheral declarations */    
#include "utility.h"
 
/*define value for led's when on and off*/
#define ON 0
#define OFF 1

/*define value for switches when up (not pressed) and down (pressed)*/
#define UP 1
#define DOWN 0
 
/*define led's*/
#define LED1 PTBD_PTBD0
#define LED2 PTBD_PTBD1
#define LED3 PTBD_PTBD2
#define LED4 PTCD_PTCD0
#define LED5 PTCD_PTCD1
#define PRESCALAR 7
#define MODULUS   32768
 

void main(void) {
 
 EnableInterrupts; /* enable interrupts */
 /* include your code here */
 SOPT_COPE=0;
 
 //Port initial
 PTAPE=0xFF;
 PTBPE=0x00;
 PTCPE=0x00;   //0b00000000;
 PTDPE=0x00;
 
 // Data Directions
 PTADD=0x00;
 PTBDD=0xff;   // all output
 PTCDD=0xff;
 PTDDD=0xff;
 
 //Pullups on upper 4 bits
 PTAPE = 0xf0;
 // Led off
 LED1 = OFF;
 LED2 = OFF;
 LED3 = OFF;
 LED4 = OFF;
 LED5 = OFF;   
 
  
 //Initialize timer TPM1 channel, assumes not touched since reset!
 TPM1SC_PS    = PRESCALAR; //clock source divided by prescalar
 TPM1MOD      = MODULUS;
 TPM1SC_TOIE  = 1;
 TPM1SC_TOF   = 0;
   
 //TPM1C0SC_ELS0A = 1; //Select the output compare low
 //TPM1C0SC_MS0B  = 1; //MS0B=1, MS0A=0; << for edge align PWM
 
 TPM1SC_CLKSA = 1;//Select BUS clock
 TPM1SC_CLKSB = 0;
   
 while (1) { 
 
   __RESET_WATCHDOG(); 
      
   if (TPM1SC_TOF) {
     TPM1SC_TOF = 0; 
   }
 }  
 
}
interrupt Vtpm1ovf void intSW1(){
 LED1 = ON;
}

Outcomes