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

64 bit math

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



Joined: 07 May 2004
Posts: 263

View user's profile Send private message

64 bit math
PostPosted: Thu Dec 23, 2010 2:38 pm     Reply with quote

I'm using a pic18f4520 and an ms5803 pressure sensor. some of the math with the sensor results in a 34 bit number. I found this page for multiplying 32bit numbers
http://ccsinfo.com/forum/viewtopic.php?t=38627&highlight=int64

but does anyone have a link to a page describing adding 32bit numbers?

The formulas I'm using are C2 * 2^16 + (C4 * dT ) / 2^7

and C1 * 2 ^15+ (C3 * dT ) / 2^8

where C1,c2,c3,c4 are unsigned 16 bit
and dT is signed 32bit.

Ringo
_________________
Ringo Davis
bkamen



Joined: 07 Jan 2004
Posts: 1615
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Thu Dec 23, 2010 2:44 pm     Reply with quote

Are you using the PIC's A/D for sample conversion?

-Ben
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
Ringo42



Joined: 07 May 2004
Posts: 263

View user's profile Send private message

PostPosted: Thu Dec 23, 2010 3:03 pm     Reply with quote

No, no A/D at all, it is all done in the 5803. I talk to it with SPI and get back 16 and 32 bit numbers, then have to do the math I mentioned to end up with a Mbar reading.
_________________
Ringo Davis
Ttelmah



Joined: 11 Mar 2010
Posts: 19506

View user's profile Send private message

PostPosted: Thu Dec 23, 2010 3:28 pm     Reply with quote

Er.
The CCS compiler supports 32bit arithmetic itself. No extra functions needed.
Just cast the int16's to int32, before the arithmetic.

Best Wishes
Ringo42



Joined: 07 May 2004
Posts: 263

View user's profile Send private message

PostPosted: Thu Dec 23, 2010 3:29 pm     Reply with quote

But multiplying two 32 but numbers results in a 64 bit number. Or adding two 32 bit numbers results in a 33bit bit number, so here 32 bit math does not help.
_________________
Ringo Davis
bkamen



Joined: 07 Jan 2004
Posts: 1615
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Thu Dec 23, 2010 3:34 pm     Reply with quote

OK, so the device has a 24bit ADC on it... if you look at the resolutions -- and the fact that you want mBar readings, you can probably throw away a lot of the bits and still end up with mBar readings.

If you look at the part itself, it's only accurate to 5mBar. so with those high res results, you can toss away a lot and probably end up with something a lot less than 32bits.

I didn't dig deep - but that what the quick look tells me.


-Ben
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
Ringo42



Joined: 07 May 2004
Posts: 263

View user's profile Send private message

PostPosted: Thu Dec 23, 2010 3:37 pm     Reply with quote

I need the highest resolution I can get for this project. At max resolution it is supposed to be 10cm altitude. I'm building a variometer so the more precision the better.
_________________
Ringo Davis
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Thu Dec 23, 2010 4:17 pm     Reply with quote

The maximum resolution specified in the datasheet calculates to 17 effective bits. Although, the resolution should be achievable with 32 bit integer, it may involve inconvenient scaling operations. But PCH doesn't provide integer data types with higher resolution. So 32 Bit float is possibly the better option.
Ringo42



Joined: 07 May 2004
Posts: 263

View user's profile Send private message

PostPosted: Thu Dec 23, 2010 9:29 pm     Reply with quote

From the CCS manual is says a float is
-1.5 x 10^45 to 3.4 x 10^38

but those are outrageously large numbers. 3.4 X 10^38 is astronomical, I must be confused. A 32 bit int goes up to about 4 billion right? And that is only 4 X 10^10. What am I misinterpreting here? I always assumed a float maxed out at 4 billion as well.
Ringo
_________________
Ringo Davis
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Fri Dec 24, 2010 1:56 am     Reply with quote

Float has a mantissa and an exponent. For accuracy considerations, just see it as a 23 Bit integer with an additional scaling factor.

http://en.wikipedia.org/wiki/Floating_point
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