Figure 4. Accessing user options screens.
USB: the Universal Serial Bus
PCs used to have a variety of “legacy” ports (serial,
parallel, etc.), carried over from the first PC shipped in the
early 1980s. Setting these up to attach peripherals such as
printers was often a configuration nightmare. Now, USB
has made connecting even very sophisticated devices to
your PC almost trivial.
The end-user’s gain has been at a cost to the developer. Designing serial or parallel port hardware is straightforward, but getting a peripheral to communicate using USB
is not for the faint-hearted. It requires a complex combination of hardware and software. Fortunately, Microchip has
made it easier by providing a few microcontrollers with
USB hardware. They also provide a software framework
that does most of the housekeeping needed to make USB
work. This allows the designer to focus on just the applica-tion-specific USB code. In practice, however, the designer
needs a good understanding of USB to be able to debug
problems as they arise during development.
Tell me what you are
When you first connect a USB device to a computer,
it goes through a process called enumeration. This tells the
computer what the device is and what drivers are
required, among other things. When enumeration completes successfully, the device becomes available to the
system. Suitable USB MIDI drivers are provided with both
Windows and Linux.
USB data are collected into packets and transmitted in
1ms “frames” (high-speed USB 2.0 uses shorter
“microframes”). Thus, there is a mismatch with the real
time needs of MIDI. As a result, some MIDI purists won’t
use a USB MIDI implementation but, in practice, this does
not usually cause a problem, especially for simple MIDI
Liquid Crystal Display (LCD)
Several LCD types are available. Many — including the
one used here — are based on the Hitachi HD44780 controller. This chip supports a number of different display
configurations, from eight characters in one row, up to
four rows of 20 characters. mistralXG uses a 16x2 display.
Four or eight data lines (number selected in software) and
three command lines give you complete control of the display. Using only four lines (four bit mode) for data makes
it an attractive proposition for microcontroller based
designs, where pin counts can be at a premium. A few
simple routines provide all the functions needed to write
messages to the display. They take care of all the critical
timing requirements so that the rest of the code doesn’t
have to worry about them.
The PIC18F2550 Microcontroller
Microchip offers an impressive range of microcontrollers that incorporate a wide variety of on-chip peripherals. These include serial ports, A/D converters, timers, EEPROM memory, and more. One less common peripheral is
the 2550’s USB port. It is USB 2.0 compatible, supporting
both the full speed ( 12 Mbps) and low speed (1.5 Mbps)
modes, but not the high speed (480 Mbps) mode. MIDI’s
31. 25 kbps data rate means that the full speed mode is
sufficiently fast for mistralXG.
Software is needed to drive the USB hardware so that
your PC can enumerate and recognize a valid USB device.
Fortunately, Microchip’s USB Firmware Framework does a
lot of the work for you, leaving you to concentrate on
your application code.
The mistralXG code is around 5-6 KB, much smaller
than the 16 KB available in the 2550. I chose this device
rather than its smaller sibling (the PIC18F2455) as I wasn’t
sure how large the code would grow. It also means there’s
plenty of room to add additional features at a later date,
such as the external storage shown in Figure 1.
Putting It All Together
Okay, so that’s a whistle-stop, tour of the main technologies used in mistralXG. Now lets look at how the user
interacts with the unit, leaving the technical detail to the
next article. As a taster, though, you can see the prototype
in Figure 2.
At front left, you can see the DB50XG, with the LCD
to the right. The PIC18F2550 is the large chip to center-right of the breadboard.
The user’s view of mistralXG is four MIDI ports (MIDI
IN, WX IN, MIDI OUT, and MIDI THRU), a USB port, the
LCD display, and two pushbuttons (SELECT and SET).
When power is applied, a Splash Screen shows the
firmware revision and copyright notice (you may use the
code for personal projects, but not commercially). After a
few seconds, the display changes to the Home Screen