Timer question on MC9S08DZ60

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

Timer question on MC9S08DZ60

跳至解决方案
1,557 次查看
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.

标签 (1)
0 项奖励
回复
1 解答
969 次查看
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 项奖励
回复
2 回复数
970 次查看
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 项奖励
回复
969 次查看
Denikar
Contributor III

 

That did it. 

 

Thank you!

 

 

0 项奖励
回复