TPM interrupts

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

TPM interrupts

3,629 Views
e_ikom
Contributor I
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;
}
Labels (1)
0 Kudos
3 Replies

921 Views
e_ikom
Contributor I
thank you for your help.
0 Kudos

921 Views
Geezer
Contributor I
-You should clear the intterupt within the timer ISR, not from within your forever loop. See the code provided by JAH.
- if you want to see the LED blink change the code within your ISR to somethin like:
LED0 = ~LED0;
0 Kudos

921 Views
jah
Contributor I
my bad i did not look at your code, no time. please search for my postings a few months ago for details on how i did it.

if the processor is in a sleep mode that disables the clock the TPI, dependant on the clock, will be down and so this int will not wake the processor. but i dont have details on how the tpi is failing. i am basically using the tpi pin as an extra external interrupt in the code below. look it over if you will and if you need more details do the search but here is some details:

//in the begining of main.c
PTDD = 0x40; // pull port D pins low, except ptd6/tpm0input
PTDPE = 0xFF; // enable pullup's on all of portD
PTDDD = 0xBF; // All of Port D Data Direction set to OUTPUT 0xFF, except b6=input
DisableInterrupts;
//Timer Int Init mod timer interrupts, remove overflow, add outcput compare (1) and //input(0)
TPM1SC = 0x08; //setup common ch1&0 control reg, clr TPM1CNTx
//clock=bus, scale=1, pwm=off, overflow irq=off
TPM1C0SC=0x48; //set ch0 as input capture w/ irq
//irq=on, PTD6/TPM1CH0=in capture mode, +e&level.
TPM1C1SC=0x90; //set ch1 as output compare, irq=off,
//output compare=on, softwre compare=on.
TPM1C0SC = TPM1C0SC;//clr any pending input capture irq
TPM1C0SC &= 0x7F;
EnableInterrupts;

//int service routine
interrupt 5 void TPM1OutputCompare_ISR (void){
TPM1C1SC = TPM1C1SC; //2part irq reset.
TPM1C1SC &= 0x7F;
if(!timercounter) timertimeout++; //report irq status to main emulation .
timercounter--;
} //interrupt 5 void Timer...


//in my linker file *.prn
//*******************************>>> define unused interrupt vectors ****************************
//081906jmp, mod timer interrupts, remove overflow, add outcput compare (1) and input(0)
VECTOR 0 _Startup //reset vector: this is the default entry point for a C/C++ application
VECTOR 1 _Startup
//VECTOR 2 _Startup //used defined
VECTOR 3 _Startup
//VECTOR 4 _Startup //used defined
//VECTOR 5 _Startup //used defined
VECTOR 6 _Startup
VECTOR 7 _Startup
VECTOR 8 _Startup
VECTOR 9 _Startup
//VECTOR 10 _Startup //used defined
VECTOR 11 _Startup
//VECTOR 12 _Startup //used defined
VECTOR 13 _Startup
//VECTOR 14 _Startup //used defined
VECTOR 15 _Startup
//******************


i hope this gives you some thoughts onto your situation, good luck.
0 Kudos