Shop OBEX P1 Docs P2 Docs Learn Events
Sharp GP2Y0A21YK WITH ADC0831 — Parallax Forums

Sharp GP2Y0A21YK WITH ADC0831

I LOVE ROBOTI LOVE ROBOT Posts: 22
edited 2007-01-16 03:23 in Robotics
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
·
·
·

Comments

  • Bruce BatesBruce Bates Posts: 3,045
    edited 2007-01-14 21:25
    Sir -

    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
  • I LOVE ROBOTI LOVE ROBOT Posts: 22
    edited 2007-01-14 22:47
    THANK Bruce Bates FOR YOUR ANSWER. BUT IF I WANT TO USE 2 OF Sharp GP2Y0A21YK SO CAN I USE ADC0834 PER OF THEM. OR I HAVE TO USE LIKE multiple inputs ADC0832. CAN YOU INDICATE ME WHICH ONE IT BETTER.
  • ZootZoot Posts: 2,227
    edited 2007-01-14 23:37
    I think Bruce means you will need to decide how many possible A/D inputs you want. The ADC0831 has ONE input (i.e, one IR ranger); the ADC0832 has TWO inputs; the ADC0834 has FOUR inputs, etc.

    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
  • I LOVE ROBOTI LOVE ROBOT Posts: 22
    edited 2007-01-15 01:40
    THANK ZOOT!! SO I THINK I HAVE TO RENEW MY CIRCUIT FIRST. I WANT TO USE Sharp GP2Y0A21YK JUST ONLY TWO. I WILL BUY ADC0832 BECAUSE HAVE 2 ANALOG INPUT. AFTER THAT I WILL RENEW MY PROGRAM.
  • ZootZoot Posts: 2,227
    edited 2007-01-15 02:04
    This is just my own personal opinion -- using an ADC0832 vs. ADC0834 is not that much different -- they're both 14 pin packages. Use the 0834 -- you'll have two extra A/D inputs ready to go without having to rewire, and you'll be familiar with your own code for accessing the inputs.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    When the going gets weird, the weird turn pro. -- HST
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2007-01-15 17:08
    Hello,

    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
  • I LOVE ROBOTI LOVE ROBOT Posts: 22
    edited 2007-01-15 19:20
    thank Chris
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2007-01-15 20:14
    Just remember, if you have to use both chips you can share the CLK and DATA lines on an SPI device but each device will need its own CS line.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • I LOVE ROBOTI LOVE ROBOT Posts: 22
    edited 2007-01-16 03:23
    OH!! THANK Chris.
Sign In or Register to comment.