AnsweredAssumed Answered

Timer question on MC9S08DZ60

Question asked by Tom Harvey on Nov 28, 2010
Latest reply on Nov 28, 2010 by Tom Harvey

Hi All,

 

I'm trying to setup a general purpose timer on the MC9S08DZ60.  I do not want it tied to pin control as I have the pins assigned to other non-timer related I/O.

 

Below is a snippet of my code:


#define    TPM1CH0IRQTIME    400    // Set timer 1 freq to 100us

...

    /* Setup timer status and control register A
    b6 = 0 TOIE disable overflow interrupts
    b5 = 0 CPWMS no PWM mode
    b4:b3 CLKSB:CLKSA = 01 sets clock source to bus clock
    b2:b0 PS2:smileytongue:S0 = 000 sets prescale to divide by 1 */
  TPM1SC = 0x08;    

    /* Enable irq on timer 1 channel 0

    Edge level bits set to 00
    MSB MSA bits set to 00 */
    TPM1C0SC = 0x40;
    
    /* Setup initial irq trigger time on timer 1 ch 0 */
    TPM1C0V = TPM1CNT + TPM1CH0IRQTIME;

    /* Clear any pending timer interrupts */
    TPM1SC &= 0x7F;  
    TPM2SC &= 0x7F;  

    TPM1C0SC &= 0x7F;  
    TPM1C1SC &= 0x7F;  
    TPM1C2SC &= 0x7F;  
    TPM1C3SC &= 0x7F;  
    TPM1C4SC &= 0x7F;  
    TPM1C5SC &= 0x7F;  

    TPM2C0SC &= 0x7F;  
    TPM2C1SC &= 0x7F;  
 
...

@interrupt void tpm1ch0_irq(void)
{
    /* Timer 1 channel 0 interrupt service routine
       Used to generate system base time
       Increments free running counter every 100us */

    /* Clear timer irq flag */
    TPM1C0SC &= 0x7F;  

    TPM1C0V = TPM1CNT + TPM1CH0IRQTIME;    /* Reset trigger time */

    t100us++;                                /* Increment 100us timer */
    if(t100us >= 10)                /* Every 1ms (10*100us)  */
    {
      /* Increment the free running 1msec counter, let it overflow */
      ulFreeRunningCounter++;
      if(ulFreeRunningCounter == 0)
          uwOverflowCounter++;    /* Overflow occurred, inc counter */
        t100us = 0;                        /* Reset t100us timer */
    }

}    /* end tpm1ch0_irq */

 

Problem is the irq will not fire at all.  Any ideas as to why?  Please note I am clearing the main interrupt flag (via CLI) prior to starting the main routine.

 

Thanks in advance.

Outcomes