cancel
Showing results for 
Search instead for 
Did you mean: 

Cosmic Compiler Float Calculation Errors

tmall
Associate II
Posted on July 30, 2010 at 01:14

Cosmic Compiler Float Calculation Errors

6 REPLIES 6
tmall
Associate II
Posted on May 17, 2011 at 15:09

Greetings:

I found a work-around. I moved the float calculation function to the main.c file and then declared it as an ''extern'' function within the original file. This solved the problem with the erroneous calculation. Does anyone have any idea why this code would be file location sensitive? There are not any errors or warnings.

Best Regards,

Tom Alldread

tmall
Associate II
Posted on May 17, 2011 at 15:09

Hi Luca,

    Thanks for your interest!

    Both variables are declared as floats in the main.c file and declared as externs in the local file. Everything is the same for both.

    I am left with the impression there is a bug in the compiler as the variables are declared as floats in the same location and the calculations are within the same function. The order doesn't matter. Cz always works and Cs always fails. With the calculations moved to main.c into a stand alone function and then declared/called as extern function they both work.

    I reported the issue to Cosmic as an unsolved mystery. I can live with the work-around now that I know how to implement it.

Best Regards,

Tom Alldread

luca239955_stm1_st
Senior II
Posted on May 17, 2011 at 15:09

Hello,

from the assembler you posted it looks like Czero is a float variable, whereas Cstd is a long variable -> it is normal to have a different result.

If, as I guess, Cstd is supposed to be a float variable, check its definition AND the extern declarations for it.

Hope it helps.

Luca

luca239955_stm1_st
Senior II
Posted on May 17, 2011 at 15:09

Hi,

what I meant is the following (it's probably obvious, but I'd better make it clear)

file1.c

float fvar;

void f1(void)

{

fvar = 1.1;

}

file2.c

extern float fvar;

void f2(void)

{

fvar = 2.1;

}

if, in the exemple above, you forget ''float'' in the extern declaration, fvar will be considered as an int in file2.c

Anyway, if you ''reported the problem to Cosmic'' it will end up in my hands anyway... hopefully you included the source so that I can check where the problem is.

Regards,

Luca

tmall
Associate II
Posted on May 17, 2011 at 15:09

Greetings Luca:

    Many thanks for your follow up, your analysis is correct!

    Although I had declared the problematic variables as floats I erred when I declared them as externs. I usually use copy and paste for re-declaring variables but I guess in this case I did not and ended up with the extern variables declared as u32. Changing the externs to float resolved the issue.

    I apologize for my error!

    Changing topics can you point me to some EEPROM variable examples?

    Thank you for your assistance!

Best Regards,

Tom Alldread

luca239955_stm1_st
Senior II
Posted on May 17, 2011 at 15:09

eeprom variable example.

@eeprom char eevar;          // variable in eeprom

char ramvar;                       // variable in ram

void main (void)

{

    ramvar = eevar;               // read from eeprom is like reading from ram

    eevar = 5;                       // write to eeprom, a special routine is called

}

Notes:

- when using the eeprom variable in other modules, it must, of course, be declared with a complete extern:

extern @eeprom char eevar;          // variable in eeprom defined in another module

- a linker segment must be added: example:

+seg .eeprom -b 0x4000 -m0x400 -n .eeprom

- the eeprom writing libraries provided with the compiler are ''basic'': they work in polling and do not take advantage of some ''advanced'' parallel programming possibilities: if you want to use the eeprom in a different way you should write your own libraries.

Hope it helps.

Luca