AnsweredAssumed Answered

Data Coherency issue - MC9S08DZ60

Question asked by John Friede on Jul 17, 2009
Latest reply on Jul 22, 2009 by John Friede

Using the MC9S08DZ60 and utilizing overflow of TPM1 to generate an interrupt every 1ms for my time base.  I am having coherency issues when using a 16 bit (unsigned int) variable as a timer even though I stop interrupts before loading the number.  Looking at a port I toggle, I have proved that the high byte is being decremented occasionally before the low byte is loaded giving me 44ms (0x2c) instead of 300ms (0x12c). Below is a simplified example (COSMIC tools, not CodeWarrior).  I'm at my wits end and any suggestions would be appreciated.

 

void main(void)

{

  unsigned int x;

 

 while(1)

 {

    _asm("sei\n");

 

 

 

 

    x = 300;

    _asm("cli\n");

 

    while(x)

    {

       /* Do something */

    }

 }

 

}

 

@interrupt IntTime(void)

{

   TPM1SC &=0x7F;    //RESET INTERRUPT FLAG

 

   if(x) x--;

 

}

 

 

Added p/n to subject.

Message Edited by NLFSJ on 2009-07-17 03:35 PM
Message Edited by NLFSJ on 2009-07-17 03:36 PM
Message Edited by NLFSJ on 2009-07-17 03:37 PM

Outcomes