This is a project for measuring speed of toy-cars on a race track.


This project is a good way to learn about digital circuits and displays..

It uses standard logic chips and doesn't need any software.


The counter:
The timer uses a 74HC192, which is is a BCD (Binary Coded Decimals) counter that can count up or down between 0 and 9 (4 bits).
It has inputs and outputs that can be interconnected so several chips can be used together for counting longer times.
It also has a "load" functionality that can reset the output to a predetermined value (D-inputs), but we don't use that here.
Using BCD counters means that every chip represents one decimal (between 0 and 9) of a bigger number, exactly as we write decimal numbers.
The output of each chip can then be decoded and shown on a display.

The following schematic is a 3½ digit BCD counter. It can be used to count from 0000 to 1999.
When the counters are clocked with a 1msec (1kHz) clock, we can count to 1.999 sec.
The Terminal Count Up output of the 74HC192 clocks the next.
More 74HC192 can be added in the same way, in order to get more digits.
The last 74HC192 clocks a flipflop (there are 2 flipflops in a 4013), in order to get 1 extra bit (Most Significant Bit) which is called a half digit (even though it really is just a quarter).
(NB in the final version of the timer, we used 4 pieces 74HC192 instead, and can count from 0 to 9.999 sec).
The reset input can be used to reset the output to 0000 before starting the counter clock.

counter


The 74HC192 has the following pins:
MR  Master Reset: When this pin is 1, it resets all outputs to 0.
PL  Parallel Load: When 0, it loads the D inputs into the Q outputs.
CP_U Clock Pulse Up: on a transition from 0 to 1, the counter counts 1 up.
CP_D Clock Pulse Down: on a transition from 0 to 1, the counter counts 1 down.
TC_U Terminal Count Up: when counting up and reaching 10, this output clocks the next counter 1 up.
TC_D Terminal Count Down: when counting down and reaching less than 0, this output clocks the next counter 1 down.
NB:
Reset overrides all load and count inputs.
When counting up or down, the unclocked clock input must be 1.

An example of a 74HC192 counter sequence, using all inputs:
counter

In the above sequence, the following happens:

Clear (MR resets the outputs to 0).
Preset (Loads to 7).
Count UP to 8 -> 9 -> 0 & Terminal Count Up -> 1 -> 2
Count DOWN to 1 -> 0 -> 9 & Terminal Count down -> 8 -> 7



The clock:

The clock for the timer has to be quite accurate and stable over temperature.
Also the following has to be considered: if we e.g. have the clock running all the time and start the timer by releasing the Master Reset of the counters, there can be a delay anywhere between 0 and 1 clock cycle before the first flank happens. If we use a 1msec clock and we cannot live with a 1msec latency, we might want to add some extra counter between clock circuit and counter, and also control that with the same Reset. By adding a divide-by-4, we will only have 0.25msec latency which is much better.
A better way of getting rid of the latency, is to start the clock at the same time as the counter. This can be done with the following clock oscillator circuit that has an enable input.

The wellknown LM555 is a great chip for a clock oscillator (and for learning how stuff works) :
It contains a flipflop, which output goes high when the S (set) input is triggered (transisiton from low to high),
and goes low when the R (reset) input is triggered.
Those flipflop inputs are controlled by comparators, which are connected to 3 equal value resistors that set thresholds at 1/3 and 2/3 of the supply voltage.
The other inputs of the comparators are both connected to the capacitor C1 (pins 'threshold' and 'trigger').
When the powersupply 5V is applied, capacitor C1 is charged through R1+R2, until the voltage reaches 2/3 of 5V.
Then the upper comparator will make a Reset, and thus the flipflop's inverted output goes high and activates the transistor, that in its turn discharges the capacitor C1 with R1 to ground.
When the voltage falls below 1/3 of 5V, the lower comparator makes a Set, so the flipflop output goes high and the inverted low thus releasing the transistor.
C1 will now be charged again with R1+R2.
This keeps repeating and thus the chip generates a square output, while the voltage on C1 is a sort of triangle.
When R2 is small compared to R1, the discharging time is apprimate the same as the charging time.
Since both the charge current and the voltage thresholds are directly related to the supply voltage, the frequency of the output will be independent of the supply voltage.
For a 1.0kHz clock (1.0msec pulses) we used C1=2.2nF, R2=2k7, R1=215K (100k+68k+4k7).

counter

The oscillator can be stopped by holding the enable signal low.
This has one drawback; when it is enabled to start the oscillator, the capacitor voltage has to be charged from 0V during startup and thus the first clock cycle is longer than normal.
But this can be easily fixed by making sure that the voltage on the capacitor never can get very much lower than 1/3.
This is accomplished by the diode D1 connected to a voltage divider with R3 and R4. In this way, when the Discharge pin pulls R1 to ground when the chip is not enabled, D1 starts conducting and keeps the voltage at a 'startup-voltage' of the voltage divider minus 0.6V (diode voltage drop).
NB the resistors of the voltage divider should have a value much smaller than R1, because otherwise R1 loads the startup voltage (e.g. use a 10k trim-potmeter for the voltage divider).
->> Important: adjust the voltage with a safe margin lower than 1/3, because if it gets higher than 1/3 the oscillator will stop forever!! And beware that the diode voltage drop gets slightly less than 0.6V at higher temperature!!
We used R3= 3k9 and R4= 2k2.



The start / stop circuit:

When pushing the START button, we want 3 things to happen very fast after each other:
1) switch on the mechanism that releases the cars.
2) start the clock that makes the timer start counting.
3) reset the time counter to zero.
The reason that the release comes first is, that it can take a fraction of a millisecond to activate it.
The reason that the timer zero comes last, is that we don't want the counter to count to 1 right away when the clock starts, but of course first after 1 msec.
So when the clock starts and right away triggers the counter with a positive flank, we keep the counter reset to ZERO for a short time (not critical, as long as it is less than 1 msec).
Thus the next positive clock flank is the first that clocks the counter so it goes from 0 to 1 at 1msec after START.

When STOP is activated, we want the counter to stop and stay at the final counter value.
This can be accomplished by just stopping the clock.

counter

Care has to be taken when using mechanical switches to trigger digital circuits, because switches can have "bounce" which means that it doesn't directly switch from on to off, but has a short time where it can be bouncing multiple times between on and off.
Also, the circuit must not be compromised when e.g. the Start button is pushed for a long time.

Schmitt trigger:
Bounce is normally taken care of by filtering with a resistor+capacitor, and a circuit with hysteresis (called a schmitt-trigger) that will nicely switch between 0 and 1 at the output even with a noisy signal on the input.

counter

schmitt


A schmitt trigger is also needed if you want to make a pulse, e.g. a constant length short pulse when trigger by a random length, or a long pulse triggered by a short one:

schmitt




Flipflops:
A flipflop can be used to enable/disable the oscillator, and can at the same time be used to "de-bounce" the buttons.
When one switch is connected to the SET pin, a 0-to-1 flank will make the flipflop output go to 1 and stay there even for multiple flanks.
The other switch can then be connected to the RESET pin, where a 0-to-1 flank will make the flipflop output go to 0.

Two often used flipflop chips are CD4013 and 74HC74, that both have 2 D-flipflops in one package.
The only functional difference is the SET and RESET inputs, that are inverted in the 74HC74.
The pinouts are different as seen below (NB the signal names are also slightly different but mean the same):
counter

The following tables (from 74HC74 datasheet) are very helpful to understand how a D-flipflop works.
There are 2 different ways to use the flipflop, as in table 1 (only use the SET and RESET) or in table 2 (use the CLOCK and D inputs).
counter

The simple set/reset Flipflop action without the D and Clock functionality, can also be made with just 2 NAND gates (CD4011 or 74HC00 or CD4093).
counter

If we use the CD4093, which is a 4x NAND with schmitt-trigger inputs, we can use the unused NAND gates to make the "counter-RESET" pulse.
The positive flank of the enable signal is differentiated with a little series capacitor, resulting in a 0.3msec pulse. (the diode is added in order to avoid a pulse with negative voltage when the enable signal goes low again).
counter

NB the counter_reset output comes in fact a few nsec after the clock_enable (because of propagation delay in the gate), which means that the counter could count from 0 to 1 right at the start, but that doesnt matter and will not be visible because the counter will immediately be reset to 0. So first after the 0.3msec long counter_reset the counter will be released, and when 1msec has passed after the START button was activated it will count to 1 at the positive clock flank.



Controlling the release of the cars at start:

When the START button is pushed, the racing cars will be released by a mechanism made of an old CD-drive.
This can be done like described on a separate page. Click the picture to go there:
counter








Displaying the time results:

We can either use LED displays or LCD displays.
LED displays look nicer, but can be hard to read in sunlight, so an LCD is used. This also uses much less current, but is a bit more difficult to drive because you need a symmetric clock for the backplane.

A 40-pin 4½ digit LCD display is used. Digit 5 is just a ½ digit, which means it can only be 0 or 1.
The pin nrs and segment explanation, are as seen from front:

counter

Fortunately the pinout is almost standard for all brands of LCD displays, but the pins can be named slightly differently.
A 40-pin 3½ digit display could also be used; there the connections are the same but all 4th digit segments are n.c.

Pin numbers are as seen from the backside (which is easiest when you want to measure some of the signals)

pin nr segment pin nr segment
40 backplane (com) 1 backplane (com)
39 sign vertical (|) 2 sign horizontal (-)
38 low battery 3 5bc half digit (K)
37 4g 4 4 digital point (DP)
36 4f 5 4e
35 4a 6 4d
34 4b 7 4c
33 3 colon (L) 8 3 digital point (DP)
32 3g 9 3e
31 3f 10 3d
30 3a 11 3c
29 3b 12 2 digital point (DP)
28 2 colon (L) 13 2e
27 2g 14 2d
26 2f 15 2c
25 2a 16 1 digital point (DP)
24 2b 17 1e
23 1g 18 1d
22 1f 19 1c
21 1a 20 1b



The display driver:

Here we use the MC14543, 1 chip for each digit of the display.
The Latch Disable pin has to be 1 because it is only used for freezing the number, and the Blank pin has to be 0 otherwise all segments will go OFF.
The Phase pin must be connecte to the LCD display Backplane squarewave clock. When a segment is switched ON, its output is a squarewave with a phase opposite to the LCD backplane, when OFF it has the same phase as the backplane.

counter

The backplane clock is also driving the LCD Display Backplane, which is quite a high load and thus needs a buffer.
Another important thing is that the clock needs to be perfect 50% on/off, otherwise the display will be destroyed after some time. So normally a flipflop is used to divide by 2 (this flips between 0 and 1 for every input clock positive flank, and thus creates a perfect symmetric squarewave).
The display and driver of a surplus circuit were used.
This board had the following circuit for the backplane clock (the non-connected parts in the schematic below are used for other functions on this surplus board):

counter

The CD4093 forms the oscillator, the CD4013 is the flipflop where Q is the divided output. The inverted_Q output can be used to be connected to e.g. digital points and colons that have to be ON and thus must be in a phase that is opposite to the backplane.





to be continued...to be continued...to be continued...to be continued







 this page is made with Notepad2