
Originally Posted by
scalerobotics
Nice work on the sensor code!
Thanks, although it's not complete just yet. I'll show you the main sensor code snip in case you are interested. It complies now (if selecting a bigger PIC) and I know the result of the lCTemp section is 100% correct (+ & - Deg C ). The UPres calculations are as of right now untested.
If you see any blindingly obvious code bloat in the calculations let me know...
I will post the complete code as soon as I know it works fine.
I did know what the code size used was telling me in MCS, I was more curious about RAM (variables etc) as I have been caught before going to a PIC with more code space, only to be quickly stumped by running out of variables...
All variables are signed Longs, except MD, AC5 and AC6 which are Words.
Code:
'Calculate temperature in 1/10ths of Deg C from lUTemp ' Note 2^15 = 32768 Dec or $8000
X1 = ((lUtemp - AC6) * AC5) / $8000 'find X1
X2 = (lMC << 11) / (X1 + MD) 'Find X2
B5 = X1 + X2 'Find B5 from X1 and X2
lCTemp = (B5 + 8) / 16 'Hey presto, lCTemp appears...
'Calculate pressure in Pa from lUpres (1/100th's of hPa's)
B6 = b5 - 4000
x1 = (b2 * (B6 * B6 / $1000)) / $800
x2 = (lac2 * B6) / $800
x3 = x1 + x2
B3 = ((lac1 * 4 + x3) << 5) / 4 'My OSS = 3 (might need to * here not <<)
x1 = (lac3 * b6) / $2000
x2 = (b1 * (b6 * b6 / $1000)) / $10000
x3 = ((x1 + x2) + 2) / 4
B4 = (lac4 * (x3 + 32768)) / $8000
B7 = (lUPres - B3) * 50000
If B7 < $80000000 then
lPres = (B7 * 2) / B4
Else
lPres = (B7 / B4) * 2
Endif
X1 = (lPres / 256) * (lPres / 256)
X1 = (X1 * 3038) / $10000
X2 = (-7357 * lPres) / $10000
lPres = lPres + ((X1 + X2 + 3791) / 16)
Serout2 SO,16780,["T=",DEC lCtemp," "] 'Send Word size number to LCD
Serout2 SO,16780,["P=",DEC lPres," "] 'Send Word size number to LCD
Bookmarks