speed measure


Closed Thread
Results 1 to 10 of 10

Thread: speed measure

  1. #1

    Default speed measure

    Hello i need to make a speed measuring device to check the top speed of electric wheelchairs.

    I use two sensors on the floor to detect the chair. sending start and stop signals to my 16f877-20 pic.
    the distanse between the sensors are 1000mm. i need the display to give me the correct speed presented in km/h on the display.
    I need some tips in how to set up a counter in the pic and how to express the speed in km/h
    The range is 0.0-20.0km/h.

  2. #2
    Join Date
    Dec 2012
    Location
    Tennessee
    Posts
    262


    Did you find this post helpful? Yes | No

    Default Re: speed measure

    read the manual on PulseIn, and you will need some kind of Encoder on the wheels.
    Chris


    Any man who has accomplished anything in electronics at one time or another has said... " STOP! WAIT! NOOO! Dangit.... Oh Well, Time to start over..."

  3. #3


    Did you find this post helpful? Yes | No

    Default Re: speed measure

    Thanks for your reply.
    I am planning to make a stand alone system for speed registration for chairs driving over the floor sensors. and not a speedometer for the chair.

    I have made a board with a pic prossesor and LCD. i know how to programme this.

    What i dont know (a lots of stuff) is how to set up a timer inside the pic to give me the time it takes from the start sensor are trigged to the stop sensor stops the counter.
    i also need help to do the mathematics so i can convert the time/m to Km/h.

    Dag

  4. #4
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,605


    Did you find this post helpful? Yes | No

    Default Re: speed measure

    Hi,
    I don't see the need for an encoder.... he has two sensors detecting the wheelchair, they are spaced 1m apart and he wants to measure the time it takes the wheelchair to travel that 1m, then convert that to velocity.

    However, more details are needed to come up with a suitable solution.
    At the specified top speed of 20km/h it takes 180ms to travel 1m. But at the specified minimum speed of 0.0km/h it takes forever. Obviously you can't time that no matter how many bits you have. So you're going to have to specify a minimum speed other than 0. Next question is what requirements you have when it comes to resolution, is it enough if the display shows the speed in steps of 1km/h or do you need steps of 0.001km/h - or perhaps something in between?

    Since you're using a 16F part you're limited to WORD sized variables (without resorting to the N-Bit routines or similar).
    Are the 1m distance fixed or can you move the sensors closer/further apart? Doing that could possible make the math easier and/or the result more accurate.

    /Henrik.

  5. #5


    Did you find this post helpful? Yes | No

    Default Re: speed measure

    Hello Henrik.

    the sensors are not fixed and i can move them closer/further apart.

    i dont need to measure the speed with higher resolution than steps of 0,1Km/h
    minimum speed of 1,0km/h is ok.

    Dag

  6. #6
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,605


    Did you find this post helpful? Yes | No

    Default Re: speed measure

    Hi Dag,
    Here's something that might get you started. It's based on 1m distance and 4MHz oscillator for the PIC. It compiles for 16F877 but it's not tested.

    It gives you 0.1km/h resolution but due to rounding errors the accuraqcy will be +/-0.1km/h. It's likely possible to improve that though but lets start with this and see if works at all.

    See if it makes any sense:
    Code:
    '****************************************************************
    '*  Name    : Speedometer.pbp                                   *
    '*  Author  : Henrik Olsson                                     *
    '*  Notice  : Copyright (c) 2013                                *
    '*          : All Rights Reserved                               *
    '*  Date    : 2013-08-01                                        *
    '*  Version : 1.0                                               *
    '*  Notes   :                                                   *
    '*          :                                                   *
    '****************************************************************
    DEFINE OSC 4
    
    ' If the PIC is running at 4MHz and we run TMR2 with a prescaler of
    ' 1:4 it'll "tick" every 4us. Setting PR2 to 225 will make it overflow
    ' every 225*4=900us.
    T2CON = %00000001                       ' 1:4 Prescale, timer is off
    PR2 = 225                               ' Overflow every 225*4=900us
    
    StartSignal VAR PortB.0
    StopSignal VAR PortB.1
    
    TMR2ON VAR T2CON.2                      ' Alias to TMR2ON bit
    T2INT VAR PIR1.1                        ' Alias to TMR2 Interrupt flag
    
    Time VAR WORD                           ' This is the measured velocity in units on 0.1km/h
    Velocity VAR WORD                       ' Calculated velocity
    
    Main:
        TMR2ON = 0                          ' Timer is OFF
        TMR2 = 0                            ' Reset timer
        Time = 0
        Velocity = 0
    
    WaitForStartSignal:
        While NOT StartSignal : WEND        ' Wait for start input.
        TMR2ON = 1                          ' Start the timer
        
    WaitForStopSignal:
        WHILE NOT StopSignal
            IF T2INT = 1 THEN               ' 900us has passed
                T2INT = 0                   ' Clear flag
                Time = Time + 1             ' Count up, units of 900us
                IF Time = 4500 THEN ABORT   ' ~4 seconds has passed, lets stop.
            ENDIF
        WEND
        
        TMR2ON = 0                          ' Stop the timer
        
        ' At this point the variable Time contains the time from start signal
        ' to stop signal in units of 900us.
        
        ' Velocity in km/h = 3.6 / time in seconds
        
        ' If Time is 200 it took 200 * 900us = 180ms which equals 20km/h.
        ' If Time is 745 it took 745 * 900us = 670ms which eqauls 5.4km/h. 
        ' IF Time is 2000 it took 2000 * 900us = 1800ms which equals 2km/h.
        ' If Time is 4000 it took 4000 * 900us = 3600ms which eqauls 1km/h.
    
        ' If we do 40000/200 we get 200 = 20.0km/h
        ' If we do 40000/745 we get 53 = 5.3km/h
        ' If we do 40000/2000 we get 20 = 2.0km/h
        ' If we do 40000/4000 we get 10 = 1.0km/h
        
        Velocity = 40000 / Time
        
        LCDOUT $FE, 1, "Velocity: ", DEC Velocity/10, ".", DEC Velocity // 10, "km/h."
        
    Goto Main
    
    Abort:
        LCDOUT $FE, 1, "Timing aborted after ~4s"
        Goto Main
    /Henrik.

  7. #7
    Join Date
    Dec 2011
    Location
    IO93ok
    Posts
    190


    Did you find this post helpful? Yes | No

    Default Re: speed measure

    Post deleted not needed

  8. #8


    Did you find this post helpful? Yes | No

    Default Re: speed measure

    Thanks Henrik
    I will read it carfully and try to understand how the program works.


    Dag

  9. #9
    Join Date
    Sep 2010
    Location
    Las Vegas, NV
    Posts
    305


    Did you find this post helpful? Yes | No

    Default Re: speed measure

    A wheelchair going 20 klicks sounds like a recipe for disaster. I just want the job handing out tickets for the speed violators.

    Back to seriousness: This is getting to sound like a school assignment. If you installed these speed, errr, traps how many would you use? I'm curious as to the application.

  10. #10


    Did you find this post helpful? Yes | No

    Default Re: speed measure

    God morning everybody.

    The code Henrik gave me yesterday works fine.
    I have integrated it with the rest of my program.
    Thanks Henrik.

    Regarding wheelchair speed.
    I actually have a 25Km/h special chair.(max speed normally 10K). And yes this is not a chair for the street.
    This is not a school project, I am going to use this application to check the max speed after replacing motors on wheelchairs.

    Best regards
    Dag

Similar Threads

  1. how to measure RPM and SPEED at the same time
    By teeeeee in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 30th July 2012, 08:34
  2. Pic Speed / Instruction Speed etc
    By jamie_s in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 4th July 2012, 20:19
  3. Replies: 0
    Last Post: - 7th August 2008, 09:02
  4. measure the xtal
    By savnik in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 8th June 2007, 10:22
  5. Pulse measure
    By Acetronics2 in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 11th August 2004, 06:14

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