I have 6000ish points of interests, which I separated into three equally large arrays and wrote in my memory. The reason for the seperation was basicly the maximum array size.
So I wrote a function to read from these arrays precisely, which I intend to loop over:
double readFromMemory(int arrayIndex, int firstDimension, int secondDimension) {
if (arrayIndex == 1) {
return pgm_read_float_far(pgm_get_far_address(radarPositions1[firstDimension][secondDimension]));
}
if (arrayIndex == 2) {
return pgm_read_float_far(pgm_get_far_address(radarPositions2[firstDimension][secondDimension]));
}
if (arrayIndex == 3) {
return pgm_read_float_far(pgm_get_far_address(radarPositions3[firstDimension][secondDimension]));
}
That way, my intention is, that I dont load 140+ kb Data into my 8kb memory. Instead only load one, evaluate and discard, repeat.
Here is my loop:
int loopLimit = sizeof(radarPositions1)/sizeof(radarPositions1[0]);
for (int i = 1; i < 4; i++) {
for(int j = 0; j < loopLimit; j++) {
readFromMemory(i, j, 0));
}
}
And this dont compile. I get following error:
<artificial>:(.text+0xfec): undefined reference to `r30' (this one comes 3 times)
collect2.exe: error: ld returned 1 exit status
Since readFromMemory(1, 0, 0)); compiles and runs properly, also Serial.println ing in loop works properly, I think I am filling the memory with some stuff which is not removed afterwards.
I think the argument to pgm_get_far_address has to be know at compile time, so you can't give it an indexed value directly. Last time I stored something that large I had to get the base address of the array then calculate the position of the variable instead of using array indexes.
Is the 3rd entry in your table always a whole number? I didn't look at all the entries, but I don't see any values over 180 or negative, if you can store that as a byte all your data would fit in two arrays.
This is a gamechanger dougp! Thanks. I don't need any optimization neither on memory nor runtimewise yet but this will come in handy, when I refactor the whole thing when it is finished!
dr-o:
This is a gamechanger dougp! Thanks. I don't need any optimization neither on memory nor runtimewise yet but this will come in handy, when I refactor the whole thing when it is finished!