Sharp GP2D12 Range Finder???


Results 1 to 5 of 5

Threaded View

  1. #1
    Join Date
    Dec 2007
    Location
    Toronto, Ontario
    Posts
    23

    Question Sharp GP2D12 Range Finder???

    Hi,

    Thanks to replies to my last post, I now have 4 channels of ADC to serial LCD working great on a pic16f877/04. With my current setup, I can measure 0-5 volts on ch 0. Channel 1 is for displaying distance based on the output of a Sharp GP2D12 IR range finder, but I can't make it work, the readings are all over the place. I do know that the analog output from the sensor is not linear, so how do I get accurate readings throughout it's range, which is up to 80 cm.
    Thanks alot,
    John
    code:

    include "modedefs.bas"

    DEFINE LOADER_USED 1
    DEFINE OSC 4
    DEFINE ADC_BITS 10 ' Set number of bits in result
    DEFINE ADC_CLOCK 3 ' Set clock source (3=rc)
    DEFINE ADC_SAMPLEUS 40 ' Set sampling time in uS

    ' PROGRAM VARIABLES
    vstep CON 1252 ' For 10-bit A/D +Vref = 5V : 5V/1023*256=1.252=vstep
    div con 1000'distance multiplyer
    volts VAR WORD ' Storage for A/D result
    distance var word
    temp var word
    light var word

    'ADC CONFIGURATION
    TRISA = %11111111 ' Set PORTA to all input
    'adcon1 = %10000000' --THIS IS BINARY EQUIV TO BELOW !!
    ADCON1.7 = 1 ' 10-bit A/D RA.3 = +Vref, Set PORTA analog and right justify result
    SEROUT2 portb.5,84,[12,22,17]
    loop:
    'ADC ROUTINE
    ADCIN 0,volts ' Read A/D channel 0 to 'volts' variable
    pause 10
    adcin 1,distance
    pause 10
    ADCIN 2,temp
    pause 10
    ADCIN 3,light
    'MATH ROUTINE
    volts = volts */ vstep
    DISTANCE = (distance */ div)*10
    temp= temp*/25
    light= light/10
    'SERIAL LCD OUTPUT
    SEROUT2 portb.5,84,[128,"BUSS VOLTAGE:",dec volts diG 3,".",dec2 volts,"vDC"]
    serout2 portb.5,84,[148,"IR DISTANCE.:",DEC DISTANCE dig 3,".",DEC2 DISTANCE," cm "]
    SEROUT2 portb.5,84,[168,"TEMPERATURE.:",DEC temp," c "]
    serout2 portb.5,84,[188,"LIGHT LEVEL.:",DEC light]

    Pause 50
    Goto loop
    End
    Last edited by Gixxer; - 12th December 2007 at 19:42.

Similar Threads

  1. Questions on ultrasonic distance finder
    By lilimike in forum mel PIC BASIC Pro
    Replies: 19
    Last Post: - 20th April 2010, 21:19
  2. using a pot to control a time range
    By glkosec in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 17th June 2008, 19:59
  3. Sharp GP2D12 8bit
    By Argo in forum mel PIC BASIC
    Replies: 0
    Last Post: - 25th October 2007, 23:40
  4. sharp GP2D12 interface pic16f676
    By jojokatada in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 19th April 2006, 17:26
  5. SRF04 Range Finder 16F628 R18iXL Board
    By Spindle in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 20th June 2005, 02:08

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts