CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

constant type conversion

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Regas



Joined: 08 Jan 2010
Posts: 8

View user's profile Send private message

constant type conversion
PostPosted: Fri Nov 29, 2013 3:23 pm     Reply with quote

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: 19496

View user's profile Send private message

PostPosted: Fri Nov 29, 2013 3:57 pm     Reply with quote

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. Smile

Best Wishes
Regas



Joined: 08 Jan 2010
Posts: 8

View user's profile Send private message

PostPosted: Sat Nov 30, 2013 3:21 am     Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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