|
|
View previous topic :: View next topic |
Author |
Message |
Regas
Joined: 08 Jan 2010 Posts: 8
|
constant type conversion |
Posted: Fri Nov 29, 2013 3:23 pm |
|
|
For a CAN Parameter table I have to write int and float constants to the same variable.
Code: | Int32 value; //variable to transmit
value = 0x001 //Int32 1 |
This is OK.
Code: | value = 0x3B23D70A; //float32 0.0025 |
This works, but I have to calculate every entry, and there are lots of them.
Is there any possibility to let the compiler work for me, like this:
Code: | value = (float32) 0.0025; // wrong result 0 |
Thanks for help. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19497
|
|
Posted: Fri Nov 29, 2013 3:57 pm |
|
|
The first part of this is where unions come in.
However this can't be 'pre-solved', since you are sending IEEE fp values as 4 bytes, not Microchip/CCS fp.
CCS supplies code to convert these at run time, but no way of doing this at compile time.
So, if you wanted to send CCS fp values, you could have a union:
Code: |
union {
int32 ival;
float fpval;
} typechange;
|
and then write 0.25 to 'typechange.fpval', and send 'typechange.ival' as the int32, which would work for a constant table if required. Problem here is it'll only send CCS floats.
However the code to convert to IEEE is in 'ieefloat.c', so with this loaded, you could then use:
value=f_PICtoIEEE(0.25);
This will convert the byte order to IEEE format, and the result to int32.
But this can't be used to declare constants.
Easiest probably, to just store the table as an array of PIC constant float values, then use the f_PICtoIEEE routine to send these to the bus.
To 'pre solve', remember the conversions can be easily done with the PConvert tool. Type in the FP number into the IEEE float box, and the four bytes can be direct cut from the 'hex' box, with CTRL-C, then pasted to your code.
Best Wishes |
|
|
Regas
Joined: 08 Jan 2010 Posts: 8
|
|
Posted: Sat Nov 30, 2013 3:21 am |
|
|
Yes thanks for competent answer Ttelmah.
It seems there is no possibility to make it easier, I have to use the “CCS Base Converter” or another PConvert tool, and paste and copy the values.
Regas |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|