I'm having trouble with my firmware when I pass a value to a function that receives a float (The controller won't initialize correctly). The function is as follow:
u16 u16SUPPLY_REF; //Global
void Switcher_Mode(float Voltage) {
float fSUPPLY_REF; s16 s16SUPPLY_REF;
fSUPPLY_REF = Voltage * 38.7; s16SUPPLY_REF = (s16)fSUPPLY_REF; u16SUPPLY_REF = (u16)s16SUPPLY_REF; }
And I will pass a value to the function like this:
Switcher_Mode(9);
But when I pass the value like this:
Switcher_Mode(9.0f);
The controller will initialize correctly. I'm not sure if the above will make a difference to my porblem because I've tried a few other things that worked for a while.
I know the 'f' is not added to the end of the value, the compiler won't know as what type it should interpret the value.
I'm not sure what causes the controller not to initialize but I'm SURE it has something to do with the passing of the value to the function. Also when I change the receiving type of the function to byte, then the controller will initialize. But I must use a float.
Some ideas and help please.
In the example I use a fixed value '9' but in my real situation I pass different values at runtime.
As constants or as variables ?
If they are passed as variables, the MCU will spend quite a bit of time turning them into floats before actually entering the function.
How critical is the timing of the function ?
How critical is the timing of the function ? and, how much time do you have avalilable totally. Often the tree (the function) is in the way of seeing the forest (the program).
Many have failed because some function "ate" time sometime infrequently required for something else and that, ladies and gentlemen, is a debug you do not want to go through. There is no worse bug to trace than "once a week it burps"
Erik