Shop OBEX P1 Docs P2 Docs Learn Events
Urgent Help needed with Sharp IR GP2D12!!! — Parallax Forums

Urgent Help needed with Sharp IR GP2D12!!!

haunteddansionhaunteddansion Posts: 68
edited 2007-06-11 18:12 in BASIC Stamp
I am working on a motion sensor for a client the GPD12 fits the critera perfectly. I have wired up one sensor and it works great, BUT we need a wider "cone" of trigger zone. So I believe we could use 2 sensors in unison. For the life of me I cannot figure out how to modify this code and how to wire it up into the BS1. I have attched the code and if anyone could please walk me through this for I am new to the adc with the stamp from connecting it to my code. Thanks soo much

Best,
Daniel



' {$STAMP BS1}
' PROGRAM: AD_CONV.BAS





SYMBOL CS = 0
SYMBOL AD = PIN1
SYMBOL CLK = 2

SYMBOL DATA = B0
SYMBOL i = B2

setup: LET PINS = 255 'Pins high (deselect ADC).
LET DIRS = %11111101 'S_out, CLK, CS outputs; AD input.

loop: GOSUB conv 'Get the data.

DEBUG DATA
PIN6=1
PAUSE 25 'Wait 2 seconds
IF DATA > 23 THEN Trigger
GOTO loop 'Do it forever.



conv: LOW CLK 'Put clock line in starting state.
LOW CS 'Select ADC.
PULSOUT CLK, 1 '10 us clock pulse.
LET DATA = 0 'Clear data.
FOR i = 1 TO 8 'Eight data bits.
LET DATA = DATA * 2 'Perform shift left.
PULSOUT CLK, 1 '10 us clock pulse.
LET DATA = DATA + AD 'Put bit in LSB of data.
NEXT 'Do it again.
HIGH CS 'Deselect ADC when done.
RETURN


Trigger:
PIN6=0
PAUSE 500
PIN6=1
GOTO loop:

Comments

  • ZootZoot Posts: 2,227
    edited 2007-06-08 05:58
    What kind of ADC are you using? If it's one channel (looks like it is), then you will need another ADC for the second IR sensor.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    When the going gets weird, the weird turn pro. -- HST
  • haunteddansionhaunteddansion Posts: 68
    edited 2007-06-08 06:10
    I have a adc0831 for this code, but I just bought an adc0834 with 4 channels, how can i code it and also hook it up, thanks soo much for responding!
  • ZootZoot Posts: 2,227
    edited 2007-06-11 18:12
    That ADC requires you to "shiftout" 2 bits for choosing the channel right? Since the BS1 doesn't have SHIFTIN or SHIFTOUT, you'll need to construct another subroutine similar to the one you have that sends the channel to convert to the ADC. Then you use the routine you have now to get the data for that channel.

    In pseudocode it would be something like:

    chan = 0
    GOSUB select_chan
    GOSUB conv 'returns the variable "val" -- I would watch out for a variable named DATA, which is a reserved word for BS2s
    leftReading = data
    chan = 1
    GOSUB select_chan
    GOSUB conv
    rightReading = data
    '...etc.

    select_chan:
    'a routine similar to conv that places two-bit channel selection from "chan" onto the clk and sout pins
    return

    conv:
    'etc.


    On the BS2 I would do it as an array and use shiftin/shiftout:

    vals VAR Byte(3) 'three bytes
    i VAR Nib

    for i = 0 to 2
    GOSUB chan_sel
    GOSUB conv
    next

    'now vals(0), vals(1), vals(2) all have the appropriate data

    chan_sel:
    SHIFTOUT i channel selection, etc.
    RETURN

    conv:
    SHIFTIN to val(i), etc.
    RETURN

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    When the going gets weird, the weird turn pro. -- HST
Sign In or Register to comment.