slope intercept
J^3
Posts: 121
Good Evening all,· I am trying to write this equation y= (-50/41)X + (193700/41), and am having a little trouble.· So far this is what I have come up with, and it is close but I would like my results to be within +- .1 degree.· Any help would be appreciated.· Thank you.
' File:AD592.bsp
' Author:
' Date:2-29-08
' {$STAMP BS2p}
' {$PBASIC 2.5}
'----Program Description
'Display temperature in degrees celsius
'----PIN Declaration
'----Constants
Slope··· CON $0138
Offset·· CON 4724
'----Variables
rawvalue VAR Word
adjvalue VAR Word
celsius· VAR Byte
'----EEPROM DATA
'----Initialization
DEBUG CLS
'----Program Code
Main:
· DEBUG "Enter rawvalue:"
· DEBUGIN DEC rawvalue
· IF ((rawvalue >=3792) AND (rawvalue <=3874)) THEN
··· adjvalue = rawvalue */ Slope
··· celsius = (Offset - adjvalue) - 3
··· DEBUG "Celsius = ",DEC celsius," Degrees",CR
· ELSE
··· DEBUG "Out of range",CR
· ENDIF
GOTO Main
'----Subroutines
' File:AD592.bsp
' Author:
' Date:2-29-08
' {$STAMP BS2p}
' {$PBASIC 2.5}
'----Program Description
'Display temperature in degrees celsius
'----PIN Declaration
'----Constants
Slope··· CON $0138
Offset·· CON 4724
'----Variables
rawvalue VAR Word
adjvalue VAR Word
celsius· VAR Byte
'----EEPROM DATA
'----Initialization
DEBUG CLS
'----Program Code
Main:
· DEBUG "Enter rawvalue:"
· DEBUGIN DEC rawvalue
· IF ((rawvalue >=3792) AND (rawvalue <=3874)) THEN
··· adjvalue = rawvalue */ Slope
··· celsius = (Offset - adjvalue) - 3
··· DEBUG "Celsius = ",DEC celsius," Degrees",CR
· ELSE
··· DEBUG "Out of range",CR
· ENDIF
GOTO Main
'----Subroutines
Comments
Stamp plot software page scroll down for download
file name, I assume you're using an AD592 to measure the temperature
which yields 1 ua per degree K.
Then running the 592 current thru a resistor (value unknown) and a
12-bit ADC generates the variable, "rawvalue".
The constant, $0138, you found by evaluating the fraction 50/41 or
1.219512.
0.219612 x 256 = 56.1951219512
56 decimal = 38 hex
The problem is that the Stamp works with only integers and using 0138 hex
is only a close approximation of the slope. Using 0138 hex introduces a
error in the calculated slope of roughly 0.06 percent.
The error introduce by using 4724 for the offset is less and can be
ignored.
My first thought would be to slightly change the value of the resistor
that converted the AD592 current to voltage. Change this resistor
such that the constant, $0138 gives the slope exactly and not
approximately.
phil
Post Edited (phil kenny) : 3/2/2008 5:23:52 PM GMT
y= (-500/41)X + (1937000/41)
y = -12.19512 + 47244
Then the multiplier for */ is 12.19512 * 256 = 3122. In PBASIC,
The display routine works for both + and - temperature, displays to tenths.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com