This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Compiler interpretation of "Types"

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.

Parents
  • 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).

    Did you check what value Voltage has inside the function if you call Switcher_Mode(9); (with an integer argument instead of float) ?

    Is the initialization time-critical, i.e. could run-time conversion from integer to float disturb it ?

    But I must use a float.

    Is there hard reason for this ? Will a fixed-point variable be insufficient ?

    floats are rarely necessary in control application and come with their very own set of problems (value-dependent granularity, for example). There's usually some way to avoid using floats - fixed point numbers being the most likely candidate.

Reply
  • 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).

    Did you check what value Voltage has inside the function if you call Switcher_Mode(9); (with an integer argument instead of float) ?

    Is the initialization time-critical, i.e. could run-time conversion from integer to float disturb it ?

    But I must use a float.

    Is there hard reason for this ? Will a fixed-point variable be insufficient ?

    floats are rarely necessary in control application and come with their very own set of problems (value-dependent granularity, for example). There's usually some way to avoid using floats - fixed point numbers being the most likely candidate.

Children