Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
10 years, 10 months ago.
storing a sinewave data on flash
Hi,
I would like to store a sinewave amplitude data on an float type array of let say 400 elements on flash memory.
I can declare that array using : extern const float sine_in_flash_array [400] ={0.0};
But, I want to fill up that sine_in_flash_array automatically somehow using preprocessor or other way.
Could someone help me on that...
Thank you
.
2 Answers
10 years, 10 months ago.
I assume you would want it to use some kind of loop, for another reason I looked into it a while ago: As far as I could find it is not possible to make the preprocessor loop.
You could I guess make a function macro, and then make the list once, so something like:
#define function(x)... float sine_in_flash_array[] = {function(0), function(1), function(2), ...};
With some creative usage of excel you can probably make that without typing everything. I would place it in a seperate file however to keep it from cluttering your code too much ;).
Finally if it is something you don't have to do too often, make the values in excel, copy to notepad, replace tab characters by commas, copy to the compiler. Not automatic, better than typing everything by hand.
Assuming you dont need to generate the table data very often, it should be possible to write a small program that runs on mbed and generates a text file in the localfilesystem using fprintf. The file should contain the constant tabledata in C language format. You can then include the file as .h or copy/paste the text in your main. Dont forget to use the 'constant' modifier to make sure the table ends up in flash memory.
posted by 12 Jan 2014