Sharp GP2Y0A21YK WITH ADC0831
I LOVE ROBOT
Posts: 22
I HAVE THIS PROGRAM FROM GAZBOT.· THAT PROGRAM USE ONLY ONE SENSOR (Sharp GP2Y0A21YK ) CONNECT WITH ADC0831.·SO!! IF I WANT TO ADD MORE 2 OR 3··Sharp GP2Y0A21YK·.·HOW CAN TO ADJUST IT. (I BUY 2 Sharp GP2Y0A21YK AND 2 ADC0831 ALREADY·CIRCUIT IS NOT HARD BUT THE PROBLEM IS HOW TO RENEW THAT PROGRAM) THANK.
_________________________________________________________________________________________
' {$Stamp bs2}
' File name IRgazbot.bs2
' Author G.Duran
' This program will allow the Gazbot to control a Boe Bot with it's built on Sharp·· GP2Y0A21YK··sensor
·
·
' Variable declarations
pulse_count··· VAR· Byte······· ' For...next loop counter.
CS······ CON·· 3·· ·····' ADC0831 chip select
CLK······ CON· 4······· ' ADC0831 clock line
D0······ CON·· 5······· ' ADC0831 data line
adcbits···· VAR·· Byte······· ' Variable for A/D data
·
' Main routine
Main:
· PULSOUT 12,500
· PULSOUT 13,1000
· HIGH cs·········· ·'·· Deselect ADC0831
· LOW cs··········· '·· "Active low" select ADC0831.
· LOW clk··········· '·· Set ADC0831's clock pin low.
· PULSOUT CLK,210········· '·· Start pulse.
· SHIFTIN d0,clk,MSBPOST,[noparse][[/noparse]adcbits\8]· '·· Shift in valid data bits.
· IF adcbits > 100 THEN u_turn
GOTO main
·
'
Navigation Routines
·U_turn:
·
FOR pulse_count = 0 TO· 42
· PULSOUT 12, 500
· PULSOUT 13, 500
· PAUSE 20
NEXT
GOTO main
·
·
·
_________________________________________________________________________________________
' {$Stamp bs2}
' File name IRgazbot.bs2
' Author G.Duran
' This program will allow the Gazbot to control a Boe Bot with it's built on Sharp·· GP2Y0A21YK··sensor
·
·
' Variable declarations
pulse_count··· VAR· Byte······· ' For...next loop counter.
CS······ CON·· 3·· ·····' ADC0831 chip select
CLK······ CON· 4······· ' ADC0831 clock line
D0······ CON·· 5······· ' ADC0831 data line
adcbits···· VAR·· Byte······· ' Variable for A/D data
·
' Main routine
Main:
· PULSOUT 12,500
· PULSOUT 13,1000
· HIGH cs·········· ·'·· Deselect ADC0831
· LOW cs··········· '·· "Active low" select ADC0831.
· LOW clk··········· '·· Set ADC0831's clock pin low.
· PULSOUT CLK,210········· '·· Start pulse.
· SHIFTIN d0,clk,MSBPOST,[noparse][[/noparse]adcbits\8]· '·· Shift in valid data bits.
· IF adcbits > 100 THEN u_turn
GOTO main
·
'
Navigation Routines
·U_turn:
·
FOR pulse_count = 0 TO· 42
· PULSOUT 12, 500
· PULSOUT 13, 500
· PAUSE 20
NEXT
GOTO main
·
·
·
Comments
What you want to consider is a multiple input, single output ADC, like (say) the ADC0834. The ADC 0831 is the smallest member of a family of ADC's which can utilize one (ADC0831) or multiple inputs (ADC0834, ADC0838). The last digit dictates the maximum number of inputs (fancy that!).
When you use a multiple input ADC, you merely tell the chip which set of input pins to use. It then retrieves the data from that set of input pins, and waits for the next command.
If you were to put the retrival in a FOR or DO loop, you could loop through all of the necessary inputs, using an array for your output data. Both the input and output would use the same index (input pins and numbered array). Just remember that PBASIC starts arrays at ZERO, so you may have to make accomodations for that in your coding (i.e. index - 1 rather than just index)
Regards,
Bruce Bates
Post Edited (Bruce Bates) : 1/14/2007 9:32:29 PM GMT
So if you need at least 3 A/D inputs for 3 IR rangers, you would need at least one ADC0834. You can hook up 3 IR rangers and still have one A/D input left over for the future. The multiple input ADC083x converters required you to SHIFTOUT your choice of which input pin to read from the ADC, then you SHIFTIN the actual reading just like you do with the single channel ADC0831.
There other A/D converters out there -- lots of them. There are lots of code examples around on the forums for the ADC083x converters though, and they return a single byte of data, which is one reason I think they are popular.
Attached is datasheet for the ADC083x. If you look at the pin diagrams for the ADC0834 you'll see where you can hook up more than one analog input.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST
I think you may have to use the ADC0832 for two additional sensors. If memory serves the electronics for the GazBot sensors is already integrated onto the board on there so unless you bypass it somehow you still need to use the ADC0831 that is on-board for the main sensor. I hope this helps. Take care.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support