Sharp 2Y0A21 sensor + Analog to digital TLC0831 problem.

Digital Fiber, Photoelectric, Laser Range, Optical, Temperature, Rotary Encoder, Ultrasonic, Gas, Gyro, Accelerometer, FlexiBend, Flexiforce, Compass......

Sharp 2Y0A21 sensor + Analog to digital TLC0831 problem.

Postby Elenssar » Fri Jun 18, 2010 12:15 pm

Hello,

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.

Image
Image
Elenssar
Greenhorn
 
Posts: 2
Joined: Fri Jun 18, 2010 12:08 pm

Re: Sharp 2Y0A21 sensor + Analog to digital TLC0831 problem.

Postby ober » Fri Jun 18, 2010 9:25 pm

Very tidy work you have there. Well documented source code and nice prototyping wiring.

From the data sheet of TLC0831, it seem that your connection is correct. Assuming the connection is really correct, then we left the source code before concluding the IC is broken.

I am not familiar with SPIN code hence cannot help much on source code, but can you make sure the clock of SPI is giving pulses?
Ober Choo
Cytron Technologies Sdn Bhd
www.cytron.com.my
User avatar
ober
Moderator
 
Posts: 1486
Joined: Wed Apr 15, 2009 1:03 pm

Re: Sharp 2Y0A21 sensor + Analog to digital TLC0831 problem.

Postby Elenssar » Fri Jun 18, 2010 10:42 pm

I just go it working now!

It was a mistake in the breadboard continuity connection that was mixing up the signal, It was the only thing I didn't check.

Thank you very much for your support!
Elenssar
Greenhorn
 
Posts: 2
Joined: Fri Jun 18, 2010 12:08 pm

Re: Sharp 2Y0A21 sensor + Analog to digital TLC0831 problem.

Postby shiyan » Sun Jun 20, 2010 9:55 am

Elenssar WROTE:It was a mistake in the breadboard continuity connection that was mixing up the signal, It was the only thing I didn't check.


I always make mistake about that too.... people seldom notice that :lol:

Anyway, why Propeller does not come with ADC? It is very useful peripheral :roll: , still I heard Propeller is very powerful microcontroller from Parallax, right?
User avatar
shiyan
Amateur
 
Posts: 189
Joined: Wed Jun 09, 2010 10:59 am


Return to Sensor

Who is online

Users browsing this forum: No registered users and 20 guests

cron