AnsweredAssumed Answered

MC9S08QE16: Problem when Timer is re-enabled

Question asked by June on Apr 22, 2014
Latest reply on Apr 24, 2014 by iansmusical

Hi, i'm having problem when re-enabling timer 1. Here's the problem:

/// This code doesn't work. TPM1C1V doesn't get updated - when i stepped through the assembly code, this register was supposed to get updated, but in the register watch window, it was not.
interrupt VectorNumber_Vtpm1ch1 void Timer_TPM1Channel1SMIrq (void)
{
  TPM1C1SC &= 0x7fu;        /* clear interrupt flag */
  TPM1C1SC &= ~0x40;  /* Disable interrupt.  */
  TPM1C1V = TPM1CNT + 98u; /* 6ms */
  TPM1C1SC |= 0x40u;         /* enable channel 1 interrupt */ 
  PTED_PTED7 ^= 1;
}

/// When i remove the disable  / enable portion, it worked:
interrupt VectorNumber_Vtpm1ch1 void Timer_TPM1Channel1SMIrq (void)
{
  TPM1C1SC &= 0x7fu;        /* clear interrupt flag */
  TPM1C1V = TPM1CNT + 98u; /* 6ms */
  PTED_PTED7 ^= 1;
}

 

/// The timer clock is sourced from bus clock with prescaler of 64.
/// Bus clock is from FLL output with external oscillator (32768Hz) enabled. Here's the initialization code:

  SOPT1  = 0x23;                          // Disable COP, enable STOP,BKGD,RESET
  SOPT2  = 0x90;                        

  SPMSC1 = 0x00;                          // Disable LVD
  SPMSC2 = 0x80;                         
  SPMSC3 = 0x00;                          // Disable LVWIE, low trip points
  SCGC1 = 0xE8u;                          /* Enable bus clock to TPM1,2,3. Bit 3 must be 1 per datasheet. */            
  SCGC2 = 0x32u;                          /* Enable bus clock to IRQ and KBI. Bit 1 must be 1 per datasheet. */
  ICSC1 = 0x00;       /* FLL selected */
  ICSC2 = 0xCF;       /* Bus frequency diver = 8 */
  ICSSC = 0x00;       /* DCO low range selected */

/// Here's the timer 1 initialization code:

  TPM1SC = 0x00u;
  TPM1C1SC = 0x00u;
  TPM1C1V = 205u;    /* 12.5ms */
  TPM1SC = 0x0Eu;           /* bus clock, prescaler = 64 */ 
  TPM1C1SC = 0x50u;         /* don't enable channel 1 interrupt first, software output compare only */ 


Appreciate some advice on what's wrong with re-enabling the timer. Thanks.

Outcomes