My
nephew Brick called me one day and asked if there was a way to slow down his
slot car track so his son could play with it. At 2 years old, his son only
know 2 speeds, all the way on or all the way off.
I knew this would be a fairly easy task for a
microcontroller, so I started working on a design. A precision analog
throttle control needs 2 A/D channels, 2 PWM channels and a way to set the
top speed. Another A/D channel with a pot attached would have been the
simplest solution, but I thought I'd make it a little more capable.
With the power of the DevBoard-M32 available, I added an LCD display,
control menu, lap counter and a racing clock. All of this still
doesn't utilize the full power of the M32.
The controller grew into a complete slot car racing
system. It features:
- Precision analog throttle control
- Digitally proportional speed using PWM (pulse-width
modulation)
- Adjustable maximum speed
- Drag Racing style starting lights
- Early start fault system
- Racing timer to 1/100 of a second
- Timed and free running modes
- Lap counting and lap timing
- Displays each drivers current and best lap speed
- Complete user interface for controlling all aspects
of the system
- Settings are preserved when unit is powered off.
The code is rather large but only consume 1/4 of the
available flash in the M32. This leaves plenty of room for more user
menus or types of racing. I programmed the M32 using MCS Electronics
basic compiler, BASCOM-AVR. This is by far my favorite compiler for
the AVR class of microcontrollers.
I came across the case at Cascade
Surplus Electronics for $1.75. It has lots of room inside and a
replaceable bezel to hold the LCD. I created a replacement using
standard polystyrene.
Other than the M32, I put all of the electronics on a
basic perf board.
Let's Break It Down
The controller consist of 6 main parts:

Inputs
The M32 receives input from 3 sources - the analog
throttle control, the user interface and the lap counter.
Throttle
Control - This was simple to design but tough to build. The
typical speed control is a wire wound resistor with a metal wiper that
slides alone the side. This would not work with any precision so I pulled
it out and replaced it with a 10k pot and replaced the cable with a longer
telephone handset cord. This provides extremely consistent and precise
positioning of the throttle trigger. The M32 converts the analog voltage
from the controllers into a 10-bit value, then applies the throttle
percentage set by the driver. For children, you can set the speed down to
less than 50% of maximum throttle and the cars won't fly off the track.
Lap
Counter - The track had a mechanical lap counter section that used a
wheel to display up to 9 laps. I considered using hall effect sensors but
opted to use a similar method to the original counter. After
removing the wheel lap counter, I installed a pair of roller switches in
their place. These work extremely well and don't slow the cars down
at all. The roller switches are attached to external interrupts on
the M32. This allows for precise measurement of the lap speed and
lap counts but also introduced a challenging noise problem. Slot cars
create a lot of noise on the power line. I had to do a lot of
filtering to reduce the noise but still had to compensate for false
triggers in software.
User
Interface - The 20x4 character LCD provides the visual interface for
the drivers. It displays the race information and the user
menu. 2 buttons allow for navigation of the menus. The user
menus are 2 levels deep; first level selects the option to change, the
second level changes the value for that option.
Control
The
DevBoard-M32 controller is the brain of the system. I used 17 of the
available 32 I/O lines, 1/4 of the program space and less than 1/2 of the
available memory - and it's only running at 4 MHz! 4 MHz simplified
the math for the 1/100 of a sec timer. I decided to not use the
.1" square post headers on this board and instead direct solder the
wires, since I was dedicating the M32 to this project permanently.
It doesn't look as clean as the push on crimp connectors but it did save
some time.
More information on the DevBoard-M32 is available by
clicking
here.
Output
PWM Speed Control - The M32 uses PWM to
control the speed of the cars instead of the mechanical current limiting
resistor in the original controllers. PWM is much cleaner way to
vary the speed of a motor, giving smoother performance at lower speeds
than just reducing the current to the motor. Since the M32 is
actually controlling the cars, it's even possible to put in a demo mode
that allows the cars to race without drivers. I haven't added this
feature yet.
Racing
Tree Lights - I added this just for fun. Drag racing uses a
series of lights to tell the drivers when to go. If a driver takes
before the green light comes on, a fault light comes on and the driver is
penalized. I built on this concept to capture the reaction time of
the drivers. When the race is ready to start, the racing lights blink
yellow, yellow, yellow then green. If a driver pulls the trigger
before the green light comes on, his car won't move and the fault light is
lit. To make the car move, he has to release the trigger then pull
it again.
Schematic
Here is the
schematic for the Digital Race Track Controller:
Program
Click here to view
the Bascom code or download the file.
|