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

PCD: type conversion float32 to signed int16

 
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

PCD: type conversion float32 to signed int16
PostPosted: Wed Jun 16, 2010 12:59 pm     Reply with quote

I use PCD compiler v.4...

For a Project with CAN Bus I need to convert an incoming float32 number to an signed int16 number. The value of 0.1 - 200 should be converted to the value 1 - 2000 and -0.1 - -200 to -1 - -2000.

Does anybody know how this can be done in a simple way?

Or a link to help me to get further?

Many thanks for helpful ideas.
newguy



Joined: 24 Jun 2004
Posts: 1911

View user's profile Send private message

PostPosted: Wed Jun 16, 2010 2:14 pm     Reply with quote

...worth a try:

Code:
float32_number = 10 * float32_number;
signed_int16 = (signed int16) float32_number;


There's probably a more efficient/elegant way, but I'll bet that this works.
Wayne_



Joined: 10 Oct 2007
Posts: 681

View user's profile Send private message

PostPosted: Thu Jun 17, 2010 2:06 am     Reply with quote

Where is the float coming from and in what form.

CCS use the microchip format for floats which is different from the IEEE standard so you may need to convert it.
Regas



Joined: 08 Jan 2010
Posts: 8

View user's profile Send private message

PostPosted: Thu Jun 17, 2010 5:28 am     Reply with quote

Hi newguy

Thanks, amazing, it works!
A measured execution time is about 6us with
slightly overclocked dsPIC30F6014A (32Mhz).
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