I have a Sharp 2Y0A21 distance sensor (10cm-80cm) that I want to connect to my Propeller chip. As the sensor output is analog, I am using an Analog to Digital converter TLC0831 (It suppose to work the same way as ADC0831)
I did my connections following this link:
http://www.parallax.com/dl/docs/prod/ac ... 12Snrs.pdf
My code is in Spin (Propeller language), It is not so difficult to understand, I have been doing the following:
CS_BAR_PIN = 0 '(Pin numbers in the Propeller Chip, P0, P1, P2)
CLK_PIN = 1
DO_PIN = 2
- CODE: SELECT_ALL_CODE
Initialization:
{{ Initialize the pins direction and state. Must be called once. }}
dira[DO_PIN]~ ' set DO pin as input
outa[CS_BAR_PIN]~~ ' sets pin -CS high
dira[CS_BAR_PIN]~~ ' sets -CS pin as output (this means disabled !)
outa[CLK_PIN]~ ' sets clock pin low
dira[CLK_PIN]~~ ' sets pin as output
-------------------------------------------------------------------------------------------------
AcquireValue | data ' data could also be a byte VARiable
{{ Aquiring data requires to assert CS, pulse the clock once to start aquisition, then
pulse the clock 8 times to read each bit after the descending edge of the clock.
The chip is driven by the clock signal we generate, so timing is not critical. }}
data := 0 ' This will accumulate the resulting value
outa[CS_BAR_PIN]~ ' sets pin -CS low to activate the chip
outa[CLK_PIN]~~ ' pulse the clock, first high
outa[CLK_PIN]~ ' then low, this starts the conversion
'Read 8 bits, MSB first.
repeat 8
data <<= 1 ' Multiply data by two
outa[CLK_PIN]~~ ' pulse the clock, first high
outa[CLK_PIN]~ ' then low, this makes the next bit available on DO
data += ina[DO_PIN] ' Add it to the current value
end repeat
outa[CS_BAR_PIN]~~ ' Terminated, deselect the chip
return data
My problem is I don't get any result, all the output coming for the TLC0831 is 0.
I have tested the Sharp sensor with a multimeter and it is working good, so I guess the problem is with the TLC0831 connections.
At this point I don't know what else to try, I have attached the pictures of my setting, any suggestion would be appreciated,
Thank you.