Urgent Help needed with Sharp IR GP2D12!!!
haunteddansion
Posts: 68
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:
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:
BAS
906B
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST
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