Analog-Digital Converter
mgxdb
Posts: 8
I am having trouble turning the output from an ADC0804 into the input for the BS2. I am trying to use the input·to set off LED's in that lie in a row. A Variable voltage controls the output of the ADC and I have successfully got it to light up LEDs in binary, but i need the ones on the BS2 board to light up sequentially, not the ones on the ADC proto board. Pins 8-15 on the BS2 board are outputs to the LEDs.
In short, I need to convert the binary from the ADC into a decimal value for the BS2's input.
Currently, i have it set up as follows in the picture:
Post Edited (mgxdb) : 4/23/2007 7:43:28 PM GMT
In short, I need to convert the binary from the ADC into a decimal value for the BS2's input.
Currently, i have it set up as follows in the picture:
Post Edited (mgxdb) : 4/23/2007 7:43:28 PM GMT
Comments
2) How have you connected the LEDs? Are they setup to light when the I/O pin is LOW or HIGH? What current limiting resistor value are you using?
3) If the LEDs are set to light when the I/O pin is HIGH, you can simply set "OUTH = 0 : DIRH = $FF" to enable the outputs and leave them off (LOW).
4) To light the LEDs based on the byte value "v", just do "OUTH = v". If the pins are in the wrong order, you can do "OUTH = v REV 8".
5) If the LEDs are set to go on when the I/O pin is LOW, make them all off with "OUTH = $FF : DIRH = $FF", then do either
"OUTH = !v" or "OUTH = !(v REV 8)"
SELECT ADC_VALUE
CASE· >239
OUTH=255
CASE· >207
OUTH=127
CASE· >175
OUTH=63
CASE· >143
OUTH=31
CASE· >111
OUTH=15
CASE· >79
OUTH=7
CASE· >47
OUTH=3
CASE· >15
OUTH=1
ENDSELECT
Jeff T.
I will do what i can for now. If i run into trouble again, i may return to the forums.
Thanks again, and wish me luck!
~MGXdb
Will this work for that purpose?
How do I read the Output of the ADC with the BS2?
Yes, that should work if everything is connected properly, In general you need to use the SHIFTOUT and SHIFIN commands to control the ADC0804:
SHIFTOUT .... 'Set appropriate chennel number
'Start conversion, as appropriate to the device
SHIFTIN .... 'Retrieve data from the ADC
Check the data sheet for particulars as to what the ADC0804 requires. Check the PBASIC Reference Manual for the syntax of SHIFTIN and SHIFTOUT.
Regards,
Bruce Bates
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
How do i READ pin 0 - 7 as a Word??
i need to read the output of the ADC
And I believe it's referred to as "InL", as in "input pins, the Low 8 bits"
So:
MyByte VAR BYTE
MyByte = InL ' This will read all 8 pins at the same time.
My error, I apologize. I thought this was a serail device, but it's a parallel device.
A waste of pin ports, IMHO.
What Allan has above is much more appropriate.
Regards,
Bruce Bates
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
IF INL>1 THEN "Label" ?
If not, is there a command that will perform that same function?
Thanks
Thanks for your help and (and support i guess you could say).
Here is a picture of the finished product.
The LEDs light up in a "thermometer sequence" quite nicely
Could you post your final working code? I'de like to see what you came up with. Thanks
' {$STAMP BS2}
' {$PORT COM1}
Bits VAR Byte
Pins VAR Byte
Bits = INL
FOR Pins = 8 TO 15
Start:
DEBUG ? INL
IF INL > 0 AND INL < 5 THEN led
IF INL > 5 AND INL < 20 THEN led2
IF INL > 20 AND INL < 40 THEN led3
IF INL > 40 AND INL < 75 THEN led4
IF INL > 75 AND INL < 90 THEN led5
IF INL > 90 AND INL < 126 THEN led6
IF INL > 126 AND INL < 254 THEN led7
IF INL = 255 THEN led8
GOTO Start
led:
HIGH 8
PAUSE 1
FREQOUT 0, 50, 1
LOW Pins
GOTO Start
led2:
HIGH 8
PAUSE 1
HIGH 9
PAUSE 1
FREQOUT 0, 50, 1
LOW 8
LOW 9
GOTO Start
led3:
HIGH 8
PAUSE 1
HIGH 9
PAUSE 1
HIGH 10
PAUSE 1
FREQOUT 0, 50, 1
LOW 8
LOW 9
LOW 10
GOTO Start
led4:
HIGH 8
PAUSE 1
HIGH 9
PAUSE 1
HIGH 10
PAUSE 1
HIGH 11
PAUSE 1
FREQOUT 0, 50, 1
LOW 8
LOW 9
LOW 10
LOW 11
GOTO Start
led5:
HIGH 8
PAUSE 1
HIGH 9
PAUSE 1
HIGH 10
PAUSE 1
HIGH 11
PAUSE 1
HIGH 12
PAUSE 1
FREQOUT 0, 50, 1
LOW 8
LOW 9
LOW 10
LOW 11
LOW 12
GOTO Start
led6:
HIGH 8
PAUSE 1
HIGH 9
PAUSE 1
HIGH 10
PAUSE 1
HIGH 11
PAUSE 1
HIGH 12
PAUSE 1
HIGH 13
PAUSE 1
FREQOUT 0, 50, 1
LOW 8
LOW 9
LOW 10
LOW 11
LOW 12
LOW 13
GOTO Start
led7:
HIGH 8
PAUSE 1
HIGH 9
PAUSE 1
HIGH 10
PAUSE 1
HIGH 11
PAUSE 1
HIGH 12
PAUSE 1
HIGH 13
PAUSE 1
HIGH 14
PAUSE 1
FREQOUT 0, 50, 1
LOW 8
LOW 9
LOW 10
LOW 11
LOW 12
LOW 13
LOW 14
GOTO Start
led8:
HIGH 8
PAUSE 1
HIGH 9
PAUSE 1
HIGH 10
PAUSE 1
HIGH 11
PAUSE 1
HIGH 12
PAUSE 1
HIGH 13
PAUSE 1
HIGH 14
PAUSE 1
HIGH 15
PAUSE 1
FREQOUT 0, 50, 1
LOW 8
LOW 9
LOW 10
LOW 11
LOW 12
LOW 13
LOW 14
LOW 15
GOTO Start
You could set the "LOW" commands to a variable (like i tried to do), but it wasnt working immediately, and being pressed
for time, i didnt bother with it.
If youre wondering why i have FREQOUT in every section is because it would cause the stamp to deliver more power to the
LEDs, making them brighter.
Good luck
~Dakota (aka mgxdb)