cancel
Showing results for 
Search instead for 
Did you mean: 

What is going on?

sarling
Associate II
Posted on April 06, 2009 at 14:02

What is going on?

16 REPLIES 16
sarling
Associate II
Posted on May 17, 2011 at 13:08

So, I have a strange problem. I have an array that is filling it self with strange values. I'm using two global arrays and I fill them with values and send the values via USB to a PC where I plot them. The size of the arrays are 1000 and the type is short:

Code:

short acc_y[1000];

short vel_y[1000];

If I use a loop:

Code:

for (i = 0; i < 1000; i++) {

vel_y[i] = buf[i];

acc_y[i] = buf[i];

}

The result will be like in the plot1, what's wrong with vel_y? Even if I assign both arrays to zero there are still those strange values between index 163- But not acc_y. The red line is acc_y and the blue line is vel_y.

Plot1:

http://home.aland.net/masa/plot1.jpg

If I do like this:

Code:

for (i = 0; i < 1000; i++) {

//vel_y[i] = buf[i];

acc_y[i] = buf[i];

}

*vel_y = *buf;

The result is:

http://home.aland.net/masa/plot2.jpg

Any ideas? I'm clueless.

briand.myers9
Associate II
Posted on May 17, 2011 at 13:08

In general, if you don't know what is going on, gather more data.

You say you transfer the data via USB to PC for plotting. Do you know if your data looks good before passing it to the PC? I would do something like this : Fill your buffers with some known data - a specific byte-value, or an incrementing pattern maybe; whatever. Add some test code to check the values in your arrays, before passing it to the PC. If it's good, you might suspect that your data is not being passed to the PC correctly. If it's not good, step through your code and watch what's happening as it happens.

trevor1
Associate II
Posted on May 17, 2011 at 13:08

Can you also show how ''buf'' is created and how it is assigned its data?

sarling
Associate II
Posted on May 17, 2011 at 13:08

I have output the data on an LCD and I get the same numbers. I have also made checks in the code when these large positive numbers fill the array, to me it looks like some form of memory corruption. But I don't know, because the same pattern repeats every time I fill the array, regardsless of what I fill it with.

If you have any idea what I should check for, please share.

Anyone have any ideas?

andreas2
Associate II
Posted on May 17, 2011 at 13:08

Does the pattern shift if you move the vel_y array in memory (by for example making acc_y 1100 elements)? If it doesn't, search your code for references to vel_y, maybe some old debug code lying around.

Check your interrupt routines if they write to memory. Make sure they don't have some hard coded pointer values. Do you use DMA? Is it set up correctly?

sarling
Associate II
Posted on May 17, 2011 at 13:08

@andreas1: It doesn't shift if I set acc_y[1100], but if I declare vel_y[1100], the pattern is shifted right to index 263-282 (+100). I did use DMA for ADC but I disabled it and no change. I also use SysTick_Handler for data sampling, but before I do anyt

sarling
Associate II
Posted on May 17, 2011 at 13:08

I found something interesting, if declare my global variables like this, the problem occurs:

Code:

<BR><BR>const u16 SMPL = 1000; <BR><BR>short acc_y[SMPL]; <BR><BR>short acc_x_raw[SMPL+16]; <BR><BR>short acc_y_raw[SMPL+16]; <BR><BR>short acc_z_raw[SMPL+16]; <BR><BR>short vel_y[SMPL]; <BR><BR>

but if I move vel_y like this:

Code:

<BR><BR>const u16 SMPL = 1000; <BR><BR>short acc_y[SMPL]; <BR><BR>short vel_y[SMPL]; <BR><BR>short acc_x_raw[SMPL+16]; <BR><BR>short acc_y_raw[SMPL+16]; <BR><BR>short acc_z_raw[SMPL+16]; <BR><BR>

The problem does not occur.

Am I running out of memory? Should perhaps reduce number of global variables.

[ This message was edited by: sarling on 06-04-2009 10:57 ]

[ This message was edited by: sarling on 06-04-2009 10:58 ]

trevor1
Associate II
Posted on May 17, 2011 at 13:08

what if you use

#define SMPL 1000

instaed of

u16 SMPL = 1000;

sarling
Associate II
Posted on May 17, 2011 at 13:08

There's no difference.