View previous topic :: View next topic |
Author |
Message |
Ringo42
Joined: 07 May 2004 Posts: 263
|
64 bit math |
Posted: Thu Dec 23, 2010 2:38 pm |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
bkamen
Joined: 07 Jan 2004 Posts: 1611 Location: Central Illinois, USA
|
|
Posted: Thu Dec 23, 2010 2:44 pm |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
Ringo42
Joined: 07 May 2004 Posts: 263
|
|
Posted: Thu Dec 23, 2010 3:03 pm |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19366
|
|
Posted: Thu Dec 23, 2010 3:28 pm |
|
|
Er.
The CCS compiler supports 32bit arithmetic itself. No extra functions needed.
Just cast the int16's to int32, before the arithmetic.
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
Ringo42
Joined: 07 May 2004 Posts: 263
|
|
Posted: Thu Dec 23, 2010 3:29 pm |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
bkamen
Joined: 07 Jan 2004 Posts: 1611 Location: Central Illinois, USA
|
|
Posted: Thu Dec 23, 2010 3:34 pm |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
Ringo42
Joined: 07 May 2004 Posts: 263
|
|
Posted: Thu Dec 23, 2010 3:37 pm |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Thu Dec 23, 2010 4:17 pm |
|
|
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. |
|
![](templates/subSilver/images/spacer.gif) |
Ringo42
Joined: 07 May 2004 Posts: 263
|
|
Posted: Thu Dec 23, 2010 9:29 pm |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
![](templates/subSilver/images/spacer.gif) |
|