PDA

View Full Version : speed measure



daghelgeland
- 31st July 2013, 14:04
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.

wdmagic
- 1st August 2013, 11:35
read the manual on PulseIn, and you will need some kind of Encoder on the wheels.

daghelgeland
- 1st August 2013, 12:35
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

HenrikOlsson
- 1st August 2013, 12:47
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.

daghelgeland
- 1st August 2013, 13:26
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

HenrikOlsson
- 1st August 2013, 13:54
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:

'************************************************* ***************
'* 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.

tasmod
- 1st August 2013, 14:02
Post deleted not needed

daghelgeland
- 1st August 2013, 14:05
Thanks Henrik
I will read it carfully and try to understand how the program works.


Dag

AvionicsMaster1
- 1st August 2013, 14:26
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.

daghelgeland
- 2nd August 2013, 08:07
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