Discussion forum for the BasicX family of microcontroller chips.
|
I now have the lm34 working (Thank you to Dave & Tom). I am however unable to figure out how to display the temp with 2 digits after the decimal point (72.45) I have tried Dim Temp as Integer GetADC(13)*5/10 I get actual temp values pretty close to my digital thermometer, but they integers (72) I've tried Dim Temp as Single GetADC(13, temp) I get something like 0.145678 If I use my calculator and multiply 0.14567 by 500 I get 72.835 I try this in the program and I end up with type mismatch and all kinds of things I would be most grateful if someone could point me in the right direction or provide a tidbit of code showing how to use GetADC with the lm34 and have a display showing the temp with 2 digits to the right of the decimal point. William [Non-text portions of this message have been removed] |
|
|
|
Dim Temp as Single GetADC(13, temp) I get something like 0.145678 If I use my calculator and multiply 0.14567 by 500 I get 72.835 I try this in the program and I end up with type mismatch and all kinds of things '---------- GetADC(13, temp) tmp = tmp * 500.0 try this. the type missmatch was because there was no ".0" after your 500 ===== Tony Brenke North Tacoma, WA __________________________________________________ |
|
> ... how to use GetADC with the lm34[, displaying] the temp with 2 digits to the right of the decimal point. There are two issues. First, the BX-24 ADC resolves to about 5mV, which is 0.5 degree from the LM34; that's the best resolution you'll get from a direct connection; once you have the significant data, then you need a method to display 1.2345Volt as 123.45. Both are easy. To see 0.01 degree resolution, you'll need either external gain and offset - still limited by the 10-bit ADC, so the maximum range would be only 10.23 degrees, probably unacceptable - or software that synthesizes the additional resolution via averaging or successive approximation (discussed here recently), in exchange for response time. If you need full-range or negative temps, this won't work; you'll need more smarts, but here's my direct-connect LM34DZ code: sT=csng(GetADC(bTempPin))/1024.0 '0-0.9999... (*5V=temp, 1.0V=100degreesF) sTav=sTav+(sT-sTav)/100.0 'approximation of average temp, + two decimal places sTav will be the value you'll use. 1.0 represents 100.0 degreesF. To display "123.45" from 1.2345, I did this: strZ=cstr(clng(fix(sTav*10000.0+0.5)+100000.0)) strX=strX & mid(strZ,2,3) & "." & mid(strZ,5,2) call putstr_n(strX) Tom Becker --... ...-- The RighTime Clock Company, Inc., Cape Coral, Florida USA www.RighTime.com |
|
It's in the comment but not in the code: multiply sT by the 5.0v ADC reference: sT=5.0*csng(GetADC(bTempPin))/1024.0 '0-0.9999... (*5V=temp, 1.0V=100degreesF) sTav=sTav+(sT-sTav)/100.0 'approximation of average temp, + two decimal places sTav will be the value you'll use. 1.0 represents 100.0 degreesF. Tom Becker --... ...-- The RighTime Clock Company, Inc., Cape Coral, Florida USA www.RighTime.com |