Shop OBEX P1 Docs P2 Docs Learn Events
Infrared Sensor (Sharp GP2Y0A02YK0F)-Long Range Infrared Pro — Parallax Forums

Infrared Sensor (Sharp GP2Y0A02YK0F)-Long Range Infrared Pro

B.ASHISHB.ASHISH Posts: 28
edited 2012-03-11 10:17 in General Discussion
Sir,
The Infrared Sensor produces an output analog voltage.
I want to interface it with the Propeller Microcontroller(Propeller Board used has a Product Number 555-32100.
Propeller IC is P8x32A-044 0739

Comments

  • B.ASHISHB.ASHISH Posts: 28
    edited 2012-03-06 10:02
    Sir,
    I want the code in Spin
  • BitsBits Posts: 414
    edited 2012-03-06 10:13
    Not sure who you are calling sir but, Ill chime in here.

    Generally as a rule of thumb if the signals are analog then it needs to be converted to digital, I say this lightly because there is always another way to skin a cat.

    So if the signal is analog use a ADC to convert it to digital.

    No code for you...

    Cause you need to select a ADC.
  • Mike GreenMike Green Posts: 23,101
    edited 2012-03-06 10:17
    There is no readily accessible interface on the Demo Board for an analog voltage. It's not hard to add using the little breadboard area on the Demo Board. Pick up an analog to digital converter like the MCP3202. There's an object in the Object Exchange that handles the interfacing. Look at the comments in the Spin source files for details and examples. You can use any 3 I/O pins to interface to the MCP3202 and you specify which pins when you initialize the object as noted in the comments.

    There are other objects in the Object Exchange for some other analog to digital converters, but the MCP3202 is very easy to use. It's possible to do analog to digital conversion with the Propeller with only a few passive components, much like the Stamps do it. You'll have to do your own coding though. Look at the discussion on the "app-notes" page here under battery voltage monitoring for some ideas. There is some useful code in the BS2_Functions object to provide the same functionality as the Stamps' RCTIME statement.
  • B.ASHISHB.ASHISH Posts: 28
    edited 2012-03-07 03:45
    Is it possible to use the Infrared Sensor with Counters without using an ADC?
  • Martin_HMartin_H Posts: 4,051
    edited 2012-03-07 06:04
    I would just use a RC circuit with an RCTIME command to measure the voltage. In the book "What's a Microcontroller" there's a section on measuring analog voltages using RCTIME.

    http://www.parallax.com/dl/docs/books/edu/wamv2_1.pdf

    You can do this on the propeller chip as well using the basic stamp functions.
  • B.ASHISHB.ASHISH Posts: 28
    edited 2012-03-11 04:34
    Sir,can you please explain me how to connect the sensor along with the RC Circuit.this is the code I'm using for the RCTime.Sir,Please check it.
    CON
      _xinfreq = 5_000_000
      _clkmode = xtal1 + pll16x
    VAR
    long RCValue
    OBJ
    pst  : "Parallax Serial Terminal"
    RC   : "RCTIME"
    PUB main
    pst.Start(115200)
    RCValue:=0
    RC.start( 0,1,@RCValue)
    repeat
      pst.Dec(RCValue)
      pst.NewLine
      RC.Pause1ms(10)
    
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2012-03-11 08:59
    I have used analog output sensors without ADCs or RCTIME.
    In one instance I used the sensor output as the control voltage input for the VCO section of a 4046 (CD4046, 74HC4046, etc.) and COUNTed its output. In another, I had the sensor output going to the inputs of a couple of comparators where crossing the threshold of one indicated "near" and the other indicated "closer still".
  • T ChapT Chap Posts: 4,223
    edited 2012-03-11 10:17
    Similar to PJ Allens idea, I have produced a ramping voltage from a Prop pin using PWM(ramp frqa), the voltage looks like a reverse sawtooth. Connect the voltage to a comparator, the other input of the comparator to the analog source(sensor). As the voltage ramps up from the PWM, and at the trip point on the comparator, the Prop code can take note of the comparator output going low(active low), and then convert the PWM (counter frqa value) at the point of the trip to a usable value. The frqa value can be scaled to the voltage. It just takes some experimenting to document the voltages out of the Prop in order to create your scale.This methods of course is not for high speed changes, as the ramp does take some time to move from 0v to 3v3V and start over. But for distance or motion sensing is quite OK. An advantage of this method is that it is not so delicate as trying to use the Prop ADC method.
Sign In or Register to comment.