Questions on ultrasonic distance finder


Closed Thread
Results 1 to 20 of 20

Hybrid View

  1. #1
    Join Date
    Nov 2005
    Location
    Perth, Australia
    Posts
    429


    Did you find this post helpful? Yes | No

    Default

    Not sure about that. I didn't use any of the code from that site - i wrote my own in PBP.

    All i used from that site was the receiver amplification/detection part of the circuit shown there.
    "I think fish is nice, but then I think that rain is wet, so who am I to judge?" - Douglas Adams

  2. #2
    Join Date
    May 2009
    Location
    Montreal, QC, Canada
    Posts
    118


    Did you find this post helpful? Yes | No

    Default

    Hi Kamikaze,

    I guess the answers to my questions is test and evaluate, in this case I am on the right track.

    I started to design arround This guy's project but I was never able to observe what I was expecting on the scope for the input amplification stages and I was not completely understanding what I was doing so I've decided to start with the basics and found this link from Les Johnson which is really basic and I am having some difficulties understanding 100% of his code but I do get the basics.

    I am pretty close to a newbe with PBP Pro and PICs, but I am really good at playing sounds on piezzo and blinking LEDs and I think now I am good with LCDs so like I said, I have a long way to go.

    I was wondering if it is better to do more hardware and less code or vice versa but I guess the opposite is better since it is faster to change code than it is to change hardware, I am just not sure yet where I have to draw the line.

    I am presently intensivelly playing with timers and interupts and I must say I am having a lot of fun trying to understand but as I am doing this on an average of 16 hours per day, I should get the hang of it in no time.

    While I am at it maybe if someone can explain something; in my code I have
    Code:
    CMCON = 7                   ' Disable comparator
    INTCON = $80                ' Disable interupts
    T1CON = 0                   ' Timer1 off, prescaler 1:1
    and then I do this:
    Code:
        
    TMR1H = 0:TMR1L = 0
    T1CON.0 = 1
    PAUSEUS 1
    LCDOUT $FE,$80,"TMR1H = ", dec TMR1H
    LCDOUT $FE,$C0,"TMR1L = ", dec TMR1L
    I get: TMR1H = 4 and TMR1L = 23

    What I understand from the datasheet is TMR1H cycles when TMR1L overflows so the value I am getting is actually:
    4 x 65535 +23 ?

    how did it get do far with PAUSEUS 1 ?

    Then if I do PAUSEUS 2
    I get: TMR1H = 4 and TMR1L = 24

    I am confused!

    Mike

  3. #3
    Join Date
    Nov 2005
    Location
    Perth, Australia
    Posts
    429


    Did you find this post helpful? Yes | No

    Default

    TMR1H increments when TMR1L overflows at 256. So its 4x256+23.

    Keep in mind that the timer will run at 1/4 the frequency of your main oscillator.

    edit: also, pauseus 1 will not result in a 1us pause because pauseus has a minimum pause time. have a look at pauseus in the PBP manual.
    "I think fish is nice, but then I think that rain is wet, so who am I to judge?" - Douglas Adams

  4. #4
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,170


    Did you find this post helpful? Yes | No

    Default

    Do you really have to built it yourself?

    Look at the http://www.robot-electronics.co.uk/a...c_Rangers.html

    Once I had to built that ranger in 1990 but then I could not find ready made modules.

    After a few year I tested the modules of the above link and was surprised.

    First of the idea to drive the Tx US transducer by the well known MAX232 chip (it can produce fast +/- 10 volts of pulses!) and second by its simplicity and performance.

    Ioannis

  5. #5
    Join Date
    May 2009
    Location
    Montreal, QC, Canada
    Posts
    118


    Did you find this post helpful? Yes | No

    Default

    Well the main reason why I want to build it myself is to learn everything about it, I really like the challenge and when I go to bed just about every other day or so I sleep well because I like the feeling of having learned something new.

    Now trying to calculate and figure how I got this result on my display is probably going to keep me up for a few days because even after Kamikaze's response I am still confused. Maybe it's all about the timing differences between the speed my brain works and the speed of a PIC at 4MHz.

    Or maybe I am trying to calculate something that is uncalculatable!

  6. #6
    Join Date
    Nov 2005
    Location
    Perth, Australia
    Posts
    429


    Did you find this post helpful? Yes | No

    Default

    OK, if you are running your PIC at 4MHz, then the timer will run at 1MHz, which means that TMR1L will increment every 1uS (when the prescale is set to 1:1).

    timing the command PAUSEUS 1 will not give you a result of 1 becuase of 2 reasons. First, PAUSEUS has a minimum pause time and 1uS is so fast that the time it takes to check the timer value comes into play.

    Try this:

    temp VAR word

    TMR1H=0 ' Reset timer value
    TMR1L=0
    T1CON.0=1 ' Start the timer
    PAUSEUS 1000 ' Pause 1000uS
    T1CON.0=0 ' Stop the timer
    temp.HighByte=TMR1H
    temp.LowByte=TMR1L
    LCDOUT $FE,$80,"TMR1 = ", dec temp

    The LCD should display somewhere around 1000 - Probably a little more because of the time it takes to start and stop the timer.
    "I think fish is nice, but then I think that rain is wet, so who am I to judge?" - Douglas Adams

  7. #7
    Join Date
    May 2009
    Location
    Montreal, QC, Canada
    Posts
    118


    Did you find this post helpful? Yes | No

    Default

    you are absolutely right, 1001 is what I get.

    I am sorry if I ask again about the timing but are you able to explain this?

    if I keep the timer running, I removed the PAUSEUS and I do something like this:
    Code:
    LCDOUT $FE,$80,"H",dec TMR1H,"L",dec TMR1L,"H",dec TMR1H,"L",dec TMR1L
    The first set of H/L I get 401
    The second set I get 4604

    Why it isn't the second set taking arround 800?
    Is it because the actual calculation is based on the assembly and when it is compiling it is doing funny things?

Similar Threads

  1. Ultrasonic distance sensor with PIC16F84A
    By MrRoboto in forum mel PIC BASIC
    Replies: 3
    Last Post: - 29th June 2009, 09:01
  2. Sharp GP2D12 Range Finder???
    By Gixxer in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 13th December 2007, 09:21
  3. sensor ultrasonic 8051&PIC
    By hd_uni_pro in forum Schematics
    Replies: 1
    Last Post: - 13th September 2006, 12:58
  4. ultrasonic sensor
    By PoTeToJB in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 9th May 2006, 20: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 : 1

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