Help Requested - ADC Value Comparison
Keith
Posts: 5
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
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
· GOSUB Read_0831
· mVolts = result */ $139C
· IF (mVolts > maxMVolts) THEN
··· maxMVolts = mVolts
· ENDIF
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
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
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Sid Weaver
Do you have a Stamp Tester yet?
http://hometown.aol.com/newzed/index.html
·
Keith
What did you do to get it working properly?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔