# Timer help

I am trying to figure out how to sample multiple times on my inputs. The scenario is:
16 inputs of 5volt pulses. Of these sixteen a pair makes up on timing event, in other words I get a pulse when sensor 0 gets blocked and a pulse on sensor 1 when it gets blocked. The timing between these two pulses is my speed. The speed between pulses will be greater than 50ms. 16 inputs divided by two wires for each means I need a total of 8 timers. Any of the inputs could trip at any time.
To help explain this, my application is to measure the speeds of all 8 lanes on a highway. I have two sensors for each lane that will be spaced a few feet apart.

My question is how do I capture each event and not miss any? If I start a timer, doesn’t that hold up the processor.

Code thinking:
function myTimer()
Start timer
When second input sensed stop timer.
Subtract timer values to get total time.
end

Any help would be appreciated. I think I’m thinking too hard about this.
Thank you,
Steve

I first thought was I can use the millisecond timer that is already running in Dynamic C with the MS_Timer function.

I thought–how far does a car travel in one millisecond?

MPH ft/sec ft/msec ms/100 ft
10 14.7 0.0147 6818
20 29.3 0.0293 3409

60 88.0 0.0880 1136

80 117.3 0.1173 852

100 146.7 0.1467 682

For each pair of sensors, I would read the MS_TIMER when the start pulse was received and read it again when the stop pulse was received and subtract to get the number of milliseconds between pulses. I calculated the number of milliseconds you would be able to count at various speeds, if the two sensors were 100 feet apart.

auto unsigned long t1;
int ms;
t1=MS_TIMER; // when start pulse is received
ms=MS_TIMER-t1; // when stop pulse is received

The answer then is calculated by the formula of:

# feet/hour = ((100*3600)/ms)*1000

mph = # feet/hour/5280

What do you think of that solution?

Thanks Steve for responding.
I am concerned that I wont catch all the cars. If all eight sensors were tripped at the same time would your idea work? I also need to send the speed data out to a seven segment display for each lane so that will also take up processor time when I need to be watching the sensors. Is it possible to multitask?

Thank you,
Steve

Yes, you can multitask with Dynamic C. There are two multi-tasking schemes. One is premptive time slice method, the other is a costate machine.

I think you could do it with the costate state machine process. Set up one costate for each of the 8 lanes. The seven segment display routine shouldn’t be too hard, or time consuming, You will basically have to send out three bytes for each lane. I’d need more information about the displays to give you concrete ideas, but I think this is totally possible. Are you planning on a serial link to each display? Are you directly controlling each segment of each digit? How are you planning on managing the power transfer at the segment so it is visible to the drivers? Etc.

In each costate machine, while you are waiting for the start/stop pulses, you use the YIELD function to give all the costate functions time on the processor.

Are you planning on reading the digital inputs in banks (8 at a time)? Or, are you planning on reading each point individually? Will the sensors be looking at interruptions of light by a tire? If so, what will you do with the extra pulses from the rear tires? What about motorcycles?

These are some questions I have.

Steve