AnsweredAssumed Answered

MC9S08QE16 slow timer startup

Question asked by June on May 6, 2014
Latest reply on May 6, 2014 by iansmusical

Hi,

I'm using MC9S08QE16 microprocessor. I noticed that upon startup and initialization, the timer interrupts take a long time to be up and running. Based on my measurements, Timer2 takes approximately 4s and Timer3 takes approximately 8s to be up and running. 

 

In the attached screen capture, I can see that all initialization routines completed within 435ms upon power up. However, the first Timer2 interrupt (WDI timer on the screen capture) fired 4.435s later. I appreciate some advice on what is causing the slow startup of the timers. Thanks!

 

The initialization routines as follows:

 

void main(void) {

  //Put this into initialisation if you want

  MCU_init();

  PTCD_PTCD6 ^= 1;

  Timer1_Module_Init();

  PTCD_PTCD6 ^= 1;

  Timer2_Module_Init();

  PTCD_PTCD6 ^= 1;

  Timer3_Module_Init();

  PTCD_PTCD6 ^= 1;

  Power_Supply_Detect();

  PTCD_PTCD6 ^= 1;

  RelayInfo_Init();

  State_Machine_Init();

 

  KBI_Module_Init();

  ResetTimeoutTimer();

  PTCD_PTCD6 ^= 1;

 

  EnableInterrupts

  for (;;)

  {

  }

}

 

 

The following are the MCU init and Timer module init routines:

 

void MCU_init(void)

{

/* Select "Generate Code" to create initialization code here */

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

  SOPT2  = 0x90;                          // TPM2CH2 on PTC1, TPM1CH2 on PTC0

  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 */

 

  PTASE = 0x00u;

  PTADS = 0x00u; 

  PTAPE = 0x00u;

   

  PTADD = (uint8)0xC0u;

  PTBDD = (uint8)0x10u;

  PTCDD = (uint8)0xCFu;

  PTDDD = (uint8)0xFFu;

  PTEDD = (uint8)0x80u;

}

 

void

Timer1_Module_Init( void )

{

/* Channel 0 for state machine */

  TPM1SC = 0x0Eu;           /* bus clock, prescaler = 64 */ 

  TPM1C0SC = 0x10u;         /* don't enable channel 0 interrupt first, software output compare only */ 

  TPM1C0V = 205u;                 /* 12.5ms */

 

/* Channel 1 for 2ms delay before re-enabling KBI to prevent glitches */

  TPM1C1SC = 0x10u;         /* don't enable channel 1 interrupt first, software output compare only */ 

  TPM1C1V = 99;                   /* 6ms */

 

 

  /* Channel 2 for 1sec communication timeout */

  TPM1C2SC = 0x10u;         /* don't enable channel 2 interrupt first, software output compare only */ 

  TPM1C2V = 16384;                /* 1sec */

}

 

 

/*++

**==============================================================================

** Initialize Timer 2 Module's registers.

**    This timer is in charge of just counting for the time outs and setting

**    flags along the way.

** Called with      : nothing

** Returns          : nothing

** Global variables : TPM2 registers

**==============================================================================

*--*/

void

Timer2_Module_Init( void )

{

  TPM2SC = 0x00u;

  TPM2C2SC = 0x00u;

  TPM2C2V = 164u;                 /* 10ms */

  TPM2CNT = 0x00u;          /* clear the counter */   

  TPM2SC = 0x0Eu;           /* bus clock, prescaler = 64 */ 

  TPM2C2SC = 0x50u;         /* enable channel 2 interrupt, software output compare only */ 

}

 

/*++

**==============================================================================

** Initialize Timer 3 Channel 5 Module's registers.

**    This timer is in charge of LED time division

** Called with      : nothing

** Returns          : nothing

** Global variables : TPM3 registers

**==============================================================================

*--*/

void

Timer3_Module_Init( void )

{

  TPM3SC = 0x00u;

  TPM3C5SC = 0x00u;

  TPM3C5V = 41u;                  /* approximately 4ms */

  TPM3CNT = 0x00u;          /* clear the counter */   

  TPM3SC = 0x0Fu;           /* bus clock, prescaler = 128 */ 

  TPM3C5SC = 0x50u;         /* enable channel 5 interrupt, software output compare only */

      

}

Attachments

Outcomes