2009-04-06 05:02 AM
What is going on?
2011-05-17 04:08 AM
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: Any ideas? I'm clueless.2011-05-17 04:08 AM
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.2011-05-17 04:08 AM
Can you also show how ''buf'' is created and how it is assigned its data?
2011-05-17 04:08 AM
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?2011-05-17 04:08 AM
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?2011-05-17 04:08 AM
@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
2011-05-17 04:08 AM
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 ]2011-05-17 04:08 AM
what if you use
#define SMPL 1000 instaed of u16 SMPL = 1000;2011-05-17 04:08 AM
There's no difference.