Shop OBEX P1 Docs P2 Docs Learn Events
slope intercept — Parallax Forums

slope intercept

J^3J^3 Posts: 121
edited 2008-03-02 21:52 in BASIC Stamp
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

Comments

  • skylightskylight Posts: 1,915
    edited 2008-03-02 08:51
    Im not a maths person and what you are asking is way over my head but i wondered if the stamp plot software would do what you want? One of the graphs allows formulas to be input.

    Stamp plot software page scroll down for download
  • phil kennyphil kenny Posts: 233
    edited 2008-03-02 17:05
    I've been able to deduce most of what your code does. From the
    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
  • Tracy AllenTracy Allen Posts: 6,666
    edited 2008-03-02 18:27
    Write the equation as ten times:
    y= (-500/41)X + (1937000/41)
    y = -12.19512 + 47244

    Then the multiplier for */ is 12.19512 * 256 = 3122. In PBASIC,

    celsius = 47244 - (rawvalue */ 3122) -3 ' not sure why -3
        DEBUG "Celsius = ",REP "-"\celsius.bit15,DEC ABS celsius/10,".",dec1 ABS celsius," Degrees",CR 
       ' in units of xx.x
    



    The display routine works for both + and - temperature, displays to tenths.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • J^3J^3 Posts: 121
    edited 2008-03-02 19:14
    Thank you all for your posts.· The -3; when I first tried my code values were off by 3 consistently so I just said -3.· Don't know if that was the right way to deal with the problem, but it worked,· I will try the times ten tonight and let you all know how it gos.· Once agian thank you very much.
  • J^3J^3 Posts: 121
    edited 2008-03-02 19:20
    Mr. Allen, how do you post your code in the little box, instead of copy and paste.
  • Tracy AllenTracy Allen Posts: 6,666
    edited 2008-03-02 21:42
    The little box, see in the editor window that has all the annoying little emoticons to the left, along the top there are some formatting buttons. Click on the one labled CODE before the stuff you want in the little box and click on it again at the end. Or, you can just enclose the word in square brackets like this [noparse][[/noparse] code]stuff to be in the box[noparse][[/noparse] /code]. In the previous sentence I put a space after the left square bracket, and that prevented it from making the box, but without the space it would be
    stuff to be in the box
    

    .

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • J^3J^3 Posts: 121
    edited 2008-03-02 21:51
    Thank you
  • J^3J^3 Posts: 121
    edited 2008-03-02 21:52
    Got it
    
Sign In or Register to comment.