Questions on ultrasonic distance finder


Closed Thread
Results 1 to 20 of 20

Hybrid View

  1. #1
    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?

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


    Did you find this post helpful? Yes | No

    Default

    Its possible that the LCDOUT routine really is taking that long.

    But ive found that its generally best to stop the timer to take a reading, and usually best to store that reading in a variable before displaying it, or doing anything else with it.

    See what happens if you do it like this:


    temp VAR word

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

    The difference between the 2 results will tell you how long the first LCDOUT routine is taking.
    "I think fish is nice, but then I think that rain is wet, so who am I to judge?" - Douglas Adams

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


    Did you find this post helpful? Yes | No

    Default

    ...well I am getting closer to the numbers I am expecting but...

    My values were 1001 and 4206 so it took 3205 to perform LCDOUT.

    Then I restarted the timer just before the last LCDOUT and added this to your code and got a value of 7405

    T1CON.0=0 ' Stop the timer
    temp.HighByte=TMR1H
    temp.LowByte=TMR1L
    LCDOUT $FE,$80,"TMR1 = ", dec temp

    So the second time LCDOUT executed it took 3199
    I did it a third time and found a different number again.

    So LCDOUT executed 3 times and it took less time everytime it executed.

    1st time took 3205
    2nd time took 3199
    3rd time took 3187

    I figured writting to the LCD on a blank line took 3205
    overwriting on the first line of the LCD took 3199
    and overwritting on the second line took 3187

    But I did it a fourth time (overwrote on the first line) and it took 3312
    This is the code I ended up with:
    Code:
    temp VAR word
    TMR1H=0 ' Reset timer value
    TMR1L=0
    T1CON.0=1 ' Start the timer
    pauseus 1000
    T1CON.0=0 ' Stop the timer
    temp.HighByte=TMR1H
    temp.LowByte=TMR1L
    T1CON.0=1 ' Restart the timer
    LCDOUT $FE,$80,"TMR1 = ", dec temp
    T1CON.0=0 ' Stop the timer
    temp.HighByte=TMR1H
    temp.LowByte=TMR1L
    T1CON.0=1 ' Restart the timer
    LCDOUT $FE,$C0,"TMR1 = ", dec temp
    T1CON.0=0 ' Stop the timer
    temp.HighByte=TMR1H
    temp.LowByte=TMR1L
    T1CON.0=1 ' Restart the timer
    LCDOUT $FE,$80,"TMR1 = ", dec temp
    T1CON.0=0 ' Stop the timer
    temp.HighByte=TMR1H
    temp.LowByte=TMR1L
    T1CON.0=1 ' Restart the timer
    LCDOUT $FE,$C0,"TMR1 = ", dec temp
    T1CON.0=0 ' Stop the timer
    temp.HighByte=TMR1H
    temp.LowByte=TMR1L
    LCDOUT $FE,$80,"TMR1 = ", dec temp
    This beeing said, if I start over from the begining, no matter how many times I am always getting the same results so this rules out a bad resonator or voltage noise or any othe hardware issue.

    So there is something in the process that is hapenning which is irregular and I wish I could understand what it is!

    I am really sorry to be such a pain and I appreciate your patience but I am still a little confused.

    Mike

  4. #4
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166


    Did you find this post helpful? Yes | No

    Default

    lilimike, A answer to your question is in the delays you have programmed into the LCD DEFINES. Just look at what you have....

    LCD_DATAUS CON 50 ' Data delay time in us
    LCD_COMMANDUS CON 2000 ' Command delay time in us

    Everytime you send a cursor command proceeded with $FE your code is waiting 2 milliseconds...

    Dave Purola,
    N8NTA

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


    Did you find this post helpful? Yes | No

    Default

    Hi Dave,

    This I can understand that the LCDOUT command is taking time to do what it has to do and it is configured with some delays but what i don't understand is why it is taking a different time each time I send data to LCDOUT.
    (I've never wrote the word "time" so many times in so little time in my life)

    Could it be that it is the LCD's controller itself that is taking a different time to generate different data?

    Maybe it is faster to write 1 than 8?

    Maybe I am trying to find the solution in the PIC process but the solution is actually in the LCD process?

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


    Did you find this post helpful? Yes | No

    Default

    The difference between 3205, 3199, 3187 and 3312 is really not a lot when you think that this is measured in microseconds.

    The command you are timing is this:

    LCDOUT $FE,$80,"TMR1 = ", dec temp

    The time this takes will depend on the value of temp. As temp increases, it takes longer to convert it into a decimal number (dec temp), and as the decimal number increases in number of digits, it takes slightly longer to write it to the screen.

    What happens if you reset the timer value each time? Try adding TMR1H=0 and TMR1L=0 just before each time you start 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

    If I reset the timer I will obviously always get the same value because temp will always display the same value.
    So I rewrote the code to this:
    Code:
    staticVal var word
    temp VAR word
    TMR1H=0 ' Reset timer value
    TMR1L=0
    
    T1CON.0=1 ' start the timer
    pauseus 1000
    T1CON.0=0 ' Stop the timer
    
    staticVal = 70
    T1CON.0=1 ' start the timer
    LCDOUT $FE,$80,"TMR1 = ", dec staticVal
    T1CON.0=0 ' Stop the timer
    temp.HighByte=TMR1H
    temp.LowByte=TMR1L
    LCDOUT $FE,$C0,"Disp Time = ", dec temp
    and I specified different values to display in staticVal.
    It turns out that displaying 1 to 9 took 3819 ms
    to display 10 to 29 and 40 to 49 took 3944 ms
    to display 30 to 39 and 50 to 69 took 3938 ms
    and so on...

    So you are right, this confirms that the difference of time LCDOUT is taking to display is based on which value is beeing displayed. This makes me wonder because technically it is always computing 4 bit at a time but at least now I know what is going on and I thank you for your help and your patience.

    Mike

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