Danny Sprogis

MC9S08GT60 Timer interrupt modulo problem...

Discussion created by Danny Sprogis on May 18, 2006
Latest reply on May 29, 2006 by Danny Sprogis
I am currently developing software for the MC9S08GT60 and i am trying to implement timer interrupts. I am using TPM1. i have set CPWMS to 0 which enables the counter as a simple up counter and i have enabled TOIE. i have my code entering the interrupt service routine (vector location 8) upon timer oferflow from 0xffff to 0x0000 but i cannot manage to get it to overflow on my software determined modulo value... in my understanding it is a simple procedure of writing to the modulo value registers (TPM1MODL and TPM1MODL ) to enable the modulo overflow interrupt. (i.e. interrupt and reset to 0x00 after my count value rather than the overflow from 0xff to 0x00) I am ovoiding using the Channels because it seems overcomplicated for my application especially when im sure its possible to trigger the int on modulo overflow!
i have included the basics of the code i am using. please feel free to scrutanise  as i would love to know a solution. obviously there are fragments of code missing but the register set up should be as shown
my intentions are this:
*enable external interrupts on PORTA bit 7
*enable internal timer interrupts with a modulo value
*change the modulo value dependant on variable (set elsewhere) and the externally generated interrupt
*do stuff when the timer reaches that modlo value (which is a certain time after the external interrupt decided by the variable)
*return to normal code and wait for the next external interrupt
PLEASE HELP ME ENABLE THE MODULO OVERFLOW INTERRUPT instead of interrupting after 0xffff
#include <hidef.h>        /* for EnableInterrupts macro */
#include <MC9S08GT60.h>   /* include peripheral declarations */
#include <Demo_1.h>
#include <UART.h>         /* include UART initialisation*/

#define PRESCALER 0
int i = 0;
int value = 0;
int flag = 0;


interrupt EXTERNAL_INT void ext_int()

DisableInterrupts;                // disable interrupts
  TPM1CNT = 0x00;      // reset timer to zero (any write to TPM1CNT does this)
    TPM1MOD = 0xffff; // write modulo value
  TPM1SC_TOIE = 1;             // timer interupt on overflow enabled
EnableInterrupts;               // enable interrupts
 KBI1SC_KBACK = 1;               // acknowlege interrupt
}                                 // RTI

interrupt INTERNAL_TMR_INT void TMR1_int()
// DO STUFF HERE when modulo expires
  TPM1SC_TOF = 0;               // clear timer overflow flag
  TPM1SC_TOIE = 0;              // timer interupt overflow disabled
}                                 // RTI

void main(void) {
SOPT_COPE = 0;                    // disable watchdog


PTADD_PTADD7 = 0;         // initalise bit 7 of port A as input 
PTAPE = 0xff;                      // enable pullups on PORTA      
KBI1PE_KBI1PE7 = 1;             // enable portA pin 7 as input with keyboard int
KBI1SC_KBI1E = 1;         // enable keyboard interrupts

/*Initalise timer TPM1 channel, asssume not touched since reset*/
TPM1SC_CLKSA = 1;                 // select bus clock (4MHz)  (B:A = 0:1)
TPM1SC_CPWMS = 0;                 // 16bit counter is set to count up from 0x00 ot 0xff or to modulo  (i.e. PWM disabled)
TPM1SC_TOIE = 1;                  // timer interupt on overflow enabled
TPM1SC_PS = PRESCALER;      // set clock divider 4Mhz when 0
EnableInterrupts;                 // enable interrupts
  /* loop forever */