Timer question on MC9S08DZ60

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

Timer question on MC9S08DZ60

Jump to solution
1,132 Views
Denikar
Contributor III

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.

Labels (1)
0 Kudos
Reply
1 Solution
544 Views
kef
Specialist I

    /* Enable irq on timer 1 channel 0

    Edge level bits set to 00
    MSB MSA bits set to 00 */
    TPM1C0SC = 0x40;

 

MSB:MSA = 0:0 is input capture mode. You need output compare mode with timer channel not connected to pin. Output compare mode is selected when  MSB:MSA=0:1 and  ELSB:ELSA=0:0 disconnects pin from timer.

 

View solution in original post

0 Kudos
Reply
2 Replies
545 Views
kef
Specialist I

    /* Enable irq on timer 1 channel 0

    Edge level bits set to 00
    MSB MSA bits set to 00 */
    TPM1C0SC = 0x40;

 

MSB:MSA = 0:0 is input capture mode. You need output compare mode with timer channel not connected to pin. Output compare mode is selected when  MSB:MSA=0:1 and  ELSB:ELSA=0:0 disconnects pin from timer.

 

0 Kudos
Reply
544 Views
Denikar
Contributor III

 

That did it. 

 

Thank you!

 

 

0 Kudos
Reply