2025-08-03 7:51 AM
Dear forum members,
I work on a project that repeatedly reads 3692 pixel intensity values from a linear CCD pixel-array. The readout process and export of the data via USB is working fine.
Now I want to enhance the application by multiplying each pixel value with its specific correction factor to compensate for the individual sensitivity. I struggle to find the right method to import the correction values from a text-file.
At first I tried to add a user include file that assigns the float values (in the range 0.90 to 1.10) to the array 'g_PixFactor' that is declared in the 'main.c' file. This approach produces errors like "re-definition of array 'g_PixFactor' ". I also tried to do the declaration and the assignment of the values in the include file, which gave other complaints.
My questions are:
- Is the concept of importing values by an include file a workable method to solve my challenge?
- Can a more experienced forum member provide me the steps to get the correction values from a file assign to the float array?
I already found out I need to specify the float constants with 'f' as suffix to prevent interpretation as int value.
Some background: I work on a PC with Windows11 and just have done a clean install of STM32CUBEIDE32 v 1.19.0 after I experienced many strange errors in pieces of code that were fine before the last upgrade. The target HW is a STM32H723VG on a WeAct board.
As always, thanks in advance for spending time on my request,
greetings from the Netherlands,
Fred Schimmel
Solved! Go to Solution.
2025-08-03 9:47 AM
These are all text files. Doesn't matter which program creates them, as long as they all live in the project somewhere and get compiled. You'll likely need to format the data into an array in some tool.
2025-08-03 8:23 AM - edited 2025-08-03 8:24 AM
If they are static, this will put them into FLASH where they can be read as needed:
// in floats.h:
extern const float gArray[1024];
// in floats.c:
const float gArray[1024] = {1, 2, 3, 4, ...};
// in any other *.c file you want to use them in:
#include "floats.h"
...
float x = gArray[124];
2025-08-03 8:43 AM
Hallo TDK,
Thanks for the very quick response.
There is one thing in your concept I don't understand. I want to import the values into the project via a file that I create externally in the program that measured the correction values. Is the 'floats.c' file the one that does the import?
Greetings,
Fred Schimmel
2025-08-03 9:47 AM
These are all text files. Doesn't matter which program creates them, as long as they all live in the project somewhere and get compiled. You'll likely need to format the data into an array in some tool.
2025-08-03 10:25 AM
A file included with #include is not required to be a complete C expression or a complete declaration.
Correct C source is only needed after all preprocessor expansions.
So you can always generate a file myvalues.txt with your values in a form like:
12.0,
13.0,
14.0,
15.0
or
12.0, 13.0, 14.0, 15.0
or
12.0, 13.0, 14.0, 15.0,
just as you like or as your tool may generate it (even a comma separated values file like from excel...).
Then you can declare the C source in a way like:
...
const float myValues[] =
{
#include "myvalues.txt"
};
int main( int nargs, char **args )
{
printf( "%g\n", myValues[0] );
return 0;
}
2025-08-03 10:34 AM
Hallo mfgkw,
Thanks for your help.
Although I have solved my "challenge", your response emphasizes the freedom one has until the compiler gets involved. In my case I coded the measuring program that determines the corrections to create the complete instructions with data and writes this to the file I incorporate in the project.
Have a nice day,
Fred schimmel
2025-08-05 2:11 AM - edited 2025-08-05 2:16 AM
@mfgkw wrote:even a comma separated values file like from excel.
I would even include the C rubric in the Excel file; eg,
Then you can just save as text, and give it a .c filename:
(note the quotes - otherwise Excel will save it as Book4.c.txt)
and there's your source file:
PS:
Sorry, forgot to make them float constants - but that's just a matter of the formatting in Excel:
#GenerateCfromExcel #CSourceFromExcel
2025-08-05 3:16 AM
Dear Andrew,
Thanks for thinking with me. In fact I follow a similar strategy where Excel is replaced by another application that produces a text file which directly can be added to my project.
Fred