A Display for Text, Photos, and Slide ShowsJan‘s electronic ID system is an MCU-based electronic badge that
displays color slide shows. Many electronic badges display
scrolling text using a matrix of discrete LEDs. This low-power
system features a graphical OLED display and can be easily upgraded
to handle animation,video, or RF communication.
Most of the time, we want to protect and hide our personal
identification information. But, every so often,it helps to be
easily identified. For instance, it makes sense to wear a badge at
exhibitions, trade shows, and seminars. If you‘ve been to such an
event recently, you've probably noticed that electronic badges are
increasing in popularity. The electronic badges currently on the
market use a matrix of discrete LEDs to display scrolling text
(e.g., names and advertisements)。Few, if any, of them feature an
OLED display. That‘s why I decided to build my own.
My Mini-Badge design is an electronic badge built around a
Microchip Technology PIC24FJ64GA004 microcontroller(see Photo 1)。
The handy badge displays scrolling text, photos,and color slide
shows. In this article,I'll explain how I built the low-power
system.
BADGE BASICS
The Mini-Badge is designed to display a color picture slide show,
but you can develop its features depending on your needs. For
instance, you can add an RFID for remote identification.
The requirements for portable devices are usually demanding,
technically challenging, and often contradictory. When I started
this project, I set out to design an aesthetically pleasing,small
(lightweight), low-power (long battery life) design that included
decent display quality. Because I planned to incorporate a small
battery,I needed an easy-to-use user interface that could display
custom information. I achieved my goals.
The hardware and software are relatively simple. However,
completing such a project requires sound engineering skills. Small
surface-mount devices like 0402 resistors, fine-pitch connectors,
and ICs in QFN packages are used. I completed the prototype
assembly by hand with a good soldering iron and a magnifying glass.
The system‘s layout is shown in Figure 1 and Figure 2.
点击查看Figure 2OLED DISPLAY An organicLED is a relatively new display technology, where thin organic
layers serve as the source of light. Its advantages over other
technologies include attractive colors and brighter pictures, a
lower power consumption than LCDs or TFTs with a backlight, a thin
form factor (no backlight is needed),and a fast response time,
which can be used for video, a wide viewing angle and high
contrast, and a wide temperature range (-30° to 70°C)。 The
technology has some disadvantages such as a limited lifetime, a low
yield(especially for bigger sizes), and an uncertain future.
The display in this project is a 1.5″Univision Technology
UG-2828GFEFF01 OLED, which has 128 × 128 RGB pixels 262,144 colors,
and a COF package with a built-in controller and SRAM with 132 ×
132 × 18 bits (SSD1339 from Solomon Systech)。 With a builtin
controller and display memory,there is no need for an external
controller and SRAM. The readily available SD1339 is a good
compromise between the physical size, current consumption, unit
price, and interface requirements. In addition, you can
programmatically select the picture quality with the following
color modes: 262,143 colors with 3 bytes per pixel, 65,536 colors
with 2 bytes per pixel, and 256 colors with 1 byte per pixel.
As for the hardware interface to the microcontroller, you have
several options: parallel interfaces with 8-, 9-,and 18-bit with a
Motorola 6800- series-style bus or an Intel 8080-seriesstyle bus
and a serial interface with a SPI bus.
For an 8-bit parallel display interface,after checking the timing
specification,the minimum time to write a single byte to the
display memory is PWCSL = 60 ns.
With 128 × 128 pixels and 3 bytes per pixel, the total time to fill
the display is 128 × 128 × 3 × 60 ns = 49,152× 60 ns = 2,949,120,
or approximately 3 ms. This is a best-case scenario and a rough
estimate to show that the display is capable of displaying 30- or
50- fps video (as 1 s/3 ms = 333 fps)。
For a SPI, if you want to display 30 fps, you need a SPI clock of
30 × 128 ×128 × 3 × 8 (for 8 bits per byte), or approximately 11.8
MHz. That is, a SPI clock speed that cannot be achieved on any of
the current PIC microcontrollers. Also, when you check the SSD1339
datasheet for the SPI minimum tCYCLE, it is 250 ns,which
corresponds to a 4-MHz maximum SPI clock.
The 8-bit parallel 8080-style interface was a good compromise
between speed and complexity. SPI is too slow. In addition, an
18-bit interface is too complex for PCB layout and it takes up too
many microcontroller pins
"PIC"-ING THE BADGE
The system has a serial flash memory that requires a SPI with a
clock speed of up to 40 MHz. The microSD memory card SanDisk
(TransFlash)also requires a SPI with a clock of up to 25 MHz or
more. The Microchip PIC24F Family Reference Manual states that the
PIC24xxx series with an FCY of 16 MHz has a maximum SPI clock equal
to 8 MHz. The PIC33xxx series with an FCY of 40 MHz has a maximum
SPI clock equal to 10 MHz.
This is not good enough to play video using serial memories like
serial flash or TransFlash and a 262,143-color picture quality.
However, for the lower quality, it will work with 65,536 and 256
colors because it needs less data leading to a lower SPI clock.
The PIC‘s (8080-like, 8-bit mode)parallel master port gives it an
advantage over GPIO. The USB interface or the UART together with an
external UART-USB bridge can be used to interface to a PC. The
second UART is handy for a Bluetooth interface (see Figure 3)。
点击查看Figure 3The PIC24FJ64GA004 microcontroller is a compromise between the
speed of execution, power consumption,available peripherals, and
more. It has more than enough program flash memory and data RAM, so
it leaves room for expansion.
The GPIO, PMP, UARTs, SPIs, and timer peripherals are used. There
are some unused peripherals, which are disabled to save power. It
also comes in a space-saving QFN package.
One of the nice features is a peripheral pin select that enables
you to assign pin numbers to some peripheral functions. It can ease
the PCB layout process and make it possible to implement functional
changes without changing the hardware.
MASS STORAGE
The STMicroelectronics M25P40 serial flash and the microSD memory
card (TransFlash) are used to store images and configurations. The
popular SD memory card is physically too big. Both devices (the
serial flash memory chip and microSD memory card) use similar
hardware SPIs. The file system is FAT16, the configuration file is
in XML, and the pictures are BMPs. The current firmware recognizes
only pictures with 128 × 128 pixels saved as 24-bit BMPs, giving
49,206 bytes per file without any compression. Figure 4 is a brief
description of the bitmap format as it is used for the project.
Figure 4-The is a BMP file format example, as seen in the hex
editor. Every pixel is represented by 3 bytes of RGB (24 bits per
pixel)。 Only 6 bits of each byte are used by the OLED in 18-bit
mode.(See the double bit shift operation in the code to ignore 2
LSB.) The linear mapping of BMP data into display RAM makes for
easy the loading of BMP files into the OLED display.
The basic version of the Mini-Badge described here has no FAT table
and no directory. Instead, the files are stored and accessed from a
fixed location within the serial flash memory chip. Because the
sector size for the M25P40 is 64 KB and the file size is 49,206
bytes, there is one file per sector,which makes addressing easy. It
might look like a waste of memory, but this arrangement provides
software compatibility between different hardware versions-the one
using serial flash with a limited file system and the one using
TransFlash with a full FAT16 file system implementation.
The XML file is located at address 0 and the seven images are
located at the addresses n × 0x10000 (n = 1......7)。 There are
eight pages (0, 1, 2, 3, 4, 5,6, 7) for the M25P40 serial flash
memory, and n is a place holder for the page number of serial
flash.
The XML file is at address 0x00000 (the hexadecimal notation for
0)。 So,image 1 is at address 0x10000 (the hexadecimal notation of
65,536),image 7 is at address 0x70000 (the hexadecimal notation of
458,752),and so on. The images are in BMP format. So, for a 128 ×
128 bitmap with a 24-bit quality,the size of a file is 49,206
bytes. The XML and BMP files are stored within the serial flash
memory (and microSD memory card) without any modification or
compression. The XML and BMP files can be copied from a PC into the
microSD card; while for the serial flash, they are downloaded
through the USB link. A virtual serial port on your PC is created
when the Future Technology Devices International FTDI232RQ USB UART
IC is connected and enumerated. (The drivers for it are built-in
for Windows XP.)
PC INTERFACE
The FT232RQ is used as a USB-to-UART bridge. One side of it is
connected to the microcontroller‘s UART TxD and RxD lines. Two
general-purpose port lines are used as RTS and CTS for flow
control. The FT232RQ acts as a virtual serial port,so you can use
HyperTerminal to test the communication. The hardware flow control
is implemented using RTS and CTS signals to cater to a proper
timing.
The 460,800 data rate works well even with a data rate difference
due to the limitation of possible microcontroller settings. To
check the data integrity, a simple protocol is implemented, as
described in the art7_SerialProtocol.doc file posted on the Circuit
Cellar FTP site. To download the files, I use terminal software
(HyperTerminal) on a PC. Refer to the System Tests section for more
details.
POWER SUPPLYThe power source is a Varta PLF263441B lithium polymer battery(see
Figure 5)。 The battery is rechargeable and is charged through the
USB. The charging circuit is based on a Microchip Technology
MCP73831 charging IC. Only the current programming resistor needs
to be set depending on your battery capacity. Check the device
specification for the formula and the selection criteria.
点击查看Figure 5
The device has a standard Mini-USB type-B connector for easy
connection to a PC to charge the battery and download pictures.
There is a small push button on the back of the device for turning
the power on and off.
The ultra-low-dropout linear regulator provides the 3.3-V supply
for most of the circuitry. I used a little switcher,but it proved
that the efficiency for ultra-low current is comparable or better
when using a linear regulator(instead of a switching one)。 With the
more complex circuit for a switching regulator and more noise, it
has the advantage over the linear regulator for higher-current
applications. The power switchover between USB and the battery is
achieved through the MOSFET and diodes circuit.
Part of the power supply includes a 12-V low-current supply circuit
built around a Texas Instruments TPS61040 switch boost converter.
The voltage should actually be between 8 and 12 V. I use 9 V, which
can be set by resistors R5_B and R6_B (see Figure 5)。
To save power, the circuits sense USB connection through one of the
microcontroller‘s lines capable of interrupt on pin
change-specifically RP15/RB15/CN11. After detecting USB
connection/disconnection,the firmware turns on or off the UART
module connected to an external USB-UART bridge accordingly for
power saving. To initialize the feature refer to Listing 1.
The OLED display doesn't like static pictures, but rather
fast-changing ones. There are periods when the screen is blank when
you perform a slide show on the device. During that time, the
microcontroller goes into low-power mode.
SOFTWARE
The embedded software was developed using Microchip‘s MPLAB IDE
and C30 compiler. The ICD2 was used to program and debug the code.
Because I had to use a small connector for in-circuit programming,I
had to build an adapter between it and a standard ICD2 connector.
The images are downloaded into the serial flash memory or copied
into the microSD memory card together with the script file. I use
the XML document to define the slide show. The use of XML is due to
its simplicity,popularity, and compatibility with different
platforms.
The embedded software works as a simple non-preemptive scheduler.
The sources contain a number of modules corresponding to the
functionality. For example, there are sflash.c and sflash.h source
files for the serial flash module. Refer to the files posted on the
Circuit Cellar FTP site for details. I will briefly explain some
software functionality of major modules.
The badge.c file posted on the Circuit Cellar FTP site is the main
one for the project and contains the power on initialization and
the scheduler for system tasks. OLED software contains the driver
and library for the OLED display. I use a table of parameters to
initialize the display using the manufacturer's recommendation and
supplied examples. When checking the initialization code in Listing
2, you will see that there is no waiting or delays between writings
typical for a classic character-based LCD.
After that, write to the display memory through the parallel master
port. When checking the OLED controller‘s specifications, notice
that there are higher-level graphical functions available, so you
might consider using them in your project.
For serial communication, I use the buffered, interrupt-driven
code, which is always a good way for fast, responsive systems. I
have to use the flow control RTS/CTS mainly because the fast
transmission from the PC has to be held while the serial flash
memory is reprogrammed or erased (slower process)。 Although
STMicroelectronics provides a library for its range of serial flash
memory chips (available at www.st.com), I used my own code,which
might be simpler, but it only covers one device (M25P40)。
SYSTEM TESTS
As with any hardware prototype,make sure that the assembly process
is neat and clean. Perform your usual inspections by looking at
solder quality,unwanted solder bridges, and more.
When building a prototype, the idea is to follow, if possible, a
specific sequence. First, assemble the power supply circuitry and
check the output voltages and the idle current consumption. The
operation of the On/Off button is a combination of hardware and
software. If there is no software (blank device) or when changing
the software, hold the button pressed. A better way is to solder
the temporary link between the pins on the push On/Off button
(SW1_C) to turn the power on permanently while you are programming
and testing. Disconnect it when the test is finished.
You need a simple adapter to connect your ISP programmer to CON1_A.
Assemble the microcontroller circuitry,open the MPLAB IDE
application and the project work space, connect your ISP
programmer, and program the microcontroller. Now you can assemble
the rest of the circuit either gradually or in one go. Do not
connect the OLED display yet. Because it has a zero insertion force
(ZIF) socket, you can connect or disconnect it at any time. (Make
sure the power is disconnected when you do it.)
Connect the USB cable to a PC. The enumeration process should
happen and the FTDI232R should be recognized automatically. On
Windows XP,the driver is built-in, so you don‘t need to install it.
Next, open HyperTerminal (or another terminal application)。
Then,select the newly created virtual serial port number with the
460800, 8, N, 1,hardware flow control settings. Use menu
Transfer>SendTextFile. Then,browse to your downloaded test_files
directory and select test_0.txt. You should see a response like
this:
$PBUB,EWWWWw$BPUB*0B
In this step, program the serial flash memory with a configuration
file. Repeat the aforementioned procedure, but select PBVF_0.txt
this time. You should see a response like the one in Listing 3.
点击查看Listing 3
Next, press any key to examine the contents of serial flash memory.
Then press the ESC key to receive the response. In this step,
program the first picture into serial flash memory. In a similar
way, you can download other test files, if needed. Disconnect the
power and connect the screen(OLED display)。 When you reconnect the
power, the Mini-Badge system should be operating.
SMART BADGE
Investigating new technologies and ideas is always a great
experience. The purpose of the project was to create a new device
by taking advantage of a few electronic technologies. Microchip
microcontrollers are useful for intelligent devices. One of the
unique features introduced in 16-bit PIC devices is peripheral pin
select,which enables the programmable assignment of a peripheral
function to a pin number. They have other supporting devices like
an integrated intelligent battery charger and the ultra-low dropout
regulator. The OLED displays have an impressive picture quality
combined with a small size and lowpower consumption. The lithium
polymer batteries come in small sizes and big capacities. The
availability of components in small packages enables you to create
small, lightweight devices.
An electronic badge like mine is more than a nice gadget. You can
easily make it an intelligent device. It already has a hardware
provision for a Bluetooth module, so adding wireless connectivity
would be easy. That would make it useful for use in remote
identification systems. If you interface some sensors to it, it
could become a node in a wireless sensor network. With your mobile
phone in one pocket and a PDA in the other one, do you need another
device? The answer will be yes if it does what other devices can't
do.
Jan Szymanski (janek@bigpond.net.au)is an electronics engineer who specializes in embedded systems
design. He runs Cherry Microsystems, a consulting company in
Australia. In his spare time, Jan enjoys music and sports.
PROJECT FILES
To download code and additional files,go to ftp://ftp.circuitcellar.com/pub/Circuit_Cellar/2008/221.
RESOURCES
Microchip Technology, Inc.,"MCP73831: Miniature Single Cell,完Fully
Integrated Li-Ion, Li-PolymerCharge Management
Controller,"DS21984A, 2005.
---, "PIC24F Family Reference Manual," DS39699B, 2007.
---, "TC2014/2015/2185: 50 mA,100 mA, 150 mA CMOS LDOs with
Shutdown and Reference Bypass,"DS21662E, 2006.
National Semiconductor Corp.,"LP3985: Micropower, 150mA Low-Noise
Ultra Low-Dropout CMOS Voltage Regulator," DS101364, 2005.
Solomon Systech, "SSD1339: Advance Information: 132RGB x 132 with 2
Smart Icon Lines Dot Matrix OLED/PLED Segment/Common Driver with
Controller," 2006.
SparkFun Electronics, "UG2828GFEFF01 OLED Display Module
Datasheet,Controller Specifications, and ExampleCode," Univision
Technology, Inc.,
www.sparkfun.com/commerce/product_info.php?products_id=712.
Texas Instruments, Inc., "TPS61040:Low-Power DC/DC Boost Converter
in SOT-23 and SON Packages,"SLVS413D, 2007.
Varta Microbattery, "PLF 263441 B PoLiFlex Battery datasheet,"
2005,
www.elektronik.ropla.eu/pdf/stock/vmb/plf263441.pdf.
SOURCES
WT12 Bluetooth module
Bluegiga Technologies
www.bluegiga.com
FTDI232RQ USB UART IC
Future Technology Devices International
www.ftdichip.com
MCP73831 Charge management controller,MPLAB C30 C compiler, and
PIC24FJ64GA004 microcontroller, and TC2015 LDO
Microchip Technology, Inc.
www.microchip.com
SSD1339 OLED Driver
Solomon Systech
www.solomon-systech.com
M25P40 Serial flash memory chip
STMicroelectronics
www.st.com
TPS61040 Switch boost converter
Texas Instruments, Inc.
www.ti.com
UG-2828GFEFF01 OLED
Univision Technology, Inc.
www.univision.com.tw
PLF263441B Lithium polymer battery
Varta Microbattery
www.varta.com