Help measuring distance....


Closed Thread
Results 1 to 6 of 6

Hybrid View

  1. #1
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,613


    Did you find this post helpful? Yes | No

    Default

    Hi,
    Every 500mS interrupt you read the count from TMR0 and add it to an accumulator. You also keep track of how many interrupt have passed and when 10 interrupts have gone by you divide the accumulator count by 9. You now have the number of metres traveled in the last 5 seconds.

    (Untested)

    Code:
    Acc var WORD		'Accumulator
    ISRCount var BYTE	'Keeps track number of interrupts
    Km var WORD		'Kilometres
    m var WORD		'Metres
    
    '//Place this in your ISR to be executed every 500mS
    ISRCount = ISRCount + 1	'Increment ISRCount
    Acc=Acc + TMR0		'Add TMR0 value to accumulator, TMR0 gets reset elsewhere.
    
    If ISRCount = 10 then	'If 10 interrupts have passed....
     m = m + (Acc / 9)	'...calculate how many metres...
    
     If m > 1000 then       'If more than 1km have passed..
      Km = Km + (m / 1000)  '...add to the Km count...
      m = m // 1000		'...and keep reminder.
     EndIf 
    
     ISRCount = 0		'reset ISR counter
    EndIf
    You can now use...
    Code:
    LCDOut $FE, 1, #Km, ".", #m
    or whatever in your main routine to display the distance traveled.

    /Henrik Olsson.

  2. #2
    Join Date
    Jan 2007
    Location
    Brazil
    Posts
    108


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by HenrikOlsson View Post
    Hi,
    Every 500mS interrupt you read the count from TMR0 and add it to an accumulator. You also keep track of how many interrupt have passed and when 10 interrupts have gone by you divide the accumulator count by 9. You now have the number of metres traveled in the last 5 seconds.

    (Untested)

    Code:
    Acc var WORD		'Accumulator
    ISRCount var BYTE	'Keeps track number of interrupts
    Km var WORD		'Kilometres
    m var WORD		'Metres
    
    '//Place this in your ISR to be executed every 500mS
    ISRCount = ISRCount + 1	'Increment ISRCount
    Acc=Acc + TMR0		'Add TMR0 value to accumulator, TMR0 gets reset elsewhere.
    
    If ISRCount = 10 then	'If 10 interrupts have passed....
     m = m + (Acc / 9)	'...calculate how many metres...
    
     If m > 1000 then       'If more than 1km have passed..
      Km = Km + (m / 1000)  '...add to the Km count...
      m = m // 1000		'...and keep reminder.
     EndIf 
    
     ISRCount = 0		'reset ISR counter
    EndIf
    You can now use...
    Code:
    LCDOut $FE, 1, #Km, ".", #m
    or whatever in your main routine to display the distance traveled.

    /Henrik Olsson.
    Hello.
    Thanks Henrik Olsson. I made a few changes and it has been working very well.
    Thanks All..

    Sylvio

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. Ultrasonic distance sensor with PIC16F84A
    By MrRoboto in forum mel PIC BASIC
    Replies: 3
    Last Post: - 29th June 2009, 09:01
  3. Long distance Communicating between PICs
    By koossa in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 4th January 2008, 06:47
  4. Distance Measurement Chips
    By sayzer in forum Off Topic
    Replies: 6
    Last Post: - 2nd February 2007, 20:57
  5. GPS waypoint distance in Km
    By Art in forum Code Examples
    Replies: 1
    Last Post: - 28th August 2005, 01:59

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