I have an Interrupt that fills a 64 Integer table with 1 Integer for each Interrupt. I need to roll the table, so it always has the last 63 values when a new value is obtained. I need to do that without overwriting the next value in the table, because the next value has to be used for the following operation.
for (k=0; k < 64; k++){
TABLE[62-k] = TABLE[63-k]; //Move Table down 1
}
Program Rolling Table in C
Re: Program Rolling Table in C
Copying data always takes time, as your buffer is a multiple of 2 why not just wrap around within the buffer.
Code: Select all
tablePtr = 0; // initial value
...
Table[tablePtr++] = sample;
tablePtr &= 63; // wrap around buffer
...
// as an example for reading the last 64 values -- add them up
sum = 0;
for (i=0; i<64; i++) {
sum += Table [(tablePtr + i) & 0x3f];
}
Re: Program Rolling Table in C
Look good, Thanks I'll try it.
Re: Program Rolling Table in C
That works OK, but I need to insert zeros, if there is no interrupt in a certain time, otherwise the old data never changes.
I suppose that I can read the Timer Value in the Main program, then
if T1_CR0 > xxxxx, Table[tablePtr++] = 0;
tablePtr would have to be extern, and I need to reset T1_CR0;
I suppose that I can read the Timer Value in the Main program, then
if T1_CR0 > xxxxx, Table[tablePtr++] = 0;
tablePtr would have to be extern, and I need to reset T1_CR0;