Define range for o/p from adc0831
rickrocker
Posts: 7
Hi All,
I'm having issues defining a range of values that the ADC0831 outputs using the IF..ELSE loop. Could someone help.
This is what I have so far:
Calc_Value:
IF (adcBits <= 26) THEN value = 2
ELSEIF (adcBits > 26 AND adcBits <= 77) THEN value = 3
ELSEIF (adcBits > 77 AND adcBits <= 102) THEN value = 4
...
...
...
...
...
ELSE (adcBits >·204 AND adcBits <= 255) THEN value = 10
ENDIF
RETURN
The error its giving me is 'ELSEIF' must be preceded by'IF'. Why is it showing that when ELSEIF is actually preceded by IF.
Also, Can someone tell me what raw value is the o/p of the 0831adc. It has to be a binary 8-bit o/p..and if that is the case can I use that instead of the decimal values like 26, 77 etc·to define my range?
Any help is greatly apprecaited!
I'm having issues defining a range of values that the ADC0831 outputs using the IF..ELSE loop. Could someone help.
This is what I have so far:
Calc_Value:
IF (adcBits <= 26) THEN value = 2
ELSEIF (adcBits > 26 AND adcBits <= 77) THEN value = 3
ELSEIF (adcBits > 77 AND adcBits <= 102) THEN value = 4
...
...
...
...
...
ELSE (adcBits >·204 AND adcBits <= 255) THEN value = 10
ENDIF
RETURN
The error its giving me is 'ELSEIF' must be preceded by'IF'. Why is it showing that when ELSEIF is actually preceded by IF.
Also, Can someone tell me what raw value is the o/p of the 0831adc. It has to be a binary 8-bit o/p..and if that is the case can I use that instead of the decimal values like 26, 77 etc·to define my range?
Any help is greatly apprecaited!
Comments
The error its giving me is 'ELSEIF' must be preceded by'IF'. Why is it showing that when ELSEIF is actually preceded by IF.
I would also reveiw the What is a Mirocontroller·Book·it starts at page 101
You need to write this way ELSEIF··· ·with·no space
I have not test code routine so i do not if it will work the way you want to work
·Main:
· DO
··· GOSUB Read_0831···························· ' read the ADC
··· mVolts = result */ Cnts2Mv················· ' convert to millivolts
··· DEBUG HOME,································ ' report
········· CRSRXY, 9, 0, DEC result, CLREOL,
········· CRSRXY, 9, 1, DEC mVolts DIG 3,
······················· ".", DEC3 mVolts
·IF (adcBits <= 26) THEN
·value = 2
ELSEIF (adcBits > 26) AND (adcBits <= 77) THEN
·value = 3
ELSEIF (adcBits > 77) AND (adcBits <= 102) THEN
·value = 4
ELSEIF (adcBits > 204) AND (adcBits <= 255) THEN
·value = 10
·ENDIF
RETURN
··· PAUSE 100
·LOOP
·
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
··Thanks for any··that you may have and all of your time finding them
·
·
·
·
Sam
Post Edited (sam_sam_sam) : 3/29/2008 4:39:20 AM GMT
·You·must write the statements like this:
Post Edit -- Emphasis on placement of the conditionals and statements and the succeeding ELSEIFs.
Post Edited (PJ Allen) : 3/29/2008 3:41:10 AM GMT
It will not compile because you can use ·value = 2····(·Error ·Expected " : " or end of the line)·· and what the problem is the " = "
that is why i had· GOSUB·value2··
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
··Thanks for any··that you may have and all of your time finding them
·
·
·
·
Sam
Sometimes, OM, I can't quite fathom your depth.
Anyway, it compiles for me (attached.)
Sorry about that I did not put····· ·value·· VAR· Byte
That is why it gave me that error
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
··Thanks for any··that you may have and all of your time finding them
·
·
·
·
Sam
or better yet...
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com