Hi - interesting topic - thank you. Have one squawk - when one of our forum ''crew'' NEEDS this info next week/month - HOW will they find it with such (forgive me) ill-defined topic? Your findings are indeed of interest - of valu
Declaring a large buffer like ''buf'' on the stack (i.e. local in a function) could be the problem. I suggest you check your stack size or declare the buffer global (or static).
const u16 SMPL2 = 1024; const u16 SMPL2 = 1000; short acc_y_raw[SMPL2]; short vel_y[SMPL]; . . void afunction() { short buf[SMPL2]; for (i = 0; i < SMPL2; i++) { sum = 0; if (i < SMPL) { sum = 0; for (j = i; j < i+16; j++) { sum += acc_y_raw[j]; } sum >>= 4; buf[i] = sum; sum = 0; } } } is what contaminates vel_y, if I remove buf[i] = sum; it doesn't. What am I missing? Even if I don't use buf[i]:
Code:
for (i = 0; i < SMPL; i++) { vel_y[i] = acc_y_raw[i]; } I don't know if this is a hardware or a software error.
This is why I asked you ''how is buf created'' and you dismissed it :( malloc will have failed (and crashed because you didn't check the return value) because the heap is not large enough. Like the stack size this is for you to configure. In embedded systems it is best to avoid using malloc if you can. Also I always fill the stack with a known value and check how much stack I have left unused after running the system for some time (aim for at least 20% free). You don't want release your product only to find that it crashes in the field due to stack overrun. Regards Trevor