EmbeddedRelated.com
Forums

MSP430 variable corruption

Started by lewis October 31, 2006
Hi,
I am implementing a sensor network on a MSp40f1611 . I have a software
clock(unsigned long variable) that is used for the real time clock by
counting evrytime(50us) TimerB counts upto TBCCR0. Another variable is
used to deciede wake up/transmission times. The eproblem i am having
is that after a random number of seconds the variable that holds the
wakeup count gets cottupted and the timing goes haywire. Please advice.
Thanx in advance
Regards,
Lewis

Beginning Microcontrollers with the MSP430

>From: lewis
>Subject: [msp430] MSP430 variable corruption
>
>after a random number of seconds the variable that holds the
>wakeup count gets cottupted and the timing goes haywire. Please advice.

Lewis,

It sounds like a few possible issues are getting to you. This first would be that the stack is growing too large and no longer fitting in the space you've allotted for it. This could happen if you have a lot of subroutines that push registers and the like on the stack or if there's a routine that's getting called repeatedly and you're not returning from it.

Another possibility would be that you have a pointer (are you working in C?) that is just walking through your memory space.

Finally, there's the possibility that a DMA channel has gone awry and data is getting stuffed sequentially into memory until it trashes the variable.

You're likely looking at the memory when you see that this value is trashed (or are you just looking at a watch window?). Are values around it changed as well? that would point towards one of these issues, or something similar.

Good luck,

Rachel Adamec
Norristown, PA, USA
One scenario: An unsigned 32-bit long requires 2 16-bit instructions to copy or
compare. Possibly you are seeing a race between capturing or comparing the
current value outside the interrupt when the interrupt is triggered between
these two instructions, such that, for example, a missed roll-over between
low-16 bits and high 16-bits gives a ridiculous result. To avoid this - or test
this case - block the isr for the duration of the two instructions, remembering
that the result of the "disable interrupts" instruction (if that is what you
choose) is delayed one instruction cycle. Or better, to avoid disturbing the
isr, read the long multiple times outside the isr, and wait until you get the
same 32-bit value twice before using.

A similar problem can occur if interrupts are enabled inside the timer
interrupt and a higher priority interrupt does something with the value.

Hugh

--- lewis wrote:

> Hi,
> I am implementing a sensor network on a MSp40f1611 . I have a software
> clock(unsigned long variable) that is used for the real time clock by
> counting evrytime(50us) TimerB counts upto TBCCR0. Another variable is
> used to deciede wake up/transmission times. The eproblem i am having
> is that after a random number of seconds the variable that holds the
> wakeup count gets cottupted and the timing goes haywire. Please advice.
> Thanx in advance
> Regards,
> Lewis
Another scenario if you are working in C would be a bad array. If you
try to write to an array location outside of the array it can corrupt a
seemingly random variable.

For example

unsigned int myarray [10]

for (counter = 0; counter ++; counter <= 10)

{

myarray[counter] = 1;

}

Would write 1 into each location of the array as well as one extra 1 to
a location outside of the array stomping on some random variable. Last
I checked, the compiler would not give a warning about this.

Dan

________________________________

From: m... [mailto:m...] On Behalf
Of Hugh Molesworth
Sent: Tuesday, October 31, 2006 2:46 PM
To: m...
Subject: Re: [msp430] MSP430 variable corruption

One scenario: An unsigned 32-bit long requires 2 16-bit instructions to
copy or
compare. Possibly you are seeing a race between capturing or comparing
the
current value outside the interrupt when the interrupt is triggered
between
these two instructions, such that, for example, a missed roll-over
between
low-16 bits and high 16-bits gives a ridiculous result. To avoid this -
or test
this case - block the isr for the duration of the two instructions,
remembering
that the result of the "disable interrupts" instruction (if that is what
you
choose) is delayed one instruction cycle. Or better, to avoid disturbing
the
isr, read the long multiple times outside the isr, and wait until you
get the
same 32-bit value twice before using.

A similar problem can occur if interrupts are enabled inside the timer
interrupt and a higher priority interrupt does something with the value.

Hugh

--- lewis > wrote:

> Hi,
> I am implementing a sensor network on a MSp40f1611 . I have a software

> clock(unsigned long variable) that is used for the real time clock by
> counting evrytime(50us) TimerB counts upto TBCCR0. Another variable is

> used to deciede wake up/transmission times. The eproblem i am having
> is that after a random number of seconds the variable that holds the
> wakeup count gets cottupted and the timing goes haywire. Please
advice.
> Thanx in advance
> Regards,
> Lewis
Hi,
Thnx for the suggestions.i guess i have a errrant array index as i
am using too many arrays.Will check all my indices
Thanx ,
Lewis
--- In m..., "Dan Muzzey" wrote:
>
> Another scenario if you are working in C would be a bad array. If
you
> try to write to an array location outside of the array it can
corrupt a
> seemingly random variable.
>
>
>
> For example
>
> unsigned int myarray [10]
>
> for (counter = 0; counter ++; counter <= 10)
>
> {
>
> myarray[counter] = 1;
>
> }
>
> Would write 1 into each location of the array as well as one extra
1 to
> a location outside of the array stomping on some random variable.
Last
> I checked, the compiler would not give a warning about this.
>
>
>
> Dan
>
>
>
>
>
>
>
> ________________________________
>
> From: m... [mailto:m...] On
Behalf
> Of Hugh Molesworth
> Sent: Tuesday, October 31, 2006 2:46 PM
> To: m...
> Subject: Re: [msp430] MSP430 variable corruption
>
>
>
> One scenario: An unsigned 32-bit long requires 2 16-bit
instructions to
> copy or
> compare. Possibly you are seeing a race between capturing or
comparing
> the
> current value outside the interrupt when the interrupt is triggered
> between
> these two instructions, such that, for example, a missed roll-over
> between
> low-16 bits and high 16-bits gives a ridiculous result. To avoid
this -
> or test
> this case - block the isr for the duration of the two instructions,
> remembering
> that the result of the "disable interrupts" instruction (if that
is what
> you
> choose) is delayed one instruction cycle. Or better, to avoid
disturbing
> the
> isr, read the long multiple times outside the isr, and wait until
you
> get the
> same 32-bit value twice before using.
>
> A similar problem can occur if interrupts are enabled inside the
timer
> interrupt and a higher priority interrupt does something with the
value.
>
> Hugh
>
> --- lewis > wrote:
>
> > Hi,
> > I am implementing a sensor network on a MSp40f1611 . I have a
software
>
> > clock(unsigned long variable) that is used for the real time
clock by
> > counting evrytime(50us) TimerB counts upto TBCCR0. Another
variable is
>
> > used to deciede wake up/transmission times. The eproblem i am
having
> > is that after a random number of seconds the variable that holds
the
> > wakeup count gets cottupted and the timing goes haywire. Please
> advice.
> > Thanx in advance
> > Regards,
> > Lewis
>
>
>
>
>