Shop OBEX P1 Docs P2 Docs Learn Events
Help Requested - ADC Value Comparison — Parallax Forums

Help Requested - ADC Value Comparison

KeithKeith Posts: 5
edited 2005-10-19 13:56 in BASIC Stamp
I'm stumped. I've got a simple ADC routine to measure a voltage with a BS2. It works fine per code below. I'm having trouble writing code to compare the value of the measured voltage (mVolts) against entered values. What I am trying to do is compare the value·of measured volts (mVolts) against a setpoint (we can call it SetV) so as to create alarm points. I would also like to track mVolts in order to determine it's highest value over the measured period. Any help would be much appreciated.

Keith


A2Ddata········ CON···· 0······················ ' A/D data line
A2Dclock······· CON···· 1······················ ' A/D clock
A2Dcs·········· CON···· 2······················ ' A/D chip select (low true)

'
' Variables
'
result········· VAR···· Byte··················· ' result of conversion
mVolts········· VAR···· Word··················· ' convert to millivolts

'
' Initialization
'
Initialize:
· HIGH A2Dcs

'
' Program Code
'
Main:
· GOSUB Read_0831
· mVolts = result */ $139C····················· ' x 19.6 (mv / unit)
· DEBUG Home
· DEBUG "ADC..... ", DEC result, "·· ", CR
· DEBUG "volts... ", DEC mVolts DIG 3, ".", DEC3 mVolts
· PAUSE 100···································· ' delay between readings
· GOTO Main···································· ' do it again

'
' Subroutines
'
Read_0831:
· LOW A2Dcs
· SHIFTIN A2Ddata, A2Dclock, MSBPost, [noparse][[/noparse]result\9]
· HIGH A2Dcs
· RETURN

Comments

  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-10-17 12:20
    That's pretty straighforward with comparison operators.· You could do something like this:

    · GOSUB Read_0831
    · mVolts = result */ $139C

    · IF (mVolts > maxMVolts) THEN
    ··· maxMVolts = mVolts
    · ENDIF

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • KeithKeith Posts: 5
    edited 2005-10-18 00:12
    Jon:

    Thanks for the quick reponse. Unfortunately, it still didn't solve the problem. When I inputted the code you suggested, it returns an error " Error - Expected A Label". Pretty much same problem I was facing before. I set maxMVolts as a word Variable and have verified that it is branching to the subroutine but it hangs up on the If Statement. I would certainly appreciate another look at this. Thanks so much.

    Keith
  • NewzedNewzed Posts: 2,503
    edited 2005-10-18 00:20
    Do you tell the program what to do after the ENDIF?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Sid Weaver
    Do you have a Stamp Tester yet?
    http://hometown.aol.com/newzed/index.html

    ·
  • KeithKeith Posts: 5
    edited 2005-10-18 10:49
    Thanks Jon and Sid. It's working just fine now. Clearly, I was making the problem a lot bigger than it was and overlooking the fundamentals. I appreciate your help very much.

    Keith
  • George SuttonGeorge Sutton Posts: 180
    edited 2005-10-19 13:56
    Keith,



    What did you do to get it working properly?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Sign In or Register to comment.