USB DEVICE CONTROL
Several URLs are provided below to help you
find parts and information. In addition to
these, don’t be afraid to search around a bit
for USB information.
Microchip, Inc. — PICs/Programmers
Jameco — Components
RadioShack — Components
Sparkfun — www.sparkfun.com
Olimex — www.olimex.com/
Microsoft — Visual C# Express
SourceForge — GPUtils
SourceForge — SDCC
Red Hat — Cygwin
USB.org — www.usb.org
Lakeview Research —
of the pulse is then loaded into
Timer3. When the next interrupt
occurs, the servo control line is
While this technique is a bit more
complicated than just counting a
delay for the duration of the servo
pulse, it allows the PIC to keep doing
useful things (like send/receive USB
packets). The firmware files servo.h
and servo.c contain the essential
FIGURE 10. Windows app to
control devices through USB.
position control for the servo.
Two views are shown in Figures 8
and 9. The former is a close-up of the
circuit implemented on a breadboard.
The latter shows it connected to the
PC and the devices themselves.
The motor is driven directly
by a Texas Instrument’s
SN74410 quad half-bridge
chip. Two pairs of half bridges
are coupled together to form a
single H-bridge circuit. The
PWM1 line from the PIC
together with two digital I/O
lines are used to control speed
and direction. This chip is good
to a couple of watts. For larger
motors, it should be replaced
with either a larger integrated
H-bridge or one made of
discrete MOSFETs. The firmware files
motor.h and motor.c contain the logic
associated with driving the chip.
The solenoid control is a little
more complicated than necessary.
The reason for this is to demonstrate
how a Windows application can display information from the device, as
well as send control instructions to it.
The PWM2 line from the PIC is used
to drive an inductor-based voltage
boost. The voltage from the boost circuit slowly charges a large capacitor.
As the voltage builds up, a progress
bar in the application fills up, giving a
visual indication when there is
sufficient charge to fire the solenoid.
The solenoid I was using gave a satisfactory clack at around 20V (YMMV).
The firmware files solenoid.h and
solenoid.c contain the firmware
associated with the voltage boost and
solenoid control. When implementing
this part of the circuit, ensure that you
use a capacitor rated for the highest
voltage you generate. Adjustments to
limit the voltage are made by changing the value of HIGH_SET_POINT in
solenoid.c, as well as by modifying the
voltage divider resistors that feed into
pin AN0 on the PIC.
Modified Windows Interface
The C# application used to control the devices is shown in Figure
10. For this application, there are a
few changes to the controls. There
are still checkboxes for LED control,
but a few new controls have been
added. There is a voltage meter and
actuation button for the solenoid, a
speed control for the motor, and a
78 June 2006
R/C-type servos are a stock item
in robotics — from steering to drive
wheels. These servos require repetitive pulses between 1 and 2 mS. The
duration of the pulse determines the
angle that the servo will move to (and
hold). This implementation uses the
PIC’s Timer3 to cause an interrupt
about 50 times a second. After the
interrupt is fired, the servo control
line will be pulled high. The duration
The PIC 18F2455 takes care of
all the low level USB details. By
adding a firmware framework, you
can quickly interface it to your PC.
The set of peripheral controllers
(PWM, A/D, Timers, etc.) built into
the PIC should be enough for most
small to medium projects. Don’t be
afraid to play around — the PIC
can be easily reprogrammed many
thousands of times. NV