Data Coherency issue - MC9S08DZ60

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

Data Coherency issue - MC9S08DZ60

Jump to solution
2,894 Views
jafriede
Contributor II

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
Labels (1)
0 Kudos
Reply
1 Solution
1,364 Views
jafriede
Contributor II

Mac,

  You somewhat indirectly solved my problem.  I was getting a "bad addressing mode" error when trying your ldhx example.  I finally figured out there is a "+hcs" option that needs to be set with the Cosmic compiler to generate hc08 code.  Thank you very much!

View solution in original post

0 Kudos
Reply
5 Replies
1,364 Views
bigmac
Specialist III

Hello,

 

While I am not familiar with the Cosmic compiler, and the way it handles local variables declared within main(), I would not expect your code to work.  With CW compiler, the variable x would need to be a global variable for the ISR function to have visibility of this variable.  The variable should also be declared as volatile because the ISR code does write to the variable.

 

Regards,

Mac

 

0 Kudos
Reply
1,363 Views
jafriede
Contributor II

Mac,

  You are absolutely right.  I was typing this out late Friday before I went home and messed it up.  The variable is global and declared as volatile.  My purpose was just to show the basic framework of what I'm trying to accomplish.

 

Thanks

0 Kudos
Reply
1,363 Views
jafriede
Contributor II
I trhink we have a misunderstanding.  The solution is not accepted.  The typos were in my post, not with my application code.  Problem is still there.  Do I need to start a new thread?
0 Kudos
Reply
1,363 Views
bigmac
Specialist III

Hello,

 

Since the low byte must be already zero for the high byte to decrement, you might try first loading a dummy value with non-zero low byte, and then immediately load the required value.  But this shouldn't be necessary if interrupts are actually being disabled prior to the write. Perhaps this might be a problem with the compiler.  Is it possible to view the assembly code that the compiler is generating?

 

Data coherency should not be an issue if the word value is written with a single assembly instruction, i.e.

ldhx #0x012C 

sthx xvar

 

Perhaps you should do some further tests by creating a very simple CW project, and see if the problem still persists.  If it does, you can then open a Service Request with Freescale.


Regards,

Mac

0 Kudos
Reply
1,365 Views
jafriede
Contributor II

Mac,

  You somewhat indirectly solved my problem.  I was getting a "bad addressing mode" error when trying your ldhx example.  I finally figured out there is a "+hcs" option that needs to be set with the Cosmic compiler to generate hc08 code.  Thank you very much!

0 Kudos
Reply