PDA

View Full Version : Analog-Digital Converter

mgxdb
04-24-2007, 02:22 AM
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

Mike Green
04-24-2007, 03:06 AM
1) Can you successfully read from the ADC0804 and produce a number that reflects the voltage measured? What number range is valid?

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)"

Unsoundcode
04-24-2007, 05:30 AM
Hi mgdxb, you have 255 possible values from the ADC and eight leds to display them with. If you intend the values be evenly spaced thats 32 between each. You have to decide then whether you want them to light at the low/mid/high range of each increment. Here's an example that illuminates each led at the mid range value of each increment in a "thermometer" style. Mess with the case values to alter the threshold.

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.

mgxdb
04-24-2007, 12:22 PM
Thanks for the help guys, appreciate it.

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

mgxdb
04-26-2007, 01:54 AM
Ok, im using the Output of the ADC0804 as the INPUT for the BS2.

Will this work for that purpose?

How do I read the Output of the ADC with the BS2?

Bruce Bates
04-26-2007, 02:11 AM
mgxdg -

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

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔

mgxdb
04-26-2007, 02:18 AM
Thanks Bruce, but i have another question

How do i READ pin 0 - 7 as a Word??

allanlane5
04-26-2007, 02:31 AM
Pin 0..7 is a BYTE, not a Word.

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.

Bruce Bates
04-26-2007, 02:34 AM
mgxdg -

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

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔

mgxdb
04-26-2007, 02:50 AM
thank you so much allan!

mgxdb
04-26-2007, 11:54 AM
Hey, is it possible to use INL in a command such as

IF INL>1 THEN "Label" ?

If not, is there a command that will perform that same function?

Thanks

mgxdb
04-27-2007, 03:26 PM
Alright, Scratch that, its all up and running!

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 http://forums.parallax.com/images/smilies/smilewinkgrin.gif

KatyBri
04-28-2007, 08:08 AM
mgxdb,

Could you post your final working code? I'de like to see what you came up with. Thanks

mgxdb
04-28-2007, 08:30 AM
Sure, Here it is.

------------------------------------------
' {\$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)