1. Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
    Dismiss Notice

PIC16f690, initialisation of ports, LEDS,reading from a pin

Discussion in 'Microcontrollers' started by fantabulous68, Aug 24, 2009.

  1. Nigel Goodwin

    Nigel Goodwin Super Moderator Most Helpful Member

    Joined:
    Nov 17, 2003
    Messages:
    39,324
    Likes:
    653
    Location:
    Derbyshire, UK
    Measuring distances using a simple beam of light reflected back is VERY, VERY difficult due to the fact the light acts at the same speed as the electronics does, and MUCH faster than a processor.

    As Bill says, consult your teacher - it's not really the sort of project you would be given without a lot of information and help been provided.
     
  2. fantabulous68

    fantabulous68 Member

    Joined:
    Feb 20, 2007
    Messages:
    323
    Likes:
    0
    :)actually, we are given zero information. the only ting we given is the topic and specifications. We can consult with our supervisors.
     
  3. Nigel Goodwin

    Nigel Goodwin Super Moderator Most Helpful Member

    Joined:
    Nov 17, 2003
    Messages:
    39,324
    Likes:
    653
    Location:
    Derbyshire, UK
    I suggest you consult then - and please let us know what he/she says.
     
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. fantabulous68

    fantabulous68 Member

    Joined:
    Feb 20, 2007
    Messages:
    323
    Likes:
    0

    Im using the hardware circuit from this link:

     
  6. fantabulous68

    fantabulous68 Member

    Joined:
    Feb 20, 2007
    Messages:
    323
    Likes:
    0
    i want to determine the distance from the time interval between pulses.
    Just imagine you dropping a stone into a deep hole and waiting for the sound of the stone hitting the floor.
    The shorter the time between the point of release of the stone and the sound of it hitting the floor, the shorter
    the distance the stone travelled.

    The is how i want to program the circuit to operate.



    Basically the sequence for programming should be as follows:

    Set timer to ZERO!
    Send signal to transmitting IR diode
    Start timer
    If your receiving IR diode(active low) - indicating it received the signal the STOP timer.

    Work out the distance from halving the time and using that speed formula : distance = speed * time.


    if i cant get the timer to work properly maybe i try this approach... its a little crude
    but should give me some results in any case...

    using an arbitrary variable say T (being an integer)

    Set T = ZERO.
    Send signal to transmitting diode.

    If your receiving IR Diode is still low (meaning no signal received as yet)
    increase T by 1

    The above loop will continue to run until the receiving IR Diode goes HIGH.

    Now you will have an unknown positive value in T which is not associated in any equation.
    But if you plot out the value of T versus the distance you set the diodes at, then you can work out the equation
    for distance - straight line equation

    y = mx + c

    m = (y2-y1)/(x2-x1)
    (x1,y1) and (x2,y2) being co-ordinates with x representing distance and y representing the various values of T.

    ^
    | /
    T| /
    | /
    | /
    | / this is a straight line
    | /
    |/
    |----------------------------- >
    0

    your two co-ordinates (x1,y1) and (x2,y2) are for the shortest and furthest distance of measurement.
    So when setting the shortest distance - use a ruler and obstruct the IR diodes approximately 5cm away.
    Your distance is known cos you measured it right But you will get a T value for this distance.

    Now set the furthest distance (50cm) - use the ruler, obstruct again at 50cm away and get that T value.
    Plot a graph and work out the equation of T versus distance.

    But this is if i cannot get the timer function to work but the procedure is the same in any case.

    yes i will consult with my lecturer and respond to you all.
     
    Last edited: Aug 27, 2009
  7. blueroomelectronics

    blueroomelectronics Well-Known Member

    Joined:
    Jan 21, 2007
    Messages:
    12,536
    Likes:
    170
    Location:
    Toronto, Canada
    Problem is your stone travels at the speed of light.

    Your project said proximity was a requirement not measurement.
     
  8. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,236
    Likes:
    645
    Location:
    Ex Yorks' Hants UK
    hi,
    Work out how short a time the IR pulse width will have to be to ensure its off before you get an echo back.:)
     
  9. Nigel Goodwin

    Nigel Goodwin Super Moderator Most Helpful Member

    Joined:
    Nov 17, 2003
    Messages:
    39,324
    Likes:
    653
    Location:
    Derbyshire, UK
    As we've been saying all along - light is FAR, FAR, too fast - when you drop the stone the sound travels at a nice slow 1000 feet per second (very roughly), this is simple to do using electronics and processors. It's why ultrasonic sound is used for measuring levels in tanks, and not IR.

    For each loop of your processor using light, the beam will have travelled 100's of meters.

    The hardware you've using is for simple proximity detection, NOT measuring distance - and as I mentioned earlier, you can do a crude and rough distance measurement by using different transmitter powers in a proximity detector.
     
  10. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,236
    Likes:
    645
    Location:
    Ex Yorks' Hants UK
    Last edited: Aug 27, 2009
  11. Nigel Goodwin

    Nigel Goodwin Super Moderator Most Helpful Member

    Joined:
    Nov 17, 2003
    Messages:
    39,324
    Likes:
    653
    Location:
    Derbyshire, UK
    Was that the one that used to be the joint Bush/Toshiba factory way back when Bush still existed?.

    If it is, back in the late 70's or so Toshiba pulled out and made Bush go bankrupt, then bought the factory cheap for themselves :mad:
     
  12. fantabulous68

    fantabulous68 Member

    Joined:
    Feb 20, 2007
    Messages:
    323
    Likes:
    0
    thanks for the help, im just getting worried, dont wana fail.
     
  13. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,236
    Likes:
    645
    Location:
    Ex Yorks' Hants UK
    hi,
    Have just read the 'set specification'.
    Whom ever set you that task as a project, has no idea of the complexity of a IR measuring system for measuring from 2cm to 50cm with 1cm accuracy off the surface of water.:)
     
  14. be80be

    be80be Well-Known Member

    Joined:
    Aug 23, 2008
    Messages:
    4,869
    Likes:
    144
    Location:
    morristown,tn
    I don't no if any one here has read 123 pic microcotroller experiments for the Evil genius but it shows how to do what you want to do that where I got the idea. Myke Predko write some killer code.

    You can't change how fast light moves. But you can set how long the led is on how long it is off and get how far the water is in the tank

    I don't think you'll get in 1cm
     
    Last edited: Aug 27, 2009
  15. blueroomelectronics

    blueroomelectronics Well-Known Member

    Joined:
    Jan 21, 2007
    Messages:
    12,536
    Likes:
    170
    Location:
    Toronto, Canada
    I've got the book, I'll have to read that section. Doesn't seem like it'll work IMHO.
     
  16. be80be

    be80be Well-Known Member

    Joined:
    Aug 23, 2008
    Messages:
    4,869
    Likes:
    144
    Location:
    morristown,tn
    In my humble opinion I don't no if it will work on water and I'm not the best coder in the world. I used it to keep from hitting the walls. You can set a range like turn at 3 inches.
     
    Last edited: Aug 27, 2009
  17. jpanhalt

    jpanhalt Well-Known Member Most Helpful Member

    Joined:
    Jun 21, 2006
    Messages:
    6,060
    Likes:
    520
    Location:
    Cleveland, OH, USA
    On another forum, the same question has been raised. Some assume that IR will bounce off the surface of water like it does from a wall. That is, when perpendicular, it bounces straight back so you can get a TOF distance measurement.

    I have a Stanley FatMax which uses IR at 630 to 690 nm and TOF to measure distance, surprisingly to fairly high precision. So, I did an experiment from a fixed height of about 4' aimed at a basin of fresh water (empty and full). It did not measure the water level surface. In fact, the measured distance when the basin was full was increased, presumably due to the higher refractive index of water compared to air and reflection from the bottom in both cases.

    That was a quick and dirty experiment, but it was enough to suggest that the fundamental assumption needs to be confirmed before doing a lot of work on the project.

    John
     
  18. blueroomelectronics

    blueroomelectronics Well-Known Member

    Joined:
    Jan 21, 2007
    Messages:
    12,536
    Likes:
    170
    Location:
    Toronto, Canada
    Ahh I remember the 123 project, it's proximity not distance measurement device. It uses the reflection to see if it's close to a wall. It cannot resolve distance. The book also has a Sharp IR Rangefinder project, they work on triangulation.
    [​IMG]
     
    Last edited: Aug 27, 2009
  19. fantabulous68

    fantabulous68 Member

    Joined:
    Feb 20, 2007
    Messages:
    323
    Likes:
    0
    Thanks for confirming that jpanhalt
     
  20. fantabulous68

    fantabulous68 Member

    Joined:
    Feb 20, 2007
    Messages:
    323
    Likes:
    0
    any1 knows of an infrared receiver IC with an analogue output,
    its output voltage should vary with the intensity of the reflected light?

    plan to do some ADC with a lookup table
     
  21. be80be

    be80be Well-Known Member

    Joined:
    Aug 23, 2008
    Messages:
    4,869
    Likes:
    144
    Location:
    morristown,tn

Share This Page