TIMER1 or RCTIME?


Closed Thread
Results 1 to 8 of 8
  1. #1
    Join Date
    Dec 2008
    Location
    Charlottesville, VA
    Posts
    31

    Post TIMER1 or RCTIME?

    A friend and I are working on a robotics project. Our mobile robot application utilizes infrared technology for object detection, and eventually, communication. However, we have recently decided to implement an ultrasonic range finder on this project. The problem we have is that we are not familiar with how to program the TIMER registers nor how to work the interrupts. We are using one pin of our PIC16F877A to drive power to a 555 timer, which in turn, generates roughly a 42khz signal to be transmitted by the ultrasonic range finder. Once this signal is received, it sends a high pulse back to another pin of the pic. The problem we are having is getting the amount of time it takes from sending the signal to receiving the signal. As many of you know, we need the elapsed time in order to calculate the distance from the object. I've been trying to read up on both the TIMER registers and the RCTIME command as possibilities for helping us fix this problem but as of yet I've really gotten no where. If any of you could provide us with a sample code to go by we would greatly appreciate it. Thank you all for your time.

  2. #2
    Join Date
    May 2008
    Location
    Italy
    Posts
    825


    Did you find this post helpful? Yes | No

    Default

    You should read the thread below, which I sure it should solve your problem.

    http://www.picbasic.co.uk/forum/showthread.php?t=190

    Al.
    All progress began with an idea

  3. #3
    Join Date
    Dec 2008
    Location
    Charlottesville, VA
    Posts
    31


    Did you find this post helpful? Yes | No

    Post

    I'm not too familiar with assembly or c code. I am using the basic like language written in microcode studio for this.

  4. #4
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,615


    Did you find this post helpful? Yes | No

    Wink

    Quote Originally Posted by mcbeasleyjr View Post
    amount of time it takes from sending the signal to receiving the signal. As many of you know, we need the elapsed time in order to calculate the distance from the object. I've been trying to read up on both the TIMER registers and the RCTIME command as possibilities for helping us fix this problem but as of yet I've really gotten no where. If any of you could provide us with a sample code to go by we would greatly appreciate it. Thank you all for your time.

    Hi, ...

    Let's see:

    sound speed @ 20°C ( SQR ( 1.4*287*(273+20)) = ~ 340 m/s

    say your min distance will be ~ 10 cm ... time will be 2x.1/340 ~ 600 µS

    RCTime @ 20 Mhz gives 2µS granularity ... for a 16 bits value

    so, the range will be 10 cm to 10cm* 65535/300 = 21.8 meters.

    Looks fine ...

    Alain
    Last edited by Acetronics2; - 29th December 2008 at 14:07.
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  5. #5
    Join Date
    Dec 2008
    Location
    Charlottesville, VA
    Posts
    31


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Acetronics View Post
    Hi, ...

    Let's see:

    sound speed @ 20°C ( SQR ( 1.4*287*(273+20)) = ~ 340 m/s

    say your min distance will be ~ 10 cm ... time will be 2x.1/340 ~ 600 µS

    RCTime @ 20 Mhz gives 2µS granularity ... for a 16 bits value

    so, the range will be 10 cm to 10cm* 65535/300 = 21.8 meters.

    Looks fine ...

    Alain
    Thank you for your help. However, I am a little confused by your calculations. Could you explain them a little more for me? I understand your calculation for speed of sound as that is what I am already using. It's from there on that I am confused.

  6. #6
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,615


    Did you find this post helpful? Yes | No

    Talking

    Hi,

    as your Tx and Rx will be on the same side, both facing the object to be detected ...

    sound will have a travel equal to ... Twice the distance you look for.

    As simple as that !

    2 x 10 cm / 340 m/s = ... 0.588 ms = ~ 600 µs

    10 cm mini ??? haha ... I let you discover why ... and why to cancel detections under these values ...

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  7. #7
    Join Date
    Dec 2008
    Posts
    13


    Did you find this post helpful? Yes | No

    Smile Your ROBOTICS Project

    Got some pictures of your ROBOT so we can see please ?

    Happy New Year 2009

    Robert.Quaas

  8. #8
    Join Date
    Dec 2008
    Location
    Charlottesville, VA
    Posts
    31


    Did you find this post helpful? Yes | No

    Smile

    First of all I want to thank you all for your help.... I believe I have figured the RCTIME command out well enough that I have a fairly accurate distance measurement.

    Here is the section of my code. The only problem that I have is the fact that you can't use floats in Microcode studio, or if you can I don't know how. So some parts of my calculations may seem awkward but it will work right once finished.

    CHECK_RANGE:
    FOR B = 1 TO 50
    SPEED_OF_SOUND = 1126 'Speed of sound at 68 degrees F is 1125.79ft/s
    DEFINE PULSIN_MAX 4000 'Limits the count to an equivalent of about 8ms
    HIGH PORTB.0 'Used to drive a 555 timer which generates 40khz signal
    RCTIME PORTB.1, 1, RETURN_TIME 'How long before pin changes logic?
    RETURN_TIME = RETURN_TIME * 2 'Calculates total microseconds
    SPEED_OF_SOUND = SPEED_OF_SOUND * 12
    DISTANCE = (SPEED_OF_SOUND * (RETURN_TIME / 1000 / 1000)) / 2
    LCDOUT $FE, 1
    LCDOUT $FE, 2
    LCDOUT $FE, $0C
    LCDOUT "DISTANCE IS ", DISTANCE, "IN" '2 x 16 LCD Display by the way
    PAUSE 500
    NEXT B
    RETURN

    Now, by my calculations, using a 20MHz clock makes the resolution of the RCTIME command 2us. So by saying (return_time * 2), this multiplies the count returned by 2 us. At max range it would be 4000 * 2 or 8000us. Then, I want to measure the distance in inches so I multiply the speed of sound variable by 12 to convert to inches. Then for the distance calculation, and this is where my problem is. I cannot store a float in a variable, instead the result of the calculation will be stored with everything after the decimal cut off. But I can deal with that for now. I would like to know if it is possible to get the right side of the decimal stored into a variable though. So, at max range of 4000 counts, (13512 inches * (8000us/1000/1000 'to convert to seconds')) / 2 'cut the amount of time in half' = 54.048 inches to target. However, only 54 will be stored in the distance variable at the current time. So my range I think would show 0 inches to 54 inches. I don't intend to let the robot get close enough to return a number as low as 0 though. As for pictures, I will post some as soon as I can. Again, thank you all for your help and feel free to double check my work above.

Similar Threads

  1. Software PWM using Timer1
    By muqasim in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 18th December 2009, 11:49
  2. Help with TIMER1 + SLEEP
    By Yodoad in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 22nd May 2009, 15:07
  3. Time Period of Timer1
    By arnol34 in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 4th May 2007, 00:31
  4. Timer1 and Interupt wierdness
    By mind in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 23rd August 2005, 01:24
  5. PULSIN and RCTIME
    By Dwayne in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 4th November 2004, 14:45

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