You are on page 1of 107

INFOTAINMENT RETRONICS

8052-AH BASIC Single-Board Computer (1987)


Jan Buiting

No flash memory devices, no


USB, no JTAG and no Internet,
but we did have those 27Cxxx
windowed EPROMs, RS232 ter-
minals or emulators, the odd
PC and a few good friends in
Intel’s IC distribution channels.
The perfect circumstances, as
it turned out, for Elektor to
become the first electron-
ics journal to not only
publish a single -
board computer
based on Intel’s
8052-AH-BA-
SIC microcon-
troller, but also to sell
the associated high-quality
double-sided PCB. The latter
went in vast quantities, report- tokeni-
edly over 5,000 pieces were sation took
sold to enthusiastic users, ama- place, boiling down
teur and professional, all over in essence to an interpreter
the globe. (ROMed in the micro) convert-
ing ASCII signs to 8051 ma- able
The instant success of the project chine code. And a pretty good standard core and an in-
proved that there was lots of in- job it did, albeit that small bugs baud rates like terpreter in on-
terest in programming a micro- and imperfections were soon no- 1200 or 2400 bits/s to chip ROM, and (2)
controller in BASIC rather than ticed by experts in 8051 family be used on the serial line con- the device was fright-
assembly language. Sceptics, programming. One particularly nected to the PC’s RS232 port. fully expensive com-
aplenty immediately after the well liked feature of MCS52 BA- The SBC design included an pared to, say, a 80C32.
publication of the November SIC was the ability for program- on-board EPROM programmer Although the method was never
1987 issue, soon fell silent when mers to insert a chunk of assem- which was cheerfully supported described in detail in Elektor for
the actual code executed by the bly code straight into the BASIC by MCS-52 BASIC. Its orderly fear of repercussions from Intel,
8052AH micro was valued in program. use comprised no more than the keen users of the SBC were soon
terms of speed. The general ver- The Elektor 8052AH-BASIC com- 8052AH faithfully programming successful in making the 8052AH
dict: “not bad at all, that inter- puter is likely to have helped 2764s and 27128s. However a micro extract and transfer its own
preter is worth its salt”. an odd-looking frequency like not so orderly application of the interpreter into a file! Next, eve-
11.0592 MHz become a stand- programmer came from simple rybody started using 80C32 mic-
The BASIC programs for this ard value for quartz crystals. The combination of two facts: (1) the ros running BASIC from external
SBC were written using an ordi- reason: the 8051 core divides 8052AH-BASIC micro is a com- EPROM. The alternative was not
nary ASCII savvy word proces- the clock frequency down to en- bination of a regular 8051 only much cheaper, but could
sor on a PC — in compliance, of also be tweaked for speed and
course, with the relevant syntax performance. At a much later
described by Intel in their MCS date, I think it was around 1992,
BASIC-52 Users Manual, which Intel released MCS BASIC-52
was much sought after. Nor sur- into the public domain. A flurry
prisingly, photocopies (138 pag- of 80C32 SBCs was the result,
es thick) soon surfaced in the including our own.
electronics retail trade.
Some IBM PC user on our staff
Next, the text file containing the must have learned the hard way
BASIC program had to be trans- that BRST at that time stood for
ferred to the 8052AH micro by Big Red Switch Time and he or
means of a communications pro- she pencilled the equivalent on
gram (a.k.a. terminal emulator) the reset pushbutton of the 8052-
like Procomm or Telix. During AH BASIC prototype in our lab,
handshake-driven downloading with due correction for colour.
to the 8052AH, a process called (075025-I)

Retronics is a monthly column covering vintage electronics including legendary Elektor designs. Contributions, suggestions and requests are welcomed; please send an
email to editor@elektor-electronics.co.uk, subject: Retronics EE.

76 elektor electronics - 3/2007


SMALL CIRCUITSCOLLECTION

AT90S2313 Programmer 035


COMPONENTS LIST IC2 = 78L05

Resistors: Miscellaneous:
R1,R2,R3 = 330Ω JP1 = 2-way pinheader with
R4 = 1kΩ jumper
K1 = Centronics socket
Capacitors: (female), PCB mount,
C1 = 100pF angled pins
C2,C3 = 33pF K2 = 24-pin ZIF-socket
C4,C6 = 100nF ceramic (e.g., Farnell # 178-235)
C5 = 10µF 63V radial or 20-pin IC socket with
C7 = 220µF 25V radial turned pins
C8-C11 = 22 nF ceramic K3 = 2-way PCB terminal
block, lead pitch 7.5 mm
Semiconductors: X1 = 4MHz quartz crystal
B1 = B80C1500, round case TR1 = mains transformer 9
(80V piv, 1.5A) V/0.35 VA (e.g., Hahn
D1 = LED BV201 0136)
IC1 = AT90S2313 PCB, order code 034036-1

T. Giesberts
nected to the ‘Serial Interface for In-system Programming’ (SPI)
In January 2003, we published an article about programming via resistors that protect the parallel port. The serial link to the
AVR microcontrollers using Bascom AVR. In that article and in internal Flash memory is enabled when the Reset signal
the manual for this Basic compiler, a circuit from Sample Elec- (pin 1) is low. The three connections for the SPI interface are
tronics is described as one of the simplest ways to program SCK, MISO (output) and MOSI (input), which are located on
the microcontroller. This circuit provided the basis for the prac- pins 19, 18 and 17 of the microcontroller, respectively. The 100-
tical implementation described here. pF capacitor (C1) is intended to avoid potential timing prob-
For this purpose, the parallel port of the PC is directly con- lems. It can be connected between the SCK line and ground
using jumper JP1. However, during
K1 MOSI our tests this proved not to be neces-
CENTRONICS SCK
19 1
sary.
R2
20 2 K2 To make building and connecting
330Ω
21 3
R1
this programmer as easy as possible,
22 4 RESET 1 24
330Ω IC1 a Centronics connector is located on
23 5 2 23 AT90S2313
R3 +5V
24 6 3 22
RST 1 20
the associated printed circuit board
330Ω
25 7 4 21
PD0 2 19 PB7 to allow a standard parallel printer
26 8 5 20
27 9 C1 X1 6 19
PD1 3 18 PB6 cable to be used to connect the pro-
XTAL2 4 17 PB5
28 10 7 18
XTAL1 5 16 PB4
grammer to a PC. If you want to pro-
100p
29 11 8 17
PD2 6 15 PB3 gram multiple microcontrollers, it is
30 12 JP1 4MHz 9 16
31 13
C3 C2
10 15
PD3 7 14 PB2 highly recommended to use a zero
PD4 8 13 PB1
32 14 33p 33p 11 14
PD5 9 12 PB0
insertion force (ZIF) socket. If you
33 15 12 13
10 11 PD6 want to build a less expensive ver-
34 16
35 17
sion, you can also use a normal IC
36 18 MISO socket. The design of the printed cir-
cuit board allows only one socket to
TR1
be fitted.
K3 C11 C8 IC2
The circuit has a small 5-V supply,
22n 22n 78L05 +5V consisting of a tiny 0.35-VA trans-
230V
C10
B1
C9 R4
former, a bridge rectifier and a 78L05
voltage regulator (IC2). Capacitors
1k

22n 22n
C7 C6 C5 C4
C4, C6 and C8–C11 suppress any
9V
D1 interference that may be present. The
220µ 100n 10µ 100n
0VA35 B80C1500 25V 63V power indicator LED D1 also acts as
POWER
a minimum load for the voltage regu-
034036 - 11
lator, in order to prevent the voltage

Elektor Electronics
SMALL CIRCUITSCOLLECTION
H2

H3

034036-1
TR1
~ K3 ~
K1
C10
C11

C9
C2
B1

C8

C3
R2

C7
IC1
R3

X1
C1

IC2 C6
C4

R4

D1
R1

1-630430 034036-1
ROTKELE )C( C5 (C) ELEKTOR
H4

H1

JP1 K2

from rising excessively in the absence of a load, which is a com AVR. The program should select the Sample Electronics
problem with some types. programmer by default. If this doesn’t happen, look under
The programmer should preferably be connected while the PC Options/Programmer to verify that the address of the parallel
is switched off. This is in any case always a good idea when port (LPT address) is properly configured.
connecting equipment to the parallel port of a PC, in order to (034036-1)

avoid damage to the hardware. After the programmer is con-


nected, switch on the PC and the programmer and start Bas- (based on an idea from Sample Electronics)

7-8/2003 Elektor Electronics 3


HANDS-ON USB DESIGN

AVR drives USB


Design: Michael Odenwald en Michael Keller, Commitor GmBH

Is it possible to use a microcontroller from the pre-USB era to fashion a USB


device without using additional ICs? The designers set themselves this question
a while ago. Many long evenings later, the answer proved to be ‘yes’. As a result,
we can now present a USB I/O board based on a standard AVR microcontroller
– without any special USB chips!

USB interfaces in embedded devices sistors (Figure 1). Besides processing ments, but for now the only thing you
are commonplace nowadays. A varie- the data packets, the microcontroller need to know is that each transaction
ty of circuits with USB interfaces have handles communication at the bit level. is initiated by the host device (usually
already appeared in the pages of Ele- The firmware looks after this entirely a PC). If the host wants to read data
ktor Electronics. Particularly with the on its own. from the connected device, the device
availability of special-purpose chips must respond by sending back the
from our Scottish friends at FTDI (and You may be thinking that the AVR has data. The data is transmitted in data
other manufacturers), it has become to run at high clock speed to manage packets, which must also comply with
very easy to include a USB interface in all this, but that’s not true at all. The various requirements.
a design. microcontroller operates with a 12-
MHz clock here, but its maximum rat- There are also several built-in mecha-
If you are looking for a more tailored so- ed clock speed is 16 MHz. It thus has nisms to ensure that the host can de-
lution, you can also take advantage of room to spare. tect new USB devices and assign them
several microcontrollers that come with addresses. This is all related to the
built-in USB interfaces. However, this ‘plug-n-play’ concept. The idea is to
solution requires a rather good under-
USB specifications minimize the actions that users must
standing of the USB bus. The firmware The USB specifications [1] clearly in- perform in order to use USB devices.
must process the data packets received dicate that the USB bus uses a serial
from the USB bus and transmit its own data protocol. Data is transmitted on
packets via the bus. If the device is not two bidirectional lines. These lines (D+
Electronics
a standard USB device, you also need and D–) transmit the data in differen- The electronic portion of this design
a special device driver – and you will tial mode. This means that the signals is fairly standard (aside from the USB
have to write it yourself. on the D+ and D– lines are opposite to connector). The AVR microcontroller
each other. An exception to this rule (IC3) forms the heart of the circuit (see
is made for synchronisation purposes: Figure 1). Crystal X1 sets the clock rate
100% soft the signal levels on both lines are set to 12 MHz.
It’s also possible to fit a USB interface low in that case.
in an FPGA, as we showed in our FPGA Our device operates in the Low Speed The circuit has three analogue inputs
Course published as a series of instal- mode, which means the data transmis- and five digital inputs, which are avail-
ments from April 2006 through Febru- sion rate is 1.5 Mbit/s. Communication able on connector K2. These lines are
ary 2007. In that case, we put an 8051 at the bit level thus places some spe- routed directly to the I/O pins of the
microcontroller core with an additional cific demands on the microcontroller. microcontroller, and they are fitted
USB interface in the FPGA. This was In physical terms, it must have at least with 100-kΩ pull-down resistors. The
our first ‘100% software’ USB device. two bidirectional ports. It must also be resistors prevent the inputs from gen-
The device described in this article able to read and process the status of
shows that a standard AVR microcon- these ports very quickly in software in
troller can also communicate via the order to keep pace with the data rate. Figure 1. As you can easily see from the schematic diagram,
USB bus with the aid of only three re- There are also numerous other require- the microcontroller forms the heart of the circuit.

34 elektor electronics - 3/2007


A development board
with a software-defined
USB interface
erating annoying problems due to stat- usual control signals. The microcontrol-
ic charges if they left open. ler can also drive five relays. There an
The circuit also has a temperature sen- LED for each relay to indicate whether
sor (IC2). This is a ‘1-wire’ chip, which the relay is actuated.
means that only one I/O pin is neces- The USB port is extremely simply with
sary to use the sensor. The input op- regard to the electronic components.
tions are rounded out with five push- Resistor R4 causes the host to recognise
button switches. that a Low-Speed device is connect-
ed to the USB port. Resistors R6 and
The circuit is fitted with an LCD that R7 provide current limiting in case of
is driven using four data bits and the problems. They also have the pleasant

5V
IC1
MC7805BT
K1 D1
S5 S4 S3 S2 S1 2 1 3
5V
1
1N4001
3
S1
2

C3 C5 C4 C1
S2
S3 47u 100n 100n 22u
S4 5V 20V 20V
S5 K2
1 GND
5V
AIN1 AIN1 2
AIN1 C6 K5 LCD
AIN2 AIN2 3 5V
AIN2
AIN3 AIN3 4
AIN3 100n 5V
1
2
3
4
5
6
7
8
9
10
11
12
13
14
DIGIN1 5 R2
DIGIN1 5V GND
DIGIN2 6
DIGIN2
1k

10
9
8
7
6
5
4
3
2

2
4
6
8

DIGIN3 7 P1
DIGIN3 K4
DIGIN4 8 D2
DIGIN4 PROG
DIGIN5 9
DIGIN5
1
3
5
7
9

10 10k
R3 8x 100k GND POWER
1

RESET
MOSI

MISO
SCK

R/W
RS

EN

D4
D5
D6
D7
GND GND
GND GND
5V

5V
5V 5V
R1
C2
IC2
4k7

R9 8x 470 Re1
3

1
10

30

32

100n K6
VCC

AVCC

AREF

2 ONEWIRE
GND DQ COM
LED1 1 40 AIN1
PB0 (XCK/T0) PA0 (ADC0) NC
LED2 2 39 AIN2
DS1820 PB1 (T1) PA1 (ADC1) NO
1

9
8
7
6
5
4
3
2

LED3 3 38 AIN3
PB2 (AIN0/INT2) PA2 (ADC2)
GND LED4 4 37 S1 Re2
5V PB3 (AIN1/OC0) PA3 (ADC3) K7
LED5 5 36 S2
PB4 (SS) PA4 (ADC4)
MOSI 6 35 S3 COM
R5 R4 PB5 (MOSI) PA5 (ADC5)
MISO 7 34 S4 D4 D5 D6 D7 D8 D9 D10 D11 NC
K3 PB6 (MISO) PA6 (ADC6)
1k

1k

SCK 8 33 S5 NO
PB7 (SCK) IC3 PA7 (ADC7) IC4
1 R6
68 ATmega32-16PC Re3
2 D- 14 22 RS LED1 1 18 K8
PD0 (RXD) PC0 (SCL) IN1 OUT1
3 R7 D+ 15 23 R/W LED2 2 17
PD1 (TXD) PC1 (SDA) IN2 OUT2 COM
4 D3 68 16 24 EN LED3 3 16
PD2 (INT0) PC2 (TCK) IN3 OUT3 NC
DIGIN2 17 25 DIGIN1 LED4 4 15
PD3 (INT1) PC3 (TMS) IN4 OUT4 NO
ONEWIRE 18 26 D4 LED5 5 14
5
6

PD4 (OC1B) PC4 (TDO) IN5 OUT5


DIGIN3 19 27 D5 MOSI 6 13 Re4
PD5 (OC1A) PC5 (TDI) IN6 OUT6 K9
GND DIGIN4 20 28 D6 MISO 7 12
PD6 (ICP) PC6 (TOSC1) IN7 OUT7
DIGIN5 21 29 D7 SCK 8 11 COM
5V PD7 (OC2) PC7 (TOSC2) IN8 OUT8
NC
RESET 9 9 10 NO
R8 RESET GND K
XTAL2

XTAL1
GND

GND

Re5
10k

ULN2803A K10
X1
11

31

12

13

COM
RESET
R10 NC
C7
C8 C9 NO
100k

S6
100n
18p 12MHz 18p
RESET
060276 - 11
GND GND GND

3/2007 - elektor electronics 35


HANDS-ON USB DESIGN

proper-
ty of reduc-
ing reflections
on the data lines,
which helps reduce
errors.

The D+ and D– signal lines are


connected to separate I/O pins of
the microcontroller. D+ is also con-
nected to the INT0 input of the micro-
controller. This makes it possible to
generate an interrupt each time the
signal level on the D+ line changes.
Don’t be misled by the fact that the
D+ and D– lines are connected to the
UART pins of the microcontroller. The
software uses these two pins as nor-
mal I/O pins. The built-in UART of the
microcontroller is not used for the USB
interface.
The PCB track and component layouts
are shown in Figure 2.

Power supply
An AC mains adapter is suitable for
powering the entire circuit. In princi-
ple, it is also possible to power USB
devices from the host, but this option
is not suitable here. According to the
specifications, the voltage on the USB
bus can range from 4.4 V to 5.25 V.
However, voltages seen in practice of-
ten differ from the specifications. With
regard to current consumption, the
maximum current a device is allowed
to draw before enumeration (see in-
set) is 100 mA. During the enumeration
process, the device states how much
current it wishes to draw from the USB
port (up to a maximum of 500 mA).

In this case, we need a minimum voltage


of 5 V for the microcontroller. Although
it would be possible to use a step-up

Figure 2. The microcontroller also occupies the central position


on the circuit board.
As you can see, there is a wealth of I/O options.

36 elektor electronics - 3/2007


2.5mm
COMPONENTS IC1 = 7805CP
IC2 = DS1820
LIST IC3 = ATmega32-16PC (programmed, E-
SHOP # 060276-41)
IC4 = ULN2003A
Resistors
R1 = 4kΩ7
Miscellaneous
R2,R4,R5 = 1kΩ
K1= 2.5mm mains adaptopr socket
R3 = SIL array 8x 100kΩ
K2= 10-way PCB terminal block, lead
R6,R7 = 68Ω
pitch 2.54 mm (e.g. Phoenix contact #
R8 = 10kΩ
1725737)
R9 = SIL array 8x 470Ω
K3= USB-B connector
R10 = 100Ωk
K4 = 10-way boxheader
P1 = 10kΩ preset
K5= 14-way pinheader
K6-K10= 3-way PCB terminal block, lead
Capacitors
pitch 2.54mm (e.g. Phoenix contact #
C1 = 22µF 20V radial
1725669)
C2,C4,C5,C6,C7 = 100nF
con- Re1-Re5 = 5V relay (e.g. OMRON
C3 = 47µF 20V radial
verter G5V-1-DC5)
C8,C9 = 18pF
S1-S6 = pushbutton (e.g. OMRON
to boost the
B3F-1002)
voltage on the Semiconductors
X1 = 12MHz quartz crystal, HC49/U case
USB port to 5 V if it D1 = 1N4001
LCD module, 2x16 characters
D2-D11 = low-current LED, red, lead pitch
is too low, this would PCB, E-SHOP # 060276-1
increase the current con-
sumption. It could also gen-
erate noise (and thus problems).
Our aim here is to create a reliable
Compiling into the microcontroller while it is fit-
DIY design that is also reliable in oper- The complete firmware, including the ted to the board (‘in system’). However,
ation, so we chose the simple solution assembly-language code, can be com- you must set the proper fuse bits for
of a standard power supply using an piled using the AVR GCC compiler [2], this, since otherwise the entire process
AC mains adapter. Diode D1 protects which is a (free) open-source compiler. won’t work. The palmaver site [4] de-
the voltage regulator (IC1) against re- There is also a downloadable ‘make’ scribes a convenient way to determine
verse-polarity connection of the mains file, which makes the compilation proc- the proper configuration bytes. You can
adapter. ess a lot easier (see [3]). determine the right settings for this
circuit by entering ‘0x3fDf’ in the box
The circuit has a programming inter- at the upper right (see Figure 3). This
Firmware face, so you can program new firmware corresponds to programming the BOD-
Naturally, the driving force of this
project is the firmware. The firmware
consists of several modules, which are
predominantly written in C. Assembly-
language code is only used for driving
the USB lines, since it is faster.

The device descriptor is located in


the usb.h file. During the enumera-
tion process, the host uses the data
in the device descriptor to determine
what sort of device is connected. If you
want to adapt the circuit to your own
purposes (or just play with it), this is
where you can ensure that the host
recognises your device correctly. Of
course, this requires a certain amount
of knowledge of the USB protocol.

The avr-usb.h file contains a list of re-


quests that are supported by the con-
nected device. The host can send a re-
quest to the device, which performs
the associated action in response.
Some examples of typical actions are
clearing the LCD, actuating or releas-
ing a relay, and so on. In some cases,
the request requires the device to re-
turn data to the host. One example of
this is reading the temperature. Figure 3. It’s easy to determine the right fuse settings with this handy online tool [4].

3/2007 - elektor electronics 37


HANDS-ON USB DESIGN

In response to the change in the signal level on the data line,


Enumeration the host uses a predefined protocol to try to determine what
sort of device is connected to the USB port. Besides the ex-
The host device must perform a process called ‘enumera-
pected data (such as the VID and PID), the device must also
tion’ before it can use a connected USB device. The first step
report which class it belongs to, along with other information
in the process takes place in he USB device, where a pull-up
resistor in the device signals its presence on the USB bus. such as its version number, name, and so on. A USB address
is also assigned to the device. The host uses the addresses to
In the case of a Low-Speed device (1.5 Mbit/s), the pull-up
distinguish the different USB devices.
resistor must pull the D– line to +3.3 V. In the case of Full-
Speed (12 Mbit/s) and High-Speed (480 MB/s) devices, the The information described above enables the host to deter-
D+ line must be pulled to +3.3 V. mine which device driver it needs in order to use the device.

enumeration process.
You can skip installation of the driver
for now, since you don’t yet have a spe-
cific driver for this circuit. The driver
(which is also open-source software) is
described in the ‘Universal USB Driver’
article in this issue.

USBview
You don’t necessarily need a driver to
test USB communications. Instead, you
can use Microsoft’s USBview utility.
This program is included in the Micro-
soft Driver Development Kit (DDK) [5].
You can use it to view the data from
the device descriptor of the USB device
(see Figure 4).

This program works without a device


driver. You can test USB communica-
tions by viewing the data from your de-
vice in the USBview window. All the
data you see there comes from the de-
vice and is sent to the PC via the USB
bus.

If all the test results are positive, the


hardware is ready and you can start
Figure 4. USBview gives you a bird’s-eye view of everything connected to the USB. working on the device driver. Refer to
the ‘Universal USB Driver’ article else-
where in this issue for the details.
(060276-1)
LEVEL, BODEN and SPIEN bits (set- are good and you haven’t created any
ting them to logic 0) and leaving the shorts. It’s also a good idea to double-
other bits unprogrammed (logic 1). check the values of the resistors and
capacitors and verify that all the ICs
are oriented correctly in their sockets.
Assembly and testing
The circuit should be easy to assemble Once you have completed the inspec-
if you use the accompanying PCB de-
sign. The circuit does not include any
tion, you can start testing the board
– cautiously of course! First connect
Web links
difficult SMD components, and every- an AC mains adaptor with a DC out- [1] www.usb.org/developers/docs.html
thing is readily available. The PCB is put voltage of 9–12 V. If everything is [2] winavr.sourceforge.net/
also available from our E-SHOP [3]. as it should be, LED D2 will light up.
[3] www.elektor-electronics.co.uk
Next, connect the circuit to a PC via
After soldering all the components a USB cable. LED D3 should also light [4] palmavr.sourceforge.net/cgi-bin/fc.cgi
in place, inspect the results careful- up now. Windows (assuming you are [5] www.microsoft.com/whdc/devtools/ddk/
ly to ensure that all the solder joints running Windows) will then start the default.mspx

38 elektor electronics - 3/2007


MICROCONTROLLER

C Compilers
for the PIC Micro
Efficiency from a higher programming language
By O. Beckman Lapré

The PIC microcontroller in its many guises is found at the heart of


countless electronic projects and designs (including those from Elektor).
Most software developers use brick-by-brick assembly code to write
programs for the PIC. However, it is also possible to program these
wonderful micros using a higher programming language like ‘C’ which
rightly became an industry standard.

The tremendous popularity of the C program- been designed, right from the start, ware. Also, C is not a bad performer
ming language is largely due to it having for better access to the system hard- when it comes to code efficiency.
These days, C allows you to develop
almost anything for microcontrollers
(from the smallest PIC to X-scale
‘monsters’), digital signal proces-
sors, operating system programs for
Windows or Linux, right up to UNIX
and mainframes, not forgetting
administrative programs.
C is also great for building
device drivers and even complete
operating systems (including Linux
and Windows 2000/XP), and of
course application programs we use
every day (from Word to Mozilla).
Very likely, C is currently the most
universally applicable higher pro-
gramming language — and likely to
remain for some time to come. It
pays to learn C!
In this article we look at three C
compilers for the Microchip PIC
series of microcontrollers. In elec-
tronics hobby land, the PIC currently
ranks among the most popular
microcontrollers, although the com-
petition from the Atmel AVR side is
Figure 1. The standard CS compiler in combination with the ConTEXT program editor. fierce. The PIC is easy to apply in

52 Elektor Electronics 6/2003


MICROCONTROLLER
practice and often just as good as
the industry-standard (and up-mar-
ket) 8051 controller.
Hobbyists typically have their
own requirements for a C compiler,
like ease of use and low cost (the lat-
ter to avoid lengthy explanations to
the missus). Three compilers that
certainly meet these requirements
are ‘PCM compiler’ from CCS, ‘C2C
compiler’ by Pavel Baranov, and the
‘C for PIC Microcontrollers’ from
Matrix Multimedia. Although these
products differ considerably in prac-
tical use and features, they certainly
meet the requirements of the home
programmer. The product versions
discussed here are probably not the
latest and may differ in some
respects from the most up to date
releases.

Development suite
If you do a lot of microcontroller code Figure 2. De C2C compiler has a Windows-based development suite for C programs.
building, ease of use is a primary
requirement. Also, the beginning
programmer should not have to times, the program did dot crash. allows you to program the PIC simply by call-
wade through hundreds of pages in The C2C compiler optionally ing a programming utility.
the User Manual to learn the basics.
All three C compilers assume a good
command of C. Especially in the case
of PCM and C2C, the relevant docu-
mentation on the language itself is Listing 1.
rather scanty and mainly intended to Structure ‘mapped’ to an I/O port
describe the possibilities, impossi- Example for PCM compiler:
bilities and the library routines.
The compilers show significant struct _keys
differences when comparing their {
development surroundings. bit mode_sw; // LSB
The standard CSS compiler is, bit plus_sw;
well, a compiler and actually works bit minus_sw;
‘alone’. It has to be invoked through bit set_sw;
a DOS window or a console com- bit unused : 4;
mand line that includes the name of } keys
the file options, if any. Obviously, it
would be far more user friendly if the #byte keys = 5 // ‘keys’ struct is mapped to address 5 = PORTB
compiler could be launched from an
editor. For that purpose, the program if (keys.mode_sw == 1)
(text) editor ConTEXT is just fine {
(see Figure 1 and the web reference // mode switch was pressed
at the end of this article). }
The C2C compiler (version 4.0e,
see Figure 2) has a Windows-based With the C2C compiler, the port first has to be read. Next, the ‘&’ operator is used to test
if a bit is set or not, as in the example below:
platform around it and is slightly
easier to use than PCM. A disadvan- char keys@5 // keys are mapped to address 5 = PORTB
tage, however, was found in a num-
ber of bugs in the program that if (keys & 1)
caused text to be displayed erro- {
neously (on occasions, and in the // mode switch was pressed
version available to the author). }
Although this caused problems at

6/2003 Elektor Electronics 53


MICROCONTROLLER
The C2C compiler is distributed as employed by print(f). In this way,
Internet addresses: shareware and a lot cheaper than print(f) output may be directed to a
C for PIC Microcontrollers. CD-ROM prod- the CSS products. New releases graphic LCD just by writing a putc()
uct, price from £39: keep appearing. The author tested routine for your particular LCD (in
www.matrixmultimedia.co.uk versions 4.0 and 4.6 but in the mean other words, a kind of device driver).
time a major new version, 5.0, A large number of exotic drivers is
PCB compiler (for 12-bits PICs), PCM com-
piler (for 14-bits PICs), PCH compiler (for appeared, consisting of a complete supplied for countless applications
18-bits PICs) and PCW(H) compiler (Win- IDE called PicAntIDE. like touchscreen control and temper-
dows version): The excellent C for PIC Micros is ature sensor reading. These, how-
www.ccsinfo.com/picc.shtml supplied on CD-ROM only, and is ever, require ICs to be used in the
Price: from $125 + P&P competitively priced at £39 for the application circuits that are actually
student version. The current version controlled via the available drivers.
PCW demo version (1 k): is 2.0. In all other cases, you have to ‘write
www.ccsinfo.com/demo.htm your own’!
As opposed to the C2C compiler,
C2C compiler: Library PCM also supports 32-bit IEEE float-
www.picant.com/c2c/c.html
When comparing the programs, ing point routines. Fortunately, that
Registration: $ 59
major differences are also observed need not be a problem in all cases
ConTEXT programming editor: in the ‘library’ department as well as because the PIC is usually applied in
www.fixedsys.com/context/ in the possibilities of the C language. relatively simple control systems. All
For example, the C2C compiler has a compilers cheerfully handle 8-bit and
‘tighter’ link with the hardware 16-bit variables.
because that is handled at a low
C2C and PCM are capable of producing a level. By contrast, with the PCM
.LST file that enables the generated assem- compiler the emphasis is clearly on Further outlook
bly code to be checked by the compiler. That a quick start involving a minimum All three compilers represent excel-
is often used as a last resort when you’ve dis- amount of programming effort. lent value for money and are perfect
covered that the code does not do what you Many of the library routines incor- for home programmers, although it
want it to, or to tweak the efficiency of the porated into the PCM compiler are must be said that C2C is a bit more
code. In some cases, it may be worthwhile to also available on the C2C complier aimed at the advanced programmer.
apply a different algorithm to see if it website, which was written by a The PCM compiler has more to offer
improved upon the compiler efficiency. Fortu- third party. In both cases, a built-in than the C2C product (floating point,
nately, this is not normally required. However, library is available for RS232 and bit fields) and comes with an exten-
the author came across cases where prob- delays. sive library (for a really quick start)
lems could be solved by disabling the com- The advantage of the PCM com- but on the down side costs twice as
piler’s code optimiser feature. piler is its ability to support struc- much as C2C. C for PIC Micros best
The CSS compiler comes in no fewer than tures and bit fields. For example, a covers the educational side, i.e.,
five different versions. The PCB version is structure may be ‘mapped’ directly learning to program in C, and is
intended for 12-bit PICs. The PCM variant onto an I/O port with the ability to remarkable for its broad range, com-
we’ve mentioned so far is for 14-bit PICs, control individual port lines, as illus- prehensiveness and relatively low
while the most recent version, PCH, handles trated in the code example in List- price.
18-bit PIC micros. All program versions are ing 1. Finally, programmers as well as
Windows command line applications, which, The PCM compiler comes with an hardware designers should ensure
on being invoked, pop up a dialogue showing extensive library for the I2C and that the target circuit is suitable for
the progress of the compilation process. As RS232C serial communications pro- in-system programming (ISP), allow-
already mentioned, their functionality needs tocols and there’s even HD44780 ing the cycle consisting of compiling,
to be completed with a programming editor LCD controller software, including chip erasure, programming and
like ConTEXT. We also came across real Win- an extensive print(f) command. The debugging to be kept as short as
dows versions (called PCW and PCHW), but output of the print(f) routine, by the possible.
they are far more expensive than their com- way, is subject to adaptation using a (030098-1)
mand line counterparts. user-defined putc() routine that’s

54 Elektor Electronics 6/2003


MINIPROJECT

COM Port Tester


With 3 LEDs and 4 switches
Design by P. Goossens

The serial port (often called the COM port) is perfect for connecting
various electronic circuits to the PC. The complexity of the connected
circuit varies from a few I/O lines to control something and read the state
of switches, to a complex communications system between several
computers. This circuit is in the first category and uses the serial port to
perform a few simple I/O tasks.

The COM Port Tester is a simple circuit that the RS-232 standard and was drawn In the RS-232 standard equipment
shows how the signals on a serial port can be up early in 1960 by the ‘Electronics has been divided into two distinct
used to control another electronic circuit. We Industries Association’. The aim was groups, these being DTE and DCE.
will have to disappoint those of you who to define a standard port that could These abbreviations stand for ‘Data
expect to use the serial port to control motors be used with equipment from vari- Terminal Equipment’ and ‘Data Com-
and lights etc. This circuit is limited to driving ous manufacturers to communicate munication Equipment’ respectively.
three LEDs and reading the state of four between each other. A good 40 These two terms were chosen by the
switches, nothing more and nothing less. years later this standard (although authors of the standard due to the
with a few modifications) is still in way in which the serial port was
widespread use in all kinds of equip- used at that time: on one side of the
RS-232 ment. The best known of these are of connection was a terminal, which
The functions and electrical characteristics of course the mouse, modem, etc., but was nothing more than a screen
the signals in a serial port have been laid in industrial equipment the presence with a keyboard, and on the other
down in a standard. This standard is called of an RS-232 port is also common. end of the link was some sort of

34 Elektor Electronics 3/2003


MINIPROJECT
communication equipment.
DTE DCE DTE DCE
The function of a terminal (DTE) is K1
full K2 K3
3-wire K4
very simple in this set-up: every key 1 DCD 1 1 DCD 1

that is pressed is transmitted via the 6 DSR 6 6 DSR 6


2 RxD 2 2 RxD RxD 2
serial link, and every character
7 RTS 7 7 RTS 7
received is displayed on the screen. 3 TxD 3 3 TxD TxD 3
The communication equipment 8 CTS 8 8 CTS 8

(DCE) takes care of all other aspects 4 DTR 4 4 DTR 4


9 RI 9 9 9
of the communication. The serial 5 GND GND 5 5 GND GND 5
port is obviously not limited to the
connection of terminals to communi-
cation equipment. Even so, DTE and
DCE are still used to describe the
two distinct groups of equipment.
DTE DTE DTE DTE
full 3-wire
Signals K5

1 DCD DCD 1
K6 K7

1 DCD DCD 1
K8

The RS-232 standard describes many 6 DSR DSR 6 6 DSR DSR 6


2 RxD RxD 2 2 RxD RxD 2
more signals than are required on
7 RTS RTS 7 7 RTS RTS 7
the PC’s serial port nowadays. This 3 TxD TxD 3 3 TxD TxD 3
made it possible to use a 9-way con- 8 CTS CTS 8 8 CTS CTS 8

nector instead of the original 25-way 4 DTR DTR 4 4 DTR DTR 4


9 9 9 9
connector. The extra signals that 5 GND GND 5 5 GND GND 5
were found on the 25-way connector
are (almost) never used in modern
equipment. Those signals that are in
use can be found in Table 1. The
direction of the signals is also Figure 1. Several types of cable can be used to make a serial connection.
included. ‘DCE to DTE’ means that
the signal originates from the DCE
(output) and ends up at the DTE Electrical aspect Most PCs are now quite happy with TTL
(input). ‘DTE to DCE’ obviously level signals, where a voltage between 0 V
means the opposite. The two most The signals on the RS-232 port obvi- and 0.8 V corresponds to a ‘1’, and a voltage
important signals are RxD and TxD. ously have to conform to an electri- between 2 V to 5 V corresponds to a ‘0’. Of
These signals are used for the cal specification. This is where the course the modern RS-232 ports can still
exchange of the serial information authors of the standard have withstand voltages between –25 V and +25
(‘serial’ meaning one after the other, decided on something that may V, so that equipment that conforms to the RS-
and in the case of the RS-232 port it is appear peculiar to the digitally 232 specification won’t cause any damage!
bit by bit). minded amongst you. A logical one
A DTE can be easily distinguished (called a MARK in serial communi-
from a DCE by looking at the connec- cations) is electrically represented Cabling
tor used. If the equipment has a male by a signal between –3 V and –25 V, Choosing the cable required to connect two
connector for the serial port, then it whereas a logical zero (RS-232 term: pieces of equipment together via the serial
is a DTE (for example a PC). If SPACE) has a voltage level between port often causes confusion due to the many
instead the equipment has a female +3 V and +25 V. So not only are the possible permutations. There is a big differ-
connector, then the equipment con- voltages different compared to TTL ence between connecting two DTEs (two
cerned is a DCE (for example a levels, but all signals are also PCs for example) and connecting a DCE to a
modem, home-built circuit, etc.). inverted. DTE (a modem to a PC for example). Some of
the different configurations can be seen in
Figure 1.
When you examine these cables it is
Table 1. The signals on a 9-way connector. noticeable that for connections between a
DTE and DCE no signals cross over, whereas
DCD (Data Carrier Detect) DCE to DTE for connections between two DTEs some sig-
RxD (Receive Data) DCE to DTE nals do cross over. The number of signals that
TxD (Transmit Data) DTE to DCE is required to make a connection between
DTR (Data Terminal Ready) DTE to DCE two pieces of equipment can vary from three
DSR (Data Set Ready) DCE to DTE to nine. The 25-way version has even more
RTS (Request To Send) DTE to DCE signals that can be connected. These signals
CTS (Clear To Send) DCE to DTE have been ignored here for the sake of sim-
RI (Ring Indicator) DCE to DTE plicity. They are also no longer very impor-
tant, since 25-way connectors are hardly ever

3/2003 Elektor Electronics 35


MINIPROJECT
used any more for serial connections.
Usually a 3-wire connection is sufficient to R4 R5 R6 R7 R8

10k

10k

10k

10k

10k
achieve communications, but some equip-
ment requires that all signals are connected. K1
1 DCD
These extra signals are used for hardware
6 DSR
handshaking, which we won’t cover in this 2 RXD
article. 7 RTS
3 TXD BT1

8 CTS
9V
Circuit 4
9
DTR
RI
The COM port tester (Figure 2) has been 5
R1 R2 R3 S1 S2 S3 S4 S5
kept very simple. The main reason for this is

2k2

2k2

2k2
that we did not keep to the exact RS-232
standard, which has a voltage between –3 V
LOOPBACK
and –25 V for a logical one and a voltage D1 D2 D3
between +3 V and +25 V for a logical zero.
As was mentioned earlier, PCs are quite
happy with TTL levels, so there is no longer 020370 - 11
a need to use a negative voltage to send a
logical one to the PC.
All of the inputs and outputs found on a 9- Figure 2. The circuit of the COM port tester consists of just a few resistors,
way connector have been used in this circuit switches and LEDs. A 9 V battery is used for power.
to communicate with the outside world. Here
that was implemented using a few switches
and LEDs. components required, it shouldn’t be interest to people with some pro-
An extra function is provided by switch S3. a problem if you used a small proto- gramming experience.
When this switch is closed, all serial data typing board instead. An example program for this arti-
transmitted from the output of the serial port The circuit is connected to the PC cle is obtainable from the publishers
is fed back to the input of the serial port. via a one-to-one cable (the top-left (order number 020388-11, available
Figure 3 shows the layout of the PCB for cable shown in Figure 1). on floppy disk or as a free download
this circuit. Considering the small number of from the Elektor Electronics web-
site). This permits the outputs of the
Software serial port to be controlled manually,
0V +9V
LOOPBACK The original purpose of this circuit and also shows the state of the
R6 S3
was to serve as an example to show inputs.
BT1
R3 D3 RTS
how data could be processed in a After starting the program you
simple manner via the serial port. can select the serial port required.
K1 R2 D2 DTR
1-073020 Everybody will have their own ideas Next, the port has to be opened by
R1 D1 TxD how this circuit can be put to use. clicking on the button marked ‘open’.
ROTKELE )C(
S2 This requires a program that has The program is now ready for use
R5 DSR
S1
been adapted to the specific func- and will show the state of the inputs
R4 DCD tions of the circuit. using a tick in the boxes to the right
S4
R7 CTS The writing of such a program of the connector.
S5
will be left as an exercise to the When a box contains a tick it
R8 RI
reader, but to start you off there is an indicates that the relevant input is
article elsewhere in this issue of at a low voltage, which for an RS-
Elektor Electronics about a newly 232 signal means a logical one. This
developed serial port driver for Win- corresponds to a closed switch in
dows. This is of course mainly of our circuit.

COMPONENTS LIST
(C) ELEKTOR
Miscellaneous:
020370-1 Resistors: K1 = 9-way sub-D socket (female),
angled pins, PCB mount
R1,R2,R3 = 2kΩ2
S1-S5 = slide switch or rocker switch,
R4-R8 = 10kΩ
1 make contact
9-V battery with clip-on leads
Semiconductors: PCB, available from The PCBShop
D1 = LED, 3mm, green, low-current Disk, project software, order code
D2 = LED, 3mm, yellow, low-current 020388-11 (see article ‘Serial Port
Figure 3. The PCB layout for the circuit in D3 = LED, 3mm, red, low-current Driver for Windows’)
Figure 2 (board available from The PCBShop).

36 Elektor Electronics 3/2003


MINIPROJECT
Conclusion
Naming of RS-232 signals
This circuit has been kept very simple. Because
in electronic circuits of this, it only has a limited functionality. To
Often the naming of RS-232 signals in electronic circuit diagrams is misused. A increase its usefulness you could for example
female connector is frequently used for the serial port in a circuit, which means add a buffer stage to the outputs, which could
that the equipment should be considered as a DCE. This implies amongst other then drive a relay for switching lamps. The
things that the pin where the serial data comes out should really be called RxD, switches could be replaced by an input stage
but is usually identified in the circuit diagram as TxD. The opposite applies to the with an opto-isolator, or a mercury switch etc.,
pin that receives serial data; this is usually called RxD, whereas the correct RS- thereby allowing the acceptance of different
232 term is TxD. information by the serial port of the PC.
The circuit diagrams in Elector Electronics always show the pin that transmits
These improvements have not been
serial data as TxD and the receiving pin as RxD, irrespective of the type of con-
included here, since we wanted to keep the
nector used.
This circuit is an exception to this ‘rule’, since there is no logical reason to circuit small and simple. But there is nothing
exchange signals such as TxD and RxD in this case. that stops you from extending the circuit
yourself, for example turning it into a com-
puter controlled time switch, burglar alarm,
and so on. The possibilities are only limited
The three buttons to the right of This is made visible on our circuit via by your imagination (and your knowledge of
the outputs of the connector are the LEDs. electronics of course!).
used to set the outputs high or low. (020370-1)

3/2003 Elektor Electronics 37


READERSCIRCUITS

CompactFlash (CF)
Interface Please note:
Readers’ Circuits have not been
tested or post-engineered by the
For MCS-BASIC52 systems Elektor Electronics laboratory.

Design by G. Meers

Prices of CompactFlash cards having dropped considerably over the past


year or so, the author decided to design a parallel PC interface that allows
data or programs to be written into one of these handy solid-state
memories using MCS-BASIC52.
CompactFlash (CF) cards are gaining popular- data storage, and, in a more general by storm. Thanks to ongoing develop-
ity every day, probably because the vast major- sense, because the phenomenon ‘dig- ments in CF technology, the memory
ity of digital cameras employ them for mass ital camera’ itself is taking the world capacity rises while prices drop. This

+5V +5V

+5V
C1 26
18 D0
PB0
100n 19 D1
PB1
K1 20 D2
K2
PB2
21 D3
PB3 1 26
22 D4
PB4 D3 2 27 D11
D0 34 23 D5
D0 PB5 D4 3 28 D12
D1 33 24 D6
D1 PB6 D5 4 29 D13
D2 32 IC1 25 D7
D2 PB7 D6 5 30 D14
D3 31
D3 4 D8 D7 6 31 D15
D4 30 PA0
D4 3 D9 CS0 7 32 CS1 +5V
D5 29 PA1
D5 2 D10 8 33
D6 28 PA2
D6 82C55 1 D11 IC2.A 2 IC2.D 8 9 34 IORD
D7 27 PA3
D7 40 D12 10 35 IOWR
PA4 R2
39 D13 1 1 11 36 D1
PA5
10k

6
CS 38 D14 12 37
9 PA6 1 9
A0 37 D15 13 38
8 PA7
A1 14 39 CSEL
35 14 A0
RESET PC0 15 40
5 15 A1 JP1 R1
RD PC1 16 41 RESET
1k

36 16 A2
WR PC2 17 42
17 CS3
PC3 18 43
13 CS1
PC4 19 44
12 WR
PC5 20 45 DSAP
11 RD
PC6 D0 21 46
10 RESET
PC7 D1 22 47 D8
D2 23 48 D9
7
24 49 D10
+5V +5V R4
25 50
10k
D2
IC2.F 13
IC2.C 5 IC2.B 3 IC2.E 11 CompactFlash
C2 14 Connector
R3 1
IC2 1 1 1
680Ω

100µ 7
16V 12
6 4 10

IC2 = 74LS04
020389 - 11

Figure 1. The required hardware is down to a minimum.

34 Elektor Electronics 6/2003


READERSCIRCUITS
makes the CompactFlash card partic- needed because the 82C55 pulls the If the CS signal on connector K1 selects other
ularly attractive for PC users too, and relevant port lines Low when the addresses, then the above allocations should
you should not have been surprised data direction is reversed. When this be changed accordingly.
by us publishing a CompactFlash-to- takes place, the inverters prevent Because the software is intended as an
IDE Interface as early as April 2002. contention and undefined levels on extension of MCS-BASIC52 the system must
Triggered by the above men- the control lines. provide for sufficient extra program memory
tioned publication, the author set out The following signals have to be starting at address 2000h. The program
to design a CF interface for connec- connected to the system by way of proper has a size of 1.6 kB. In case you’ve
tion to the address bus, data bus connector K1: 5 V and ground; D0- already extended the system with additional
and control bus of the PC. The resul- D8; RD; WR; A0, A1 and RESET; CS. MCS-BASIC52 commands, obviously the
tant circuit, in combination with Note that the address decoder for source code has to be adapted and re-assem-
some simple software, allows CS (Chip Select) is not included in bled. When doing so, bear in mind that the
BASIC52 programs to be stored on a the circuit. The CS signal has to go source code employs ACALL instructions
CompactFlash card. Low when addresses from 0C000h with an addressing limit of 2 kB!
The software developed for this are selected by software. The 82C55 Finally, the software for the CF Interface is
project may be downloaded free of requires four addresses: compatible with MCS-BASIC52 V1.1 and
charge from our website, www.elek- V1.3.
tor-electronics.co.uk as file number DATA register PA, base address +0;
020389-11.zip which may be found DATA register PB, base address +1;
under month of publication. The pro- DATA register PC, base address +2; PARCFFU.ASM
gram reports attempts to enter incor- CONTROL register, base address +3. This is the source code of the program you’ll
rect parameters or undesirable write be using to extend MCS-BASIC52 with extra
actions to memory blocks. The inter- A few more circuit details: LED D1 statements. The assembled (object) code
face draws a current of about 42 mA lights to indicate activity on the called PARCFFU.HEX has to be copied into
and achieves a data throughput rate CompactFlash card. D2 indicates the the system memory starting at location
of about 50 kB per second. The presence of the supply voltage. 2000h.
author actually employs the interface Finally, capacitors C1 and C2 are The following commands are then avail-
on a 20-MHz system with excellent included to decouple (filter) the sup- able:
results and reliable data transfers. ply voltage. – PCFF V – Show version of connected Com-
pactFlash card.
– PCFF R – Reset CompactFlash card.
Circuit diagram Software – PCFF L, block number, address – Load
The circuit diagram of the CF Inter- The software for the interface was data from the CompactFlash card into the
face is shown in Figure 1. As you written in ASM51 and the source system. The ‘block number’ is the location
can see, the required hardware code may be found under two on the card (0-7823) and has a fixed size of
remains limited to an 82C55 chip, a names: 8 kB. The parameter ‘address’ contains the
74LS04, two indicator LEDs and – PARCFFU.ASM (for PCFF com- start address of the system data memory
two connectors. With some luck, mands from MCS-BASIC52); (00000h through 0FFFFh). After each
many of the components may be – PARCFF.ASM (for CALL commands processed sector, an ‘L’ is sent to the termi-
found in the junkbox. from MCA-BASIC52). nal.
A 50-way connector, K2, allows The software comprises a rudimen- – PCFF S, block number, address – Save data
the CF card to be inserted. On this tary IDE driver that divides the Com- from the system data memory into the Com-
connector, pin 9 is wired to ground, pactFlash card into blocks of pactFlash card. As above, only an ‘S’ is sent
forcing the card to behave like an 8,192 bytes. A cheap 64 MB CF card after each sector.
IDE hard disk. In this mode of oper- has a storage capacity of 7,828 – PCFF F, block number –This causes the
ation, jumper JP1 (between pin 39 blocks, or 64,086,016 bytes. That’s complete contents of this block number on
and ground) must be fitted. slightly less than the nominal capac- the card to be filled with the value 0FFh. An
The complete control of the IDE ity of the card because the last vir- ‘F’ is sent on completion of a sector.
interface is handled by the 82C55 tual cylinder is not completely used – PCFF D, block number – Show status of
(IC1). Using its bi-directional ports in the software. block number: B = data; V = empty.
PB0-PB7, the chip drives data lines In the program source code, the
D0-D7, while port lines PA0-PA7 han- 82C55 has its addresses assigned as Unambiguous error reports will pop up if the
dle data lines D8-D15. Port lines PC0- follows: card is either not ready, the block number is
PC7 are programmed to look after too high or if the block is in danger of being
the control lines that form part of the P8255A EQU 0C008H ; PORT A overwritten.
IDE interface. Using software, bi- ADDRESS
directional ports PA0-PA7 and PB0- P8255B EQU 0C009H ; PORT B
PB7 are set up as inputs or outputs ADDRESS
Using the PCFF instructions
at the proper instant. By contrast, P8255C EQU 0C00AH ; PORT C Programs developed under MCS-BASIC are
port lines PC0-PC7 are always con- ADDRESS contained in the RAM memory from address
figured as outputs. P8255CO EQU 0C00BH ; CONTROL 0200h onwards. The instruction PCFF S, 10,
The inverters contained in IC2 are ADDRESS 0200H writes the program to block 10 on the

6/2003 Elektor Electronics 35


READERSCIRCUITS
card. Using PCFF L, 10, 0200H the program block 100 to 120, the following little This allocation may be changed and
may be placed into RAM memory again. program may be run: a new program address created.
If the program is larger than 8 kB (find out Obviously, the source code then has
using P. LEN) it has to be accommodated in 100 FOR T=100 to 120 to be assembled again.
multiple blocks. If this is required, you should 101 PCFF F, T The operation and practical use is
note the following. The instruction PCFF S, 10, 102 NEXT T identical with PARCFFU.ASM
0200H writes data from address range 0200H 103 END described above, only the letters
through 21FDH into block 10. This represents ‘PCFF’ in the instructions have to be
a total of 8,190 bytes, not 8,192 as you may replaced by ‘CALL 0B000H’. Infor-
have expected because two bytes are used to PARCFF.ASM mation on the way the necessary
flag that the block already contains data. For In some cases, it is not possible to variables are entered in assembly
example, to write (save) a program of 10 kB, extend the system with extra MCS- code may be found in the source
the following instructions should be used: BASIC52 statements starting at pro- code file.
gram address 2000H. That’s why the (020389-1)
PCFF S, 10, 0200H : PCFF S, 11, 21FEH source code contained in
PARCFF.ASM is intended to enable
or the program to be fitted at any loca-
tion in the system’s program mem-
PCFF S, 10, 0200H : PCFF S, 11, 0200H+8190 ory. In this source code, the start Free Download
address is 0B000h and this may be – ASM51 source code and HEX
Reloading the program is then done as fol- changed to your requirements. The files of PARCFFU and PARCFF.
lows: start address is defined using the File number: 020389-11.zip.
following code chunk:
PCFF L, 10, 0200H : PCFF L, 11, 0200H+8190 www.elektor-electronics.co.uk/
START EQU 0B000H dldl.htm
Variables may be used for the block number ORG START (select month of publication).
and the address. If you want to erase, say,

36 Elektor Electronics 6/2003


GENERALINTEREST

Data Buses
In electronic systems
By H. Nordmann

In this article we take a look at the pros and cons of different types of
data bus structure in electrical design and compare some of the more
popular varieties of serial bus available today.

Mention the word bus and chances are that source system transportation target system
most people would conjure up a picture of the
big red double-decker variety used for mov-
ing people from one point to another. In this
article we concern ourselves with the elec-
tronic variety: the data bus. There is however
a link between the two, in both cases ‘bus’ is
just the name given to the vehicle or carrier
used for transporting things, in one case it is
people and in the other it is bits of informa- data block
e.g.,
tion. 0100.0110
Choosing the right type of data bus for a
particular application is often a crucial make data bus compatible
design decision and it’s important to study
the specifications of bus structures available
today to determine which is most suitable. If
the finished equipment interfaces to third-
party products make sure that the chosen
bus is well supported and allows maximum controller cable data receiver
flexibility. (busmaster) (typ. slaves)
030148 - 11
The main questions to ask when deciding
on the type of bus system to implement in a
design are: Figure 1. Every bus is a carrier.

– How fast does the data need to be trans-


ferred? The parallel Bus other fast memory hardware.
A parallel data bus will typically
– How many devices need to connect to the have a minimum of eight bi-direc- The serial Bus
bus (now and in the future)? tional parallel data paths to send The serial bus structure uses just
information between devices on the one single data path to send or
– Is the cost of the bus design important? bus. Microcontrollers and DSPs with receive information. A typical serial
(Will the finished design be used in high- 32 bit data buses are currently being bus would use a minimum of three
volume, low-cost equipment?). produced for applications requiring wires to transfer data. A byte of
high-speed data manipulation. In information is split into its individual
Data buses can be broadly split into serial or short, parallel buses are chosen bits, passed over the serial data line
parallel configuration using either synchro- when you cannot compromise on one after another and then reassem-
nous (the data is sent along with some sort data throughput: they will typically bled into a byte at the receiver.
of clock signal to transfer the data) or asyn- be used within equipment, over Even from this simple outline you
chronous (where data is transferred without short distances to connect processor have probably already worked out
a clock). busses with their memory chips and the strengths and weaknesses of

52 Elektor Electronics 11/2003


GENERALINTEREST
VCC
bus has not been too widely adopted for this
reason and is almost exclusively used in a
‘single-master single-slave’ system. Typical
applications for this bus are memory modules
(EEPROMs) in phones to store telephone num-
SDA bers or tuner memory in TV sets or satellite
SCL receivers to store channel frequency data and
also in other consumer equipment where
Master Slave Slave Master Master
Transmitter/ Receiver Transmitter/ Transmitter Transmitter/ information is stored and does not need to be
Receiver Receiver Receiver changed very often.
030148 - 12

The I2C Bus


Figure 2. I2C bus topology. The I2C bus was designed by Philips around
twenty years ago and has since been widely
adopted throughout the electronics world.
The I2C (Inter Integrated Circuit) bus consists
of just two (bi-directional) wires SDA (Serial
SDA
Data) and SCL (Serial Clock). Originally the
bus specification defined a seven bit device
address, allowing up to 128 devices to be
addressed (27 = 128) and the maximum data
SCL 1–7 8 9 1–7 8 9 1–7 8 9 rate was 100 kbits/s but since a revision in
S P 1992 the device address has gone up to 10
START ADDRESS R/W ACK DATA ACK DATA ACK STOP
bits and the maximum data rate has been
condition condition
030148 - 13
increased to 400 kbits/s (fast-mode), back-
ward compatibility to the earlier specification
is retained (more recently the data rate has
Figure 3. Data transfer on the I2C-Bus. undergone a further speed increase). Figure
2 shows the general structure of an I2C bus
layout with all devices connecting to both
these two main contenders for bus Microwire Bus SDA and SCL.
layouts. The serial bus squeezes all Unlike the Microwire bus the I2C bus does
the information down a single wire Despite their inherently lower per- not use a separate wire to address slave
so data transfer will be relatively formance compared to parallel devices but instead defines device addresses
slow compared to the parallel bus buses, synchronous serial busses are in the communication protocol so that each
that offers many more simultaneous the most prolific, the majority of device has a unique address. Devices con-
data paths. The parallel bus requires external interfaces to PCs are serial nected to the bus can be either master or
more hardware in the form of con- and there are a host of synchronous slave and I2C is a ‘multi-master’ bus that
nectors and cabling and this can bus standards to choose from to suit allows bus control by more than one device.
give rise to problems for densely all situations. The I2C message format is shown in Fig-
packed PCB layouts. The Microwire bus is one example ure 3, each message begins with a start
In addition to data signals, the of this type of bus; it was developed sequence and is terminated by a stop
parallel bus also requires some form by National Semiconductor and is sequence. The start condition is indicated
of latch signal or chip select (some- implemented on the COP8 family of uniquely by a falling edge on SDA while SCL
times called STROBE or ENABLE) to processors. This bus is used predom- is high and the stop condition is indicated by
synchronise the data transfer. Asyn- inantly as an interface to serial EEP- a rising edge on SDA while SCL is high, at all
chronous parallel buses are another ROMs such as the 93C46 (a 64×16 bit other times SDA only changes when SCL is
variant and use a handshake system EEPROM). Microwire belongs to the low. A pull-up resistor on SDA ensures that
to transfer data: the transmitting ‘4-wire’ family of busses because the bus goes to a logic ‘1’ in between mes-
device places data on the bus and each slave connects to the bus via sages. The clock pulses on SCL are generated
then issues a strobe to the receiving SO (serial data out from the master), by the master device sending the message
device indicating that data is avail- SI (serial data into the master) and and are inhibited between messages.
able to be read. The receiver reads SK (the signal clock), together with a The message begins with a 7-bit slave
the data and sends an acknowledge chip select giving four signal wires to address followed by a single R/W
signal back to the sender to indicate each slave device. A disadvantage of (read/write) bit. If this bit is a ‘0’ the master
that the data has been read. This this bus implementation is that each will be transmitting data while a ‘1’ indicates
type of data transfer is termed ‘inter- slave device on the bus requires its that the master will be expecting to receive
locked communication’ and ensures own chip select signal so that with data from the slave. The PCF8574 port
that devices on the bus with differ- ten slave devices on the bus, the expander chip has an I2C interface and can
ent response times can communi- master device needs to generate ten be addressed to either read or write informa-
cate without problems. chip select signals. The Microwire tion so that if ‘read’ is selected it will send

11/2003 Elektor Electronics 53


GENERALINTEREST
back the logical state of its input port while DS2401 MEMORY MAP
‘write’ will output data from the master to its 8-Bit CRC Code 48-Bit Serial Number 8-Bit Family Code (01h)
output port. MSB LSB MSB LSB MSB LSB
An acknowledge (ACK) signal is used to 030148 - 14
ensure that the addressed slave device is
working correctly: the master device contin-
ues to produce the clock signal during this Figure 4. Format of the 64 Bit memory.
one bit period but releases the data line so
that it rises to a logic ‘1’ it is now the slave
devices job to pull the data line low just for The tolerances on these timing original features. The bus master can
this one bit period to produce the acknowl- pulses are deliberately wide to allow issue a Search ROM command to
edge signal. An ACK signal is also required for worst-case timing inaccuracies in allow it to identify the 64 bit codes of
after each 8 bits of data. the slaves. The 1-wire bus is classed all the attached devices on the bus
The specification has been revised to as a PWM (Pulse Width Modulated) or a Skip ROM which saves time in a
expand the numbers of device addresses, coded bus system. single drop bus system by allowing
increase data rate and also to operate at The advantages of the 1-wire bus the bus master access to the control
lower voltage levels so that this bus remains are clear: very little hardware inter- functions without the need to pro-
a popular choice for communications facing is required and the develop- vide the 64 bit ROM code. These fea-
between different micro modules in the con- ment and production costs are low. tures and many others make the 1-
sumer and entertainment fields. This stan- As an example of a 1-wire device, wire bus a very powerful solution for
dard is well supported and there is a wide the DS2401 is a ‘silicon serial num- many applications.
selection of bus devices for connecting sen- ber’ or ID chip and is packaged as an As electronic systems get larger
sors and actuators. SMD or as a three pin TO92 outline and more complex so the numbers of
(like a small-signal transistor). This sensors and actuators connected to
device just contains a unique serial the bus increases which leads to
1 Wire Bus number programmed during manu- greater bus loading and a greater
Lastly we will take a look at the ‘1-wire bus’ facture. It can be used as an identifi- volume of data to be processed. Bus
(also known as MicroLAN) from Dallas Semi- cation device for a PCB or piece of couplers (the DS2409 together with
conductor. This bus design uses just a single equipment to enable the bus master the DS2406) can be used in this case
data wire to transfer data and also power to to identify devices connected to the to split large bus systems into many
the one wire chip. This method of power feed bus, its serial number can be read smaller branches to reduce the bus
is known as a parasitic power connection. To out but it is not possible to write to loading.
complete the circuit to the bus it is of course the chip. The format of the stored A good application example for
necessary to provide an earth return path so serial number is shown in Figure 4. the 1-wire bus would be in the area
two connections are actually required. This The least significant byte is an 8-bit of personnel entry or ‘clocking in’
bus needs very little interface hardware and family code identifying the type of systems for industry. Each employee
uses a sophisticated software protocol to device. The next 48 bits is a unique would carry their uniquely coded
ensure data security. (factory programmed) serial number chip that would communicate with a
The sending device sends data by pulling while the most significant byte con- central processor and allow them
the data line low. If the line is low for less tains a CRC (Cyclic Redundancy access to permitted areas.
than 15 µs the receiving device interprets this check), used to detect any data cor- A 1-wire device called an iButton
pulse as a logic ‘1’, pulses that are at least ruption of the preceding seven has been developed for just these
60 µs are interpreted as a logic ‘0’. bytes. The large 48-bit serial number types of applications. The device is
(248 = 2.8 ×1014) ensures that each a 16 mm diameter stainless steel
device produced can have a unique capsule containing a 1-wire device
address. that can be mounted in a key fob
One-way communication is not (Figure 5). The capsule casing offers
the only thing that the 1-wire bus good electrical shielding from
has to offer, as well as the ID chips sources of interference and is robust
there is also a wide and growing enough to withstand pressure equiv-
range of different 1-wire devices alent to being stepped on… just try
ranging from simple EEPROMs to that with a chipcard! (On second
easily programmable real-time thoughts maybe that’s not such a
clocks with event counters and good idea).
multi-channel Analogue to Digital (030148-1)
converters. The unique 48-bit serial
number and 8-bit family code asso-
ciated with every individual device Web Addresses:
produced ensures complete compo-
nent traceability. www.dalsemi.com
The designers of the bus protocol www.maxim-ic.com
Figure 5. A ring iButton have built-in some interesting and www.ibutton.com

54 Elektor Electronics 11/2003


SMALL CIRCUITSCOLLECTION

Hard Disk Selector 050


Switching from one operating system
K1 K2 K3
to another — that’s a risky business,
RESET 1 2 RESET 1 2 RESET 1 2
DD7 3 4 DD8 DD7 3 4 DD8 DD7 3 4 DD8 isn’t it? Although this may be a bit of
DD6 5 6 DD9 DD6 5 6 DD9 DD6 5 6 DD9 an exaggeration, the safest approach
DD5 7 8 DD10 DD5 7 8 DD10 DD5 7 8 DD10
DD4 9 10 DD11 DD4 9 10 DD11 DD4 9 10 DD11
is still to install two different operat-
DD3 11 12 DD12 DD3 11 12 DD12 DD3 11 12 DD12 ing systems on the same PC, so you
DD2 13 14 DD13 DD2 13 14 DD13 DD2 13 14 DD13
DD1 15 16 DD14 DD1 15 16 DD14 DD1 15 16 DD14
can always easily use the ‘old’ oper-
DD0 17 18 DD15 DD0 17 18 DD15 DD0 17 18 DD15 ating system if the new one fails to
19 20 19 20 19 20
meet your needs (or suit your taste).
DMARQ 21 22 DMARQ 21 22 DMARQ 21 22
DIOW 23 24 DIOW 23 24 DIOW 23 24 A software solution is often used for
DIOR 25 26 DIOR 25 26 DIOR 25 26 such a ‘dual system’. A program
IORDY 27 28 IORDY 27 28 IORDY 27 28
DMACK 29 30 DMACK 29 30 DMACK 29 30
called a ‘boot manager’ can be used
INTRQ 31 32 IOCS16 INTRQ 31 32 IOCS16 INTRQ 31 32 IOCS16 to allow the user to choose, during
DA1 33 34 PDIAG DA1 33 34 PDIAG DA1 33 34 PDIAG
DA0 35 36 DA2 DA0 35 36 DA2 DA0 35 36 DA2
the start-up process, which hard disk
CS0 37 38 CS1 CS0 37 38 CS1 CS0 37 38 CS1 will be used for starting up the com-
DASP 39 40 DASP 39 40 DASP 39 40
puter. Unfortunately, this does not
always work flawlessly, and in most
cases this boot manager is replaced
U+ by the standard boot loader of the
RESET
R5
operating system when a new oper-
ating system is installed. In many
10k

T1
BC557B
cases, the only remedy is to reinstall
U+
T2 the software.
R4
R1
R2
2k7 The solution presented here does not
15k

suffer from this problem. It is a hard-


10k

R3 BC547B
1k

ware solution that causes the pri-


5 1 D1
D
IC1.A
mary and secondary hard disk drives
3 C 2 to ‘swap places’ when the computer
S1 R S
R6
U+ is started up, if so desired. From the
4 6
perspective of the computer (and the
15k

R9
10k

T3 software running on the computer),


BC557B
IC1 = 4013 it appears as though these two hard
U+
R8
T4 disks have actually changed places.
9
D
13 2k7 This trick is made possible by a fea-
K4 IC1.B R7 BC547B ture of the IDE specification called
1k

R 11 C 12
14
B
IC1
C1
D2
‘CableSelect’. Every IDE hard disk
R S
B
7 100n 10 8 can be configured to use either Mas-
Y
ter/Slave or CableSelect. In the latter
034050 - 11
case, a signal on the IDE cable tells
the hard disk whether it is to act as
P. Goossens
the master or slave device. For this reason, in every IDE cable
In the last few years, the available range of operating systems one lead is interrupted between the connectors for the two
for PCs has increased dramatically. Various free (!) operating disk drives, or the relevant pin is omitted from the connector.
systems have been added to the list, such as BeOS, OpenBSD This causes a low level to be present on the CS pin of one of
and Linux. These systems are also available in different the drives and a high level to be present on the CS pin of the
colours and flavours (versions and distributions). Windows is other one (at the far end of the cable).
also no longer simply Windows, because there are now sev- The circuit shown here is connected to the IDE bus of the
eral different versions (Windows 95, 98, ME, NT and XP). Com- motherboard via connector K1. Most of the signals are fed
puter users thus have a large variety of options with regard to directly from K1 to the other connectors (K2 and K3). An IDE
the operating system to be used. One problem is that not all hard disk is connected to K2, and a second one is connected
hardware works equally well under the various operating sys- to K3. When the computer is switched on or reset, a pulse will
tems, and with regard to software, compatibility is far from appear on the RESET line of the IDE interface. This pulse
being universal. In other words, it’s difficult to make a good clocks flip-flop IC1a, and depending on the state of switch S1,
choice. the Q output will go either high or low. The state on the Q out-

Elektor Electronics 7-8/2003


SMALL CIRCUITSCOLLECTION
Y B B R
K1 K2 K3
HOEK1

HOEK3

K4 C1

R1

D2
D1
R2

IC1
S1
034050-1

034050-1 (C) ELEKTOR


ROTKELE )C( 1-050430

R6

R3
R7
T3 T1
R8
T2
R5

R9
T4

HOEK4
R4
HOEK2

COMPONENTS LIST through T1 will cause LED D1 to light up and transistor T2 to


yellow conduct. The hard disk attached to connector K2 will thus see
Resistors: D2 = LED, low-current, a low level on its CS pin, which will cause it to act as the mas-
R1 = 10kΩ green
ter drive and thus appear to the computer as the C: drive.
R2,R6 = 15kΩ IC1 = 4013
T1,T3 = BC557B A high level will appear on the Q output following the reset
R3,R7 = 1kΩ
R4,R8 = 2kΩ7 T2,T4 = BC547B pulse. This will prevent T3 and T4 from conducting, with the con-
R5,R9= 10kΩ sequence that LED D2 will be extinguished and the hard disk
Miscellaneous: attached to connector K3 will see a high level on its CS pin. For
Capacitors: K1,K2,K3 = 40-way this disk, this indicates that it is to act as a slave drive (D: drive).
C1 = 100 n boxheader If S1 is open when the reset pulse occurs, the above situation
K4 = 4-way SIL pinheader
Semiconductors: is of course reversed, and the hard disk attached to connector
S1 = switch, 1 make contact
D1 = LED, low-current, PCB, order code 034050-1 K2 will act as the D: drive, while the hard disk attached to con-
nector K3 will act as the C: drive.
Flip-flop IC1a is included here to prevent the hard disks from
put is naturally always the opposite of that on the Q output. swapping roles during use. This could have disastrous con-
If we assume that the switch is closed during start-up, a low sequences for the data on the hard disks, and it would most
level will be present on D input of IC1a, so the Q output will likely cause the computer to crash. This means that you do
be low following the reset pulse. This low level on the Q out- not have to worry about affecting the operation of the com-
put will cause transistor T1 to conduct. The current flowing puter if you change the switch setting while the computer is
running. The state of the flip-flop, and thus the con-
figuration of the hard disks, can only be changed
during a reset.
The circuit is powered from a power connector for a
3.5-inch drive. This advantage of using this connec-
tor is that it easily fits onto a standard 4-way header.
However, you must observe the correct polarity
when attaching the connector. The red lead must be
connected to pin 1.
Constructing the hard disk selector is easy if the
illustrated printed circuit board is used. You will
need three IDE cables to connect the circuit. The
best idea is to use short cables with only two con-
nectors, with all pins connected 1:1 (no interruption
in the CS line). The IDE connector on the mother-
board is connected to K1 using one cable. A cable
then runs from K2 to first hard disk, and another
cable runs from K3 to the second hard disk. This
means that it is not possible to connect more than
two hard disks to this circuit. You must also ensure
that the jumpers of both disk drives are configured
for CableSelect. To find out how to do this, refer to
the user manual(s) for the drives.
(034050-1)

7-8/2003 Elektor Electronics


SMALL CIRCUITSCOLLECTION

Keypad Extension 049


1 +3V

C3 * see text R9 R10 R11 R12

470Ω

470Ω

470Ω

470Ω
100n

20

S1 S2 S3 S4
19
(SCK)PB7
11 18
PD6(ICP) (MISO)PB6 R1
9 17
PD5(T1) (MOSI)PB5 470Ω
8 16
7
PD4(T0) IC1 * PB4
15
S5 S6 S7 S8
PD3(INT1) (OCI)PB3 +3V
6 14
PD2(INT0) PB2 R2
3 13
PD1(TxD) (AIN1)PB1 470Ω
2 12
PD0(RxD) (AIN0)PB0 C4 S9 S10 S11 S12
AT90S2313
1 100n
RESET R3
XTAL1 XTAL2 16 470Ω
5 4 10 S13 S14 S15 S16
X1
1 DX 15
0 0
2 0 14 R4
C1 C2 G 1
3 7 13 470Ω
2 2
+3V IC2 12 S17 S18 S19 S20
33p 8MHz 33p 3
74HC138 11
4
R13 6 10 R5
5
+3V +3V
1k

4 9 470Ω
& 6
5 7 S21 S22 S23 S24
7
T1
R6
8
BT1 470Ω
S25 S26 S27 S28
BC640 R14
C5
2x 1V5
5Ω6

R7
220µ 470Ω
10V
S29 S30 S31 S32
D1

R8
470Ω
034035 - 11

T. Giesberts 2 AT90S2313
Bascom AVR application note no. 105 470 Ω PB0
(www.mcselec.com/an_105.htm) describes a simple circuit for
using an AT90S2313 (an 8-bit AVR microcontroller) to transmit 470 Ω PB1
RC5 or Sony remote control codes. In this circuit, a small 3 × 4
matrix is used to connect 12 pushbutton switches to only 7 470 Ω PB2

pins of the microcontroller (see Figure 1).


PB3
If you need more pushbuttons, the matrix will have to be
extended, but quite a bit can be achieved using a simple aux-
470 Ω PB4
iliary circuit. If the three column bits are used to drive a demul-
tiplexer, up to 32 pushbuttons can be connected. Figure 2 470 Ω PB5
shows and example of such an approach. Here a 74HC138 has
been chosen for the demultiplexer. This IC has inverted out- 470 Ω PB6
puts. If active-high outputs are more convenient for software
reasons, the pin-compatible 74HC238 can be used instead. 470 Ω PB7

Naturally, the software will have to be modified, since it is


unlikely that a standard statement or instruction is present in
Bascom AVR for this auxiliary circuit. It may be necessary to
write a new assembler routine. This is not a particularly diffi- 034035 - 12
cult task, and moreover, it is a pleasant challenge for would-
be users of the extended keypad.
(034035-1)

7-8/2003 Elektor Electronics


MICROCONTROLLER

LC Display with
I2C Bus
multi-purpose and for the MSC1210 board
Design by J. Wickenhäuser www.wickenhaeuser.com

Okay, your microcontroller program is finished and now you want to see
some text and other stuff on a display. Unfortunately, the LCD you
happen to have available seems to take up rather a lot of precious port
pins. Even worse, the driver you’ve been able to unearth from a software
archive seems to rely on other port pins than the ones you had in mind…

not only hardware, but also soft-


ware, and that comes in the form of
a complete driver (8051 ANSI C
source code) which allows yout
employ the lcd_printf() function
without any restrictions. The driver
proposed here even allows the out-
putting of floating point numbers
and numbers in larger sizes.
The display solution discussed in
this article is especially well suited
to battery-operated equipment
because the display can be put to
sleep by software, reducing its cur-
rent consumption to just a few
micro-amps. Besides, it is possible to
set the LCD’s I2C address with the
aid of a few jumpers (or wire links).
Using three jumpers and two avail-
able IC variants, up to 16 of these
LCD units may be connected to a
single I2C bus.
Of course it is possible to omit the
Usually, a lot of hard work has been done, in the use of just 2 (say, two) of the LCD and use the board as a simple
including the mental digestion of piles of precious port pins on your microcon- I2C bus port. That would allow you
datasheets, before the first ‘Hello World’ mes- troller. Admittedly the small printed to connect, for example, a
sage appears on your microcontroller system circuit needed for the universal LCD 3 × 4 matrix keypad or a relay dri-
display. We propose an end to this rather board represents extra hardware, ver/interface. However such alterna-
wasteful process by describing a universally but you’ll soon find that it’s well tive uses of the board are only dis-
applicable LC display with a nice set of fea- worth the investment. cussed in general terms, see the
tures, employing the I2C bus which translates Clearly this article should discuss ‘PCF8574’ inset.

56 Elektor Electronics 9/2003


MICROCONTROLLER
Remote 8-bit I/O +5V +5V

expander for the I2C bus K2


GND
C1
The 10-way boxheader on the board JP3 JP2 JP1 +5V
CONTR
has the same pinning as that on the 100n
R1
LCD4
CONTR

10k
RS
Precision Measurement Central 16 LCD5
R/W
(‘Elektor Meter’) board described in LCD6
E
1 4 LCD11
the July/August 2003 issue of this 2
A0
IC1
P0
5 LCD12
D0
A1 P1 P1 D1
magazine. Here, the industry-stan- 3
A2 P2
6 LCD13 10k D2
dard PCF8574 is used as an interface P3
7 LCD14
+5V D3
9 LCD5 LCD11
between the LCD and the signals on P4 D4
13 10 LCD4 LCD12
the I2C bus. The base address of the 14
INT P5
11 LCD6 LCD13
D5
SCL P6 T2 D6
chip is preset using three jumpers. 15
SDA P7
12 LCD14
D7
The default address is # 66 (see PCF8574 V+
LED+
‘PCF8574’ inset). The display can be K1 BS250 LED–
8 R2 R3 R4 R5
1 2
just about any alphanumeric type

270Ω

270Ω

270Ω

270Ω
C2
3 4
you may have available, as long as it 5 6
+5V
100n
is HD44780 compatible. However, 7 8
T1
the pins used for the LCD supply 9 10 V+

and backlighting (if available) should


BS170
be checked carefully as they may dif- 030060 - 2 - 11
fer between manufacturers.

The board was designed to fit Figure 1. Circuit diagram of the I2C LCD interface.
under most commonly found LC dis-
play sizes, in particular, those of the
4 × 20 character type. However, interesting generator project is change the character set during operation —
smaller types may also be connected included at the end of the article. try it for some visually interesting effects like
without problems. In case of doubt, One rather playful option is to animations.
only the first line of the display may
be shown. The display and the board
should be secured to one another
using PCB spacers. The electrical
connection is by short wires. PCF8574 8-bit I/O Expander for I2C Bus
The display can be switched off Elektor Electronics readers know the I2C bus from many projects published in books as
by software, which has a nice side- well as the magazine, so a discussion of the I2C standard is probably not required here. The
effect in that the display is reset at PCF8574 offers eight bi-directional, digital, I/O pins. The structure of the individual port
the same time (which may be neces- pins is hardly different from that of the industry-standard 8051 processor. Simplifying things
sary every now and then!). The dis- to some extent, both are ‘open drain’ lines with weak pull-up resistors. Just as with the
play is operated in 4-bit mode. 8051, an input may only be read if the relevant port pin has been set to ‘1’ before.
The uC/51-ANSI-C Compiler (for The PCF8574 has three address inputs, A0, A1 and A2, which allow up to eight PCF8574’s
all 8051 compatible micros) dis- to be connected up to a single I2C bus. There is also a PCF8574A variant which has a differ-
ent base address. This means that the total number of individually addressable I/O
cussed in parts 1 and 2 of the Preci-
expanders is 16.
sion Measurement Central article Naturally the PCF8574(A) is also perfect for other applications like driving relays or scan-
may also be used to control the dis- ning (keyboard) switches.
play. All drivers are supplied in the The addressing follows this structure:
form of source code files, hence need
no further discussion here. The com- 0 1 0 0 A2 A1 A0 0
piler and the source code files may for the PCF8574 (base address = 64), and
be obtained from the Free Down- 0 1 1 1 A2 A1 A0 0
loads section of the Elektor Electron- for the PCF8574A (base address = 112)
ics website. The driver itself is pretty
compact and requires a minimum The bits for A2, A1 and A0 correspond to the logic levels on the IC pins: ‘0’ for GND and
amount of memory to work. ‘1’ for Vcc.
On each LC display connected to
the bus, up to eight characters can In the Precision Measurement Central, the I2C address ‘66’ (decimal) is used. So, on the
be user-defined, and the driver will LCD board, jumper 1 should be connected to +5 V (logic level ‘1’) and jumpers 2 and 3, to
initialise them as a substitute for a 7- ground (logic level ‘0’). The address used is found in the program LCD_I2C.c
All activity on the SCL and SDA lines is caused by as well as taken care of by a library (com-
segment display. The same drivers
plete with source code texts) that comes with the uC/51 Compiler. Other I2C devices are
should also enable you to extend the equally simple to talk or listen to. The library was developed with great care and was found
functionality of the display to your worth its salt in many an industrial application.
own requirements. A weblink to an

9/2003 Elektor Electronics 57


MICROCONTROLLER
Three-layer software and described there.

The software written for this project operates Finally, a few words on timing. Obvi- Web links
at three levels (or layers). At the top level we ously, you will want to be able to use www.wickenhaeuser.com
find the user module. The next lower level is the bus at the highest possible Author’s homepage. Downloads
an intermediate module that copies charac- speed. Consequently the software for ANSI Compiler and drivers.
ters to a low-level driver. The driver is also has to be informed about the speed
suitable for a direct 4-bit or 8-bit connection of the controller you are using. In the www.erikbuchmann.de
to the CPU. To stay within the scope envis- uC/51 Compiler, that is done using Javascript generator.
aged for this article, only those functions are the CPU_NSEC macro which indi-
discussed that are visible to the user. The cates the effective time (in nanosec- www.lcd-module.com
main functions are: onds) spent on a single CPU instruc- Many LCD datasheets.
tion. In most cases, this will equate
lcd_init() to the average instruction time.
initialises the display and activates the over- If no display is available, all out-
sized numbers in the character set. If every- put is into cyberspace, i.e., goes to
thing is okay, a ‘0’ is returned. waste. Whatever happens, the driver given in Figure 2. The board may be
will not remain stuck somewhere, obtained from The PCBShop under
lcd_printf() but returns to the main software number 030060-2. As opposed to a
employs the same parameters as the regular within a certain time. SMD version designed by the author,
printf() command. Return value is the the Elektor board is stuffed with
number of characters supplied to the LCD. leaded components only. Please note
The printed circuit board that there are four wire links which
lcd_putc() The Elektor Electronics laboratory should not be forgotten
outputs a single character (like putc()). design for a printed circuit board is (030060-2)

lcd_cgchars()
copies a 64-byte block into the display char-
acter memory. This memory may be located
in external RAM or in the microcontroller’s
program memory.

lcd_d2_printf()
As printf(), only all numbers are displayed
‘oversized’.

All functions are employed in the demo pro-


grams for the Elektor Meter documentation

COMPONENTS LIST
Resistors: K2
R1 = 10kΩ C2
H1

H2 H5

0
R2-R5 = 270Ω IC1 R2
P1 = 10kΩ preset T2 T1 R3
R4
1
JP3
JP2
JP1

030060-2

K1
R5
Capacitors:
R1

ROTKELE )C( 2-060030


C1,C2 = 100nF
H3

H4

C1 P1
Semiconductors:
T1 = BS170
T2 = BS250
IC1 = PCF8574(A)P 030060-2 (C) ELEKTOR

Miscellaneous:
JP1,JP2,JP3 = 3-way pinheader with jumper
(or wire links) (JP1 to +; JP2 and JP3 to
ground)
K1 = 10-way boxheader, angled solder pins
PCB, order code 030060-2 from The
PCBShop
Figure 2. Layout of the single-sided printed circuit board.

58 Elektor Electronics 9/2003


Low2 Cost USB Demo Board
C your way
through USB
VDD

R1 R6 R7 R16
C1 C2
Martin Valle

330 Ω
10k

10k

10k
100n 100n

Slick graphics, reading R2


11 32

analogue values and making 470 Ω


1
MCLR/VPP RB7/PGD
40
39 R5
JP1 RB6/PGC
them appear in graphs,
R3
2 38 470 Ω D5
470 Ω RA0/AN0 RB5/PGM
3 37 R4
cockpit-style meters and dials, S1
P1
C3 4
RA1/AN1 RB4/AN11
36 470 Ω PWR
RA2/AN2 RB3/AN9
all on USB… How do they do it? 100n
5
RA3/AN3 RB2/AN8
35 S2 S3
6 34
10k RA4/T0CKI RB1/AN10
7 33
RA5/AN4 RB0/AN12
8 IC1
RE0/AN5
Like this: a single board connected up VDD 9
RE1/AN6
10
to the PC via a USB link and sporting an R8
RE2/AN7

advanced PIC microcontroller. Add some PIC18F4550


1Ω 15 30
RC0/T1OSO RD7/SPP7 R15 RD3
software and there’s your USB demo board K1 16
RC1/T1OSI RD6/SPP6
29
330 Ω
D4

doubling as a development system to help +5V


1
R10
17
RC2/CCP1 RD5/SPP5
28
2 23 27
you discover how USB is implemented on D–
3
10 Ω
24
RC4/D- RD4/SPP4
22
R14 RD2
D3
10 Ω RC5/V+ RD3/SPP3 330 Ω
a microcontroller programmed to handle D+
4
R11
25 21
GND RC6/TX RD2/SPP2
analogue and digital I/O for real world USB-B
26
RC7/RX RD1/SPP1
20
R13 RD1
D2
applications. 18
VUSB RD0/SPP0
19
330 Ω

OSC1 OSC2 R12 RD0

asy
D1

ick & E
12 13 14 31 330 Ω

USB Qu
R9
10M

n pot) JP2
uts (1 o
X1

ue in p C6

•2 analog
itches) C4 C5
uts (sw
100n
al inp 20MHz
• 2 digit 22p 22p
Ds)
outp uts (LE
•4 digital ailable
060342 - 11
0 (av
: P IC 18F455
e) IC ed )
• 1 (on -programm
ready blocks
a re b uilding Figure 1. Schematic of the USB demo board.
softw
uite of er C++
6
• Full s r Build
w a re fo
ct soft nel A/
D
• Proje 2 -chan n PC sive. You will like to hear that the Elektor website as archive # 060342-
fo r
ram ut o
o prog reado it’s available free of charge from 11.zip. The ready-programmed PIC18F4550
• Dem raph/meter
with g

Hardware
At the heart of the circuit in Figure 1 is a
PIC18F4550 microcontroller from Micro-
chip. This has built-in USB connectivity —
if you know how to activate it! The micro
is clocked at 20 MHz by quartz crystal X1.
The switches (except S1), LEDs (except D5)
and the potentiometer connected up to the
PIC micro are your basic I/O (input/output)
devices.
The circuit should be easy to build on a
piece of prototyping board or Veroboard
(a.k.a. perfboard or stripboard).

Software
In stark contrast with the minimal hardware,
the software for this project is quite exten- Figure 2. Device Manager showing the installation of the PICDEM FS USB Demo Board.

 elektor electronics - 7-8/2007


for the project is available too, it’s item
060342-41 from the Elektor SHOP.
There are actually four zipped files:
MCHPFSUSB.zip contains all the project
components freely available from Micro-
chip plus the custom project for the micro-
controller, the demo version software and
the bootloader ‘talker’.
Project.zip contains all the files needed to
build the project in Builder C++ 6.
REQUIRED.zip contains the files of the
project.zip that you have to copy if you
want to make a new project.
Without builder.zip contains all the files
needed to run the .exe file without the
Builder installed in the computer.

Here’s how to process the software.


1. Extract the file MCHPFSUSB.zip to the
C: root directory. Check that there is no
duplicated folder MCHPFSUSB, like: C:\
MCHPFSUSB\MCHPFSUSB\folders_xx,
instead of: C:\MCHPFSUSB\folders_xx.
2. Using a suitable programmer, program
the PIC18F4550 microcontroller with the
file: C:\MCHPFSUSB\fw\_factory_hex\pic-
demfsusb.hex. The chip is also available
ready-programmed.
Figure 3. PICDEM FS USB tool showing the board (device) connected.
Waking up the F4550
Once you have built the project and
checked it for mistakes, you can connect The Pdfsusb tool must show in the selec- Demo mode
the USB to the host. For the first time con- tion square the device connected just as and a small hurdle
nection, Windows XP is recommended. As in Figure 3. If you reset the board without keeping S3
soon as you connect the board to the host, pressed, the microcontroller will run the
LEDs D0 and D1 will start to blink, then
the host will detect the device as ‘PICDEM
FS USB Demo Board (C) 2004’ and ask for
the drivers. You should select the drivers
located in:
C:\MCHPFSUSB\Pc\MCHPUSB
Driver\Release\
Windows will nag that this device does
not pass the Windows logo test. Ignore
and simply continue the installation of the
device.
You can check for the proper installation
by exploring in the Device Manager win-
dow, it should look like Figure 2.
Keep pushbutton S3 (RB4) pressed and
the reset the microcontroller by pressing
and releasing S1. This procedure takes the
microcontroller into ‘bootloader’ mode.
The host will detect a new device, and it
is necessary to repeat the driver installation
procedure with the same driver location:
C:\MCHPFSUSB\Pc\MCHPUSB
Driver\Release\

From now on you can load new programs


to the microcontroller via the bootloader,
following the above sequence using the S3
and reset pushbuttons.
The PC application that communicates
with the bootloader is the executable file:
C:\MCHPFSUSB\Pc\Pdfsusb\PDFSUSB.
exe Figure 4. Demo Mode of the Pdfsusb tool.

7-8/2007 - elektor electronics 


the device to the computer. Fortunately,
the error applies to the Demo firmware
only, not to the Bootloader. There is an
easy way to avoid this — in every project
contained in the MCHPFSUSB folder there
is a file C:\MCHPFSUSB\fw\project_name_
folder\autofiles\usbcfg.h. It contains the
declarations that are causing the problem.
Just comment-out (//) the two SENSE_IO
definitions as shown Listing 1.
Having done this you can reload the Demo
project, or any project for that matter, and
all should work fine.

Build it!
Now, it is time to explore the example
application. As before, reset the microcon-
troller with S3 pressed, to run the Boot-
Figure 5. Two ADC Channels and USB of the PIC in action.
loader and load the micro with the hex file
located in:
C:\MCHPFSUSB\fw\Hid02/_output/
NICAPM.hex
Listing 1. Then, run the program.
/** D E F I N I T I O N S *****************************************/ You can run the PC application directly
#define EP0_BUFF_SIZE 8 // 8, 16, 32, or 64 without C++ Builder 6 installed in the com-
#define MAX_NUM_INT 1 // For tracking Alternate Setting puter by using the stuff in the archive file
called: without builder.zip. Obviously the
/* Parameter definitions are defined in usbdrv.h */ microcontroller must be connected to the
#define MODE_PP _PPBM0 host and running the NICAPM firmware.
#define UCFG_VAL _PUEN|_TRINT|_FS|MODE_PP The window of the demo application
should look like Figure 5, showing the sig-
//#define USE_SELF_POWER_SENSE_IO nals of Channel 0 (AN0, pin 2) and Chan-
//#define USE_USB_BUS_SENSE_IO nel 1 (AN1, pin 3). There’s also the archive
file called project.zip if you want to modify
something in the PC project.
If you want to make a new Builder project,
program loaded in memory (i.e., not the potentiometer connected to RA0, control you only have to look after two things:
bootloader). The same if you click the ‘/ the state of the LEDs connected to RD2
Execute’ button in the application. That’s and RD3 and measure a temperature of 1. Add the hid.lib file by doing:
why the first device detected by the host an SPI sensor that’s not actually connected Project ➞ Add to project ➞ hid.lib
was not the bootloader — it was a program to the board (so don’t pay attention to the
to test with the other part of the Pdfsusb temperature readings). 2. Change the Data alignment from Quad
tool (Demo mode), this is the upper left The Demo firmware uses a few pins to word to byte by doing:
tab behind the Bootload Mode tab. This monitor the USB main voltage (this is not Project ➞ Options ➞ Advanced
mode is shown in Figure 4. It allows read- implemented in the schematic). It may hap- Options ➞ Data alignment.
ing an approximation of the position of the pen that this check fails after connecting (060342-I)

 elektor electronics - 7-8/2007


LPC900 programmer
Jürgen Wickenhäuser

The LPC900 family is the Swiss Army knife


of 8051-compatible microcontrollers. The
‘LPC’ in the part number stands for ‘low
pin count’: the NXP (formerly Philips)
LPC900 family [1] consists of a range of
small and easy-to-use microcontrollers
ideal for small-scale high-speed applica-
tions. Since the LPC900 family is based on
an 8051 core it is easy to learn how to use
the devices. However, the LPC900 is more
than just a slightly spruced-up version of for their normal use. A five- the boot-
the 8051. The most important features are way cable is required for download. lo ad e r. Note
as follows: that R13 ensures that
The hardware required is minimal, as the the supply voltage to the target
• 2
 -cycle high-speed 8051 core (six times circuit in Figure 2 shows. This circuit is hardware drops rapidly when it is switched
as fast as a standard 8051); capable of supplying the LPC with power off. It is advisable to limit the capacitance
and also provides an RS-232 interface, on the 3.3 V rail in the target hardware to
• from 1kB to 16 kB of flash memory with ideal for use with a terminal program. approximately 10 µF, since otherwise the
full ISP and IAP functionality; The printed circuit board for the design is microcontroller being programmed might
shown in Figure 3. not correctly execute a power-on reset.
• internal precision 7.3728MHz RC oscil- The free program ‘Flash Magic’, also from
lator, ideal for baud rate generation up to Operation is straightforward. The CPU Embedded Systems Academy, can be
115 kbaud without an external crystal; can be powered up and down using the used to simplify programming the devices.
• C
 PUs available in DIL as well as tiny DTR signal. The RTS signal functions as a This will be familiar to Elektor Electronics
SMD (TSSOP) packages; switch: if RTS is active then signals from readers from the RFID reader project [3].
RXD are also presented to the reset pin of This tool also includes a suitable terminal
• a minimum system requires a sin- the CPU, and can thus be used to activate program.
gle capacitor as the only external
component;

• w
 ide range of on-chip peripherals:
brown-out detector, watchdog timer,
comparators, A/D converter;

• operating voltage 2.4 V to 3.6 V.

The only significant difference from the


standard 8051 is the improved I/O struc-
ture: they can now also work in a CMOS-
compatible mode, which brings many
advantages. One important point to note
in this regard is than on reset the ports are
set to CMOS input mode, and must if nec-
essary be suitably initialised before use.
Otherwise the LPC900 is very easy to use.
The datasheet is rendered almost superflu-
ous by the free ‘Code Architect’ software
by Embedded Systems Academy [2]. This
tool is capable of creating snippets of C
source code directly (see Figure 1).

Loading code into the LPC900 microcon-


troller proceeds with a minimum of fuss.
When the CPU receives a series of three
pulses on its reset pin within a specified
time window of being powered up, the
CPU jumps to a bootloader, which then
proceeds to communicate using the RXD
and TXD signals. After code is downloaded Figure 1. ‘Code Architect’ is a free tool that makes using
these three signals are of course available the LPC900 microcontroller very straightforward.

 elektor electronics - 7-8/2007


An optimising C compiler is also needed +3V3
to write programs for the LPC900 family.
C4 C5
There are various commercial prod- +3V3 IC2D

16
12 C6
ucts available; here we will briefly 13 &
11 1u 1u 2
V+
VCC
C1+
1
3 1u
discuss how to use µC/51 [4]. For 6
C1-
V-
practically all LPC900 family devices +3V3 C8
C2+
4
C7
IC3 5
the free demonstration version of the 1u MAX3232
C2-
1u
R5 R8
compiler is entirely adequate. The K2 14 11
T1OUT T1IN

220k

220k
1 13 12
only restriction of the free version R1IN R1OUT +3V3_ISP
6
R11 K3
is the 8 kB code size limit, but this 11 2 7
T2OUT T2IN
10
1k
7 8 9 CPU_VCC
R2IN GND R2OUT
10 3 R9 CPU_RXD
8 1k CPU_TXD

15
4 IC2C CPU_RES
IC2B 9 R12
9 R10 4 8 CPU_GND
6 10 & 1k
5 220k 5 & ISP connector

IC2A
R6 1 R4
3
9
220k 2 & 1k
6

IC2 = 74HCT00
K1

K1 +3V3 T1 +3V3_ISP
K2 1 5 D1
3V3 switched
R5

1 2
R 10

C 1 D1
IN OUT
070084-1
C 6 (c) Elektor

3
R8
R6

1N4001 IC1 BC857


R4

C5
6 R3 R7
IC2 LM317
7
C4

R2 R1

1k

1k
ADJ
14
C2
C3

4
R1 IC2
C7

IC3

R13
240R 7
C1 R2 C2 LED1 LED2
R12

LED2 C3
R11

IC1
C8

1k
T1 R 3
R9
R7

LED1

390R
4u7 10u 100n
R13

25V 6V
K3

LPC900 PROGR AMME R


070084 - 11

Figure 3. Layout and component mounting Figure 2. Circuit of the LPC900 programmer.
plan for the printed circuit board.

is already enough to write very complex piler is very parsimonious with the limited For example, even with this very tiny CPU
applications for an 8051-compatible micro- internal RAM in the microcontroller, using we have a fully-featured ‘printf()’ function
controller, because the compiler produces a graph-based optimisation algorithm to call. The system also includes a reliable
very compact code. In particular, the com- enable multiple re-use of memory areas. and comprehensive floating-point library.

COMPONENTS LIST
Resistors
R1 = 240Ω SMD (0805)
R2 = 390Ω SMD (0805)
R3,R4,R7,R9,R11,R12,R13 = 1kΩ SMD (0805)
R5,R6,R8,R10 = 220kΩ SMD (0805)

Capacitors
C1 = 4µF7 25V SMD (1206 or 1210)
C2 = 10µF 6V SMD (1206 or 1210)
C3 = 100nF SMD (0805)
C4,C5,C6,C7,C8 = 1µF SMD (0805)

Semiconductors
D1 = GF1M
T1 = BC857 SMD (SOT23)
LED1,LED2 = LED, red, SMD (0805)
IC1 = LM317 SMD (SO8)
IC2 = 74HCT00 SMD (SO14)
IC3 = MAX3232 (SO16)

Miscellaneous
K1 = mains adaptor socket for PCB
mounting
K2 = 9-way sub-D socket, angled, PCB
mount
K3 = 5-way SIL pinheader
PCB, ref. 070084-1, from www.
thepcbshop.com
Figure 4. Initialisation specific to the LPC900 requires just five instructions.

7-8/2007 - elektor electronics 


The µC/51 system was developed
as a tool for the company Geo-
Precision [5], and has been used
and maintained there for years.
The software tools work very well
together and make development
very quick: there are just three
steps from source code to work-
ing program.
Figure 5. The µC/51 compiler uses a well-structured
For demonstration purposes we
classical ‘make’ system. Figure 7. Settings for the RTS and DTR signals
used an 89LPC922 with an LED
in the Flash Magic terminal program.
connected to port pin P1.7. The
listing shown (Figure 4) is an
example project included with
µC/51 since version 1.20.06. As
can be seen from Figure 5, the References and links
compiler uses a well-structured [1] http://www.standardics.nxp.com/pro-
classical ‘make’ system. Down- ducts/lpc900 (NXP, manufacturer of the
loading a program to the micro- LPC900 family).
controller is an intuitive operation [2] http://www.esacademy.com (Embedded
(Figure 6). It is recommended that Systems Academy: Flash Magic, Code
you configure the terminal pro- Architect).
gram embedded within ‘Flash [3] ELEKTOR RFID Reader (using an LPC936),
Magic’ so that it is launched Elektor Electronics, September 2006,
immediately the application is p. 26.
started on the LPC. Note in par- [4] http://www.wickenhaeuser.de (µC/51
ticular that the RTS and DTR sig- compiler, demonstration version).
nals must be correctly configured
[5] http://www.geo-precision.com (geotech-
Figure 6. Flash Magic is a free tool for (both active): see Figure 7. nical research and development).
programming LPC microcontrollers. (070084-I)

 elektor electronics - 7-8/2007


READERSCIRCUITS

Optimise your
PC Soundcard
using a correction filter
Design by R. Badenhausen

Digitising analogue sound media like vinyl records and magnetic tapes is a
simple matter if you have a reasonably fast multimedia PC. After all, you
have available all the necessary ingredients and tools including a soundcard
with an analogue inputs, software and a CD-ROM burner. The circuit
described in this article enables the analogue input of your soundcard to
be linearised for optimum sonic reproduction.

Please note: Readers’ Circuits have not been R7 R9


15k 3k9
tested or post-engineered by the Elektor Electronics C2
design laboratory. L C3 R1
3 3
15k 12n C4 L
1 1
4µ7 C1 IC1.A R4 IC2.A
2 2
3k9 4µ7
The author and designer of this circuit per- 1µ
formed a series of tests on several ‘standard’ R2 R3 R6 R5 R8
6k8

10k

3k9

10k

10k

soundcards used in PCs. Although most of


these were found to have good anti-aliasing
filters, in quite a few cases the frequency lin-
R17 R19
earity of the analogue inputs left much to be 15k 3k9
C12
desired. In most cases, this deficiency is
R C13 R11
caused by a rather too small input capacitor, 15k
5
12n
5
C14 R
7 7
a digital input filter dimensioned for a too low 4µ7 C11 IC1.B R14 IC2.B
6 6
frequency, or simply by the user himself 1µ
3k9 4µ7

unwittingly connecting a cheap input cable R12 R13 R16 R15 R18
6k8

10k

3k9

10k

10k

of about 3 metres length to the input, which


then sees a far too large capacitance.

IC1, IC2 = NE5532


Correction circuit LM78L06
+U R10 IC3 +6V
The circuit shown in Figure 1 allows any 10Ω

negative deviations at both ends of the fre- 8 8


C17 C9 C10 C15 C16
quency spectrum to be ‘pulled straight’. In IC1 IC2
4 4
fact, it causes the frequency response to be 47µ 16V 10µ 16V 100n 10µ 16V 100n

lifted by a controlled amount at the two far


C18 C5 C6 C7 C8
ends. An example of this is shown n Figure 2.
47µ 16V 10µ 16V 100n 10µ 16V 100n
R20
10Ω
Figure 1. The correction circuit consists of two -U IC4 -6V
filter sections with buffer/amplifier stages. LM79L06 020184 - 11

56 Elektor Electronics 2/2003


READERSCIRCUITS
The circuit consists of two pas-
sive filters (each having two roll-off
points) — one for amplifying the low
frequencies and one for the high fre-
quencies. The first filter consists of
components R1/C1/R2/R3, the sec-
ond, of R4/C2/R5. Behind each filter
sits a buffer/amplifier (IC1a and IC2a
respectively) which serves to com-
pensate the attenuation introduced
by the filter. The Right (R) channel is
of identical design with the compo-
nent reference numbers increased
by 10.
The values of the resistors in the
buffer stages follow these easy
equations: R6 =R2/R3; R7 = R1; R8
= R5; R9 = R4. The same goes for
the Right channel: R16 = R12/R13,
etc.
Two voltage regulators, a 78L06
and a 79L06 together with a number
of reservoir and decoupling capaci-
tors, ensure a stable supply voltage Figure 2. This graph shows the measured frequency response, the correction curve and the
for the circuit. resulting curve.

Measurement procedure components in the correction filters. the response of the correction network of Fig-
Before we can have a look at the cal- The spreadsheet allows the mea- ure 1, and column C, the resulting frequency
culation of the filter component val- sured values to be entered in column response. Finally, in column E we see the
ues , we need to measure the error B (v(o), see Figure 3). The level at attenuation v(f) per filter section — the
(non-linear frequency response) 1000 Hz is taken as the reference respective values at 630 Hz and 1000 Hz
introduced by the analogue input. level (0 dB). Column A shows the indicate the attenuation which is to be com-
It is unusual for a manufacturer of frequencies at which the levels need pensated by the associated buffer/amplifier.
a soundcard to supply exact mea- to be measured. Column D shows At the right-hand side of the Excel spread-
surement data covering the inputs
and outputs of the product. So, we
have to do that ourselves. The job
requires an accurate sinewave gen-
erator with a frequency range of 10
Hz to 25 kHz and a sound editor pro-
gram like Cool Edit. If necessary, an
oscilloscope may be connected to
measure the output level at different
frequencies.
Connect the generator to the inut
of the soundcard under test, then
adjust it for the highest output level
at which the input is not overdriven
(for example, 200 mV). Next, use the
software to measure the output level
at different frequencies. Using Cool
Edit, that is done by selecting
‘Record’ and then checking the sig-
nal level indicated by the VU meters.
The range of the meters may be
adapted by right-clicking on them.

Dimensioning Figure 3. This Excel spreadsheet allows measured valued to be entered and filter
The author employs an Excel spread- component values to be adapted to requirements. The associated curves (Figure 2) show
sheet to calculate the values of the the results instantly.

2/2003 Elektor Electronics 57


READERSCIRCUITS
sheet the frequency determining components Some rules of thumb are in order Of course, all components in the fil-
are shown, with an opamp thrown in for the at this point to help you get the ter sections will interact to some
necessary gain. The values of the filter com- dimensioning right. A minimum extent. Fortunately, you’ll soon see
ponents may be entered above this section, value of 15 kΩ should be observed the effects and results when actually
whereupon the spreadsheet will instantly for R1, to prevent the output of the entering values into the spreadsheet.
compute the associated correction curve. sound source affecting the filter. The If only one correction is required,
If you click on the ‘Diagram’ tab at the bot- ratio of R1 to R2//R3 determines the (i.e., for high or low only) the other
tom, the three frequency response curves will amplification of the low frequencies. section and the associated
appear: (1) the characteristic of the filter with A higher value of R1 causes a bass buffer/amplifier may be omitted.
the required values; (2) the measured boost. The value of C1 determines The Excel spreadsheet is avail-
response of the input and (3) the result of the frequency at which the correc- able from this month’s Free Down-
combining these two. Now, you are in a posi- tion starts to act. Lowering the value loads page on our website, look for
tion to experiment with the filter components of C1 causes the roll-off frequency to file number 020184-11. Readers
until the resultant frequency response is as be increased. In the High section the without access to the Internet may
flat as possible. ration of R4 to R5 determines the order it on floppy disk using the
When the spreadsheet is started, you’ll amplification of the higher frequen- same number.
find that a number of component values and cies, while C2 provides the onset of (020184-1)
an example curve are already present. These the high roll-off point. Here, a larger
may be edited as required. value results in a lower roll-off point.

58 Elektor Electronics 2/2003


Optimised STK200/300 Programmer
for AVR Micros buffer IC type 74HC244, one 25-
K1 +5V pin male sub-D connector for
Hesam Moshiri
R1
1 20 C1 hooking up to the parallel printer

100k
14 IC1 port (‘Centronics’) on the PC, a
10 100n
26 2
The STK200/300 programmer is 15
100 kΩ pull-up resistor on the
found in nearly every program- 27 3
GND
MISO line and a .1 μF decou-
mer software for Atmel AVR 16 pling capacitor on the +5 V sup-
IC1
microcontrollers. The program- 4
19 ply rail.
17 EN2
mer shown here differs from 5
1
EN1
other, similar, circuits in not 18 With some tinkering, the com-
requiring any extra power sup- 6
2 18 CLK plete circuit can be fitted in the
19 1D1
ply for itself, while still offering 4 16
MOSI
sub-D connector housing. A short
7
STK200 as well as STK300 pro- 20
6 14 length of flatcable and a 6-way
8 12 RST
grammer functionality. 8
11 9
IDC socket at the target board
21
13
1D2
7
MISO
side complete the programmer.
9
In case you did not know, AVR 22
15 5 After programming, you simply
microcontrollers can be pro- 10
17 3
disconnect the programmer cable
grammed in-circuit with only five 23 74HC244 from the target board.
wires: Clock, MOSI, MISO, Reset 11
24
and Ground. To these should be 12
The STK200 or STK300 program-
added the +5 V supply voltage 25 mer hardware is available in lots
taken from the microcontroller 13 of microcontroller programmer
on the target board. software, for example, BASCOM
SUB D25
The programmer schematic con- 060374 - 11 and CodeVision.
tains nothing more than one (060374-I)

 elektor electronics - 7-8/2007


MICROCONTROLLER

P87LPC76x
Programmer
A simple burner for a popular microcontroller family
Design by P. Luyckx

The programmer described in this article has been designed for the well-
known P87LPC76x family of microcontrollers manufactured by Philips.
These are 8-bit devices with an 8051-derived core and serial
programming capability. The hardware we’ve in mind excels in simplicity
and the programmer software may be obtained free of charge from our
website.

The popularity of the


8-bit microcontrollers
from the P87LPC76x
series is mainly due to
their versatility and
ease of use. On the
pros and cons of these
devices, we are
informed that pro-
grammers seem to
value the limited com-
plexity, the large num-
ber of outputs, the
ample output current
specification and (last
but not least) the
presence of an I2C
bus. The chip can be
programmed using a
serial link, which
means that in-system
programming (ISP) is
within easy reach.
Having ISP on a
microcontroller is a
clear advantage to
equipment manufac-
turers because it
allows them to blow

48 Elektor Electronics 12/2003


MICROCONTROLLER
4 Visual BASIC and can be obtained as a free
download from our website at www.elektor-
PDA X
electronics.co.uk. Alternatively, those without
Serial communication
1 access to the Internet (raise your hands
please) may obtain the same on a floppy disk
PCL
which may be ordered through our Readers
2 Services.
5V +/- 0.5V
VDD 6
0V

tVPP LH tVPP HL Programming


10.75V +/- 0.25V
tVDDVPP A certain protocol, illustrated in Figure 1,
t INIT
VPP 0V 5 has to be followed to effectively switch the
3 chip into programming mode:
030313 - 12 - Initially, the PDA and PCL pins have to be
switched to high impedance;
- Next, the +5-V supply voltage may be
Figure 1. Logic sequence to initiate programming mode. applied — note that the chip does not toler-
ate ‘hot inserting’;
- After 20 µs, the programming voltage VPP
may be applied to the relevant pin. This volt-
LS bit MS bit age must have a rise time of between 1 µs
a 0 1 2 3 4 5 6 7 and 100 µs.
PDA tWAIT/WAITP LSB - The chip is now in programming mode.
However, an additional 60 µs delay has to be
observed before the floating condition of PCL
and PDA can be lifted and programming can
PCL commence.
- Leaving the programming mode is less crit-
tSDSU tSDH tSC 030313 - 13a
ical, although we have to observe a fall time of
1 –100 µs for the removal of the programming
LS bit MS bit voltage, after which the supply voltage may
b 0 1 2 3 4 5 6 7 be switched off.
PDA tWAIT LSB
Programming a P87LPC76x chip involves
sending commands to the serial interface on
the chip via the PCL and PDA lines. Each
PCL command or program byte consist of eight
bits. After eight clock cycles, all eight bits
tSCLDV tSDH tSC tSCHZ 030313 - 13b
have been clocked into the processor, leaving
the complete byte ready for fetching from the
receive register. The serial interface on the
Figure 2. Pulse timing during chip programming (2a) and chip reading (2b). P87LPC76x is identical to the 8051 compati-
ble UART in mode 0.
Data is exchanged on the falling clock
the very latest version of the The circuit described here is dri- edge and clocked into the controller on the
firmware into the controller, just ven by a PC via its serial port. These rising edge. The LSB always comes first, the
before shipping the complete prod- days, it may seem a little old-fash- MSB, last. This method applies to program-
uct. There is, however, one disad- ioned to employ the RS232 port, but ming as well as reading the controller. When
vantage that should not be left in this case it was an important con- reading the chip, the data of the first bit is
unmentioned: although we’re deal- sideration to keep the hardware valid after 40 ns. An important point to note
ing with EPROM types, there’s no costs as low as possible. After all, here is that when reading the last bit, the
glass window on the current gener- the addition of a USB interface PDA pin has to be switched to high imped-
ation of P87LPC76x devices, hence would set you back an additional ance 40 ns after the last rising edge. Conse-
they are really OTPs (one-time pro- £10 or so because of the need to use quently, sampling needs to take place before
grammable ICs). Obviously, before an USB controller chip. the last clock edge is issued.
you burn an OTP device you need to The circuit diagram and the PCB A delay of at least 2 µs has to be observed
be sure the target circuit works, so layout make it overtly clear that between two instructions. Similarly the sys-
the relevant software is best devel- we’re dealing with an extremely sim- tem needs to wait at least 250 µs at
oped and debugged using a Flash ple and therefore easily reproducible strt_prgm.
board, for example, our incredibly bit of hardware. There are no exotic The diagrams in Figure 2a and Figure 2b
popular 89C8252 Flash Microcon- components. The software running show the timing diagram relevant to pro-
troller Board (December 2001). on the host PC has been written in gramming and reading respectively.

12/2003 Elektor Electronics 49


MICROCONTROLLER
C7
10µ +5V IC6.A
1
+5V
EN
63V 2 3
2
IC6.D K3
1 V+ 13
C1 C1+ 16
EN
12 11 24 1
3 IC2
10µ C1– IC6.B 23 2
63V 13 12
R1IN R1OUT 4
22 3
8 9 EN
R2IN R2OUT 5 6 21 4
14 11
T1OUT T1IN 20 5
7
T2OUT T2IN
10 C17 +5V
19 6
4
C2 C2+
100n IC1 IC6.C 18 7
K1 MAX232 10
15 15 17 8
5 EN3 EN
10µ C2–
1 1 9 8 16 9
63V V- C2
6 15 10
6
C3 SRG8 +5V
2 14 11
3
7 C1/ 13 12
3 10µ
63V 2 4 R12
8 1D 2D 3

10k
C8 5
4
10µ +5V 6 T3
9 R8
7
5 680Ω
63V 14
2 +10V75
13 BC640
1 V+
C4 C1+ 16 12 R7

10k
IC3 11
10µ 3 D1 D2 R3
C1–
63V 13 12

1k
R1IN R1OUT 9
8 9 C16 10 T2
R2IN R2OUT R10 R11
14 11
T1OUT T1IN

1k8

1k8
7 10
100n 74HCT4094 R4
T2OUT T2IN
BC640

3k9
4
C5 C2+
MAX232 15
10µ 5 T1 R5
C2– R6 C13

4k02
63V V-
120k
6 10n
C6 IC5
D4 IC4 BC547
+5V 1N4002 7805 +5V LM317 +10V75
10µ
63V
R9
BC640 BC547
330Ω

K2
R1

C14 16 14 C15 255Ω


R2
IC1 IC6 C9 C10 D3 C11 C12
1k91

100n 8 7 100n
470µ 100n 100n 1µ
25V 63V E B C E
C B
IC6 = 74HC125 030313 - 11

Figure 3. The programmer hardware can hardly be called complex.

Hardware ious functions allocated to the out- requires clocking a byte two times
puts are described as follows: into the register. The only bit that
As you can see from the circuit diagram in differs within this byte s the clock bit
Figure 3, the complexity of the hardware – dataline for the controller to be pro- — all others remain unchanged.
remains within reason. A handful of ICs, three grammed; Consequently the shift register has
transistors, a few passive components — and – clock line for the controller; to receive two times eight or sixteen
that’s it, really! – control line to ‘high-Z’ the dataline clock pulses for each bit read by the
(active low); controller. A complete databyte then
Shift register – control line to ‘high-Z’ the clock requires this operation to take place
The heart of the circuit is formed by IC1, a line (active low); eight times.
dual shift register. The first register allows – controller supply line;
eight bits to be clocked in serially. Using a – controller programming voltage Supply voltage and buffer control
strobe pulse, the contents are copied in par- line; As already mentioned, entering the
allel fashion into the second shift register, – control line to ‘high-Z’ the read line programming mode calls for the
whose outputs are bonded out to pins. The (direction: to the PC) (active low); data and clock lines to be held in
device allows eight bits to be shifted ‘in’ at – MSB of shift register is not used. high-impedance mode until the sup-
the clock rhythm without causing any state ply and programming voltages are
changes at the chip outputs. The state When copying (i.e., clocking) a num- applied. This condition is looked
changes are not effective until the strobe ber from the PC into the shift regis- after by IC6, a quad tri-state buffer
input (pin 1) is pulled High. This feature ter, you have to observe that the LSB whose outputs are Low (0), High (1)
comes in handy here because in our circuit at the PC side corresponds to the or High-Z as a function of the volt-
seven control outputs have to be used simul- MSB n the shift register. Also, 128 age applied to its control input. The
taneously, while the serial interface ‘boasts’ clock pulses are required to convey High-Z output state is brought
only three! one byte to the controller. This is about by pulling the control input
Observing the order ‘LSB to MSB’ the var- because the ‘amount’ of one bit logic High.

50 Elektor Electronics 12/2003


MICROCONTROLLER
The supply and programming enthusiastic programmers among
voltages required by the controller you to modify or change the program
are each applied via a transistor to their heart’s content. For example,
switch, because CMOS ICs in gen- it should be possible to implement a
eral can not supply more than 4 different interface without too much
mA. For the supply voltage a single of an effort, just by changing the
driver using a p-n-p transistor contents of the output routine and
proved sufficient. The switch for the re-assembling the code.
programming voltage is a little more A detailed discussion of each rou-
complex because it involves a level tine is unfortunately beyond the
change from 5 V to 10.75 V. That’s scope of this article, hence we limit
why we first create an open-collec- ourselves to looking at the ‘shell’ of
tor output using T1, and then have the software, i.e., the user interface
T2 switch the programming voltage and its actual use.
proper. Without T2, it would be A screendump of the user win-
impossible to completely turn off T2. dow as it appears on the PC monitor
Capacitor C13 ensures that the pro- is shown in Figure 4. First, we will
gramming voltage edge has a rise briefly mention the button functions
time between 1 µs and 100 µs, at the right-hand side of the win-
while also eliminating undesirable dow: Figure 4. User interface.
RF noise.
LEDs D1 and D2 visualise the – ‘Blank check’ is available to see if
data and clock signal, respectively. the chip is unprogrammed, that is, the block ‘Security settings’ in the centre of
In view of the limited current avail- it contains nothing but ‘FFh’ val- the user screen. For the sake of completeness
able, low-current types are manda- ues (all bits at ‘1’). By program- we should mention that the security routine
tory in these positions. ming, a bit reading ‘1’ can be looks after the value of the security byte and
changed into a ‘0’. is called whenever this byte is required. In
From RS232 to TTL – ‘Read’ to read the contents of the this way, the software ensures that the most
The level conversion from RS232 to chip. recent value is always present in memory.
TTL levels is carried out by an old – ‘Program’ allows the chip to be pro- Between the block ‘Security settings’ and
faithful, the MAX232 (IC2, IC3). This grammed with the file you’ve just ‘Chip ID’ you’ll find another text window
IC contains a pair of charge pumps loaded. showing hexadecimal strings read or due for
that enable the +5-V TTL level to be – ‘Verify’: pressing this button programming.
converted to –10 V, in compliance launches a routine that runs a ver-
with the RS232 standard. Because ification process on the chip con- Task bar
we’re dealing with three control tents after programming; if a dis- – The function ‘File’ with its options ‘Open
inputs, for convenience (and with crepancy is found, an error report file’, ‘Close file’, ‘Save as’ and ‘Exit’ will be
easy availability in mind) two pops up. mostly self-evident.
MAX232s are applied in our circuit. – ‘Test hex file’ serves to check the – ‘Programmer’: this function has been added
hexadecimal file for checksum to be able to work without the programmer
Power supply errors, as well as to check if the connected to the PC. The options ‘Online’
The circuit may be powered by an hex file size does not exceed the and ‘Offline’ activate and de-activate the
ordinary mains adaptor with an memory size of the chip you want programmer, respectively.
unregulated output voltage of 15 to program. – ‘Tools’: this fold-out window display has the
VDC. In many cases, a 12-VDC type – ‘Auto’ carries out all the above same buttons as the ones directly accessi-
will also suffice as it will easily sup- functions automatically (except ble in the user window, with the exception
ply 15 to 17 V at such light output ‘Read’). of ‘Read Chip ID’.
load currents as expected here. – ‘Read Chip ID’ allows you to read – ‘Select Chip’: here you select the chip from a
The internal 5-V supply voltage is out the exact type code of the list of available types. This function is car-
obtained from three-pin voltage reg- P87LPC76x chip, which is useful in ried out automatically when running the
ulator IC4. The stabilised program- case the type print on the device ‘Read Chip ID’ and ‘Auto’.
ming voltage is supplied by an has become hard to decipher. The – ‘Select com:’: using this fold-out window
adjustable regulator circuit built result is displayed in a text win- you can select a free serial ports on your PC.
around the venerable LM317. Diode dow to the left of the button. – ‘Help’: the option ‘Index’ opens a help file
D4 acts as a polarity reversal protec- containing brief explanations about the pro-
tion and D3 as an on/off indicator. Configuration settings gram functions. The option ‘About’ supplies
The area in the upper left-hand cor- some information about the program, the
ner allows you to tick the settings for copyright holder and the author.
Software the configuration bytes. To the right
The software is marked by a univer- of it, you’ll find the oscillator config- Extra function
sal character, consisting of many dif- uration, which is actually limited to There is an another useful function that’s not
ferent routines. This structure allows just one setting! The same applies to found in the user window: all settings regard-

12/2003 Elektor Electronics 51


MICROCONTROLLER
COMPONENTS LIST
K2
030313-1
+
#4

#7

C9
D3 1-313030 K1
Resistors:
ROTKELE )C( R1 = 255Ω
K3 R2 = 1kΩ91
C17
R9
C6 C1 R3 = 1kΩ
D4
R4 = 3kΩ9
C13
C10

C5 C7 R5 = 1kΩ5
IC4

R6 = 47kΩ

IC3

IC2
C8 C2
R7,R12 = 10kΩ
T2 R8 = 680Ω
C4 C3
IC5

R9 = 330Ω
C16 R10,R11 = 1kΩ8
R5

C11
R1 Capacitors:

IC1
R2
C1,C2,C3,C4,C5,C6,C7,C8 =

IC6
C12

R6
R8
T1 10µF 63V radial
D1
C9 = 470µF 25V radial
R10

R11

R7
R3 R4 C10,C11,C14,C15,C16,C17 =
D2
C15 C14 100nF
R12 T3
C12 = 1µF 63V radial

#8
#6

C13 = 22nF

Semiconductors:
D1 = LED, low current, red
D2 = LED, low current, yellow
D3 = LED, green
D4 = 1N4002
T1 = BC547B
T2,T3= BC640
IC1 = 74HCT4094
IC2,IC3 = MAX232 CP
IC4 = 7805 (TO220 case)
IC5 = LM317T (TO220 case)
IC6 = 74HC125

Miscellaneous:
K1 = 9-way sub-D socket
(female), PCB mount
K2 = mains adaptor socket, PCB
mount
(C) ELEKTOR K3 = 24-way wide ZIF socket
030313-1
8 wire links
PCB, order code 030313-1 (see
Readers Services page)
Disk, order code 030313-11 (see
Readers Services page) or Free
Figure 5. Copper track layout and component mounting plan of the PCB designed for the Download
programmer. Mains adaptor, output 15VDC (or
12VDC, see text), 300 mA
Serial cable, 1:1 (non-crossed)
Enclosure: e.g., PacTek
ing the configuration bytes, the chip and the treated to an error message. 145 x 90 x 30 mm
serial port may be stored in a configuration
file. This works as follows: each time you quit
the program, a message appears asking you Construction
whether or not to save the current settings. If The copper track layout and compo- position will be even more prominent
‘yes’ is selected, your settings will be saved nent mounting plan of the printed cir- than on the prototype shown in the
on the C: drive in an ASCII file under the cuit board designed for the program- photograph. Connectors K1 (RS232)
name ‘settings.pl’. The next time the soft- mer are shown in Figure 5. We and K2 (mains adaptor) have been
ware is started, your are asked whether or believe it’s reasonable to claim that purposely located at the board edge
not to use the settings from the previous ses- this is a compact yet relatively unclut- to make them better accessible.
sion. If you select ‘no’ you start a new session tered board. The ZIF socket for the Because of the relatively low current
with a ‘clean slate’. In case ‘yes’ is selected controller to be programmed is found consumption of the circuit (50 mA)
the very first time you use the program, or if roughly in the centre of the board — voltage regulators IC4 and IC5 do not
no configuration file has been saved, you are on the final version of the board, this require heatsinks and may be

52 Elektor Electronics 12/2003


MICROCONTROLLER
mounted flat onto the PCB surface.
The actual soldering work is not
expected to cause any difficulty. Not
al lot can go amiss if you stick to the
component mounting plan and the
components list references and part
descriptions. Having said that, don’t
forget to fit each and every wire link
on the board (there are eight of
them) as the absence of any one of
these can cause awkward problems.
The photograph in Figure 6 shows
a correctly built up and fully func-
tional programmer board.
Considering the small size of the
board, finding a suitable enclosure
should not be too difficult. We built
our prototype into a PacTek case
with outside dimensions 145x90x30
mm. As shown by the introductory
photograph, a matching front panel
was designed and produced to add Figure 6. Assembled and fully working prototype of the 89LPC76x programmer.
the finishing touch to the prototype.
The front panel is not available
ready-made from Readers Services, under reference number 030313-F. between the PC and the programmer. A null
but you can download its artwork Finally, an important remark: use a (zero-) modem cable is not suitable.
from the Elektor Electronics website 1:1 (non-crossed) RS232 cable (030157-1)

12/2003 Elektor Electronics 53


ELECTRONICSONLINE

PDA & PPC


Overclocking
Hints & kinks for higher speed
By Harry Baggen

Over the past few years the Personal Digital Assistant or PDA has seen an
evolution from a simple electronic diary to a miniature computer that can do
almost anything its larger
brother the desktop PC is
known to be capable of,
from keeping an appoint-
ment book right up to play-
ing movies. Not surpris-
ingly, fervent PDA users
hunger after speed & more
speed, so CPU overclock-
ing is topical once again.

or quite some time the PDA has been in the


exclusive realms vaguely defined as ‘busi-
ness’, where it was really no more than a throughput, several users have tunately, some users have reported
show-off electronic diary. However, today’s started to explore the possibilities of display interference, so some caution
Palm and Pocket computers offer so much ‘souping up’ their little machines. is advised in this area.
power and performance in terms of multime- The effects, desires and trends A nicely styled (graphically, that
dia that it is seems wasteful to limit their use observed in this quest are really the is) program is called FastCPU [2],
to scheduling the odd appointment. Most same as with regular PCs: the faster which is suitable for nearly all Drag-
PDAs of the latest crop offer a clearly legible the better. Even a quick search onball processors running Palm OS
colour screen, a large amount of memory (if across the Internet is sufficient to releases 3.5, 4.0 and 4.1.
necessary, using expansion cards) and quite confirm that a lot of software is avail- Just like the latest Pocket PCs,
impressive processing speeds. A galaxy of able that allows a PDA to be souped the newer Palm OS computers
software is available at reasonable prices, up in a simple manner. (including several Sony Clië models
and some of it is even free! For example, it has For Palm computers we should like the NX60 and 70) boast an
become possible to use your portable elec- mention Afterburner [1] for use on Xscale processor that can be set to a
tronic diary to play games, play back MP3 Palm PDAs with a Dragonball higher speed using a program called
files (using the headphone connector) or even processor, like the Palm III and V. Lightspeed [3].
watch a complete movie. This little program gives a consider- For the Pocket PCs, similar pro-
The last application being quite demand- able increase in the clock frequency grams may be found on the net.
ing in terms of processor speed and data depending on the PDA type. Unfor- Pocket Hack Master is an excep-

64 Elektor Electronics 11/2003


ELECTRONICSONLINE
bells and whistles called JS Overclock [5],
comes free of charge. It is suitable for most
PDAs with an XScale processor and allows
the clock to be adjusted within a range of
162 MHz to 236 MHz.
Clear Speed [6] is an overclocking utility
specially written for the HP iPaq 1910/1915.
According to several Internet sources this
type of PPC is a particularly suitable candi-
date for overclocking. Reportedly, users are
able to run their 1910 or 1915 at 300 MHz
instead of the standard 200 MHz using a pro-
gram like Clear Speed. A free alternative to it,
Speed Stepper [7], comes with a utility called
Turbo Tray that makes controlled (i.e. step-
wise) increase of the clock frequency an
uncomplicated affair.
Just as with the ubiquitous desktop PC,
Pocket PCs are subject to a lot of experimen-
tation in the hardware department with the
clear aim of making the thing run faster. At
the Xyress’ Pocket PC Corner website [8]
you’ll find a description how to modify a
Casio EM500 for higher clock speed.
With any attempt at overclocking a CPU
or indeed any other logic circuit there is a
real risk of system ‘hang-ups’ owing to too
high clock frequencies. When that hap-
pens, the only thing you can do is give a
‘hard reset’ which unfortunately means you
lose all current data and programs. It is,
therefore, advisable to back up all your
PDA data before you start using overclock-
ing programs.
Incidentally, most of the programs men-
tioned in this article also allow the PDA to
run slower, which may be useful if you want to
reduce power consumption with a view to
stretching battery life.
Most of the software mentioned here is
available from several sources including Han-
dango [9] at a price of about 7 to 15 pounds.
You can also obtain trial and demo versions
of a number of programs, which give you an
tionally extensive program for over- tains an extensive and illustrated opportunity to see if the relevant program
clocking of PPCs with an XScale description of this program. actually runs on your Palm or Pocket PC.
processor. Test utilities are available A simpler program with fewer (035067-1)
to see at which clock speed combi-
nations the PPC continues to oper-
ate as you expect it to Not only the
CPU clock frequency may be Internet addresses
changed — you can also have a go [1] Afterburner: www.palmblvd.com/software/pc/Afterburner-2000-10-05-palm-pc.html
at increasing the refresh speed and [2] FastCPU: www.megasoft2000.com/palm_division/fastcpu.htm
the SDRAM clock. The program is [3] Lightspeed: www.clievideo.com./default.asp?item=3&intProductID=3
capable of measuring the CPU load [4] PC Counselor (Hack Master): www.pc-counselor.com/favorites/hackmaster.htm
and, if necessary, switch over to a [5] JS Overclock: www.jimmysoftware.com/Software/Overclock/
higher clock speed. That is possible [6] Clear Speed: http://revolution.cx/speed/speed.htm
because XScale processors allow [7] Speed stepper: www.elevatedstudios.com/pocket/
their clock frequency to be changed [8] Overclock your EM-500:
on the fly. The program comprises a http://mywebpages.comcast.net/andrewdcox/HowTo/Overclock.htm
number of information windows. [9] Handango: www.handango.com
The PC Counselor website [4] con-

11/2003 Elektor Electronics 65


MICROPROCESSOR

Programming
AVR Microprocessors
easy with BASCOM AVR
By Mark Alberts

This article shows that working with microprocessors has become very
straightforward these days. Thanks to the AVR-microprocessor and the
well-known BASIC programming language success is assured.

There are several different AVR-microproces- There are two available ports: all pins in one go.
sors available. The AT90S2313 is an inexpen- PORTB and PORTD Most of the pins also have an
sive 20-pin version with 2 kB of flashable Internal memory: 128 bytes alternate function. The alternate
code memory. Flash memory is the area EEPROM memory: 128 bytes function is shown in brackets. (INT0)
where the program is stored. The main Flash program memory: 2 kBytes PD2 means: the pin name is
advantage of this type of memory is that it PORTD.2 and the alternate function
can be reprogrammed a thousand times. An A noticeable feature is that 15 of the is INT0. For the purpose of this arti-
even bigger advantage is that you do not 20 pins have been used for IO ports. cle we will limit ourselves to the nor-
have to bother with special programmers or It is these pins that provide the mea- mal functionality of the pins.
UV erasers — a simple cable connected to surement and control capabilities of
the LPT (parallel printer) port of your PC is all the processor. The ports normally
you need to program a flashable micro. consist of 8 pins (bits) each. How- Working with BASCOM
ever, pin PD7 on the 90S2313 is not AVR
actually connected to a physical Before we can actually get started,
The 90S2313 external pin. we first have to install the program-
First, let’s have a look at the most important Any pin can function as an input ming software. The software is
characteristics of the 90S2313 (Figure 1): or an output. If the pin is functioning called BASCOM-AVR (BASIC COM-
as an output, it can be assigned a PILER) and can be found on the
logic level of ‘0’ or ‘1’. The processor Elektor Electronics 2002 Freeware-
can do this for each pin individually, CD-ROM. Alternatively, download
PDIP / SOIC but it is also possible to address the files from the MCS Electronics
them as a group. Pins PD0 to PD6 web site at
RESET 1 20 VCC together form the group called www.mcselec.com/elektor.htm
(RXD) PD0 2 19 PB7 (SCK) PORTD. By assigning a value to where you can read which files you
(TXD) PD1 3 18 PB6 (MISO) PORTD we can change the value of need to download, as well as find
XTAL2 4 17 PB5 (MOSI)
XTAL1 5 16 PB4
(INT0) PD2
(INT1) PD3
6
7
15
14
PB3 (OC1)
PB2 Listing 1
(T0) PD4 8 13 PB1 (AIN1) CONFIG PORTB = OUTPUT ‘ use port B pins as output pins
(T1) PD5 9 12 PB0 (AIN0) PORTB.0 = 1 ‘ pull pin PORTB.0 high
GND 10 11 PB8 (ICP) PORTB.0 = 0 ‘ pull pin PORTB.0 low again
020172 - 11 PORTB = 255 ‘ pull all pins high
PORTB = &B10101010 ‘ make pins 1,3,5 and 7 high
Figure 1. The connection details of the END
90S2313.

72 Elektor Electronics 1/2003


MICROPROCESSOR
instructions on how to install the
software. The software that has
been used here is a demo version,
which is however fully functional.
The only limitation is that the com-
piled processor code is limited to
2 kB in size — the same as the flash-
able memory of the 90S2313!

Start BASCOM AVR and select


Files ? New from the menu. A win-
dow will appear. In this window we
will type our first program (Listing 1).

Save the program with File  Save


As and give it the name
sample1.bas.

You’ve now written your first pro-


gram. The microprocessor will
understand very little of this pro-
gram however, it can only under- Figure 2. The simulation window of Bascom AVR.
stand the so-called object code.
Object code is generated by compil-
ing the BASIC program. Press F7 to line 1 has no visible effect. Click the microprocessor is also able to determine the
accomplish this. step-button again to execute line 2. logic level of a pin when the port is config-
If you do not get any error mes- LED 0 of PORTB will now light up. ured as an input. In this case the ports are
sages, then you have entered the This is because with ‘PORTB.0 =
program correctly. If you do get an 1’ we gave the instruction to make
error message however, correct the PIN 0 of PORTB a ‘1’. This simulator
mistake and compile the program indicates a logical one at a pin as an Listing 2
again. illuminated LED. The outcome of the CONFIG PORTB = INPUT
Before you program the micro- following step will not surprise you: PORTB = 255
processor with the generated object the LED goes out. DO
code, you will first have to simulate Line 4 causes all pins to go ‘1’ by PRINT PINB
the program. Only if you are satisfied writing to PORTB. With this instruc- LOOP
with the results of the simulation, tion we can change the level of all
the program may be loaded init the the pins in one go.
microprocessor. Line 5 is interesting because it called PINB and PIND.
When no more error messages shows that we can also use binary Next, you remove the END statement from
pop up, you may press F2 to open notation to provide the value of the the program and add the following lines:
the simulation window. port. The binary notation is prefixed Compile the program (F7) and press (F2)
The program as entered is with &B, followed by all the bit val- again to start the simulator.
shown at the bottom of the window ues. The first bit corresponds to pin Then press the Run button (>). You will
(Figure 2). At the top of the win- 7, the last one to pin 0. For example, see that in the centre of the screen the value
dow are the buttons controlling the ‘PORTB=&B1001’ makes only pins 0 of PINB is displayed. This is ‘0’. By clicking
simulation. Click the ‘LCD’ button in and 3 high. the green LEDs of PINB you can change the
order to open the hardware simula- Now that the program works, we levels of PINB in the simulator. You will see
tion window. can program it into the microproces- that the value changes accordingly.
There is now an LCD-panel at the sor. Press F4 to make this happen. There is also a switch in our circuit. It is
top of the hardware-simulator win- After programming is completed, connected to PINB.0.
dow (Figure 3). Ports PORTB and you will see that LEDs 1, 3, 5 and 7 You now enter a new program:
PORTD are shown at bottom left. are lit. Because the program is exe-
The purpose of the green LEDs will cuted so rapidly by the microproces-
be explained later. We can now go sor, you will not see the result of
through our program step by step. lines 2 through 4! Listing 3
By clicking the step button (<), some Naturally, it is possible to replace CONFIG PINB.0 = INPUT : CONFIG
invisible code is executed. The pur- the LEDs with a relay or some other PINB.2 = OUTPUT : PORTB.0 = 1
pose of this code is to prepare the output circuit. DO
microprocessor for use. Once you You may now like to know what PORTB.2 = PINB.0
click the step button again, the first the purpose of the green LEDs in the LOOP
line of the program is executed. This simulation window is. The AVR-

1/2003 Elektor Electronics 73


MICROPROCESSOR
Compile this program and program the micro
using F4.
If you now press button S1, the LED will
turn off. Pin 2 of PORTB is now made equal
to the logic level at input pin 0 of PINB.
In the BASCOM help file you can find the
effect and explanation for each of the state-
ments that were used here.
(020172-1)

Note:
The author of this article, Mark Alberts, is the
designer of the BASCOM compilers for the 8051
and AVR-processors. More information can be
found by visiting his website at Figure 3. The hardware simulator consists of an LCD section with below it the
www.mcselec.com. input and output levels of the two ports.

Test example
The schematic shown here
may be used to check vari-
ous things.
Using the LPT connector,
the so-called Sample Elec- R1

tronics programmer may 220Ω

be made. The series resis- +5V


tors are included for pro- K2

tection. It should be noted 14


1 R4 +5V
10k

2
that it is best to connect 15
3
20

the hardware via a sepa- 16


4
R2
1
RESET
SV1 10
17 220Ω
rate IO card. 18
5
R3
IC1 (SCK)PB7
19 15 16 1
I1
+VS
O1
18 D1
330Ω
R5
6 11 18 13 14 2 17 D2 R6
19 220Ω PD6(ICP) (MISO)PB6 I2 O2 330Ω
7 9 17 11 12 3 16 D3 R7
PD5(T1) (MOSI)PB5 I3 O3 330Ω
The DB9 connector, 20
8 8
PD4(T0)
AT90
PB4
16 9 10 4
I4 O4
15 D4 R8
21 330Ω
S2313 IC5
together with the 22
9 7
PD3(INT1) (OCI)PB3
15 7 8 5
I5 O5
14 D5
330Ω
R9
10 6 14 5 6 6 ULN 13 D6 R10
MAX232, forms a serial 23
11 3
PD2(INT0) PB2
13 3 4 7
I6
2804 O6 12 D7
330Ω
R11
PD1(TxD) (AIN1)PB1 I7 O7 330Ω
input and output that can 24
12 2
PD0(RxD) (AIN0)PB0
12 1 2 8
I8 O8
11 D8 R12
25 330Ω
be connected to the COM 13
XTAL1 XTAL2
VEE
9
port of a PC. 5
Q1
4 10

In the example, a switch is S1 C1 C2 C3


connected to PB0. SV1 is a S2
4µ7 22p 4MHz 22p
header on which jumpers RESET 16V

may be placed. The driver


chip (ULN) is necessary in
C7
this case. Normally this IC
is not required when the 10µ 25V +5V
2
LEDs are wired the other 1 V+ 16
C1+
way around and con- C4

IC2 IC3
nected to VCC via a resis- 10µ 3
C1– K1
25V 12 13 7805T +5V
tor. It is also possible to 9
R1OUT R1IN
8
1
6
R2OUT R2IN K3
drive relays with the ULN 11
T1IN T1OUT
14
2
7
3
if the power supply to this 10
T2IN T2OUT
7
4
8
4 C10 9
IC is connected to 12 V. C5 C2+
10µ
5 C8 C9
MAX232
The only purpose of this 10µ 5
C2–
15 25V
100µ 10µ
schematic is to provide a 25V V- 25V 16V
6
straightforward example. C6

Very likely you already 10µ 25V


020172 - 12

have a large number of


simple AVR schematics in
your archive that you can
use as well.

74 Elektor Electronics 1/2003


SMALL CIRCUITSCOLLECTION

044
Programing Tool for ATtiny15
IC2
R1 D1 78L05 +5V
10Ω
K1
1N4148 R2

860Ω
C1 C2 C3 C4
D2
100µ 100n 100n 100µ
25V 16V

+5V

R7
K2 D3 D5 C5

10k
1 100n
6
BAT85 BAT85
R5 8
2
10k
7
IC1
3 7 1
R4 SCK RESET
8 6 2
10k MISO PB4
4 5 3
R3 MOSI PB3
H. Volmer 9
10k ATTiny15
5
4 T1
R6
A small microcontroller like the ATtiny15 is ideal for many sim- SUB D9 10k

ple tasks not requiring too much I/O activity. The ATtiny15 has D4 D6 D7
BC547C
two I/O connections, offers a 1024-byte Flash memory and a
BAT85 BAT85
64-byte EEPROM, all in an 8-pin case.
BAT85
The programming tool shown here is connected to the RS232 030030 - 11

port on your PC. The programming clock signal is generated


using a byte sent across the serial interface.
The programmer employs the so-called low-power program-
ming algorithm under Windows ME. The associated software Identify which allows manufacturer data as well as calibra-
offers four tabs: tion register contents to be read from the ATtiny15 chip.

.equ lastflash =0x1ff Flash which expects a file in HEX or binary format for
programming into the on-chip Flash memory. When the
Reset: HEX format is used, the checksum is ignored. Read and
Ldi ZL,LOW(lastflash*2)+1 write access to the Flash memory is only possible using
Ldi ZH,HIGH(lastflash*2);//FLASHEND the HEX format. The calibration byte is read with the
Lpm ;in last memory location of calibration register
aid of PutCallbyte and then written to the indicated
buffer address. The internal oscillator is controlled as
Out OSCCAL,r0
shown in the listing.
R1

D1

C1 C2 IC2

C3
9V DC K1
1-030030 C4 030030-1
D7
D6
D5

ROTKELE )C( (C) ELEKTOR

K2 T1 D2

R6
030030
R2

R4
R5
R7

R3
C5
IC1
D3
D4

Elektor Electronics 7-8/2003


SMALL CIRCUITSCOLLECTION
COMPONENTS LIST D3...D7 = BAT85
IC1 = 78L05 EEPROM does essentially the same as Flash function, only the
Resistors: T1 = BC547C PutCallbyte is not present.
R1 = 10Ω
R2 = 820Ω Miscellaneous:
Fuses allows the chip fuses to be read and programmed. Note,
R3-.R7 = 10kΩ IC1 = 8-way DIL
programming socket however, that the Fuse and Lockbit programming is not tested
Capacitors: K1 = mains adaptor socket, because afterwards only the High Voltage mode will work.
C1,C4 = 100µF 25V radial PCB mount
C2,C3,C5 = 100nF K2 = 9-way sub-D socket A small PCB, order code 030030-1, was designed for the pro-
(female), PCB mount, grammer. The PCB artwork may be obtained from the Free
Semiconductors: angled pins Downloads section of the Publishers’ website. The software is
D1 = 1N4148 PCB, order code 030030-1
also found there. For those without access to the Internet the
D2 = LED, green Disk, project software,
order code 030030-11 software is also available on diskette, order code 030030-11.
(030030-1)

7-8/2003 Elektor Electronics 3


COMPUTER

Serial Port Driver


for Windows
Programming with Serial.DLL
By P. Goossens

In the April issue last year we published an article that showed how to
program the serial port correctly under Windows. The methods
described in that article appeared to be a bit too complex for many
people. For this reason we wrote our own DLL, which can be used to
simplify the programming of the serial port. This DLL will be described
in this article.

The serial port is still used by many electron- can keep control of all hardware
ics hobbyists to connect their computer to the access. Table 1.
outside world. This makes perfect sense, The only (proper) method for con- The complete list of functions
since such an interface is found on every trolling the serial port under Win- and routines in the DLL.
standard PC and it also provides a few input dows is via the Windows API. A
and output signals as well as the serial com- number of functions for the serial OpenCOM
munication channel. The USB port has these port has been included in the API CloseCOM
capabilities as well, but this requires some (these were described in the previ- IsPortOpen
extra circuitry and many hobbyists would ously mentioned April 2002 article).
GetPortNr
prefer to avoid that. In this context it’s better There is still a lot of work involved to
COMPortExists
to keep quiet about ISA and PCI cards too. control a serial port using these func-
SendCharCOM
The serial port still remains the favourite solu- tions. It would be much easier if the
ReadCharCOM
tion when a simple connection is required basic routines required for control-
between a PC and some electronics. ling the serial port were provided by SetTxD
a DLL, so the programmer has no ResetTxD
need to concern himself with the SetRTS
Programming communications between the pro- ResetRTS
The way in which serial ports are pro- gram and Windows. SetDTR
grammed has changed tremendously over the ResetDTR
years. Under DOS they could easily be con- GetCTS
trolled directly, without affecting the operating Serial.DLL DetDCD
system. Under Windows this changed com- Many readers will probably appreci- GetDSR
pletely. Although the earlier versions of Win- ate that we have written a DLL that GetRI
dows still permitted the direct access of the can be used to control a serial port in GetHandle
hardware, programming the serial port a simple manner. Apart from trans- CheckInputs
became much more complex. The more recent mitting and receiving characters, it BaudRateSet
versions completely refuse to let programs is also possible to request the state ParitySet
access the hardware directly. Windows now of the input pins and set the state of BitPerByteSet
takes responsibility for this and likes to stay the outputs. StopBitsSet
in control. It’s only in this way that Windows An extra feature included in the

38 Elektuur 3/2003
COMPUTER
DLL is an option for the it to keep Application DLL Thread
an eye on the serial port and send
a Windows message when its sta-
tus changes. With this it becomes CheckInputs Makes
unnecessary to poll the serial port (5100,handle) new WaitCommEvent
thread
at regular intervals. It is only when
there is a change in status that the
program is interrupted, similar to
the way in which Windows informs PostMessage
a program that a key has been (handle, 5100,
pressed. Some of you may have dif- event,0)
ficulty in using this routine, but Program
continues
there is no need to panic. You don’t
have to use this routine to operate
the serial port; it has only been Finish thread
included as an extra for the more
advanced programmer.
020388 - 11

The functions Figure 1. Implementation of the CheckInputs function.


The functions and routines of the
DLL are listed in Table 1. All rele-
vant functions have been named to but if you attempt to transmit a char- than three variables that have to be inter-
make their purpose clear. We will acter after the output has been set preted by the application and subsequently
therefore not go into detail for all high with the SetTxD function, the acted on. The first variable specifies the type
functions. For this you should look at transmission will fail and the pro- of message. The other two variables are used
the accompanying example, which gram could crash. It is sufficient to to pass on any other information that may be
can be downloaded together with reset the line using ResetTxD after required. There wouldn’t be much point if
the DLL from our website at which you can transmit as many Windows told an application that the mouse
www.elektor-electronics.co.uk with characters as you like. pointer had moved, without telling it what
the number 020388-11. The above functions don’t require the new position was.
Before a port can be used, it has much of an explanation. The oppo- There are numerous message types
to be opened. This is done by the site is true of the CheckInputs reserved by Windows, but it is also possible
OpenCOM function. This function function. In order to use this function for a program to send a message to another
requires the port number of the ser- successfully you will first have to application. For this Windows has reserved
ial port that has to be opened. A 1 learn a bit about Windows mes- messages with a type value greater than
corresponds to COM1, a 2 is for sages. But don’t let this put you off 5000. These are the so-called User Defined
COM2, etc. When the port has been from using this DLL. The following messages and are therefore not sent by Win-
opened successfully, the function section is only important if you want dows, but can be can be used by applications
returns the port number; when there to make use of the facility to get a for communicating between themselves.
has been a problem this value will signal from Windows when the sta- Most programming environments (such as
be zero. tus of the serial port changes. Delphi, Visual C++, etc.) take care of these
After use, for example when the communications without requiring program-
program is terminated, the port has mer involvement. But most programming
to be closed again. This is done by Windows messages environments also offer the programmer the
the CloseCOM routine. In between Programs can give commands to the facility to deal with these messages them-
these events, characters can be operating system via its API, and in selves when required.
transmitted using the SendCharCOM many cases Windows will issue a With Delphi it is possible to use the
routine and received using Read- reply in one form or other. But this Application.OnMessage event to
CharCOM. isn’t the only way in which applica- process the incoming Windows messages.
The status of the inputs (DCD, tions can communicate with Win- The corresponding routine in Visual C++ is
DST, CTS and RI) can be obtained dows. Application::OnMessage. This commu-
using the functions GetDCD, etc. The The messaging system is another nication mechanism is used by our DLL to
DTR output is controlled via the important means of communication. inform the application whenever the serial
SetDTR and ResetDTR functions. Virtually every Windows program port status changes. To send a message we
Similar functions are provided for the uses this. The operating system uses can use the PostMessage function from the
two other outputs, TxD and RTS. these ‘Windows Messages’ to let an Windows API.
When the TxD output is driven application know when a mouse but- The Windows API also has a function that
directly you may run into problems. ton has been pressed or if the pro- waits until there is a change in status of the
This output is normally used to gram should be minimised, to give a serial port. This function is called WaitCom-
transmit serial data. It’s true that few examples. mEvent and is suitable for our application,
this output can be controlled directly, A message consists of no more but has the problem that it halts the execu-

3/2003 Elektuur 39
COMPUTER
tion of the program until such time that there Since Windows regards the called that deals with the status
is a status change of the serial port. This is thread as a separate program, the change. In all other cases the mes-
obviously not our intention. This problem can execution of our main program con- sage has to be dealt with by the
easily solved through the use of so-called tinues normally. In this case the pro- actual Message Loop.
threads. gram is running the CheckInputs
routine, which is part of the DLL.
The DLL completes that routine and And finally
Threads the main program can continue with We can imagine that a few question
An application can run parts of the program its tasks unhindered. As soon as the marks remain after reading the pre-
in a separate thread. This means that there status of the serial port changes, vious section. We therefore recom-
are effectively two programs active at the Windows will re-start the thread and mend that you have a look at the
same time. One is the main program and the states in a variable which event source code of the accompanying
other is the thread. If this thread is halted it occurred in the serial port. The example program. Usually the quick-
won’t affect the operation of the main pro- thread subsequently passes this est way of learning about program-
gram. information on to our program via a ming is to examine and adapt a
Figure 1 shows how the CheckInputs Windows message. ready-made program. We’ve used
function is implemented in the DLL. The pro- When the program receives a Delphi for the example program
gram calls this function, at which point the Windows message it calls the func- because this language is very easy
DLL creates a thread that is automatically tion AppMessage. This function to follow. The source code could eas-
started. From this point on the main pro- checks if the message indicates that ily be converted into C++, for exam-
gramming continues to run normally, inde- the status of the serial port has ple. Elsewhere in this issue you’ll
pendently from the thread. The thread calls changed (in this case we’ve used the find a simple COM Port Tester, which
the Windows function WaitCommEvent, value 5100, but this may be any can be used to check the operation
which causes Windows to halt the execution other value as long as it hasn’t of your own programming efforts.
of the thread until there is a change in the already been used by Windows). If (020388-1)
status of the serial port. this is the case then a routine is

40 Elektuur 3/2003
GENERALINTEREST

Switched-Outlet
Power Bar
with RS232 Control
Remote switching using RS232 and I2C
Design by W. Frank

This circuit can be built into a power bar and used to remotely switch six
socket-outlets. It is controlled via an RS232 interface and uses an I2C-bus
IC (type PCF8574P) to decode the RS232 signals.

the I2C bus and feed them into a


shift register with an 8-bit output
latch. Of course, this is nothing spe-
cial, and it can be done using stan-
dard components.
However, the PCF8574 has a
number of useful features that make
it a good choice this application. For
instance, it is addressable. Three
bits of the PCF8574’s address are
freely selectable, while the four most
significant bits are either ‘0100’ (for
the PCF8574) or ‘0111’ (for the
PCF8574A version). This means that
in principle, up to 16 such devices
can be independently operated
using a single I2C bus.
The PCF8574 also has an internal
power-on reset circuit, so the output
latch assumes a defined state after
the circuit is switched on. The I2C
bus signals pass through an input fil-
ter and thus arrive at the control
A remotely switchable power bar controlled The 8-bit I/O expander logic of the IC free of interference.
by a PC via the RS232 serial interface can be Ports P0-P7 are not just outputs.
realized with a minimum of hardware and As can be seen from the block dia- They operate in a ‘quasi-bidirec-
software drivers (for use under Windows, gram in Figure 1, the IC in question, tional’ mode, so the levels on P0-P7
DOS and Linux) by using an IC to decode the a type PCF8574, is basically a serial- can not only be set in the write
RS232 signals and individually control each to-parallel converter. What it essen- mode, but also read in the read
of the socket-outlets. tially does is to take serial data from mode, without having to use a con-

32 Elektor Electronics 4/2003


GENERALINTEREST
trol signal to select the data direc-
tion. However, this capability is not
13 INTERRUPT
used in this circuit. INT LP FILTER
LOGIC

A0
1 PCF8574
2
4
The rest of the hardware A1
A2
3
5
P0
P1
Besides the PCF8574, there’s noth- 14 6
P2
SCL
ing particularly remarkable about INPUT I 2 C BUS 7
15 P3
SDA FILTER CONTROL SHIFT 8 BIT I/O
the schematic diagram of the circuit 9
REGISTER PORT P4
10
shown in Figure 2. The base P5
11
address of the IC can be set using P6
12
three jumpers (JP1-JP3). If you are P7

sure you will never want to change WRITE pulse


the address, you can omit the pull-up 16 READ pulse
VDD
resistors (R1-R3) and simply connect 8
POWER-ON
V SS RESET
the IC pins directly to ground or the
positive supply voltage.
020298 - 12
The I2C bus is emulated by the
RS232 interface of the PC, which is
connected to K6. Besides the ground Figure 1. Functional block diagram of the PCF8574 (Philips Semiconductors).
lead, only the DTR and RTS leads are
used for this purpose. The diodes
provide level conversion from ±12 V
(RS232) to the+5 V and 0 V that the
PCF8574 needs for the clock and
data signals. This simple solution
permits only one-way data traffic,
+12V
from the PC to the PCF8574, but
that’s all we need here.
1k2

1k2

1k2

1k2

1k2

1k2
Six of the chip’s eight I/O pins are
used here, with each one controlling
a relay via a driver transistor. Free- TR1
+12V
1 2 3 4 5 6
K1
wheeling diodes are connected in IC2
78L05 +5V +12V
parallel with the coils of the relays. B1
1 2 3 4 5 6
K2
The supply voltage for the relays is D5
RE1
F1 C2 C4 C3
approximately 12 V, which is taken
100mA T B80C1500R 220µ 100n 100n +12V
directly from the ‘raw’ DC voltage 25V 1N4148
T1
R4
obtained by rectifying the secondary 10k
RE2
D6
voltage of power supply transformer BC547

Tr1 using B1. A voltage regulator 1N4148


T2
provides +5 V for the PCF8574. +5V
R5
10k

LEDs with 1.2-kΩ series resistors +5V


+12V BC547

can optionally be connected from the R1 R2 R3


K3
C1
junctions of the relay coils and the RE3
10k

10k

10k

D7
100n
collectors of the driver transistors to +12V
16 1N4148
the +12-V line, as shown on the R6
T3

schematic diagram, in order to indi- JP1 JP2 JP3


1
2
A0
IC1
P0
4
5
10k
D8
RE4
A1 P1 BC547
cate the status of each of the relays. 3
A2 P2
6
K6 7
P3 1N4148
9 T4
1 P4 R7
15 10
6 SDA P5 10k

Construction and fitting 2


7 RTS
14
13
SCL
INT
P6
P7
11
12 +12V BC547
D2 R11 PCF8574 K4
The layout of the printed circuit 3
8
K5 330Ω
RE5
D1 R10 8 D9
board for this project is shown in 4
9
DTR
330Ω
2x
Figure 3. The dimensions of the cir- 5 1N4148
D4 D3
1N4148
+12V
T5
cuit board have been chosen to 5V1 5V1
R8
10k
SUB D9 RE6
allow it to be easily fitted into com- BC547
D10

monly available multi-way power


1N4148
bars. Naturally, it must be possible R9
T6

10k
to take apart the power bar. Cheap
BC547
power bars, which are usually hot- 020298 - 11

welded together, are thus not suit-


able. Also, the individual socket-out- Figure 2. The circuit combines the I2C chip with a serial interface and six output relays.

4/2003 Elektor Electronics 33


GENERALINTEREST
F1 COMPONENTS LIST
H2

H3

100mAT
1 Resistors:
RE1 T1
K2

D5
R3 R2 R1-R9 = 10kΩ
2R4
R10,R11 = 330Ω
RE2 T2 TR1
R5 JP1
D6 3
JP3 R1 Capacitors:

DTR
RTS
T
RE3 T3
K3

JP2 C1,C3,C4 = 100nF

K5
D7 R6
4 C2 = 220µF 25V radial
RE4 T4 D4 D2 B1
R7 C4

IC1
D8 R11 C3
5 R10 Semiconductors:
RE5 T5
B1 = B80C1500 in round case
K4

D9 R8 D3 D1
6 (80V piv, 1.5A continuous)
RE6 T6
R9 K1 D1,D2,D5-D10 = 1N4148
D10 + IC2

H4
H1

1-892020
020298-1
C1 C2 D3,D4 = zener diode 5.1V,
ROTKELE )C(
500mW
T1-T6 = BC547
(C) ELEKTOR IC1 = PCF8574 or PCF8574A
020298-1
IC2 = 78L05

Miscellaneous:
JP1,JP2,JP3 = jumper or wire link
K1-K4 = 2-way PCB terminal
block, lead pitch 7.5mm
K5 = 3-way SIL pinheader
K6 = 9-way sub-D socket
(female), chassis mount
TR1 = mains transformer, 9V
1.5VA, (e.g., Hahn BV EI 302
2021)
RE1-RE6 = relay, Finder type
34.51.7.012.00 (12V) (Conrad
Electronics # 504459)
F1 = fuse, 100mA, slow, with fuse
holder and protective cover
Figure 3. The printed circuit board fits exactly into a power bar enclosure. Optional: six 1.2kΩ resistors and
six LEDs
PCB, order code 020298-1 (see
Readers Services page)
Disk, order code 020298-11, or
Free Download)

lets must be interconnected using


flexible wiring, rather than solid
strips of metal. To make room for the
control circuit, remove the first of the
socket-outlets. The circuit board has
four drilled mounting holes to allow
it to be securely attached to the
power bar enclosure.
The photo at the head of the arti-
cle shows the author’s prototype.
The circuit board in this photo is not
the same as the Elektor Electronics
circuit board (see Figure 4).
Assembling the circuit board is
perfectly straightforward. All of the
passive components and discrete
semiconductors are fitted vertically.
As already noted, the three jumpers
can be replaced by wire links to
Figure 4. The fully assembled Elektor Electronics prototype circuit. ground or the 5-V supply voltage. In

34 Elektor Electronics 4/2003


GENERALINTEREST
also forms part of the software for this project
that is available by download or on diskette,
should be copied to the directory \WIN-
DOWS\SYSTEM.
The actual program, SOCKETS, uses the
functions SetDTR, Reset-DTR, SetRTS and
ResetRTS. In addition, COMPortExist deter-
mines which serial ports are available, and
OpenCOM & CloseCOM are necessary to
active and deactivate the port to which the
power bar is connected.
The most important procedure is SendI2C,
which sends a data byte to a particular I2C
address. A glance at the source codes shows
that all that this involves is driving the two
lines in the proper sequence. A brief delay is
introduced after each level change on the
lines in order to keep the data transmission
rate on the bus within allowable limits.
Figure 5 shows the window displayed by
the sample Delphi 5 program, which is avail-
able as source code. It is fairly self-explana-
tory. At the beginning, the desired COM port
is selected and opened, after which the
address of the I2C chip is selected. This
Figure 5. Using a Delphi 5 window to control the power bar under Windows. depends on the IC type (the PCF8574 has a
base address of $20, while the -A version has
a base of address of $38) and the configura-
this case, R1-R3 can be omitted. The this, SCL also goes low. The seven tion of jumpers JP1-JP3. Once these settings
narrow mains relays made by the address bits, followed by the R/W have been made, the individual socket-out-
Swiss company Finder allow the bit, are transferred sequentially by a lets can be switched on or off as desired. To
board to be kept very compact. series of rising edges on the SCL stop the program, close the serial port or sim-
line. The level on the SDA line is only ply click on Exit.
allowed to change while the SCL (020298-1)
Drivers line is low. In this application, the
The project includes source code and R/W bit is naturally always 0 (=
.exe files for Windows (a Delphi write).
application), Linux and DOS (both Normally, the slave is allowed to
written in C). All of these programs confirm the receipt of a valid address
can be downloaded free of charge by sending Acknowledge. Although
from the Elektor Electronics website, this is not the case here, the master
including the source code. They can must still generate an extra clock
also be obtained from Readers Ser- pulse, which the slave interprets as
vices on diskette (order number confirmation of the Acknowledge.
020298-11). After this, the slave is ready to
The core of the program consists receive the eight data bits. Each bit
of an emulation of the I2C bus using is directly associated with one of the
two leads of the ‘normal’ serial PC IC outputs. The data bits are fol-
interface. The DTR lead drives the lowed by an extra SCL pulse to con-
serial I2C clock line SCL, while the firm the Acknowledge the slave
RTS lead drives the I2C data line thinks it has sent, after which the
SDA. Since the PC cannot receive master terminates the transfer with Free Downloads
any data from the I2C chip, the soft- a positive edge on SDA while SCL is – source code files and .exe files for Win-
ware simply ignores Acknowledge high. dows (Delphi application), Linux and DOS
signals from the PCF8574. (both written in C).
After the PC software is started, File number: 020298-11.zip
or after a data packet has been sent, Control
– circuit board layout in PDF format.
the bus is in the idle state, with both The functions of SERIALDLL.DLL, File number: 020298-1.zip
of the I2C lines high. The bus master which has been extensively
initiates a data transfer by generat- described in the March 2003 issue of www.elektor-electronics.co.uk/dl/dl.htm
ing a negative edge on SDA while Elektor Electronics, are used to drive (select month of publication)
SCL is high (Start condition). After the serial interface. This DLL, which

4/2003 Elektor Electronics 35


COMPUTER

Temperature Indicator
for the PC
Useful and decorative!
Design by A. Köhler

Alongside its purely functional uses the PC also has a position as a status
symbol. At computer nerd get-togethers, it is de rigeur to have some novelty
to show off. And if it also serves some useful purpose, so much the better.

Enclosures with windows and internal illu- +5V


mination have already started to become
available, showing off the innards of a PC. C1 C2
There is even a special word — modding —
10µ 100n
for this type of PC (re)construction. As well 10V
R4
2k2

as various modifications whose benefits 20


R6
T1
can be argued over at considerable length, R1

2k2
1
RST 10k
there are those which have a definite use- P1.0
12
R2
T2 R9
IC1 BC557

2k2
ful purpose. 2
P3.0 P1.1
13
10k
3 14 T3
For example, the temperature inside a PC’s 6
P3.1 P1.2
15
R3
BC557
P3.2 P1.3 10k
enclosure is an important quantity. Depend- 7
P3.3 P1.4
16
ing on the processor, the fans and the ambi- 8 17 BC557
P3.4 P1.5 8
9 18
ent conditions, the temperature can rise to P3.5 P1.6
19 2
the point where trouble-free operation can no AT89C2051 P1.7 SCL
11 1 3
P3.7 SDA OS
longer be guaranteed. There are special dis- X1 X2 IC2 R5 R7 R8 R10
220Ω

560Ω

560Ω

330Ω

plays available, often in conjunction with fan R11


10 5 4
7
A0
X1 6
22k

systems, that offer a temperature readout. A1 LM75


5
A2 D1 D2 D3 D4
Unfortunately these displays occupy a full 3.5
C3 C4
inch or 5.25 inch drive bay in the PC. But 4
green blue blue red
remember that PCs have a red, yellow or 22p 22p

green LED that serves as a power indicator. 11.0592MHz 020380 - 11

Why not use this simple indicator to offer


extra functions, such as showing the temper-
ature inside the enclosure? Figure 1. The simple circuit diagram of the temperature indicator.

Before we start ature of 125 °C is in any case the It is therefore not at all unreason-
Before we can build a temperature indicator ultimate limit. An office PC will usu- able to set the measurement range
we must determine the range of tempera- ally be used in a more-or-less air- to +10 °C to +70 °C. Using these
tures over which it is to operate. Intel and conditioned environment (the Elek- values we can use the top surfaces
AMD specify their processors for a tempera- tor Electronics offices being a partic- of hard disks and heatsinks as mea-
ture of 40 °C to 45 °C inside the case. Without ularly notable exception). And hardly surement points. The temperature
expensive specialised cooling it is not really any user will want to operate their sensor used should be a readily
possible to effectively remove the heat gen- PC at temperatures below 15 °C, so available and inexpensive type, such
erated by the processor at case temperatures the PC’s components are rarely as the LM75 (or DS75). Reading the
above 70 °C. The maximum junction temper- below this temperature. temperature out can be done using a

70 Elektor Electronics 4/2003


COMPUTER
simple microcontroller such as the ues can be adjusted, since the LED nated. The green LED is turned on and a
AT89C2051, which will allow us to has reasonably wide tolerances. delay loop is entered. The same happens for
transfer the temperature value over Port 1.0 controls the green LED, the blue and red LEDs. The primary colour
an I2C bus. We can use a three- port 1.1 the blue LED and port 1.2 LEDs are driven inside a loop which is exe-
colour LED as an indicator, replacing the red LED. The LED current should cuted 255 times, so that the eye cannot dis-
the one-colour power indicator LED be around 20 mA. Communication tinguish the individual colours. Instead, the
usually provided. The multicolour with the temperature sensor is over impression of a particular colour and inten-
LED is constructed from four LED ports 1.4 (the SCL clock signal) and sity is given, depending on the time con-
chips in three colours: one red, one 1.5 (the SDA data signal). The stants and hence on the temperature.
green, and, because of their lower LM75CIM5 temperature sensor (the A particular point to note is that a value of
light output, two blue chips. In order 5 V version) has its write address 00H for a time constant corresponds to the
to give the impression of a single set to 90H and its read address set maximum possible illumination period, since
composite colour, a diffused package to 91H by the levels on A2 to A0. the first time the DJNZ instruction is exe-
is used. If the individual LED chips cuted in the loop an overflow (or rather, a bor-
can still be made out, adding an row) occurs. With a value of 01H the illumi-
extra sheet of diffuser will result in Software nation period is so brief that it is practically
the desired effect. The impression of The most interesting part of this pro- invisible to the eye. Delay routine ZEIT is
different colours is achieved by dri- ject is the software. The software is used to extend the (otherwise very short) illu-
ving the individual LED chips using available as source and compiled on mination period. If the crystal frequency is
pulse-width modulated signals from the Internet from the Elektor Elec- changed, it may be necessary to adjust this
the microcontroller. tronics website (which is free) and delay somewhat. The values given have been
on diskette 020380-11 (for which tested with a 11.0592 MHz crystal. The
there is a nominal charge). If you colours themselves can be changed by alter-
The circuit cannot, or do not wish to, program ing the values in the table.
Figure 1 shows the complete cir- the device yourself, a ready-pro-
cuit, using an 89C2051 microcon- grammed microcontroller is also The example program given indicates low
troller from Atmel. This device’s available (order number 020380-41). temperatures by a blue colour. As the tem-
baby brother, the 89C1051 (which The details of the program can be perature rises, so does the proportion of
offers 1 kbyte of memory) can also seen from the listing. The program green in the colour. At 35 °C the green LED
be used. The reset circuit on pin 1 uses pulse-width modulation, con- alone is lit. If the temperature climbs further,
is not critical: the capacitor value trolled by a program loop rather than red is added into the colour. Over 50 °C only
can be anything from 1 µF to 10 µF, using the internal timers. The pro- the red LED lights.
the resistor anything from 10 kΩ to gram begins by initialising the port
50 kΩ. Likewise, the oscillator cir- outputs. A register is allocated to Since the maximum offset available is 255
cuit between pins 4 and 5 is not each colour to store the time for (an 8 bit register is used for the temperature),
critical: crystals from 7.3728 MHz to which the corresponding LED is illu- the table can only be extended to about 70
14.318 MHz have been tested. The minated. Next the program selects °C, but above this temperature an office PC is
three-colour LED is connected via a the temperature register of the LM75 unlikely to operate correctly in any case.
PNP transistor driver. A 5 mm LED and reads out the temperature value Communication with the temperature sensor
in a diffused package is used: suit- stored there. Only the four most sig- uses the I2C bus routines START, STOP, READ
able devices are available from, for nificant bits are used, the four least and WRITE in their minimal configuration.
example, Reichelt Electronics significant bits of the temperature Error handling is not provided as transmis-
(www.reichelt.de) and Conrad reading being ignored. Since the full sion errors on the I2C bus will not have seri-
Electronics (order code 185353, temperature range of the device is ous consequences. With the source listing to
www.int.conradcom.de). The LED not used, the temperature scale is hand there should be no difficulty in making
is manufactured by Kingbright shifted to start at 10 °C by subtract- modifications to the display.
under part code LF59EMBGMBW. ing 0AH from the value read. This (020380-1)
Note that many devices advertised value is to be converted into a
as ‘three-colour LEDs’ are not suit- ‘colour value’. Each colour value con-
able for this application. The King- sists of three time constants which
bright device you need has six ter- determine for how long the corre-
minals, see also the datasheet sponding primary colour LED is illu-
which may be found on the Conrad minated. The time constants are
webserver. obtained from a table indexed by the
Each BC557 transistor has a temperature. Routine ZAU causes
series base resistor and a pull-up
resistor to ensure that the transistor
the colour value to be displayed.
The data pointer is used to point
Free Download
is turned fully off. Because of the dif- into the table containing the illumi- source code file (in German) and hex file for
programming the microcontroller. File num-
ferent forward voltages and different nation time values. Each tempera-
ber: 020380-11.zip.
light intensities of the LEDs, differ- ture value uses three bytes of table www.elektor-electronics.co.uk/dl/dl.htm
ent values of current-limiting resis- space. The first byte gives the time (select month of publication).
tor are required. These resistor val- for which the green LED is illumi-

4/2003 Elektor Electronics 71


Computer Network Lead Tester Project
This project was designed for confirming the continuity and correct wiring of computer network leads
which have 8 wires, but it can be used to check any lead with up to 8 wires by using appropriate
connectors. For example stereo audio leads with 5-pin DIN plugs can be checked by just using the first 5
LEDs. The tester is simple but it can save a great deal of time when making up leads and it is much
cheaper than the more sophisticated alternatives!
The tester works by connecting each wire to an output at one end and an LED at the other end. The
outputs are switched on one at a time in sequence so that a correctly wired lead will make each LED light
in turn. The 4017 IC counts up to 10 so there is a pause (for the 9th and 10th counts) before the LED
sequence repeats. If the LEDs light up in the wrong sequence one (or both) of the connectors is wired
wrongly. If an LED fails to light it indicates a broken connection. Please note that the RJ45 computer
network plugs cannot normally be re-wired, instead they must be cut off and replaced.
Parts Required
• resistors: 2.2k, 22k, 180k, 560 ×8 • 555 timer IC
• capacitors: 0.1µF, 1µF 16V radial ×2 • 4017 counter IC
• red LEDs ×8 • DIL sockets for ICs: 8-pin, 16-pin
• push switch • battery clip for 9V PP3
• stripboard: 16 rows × 19 holes
• RJ45 computer network sockets ×2 (a dual socket for example)
(or choose suitable connectors for the leads you wish to test)
555
Stripboard Layout red

0.1µF
2k2

180k 1µF
red Press to
to test
5 560
6 560
8 wires to the red
2 560
network lead socket 1µF
1 560
then to LED anodes 560
3
(the numbers show 560
7 22k
the LED sequence) 8 560 black
4 560

to LED cathodes (0V)


4017
cut the track under = cut track
each 560 resistor

Each socket should be wired up in the to stripboard (see above)


8 wires
socket

same way, so that wire 1 from the Network lead


1 wire being tested
stripboard connects to pin 1 on the first 8 wires

socket, and pin 1 on the second socket 0V wire to LED cathodes


8 wires to
LED anodes socket
connects to LED 1. LEDs mounted on case (long leads)

Circuit diagram +
2k2 1µF

8 4 16
7
14 4017 1-of-10 counter 15
555
6 timer 3 8 13 3
180k 2 4 7 10 1 5 6

0.1µF 2 1 8x 22k 9V
560
+ 8-way lead is connected in here
1µF

1 2 3 4 5 6 7 8

If the lead is OK each LED should light up in


sequence from left to right (1 to 8 above).

© John Hewes 2006, The Electronics Club,


THE www.kpsec.freeuk.com
ELECTRONICS A kit for this project is available from
CLUB
RSH Electronics
GENERALINTEREST

The P89LPC900
Part 1: the architecture
By M. Stottelaar Eurodis Texim

Under the moniker of P89LPC900, Philips have introduced an entirely


new family of 80C51 successors that have a number of pins ranging from
8 to 80 and are all based on an (in-system-programmable) flash memory.
An important characteristic of the controller is that despite a large number
of new features it is still fully compatible with the 80C51.

That the 80C51-based controllers are


extremely popular is nothing new, certainly
when considering the large number of
designs that have appeared in this magazine
over the years. The reason may well be the
fact that the tools (both hardware and soft-
ware) that are available for this controller are
very affordable and there is an enormous
amount of information readily available. In
addition, a very active forum provides
answers to many questions.
Philips, one of the biggest players in the
80C51 field has, with the part number
P89LPC900, recently breathed new life into
this architecture and improved the controller
family to the point that its lifespan has been
extended for many more years.
In this article we will describe the archi-
tecture of the P89LPC900. In a follow-up tion and EMI. The P89LPC900 is onator or external clock signal is con-
instalment we will publish a simple pro- therefore very appropriate for low- nected directly to the CPU and also
grammer/I/O-board. energy designs such as battery-pow- to the peripherals. In contrast, the
ered devices. On average, the current P89LPC900 has a much more elabo-
consumption per MHz is not much rate mechanism, which allows the
The heart of the controller lower than before, but you do get a user to determine where the clock
One of the most significant features of the six times improvement in perfor- source comes from and how it is to
P89LPC900 is that the core now requires only mance. In practice, this means that be presented to the CPU and periph-
two clock cycles per instruction. 8051 the crystal frequency can be drasti- erals. A standard, and in the context
experts will already know that this used to be cally lowered. The lowest possible of microcontrollers, very accurate
12 or 6 cycles until now. But to be fair, it needs current consumption, by the way, is internal RC oscillator (2.5% over the
to be mentioned that the maximum clock fre- only 1 µA. entire temperature range) will in
quency has been reduced to 12 MHz (167 nsec many cases suffice as the clock
per instruction). The net improvement is still source. Even a UART will generally
more than a factor of two, compared with pre- The clock operate very well with this kind of
vious solutions that used to run at 33 MHz. Most of the existing 80C51 con- accuracy. In the event that the
The improved performance at lower crystal trollers have a relatively simple clock requirements are more stringent, the
frequencies is beneficial to power consump- distribution circuit. A crystal, res- processor offers the option of mea-

42 Elektor Electronics 10/2003


GENERALINTEREST
P89LPC900 partly consists of a section that
can be directly or indirectly addressed (256
bytes) and, depending on the type, can be
supplemented with a section of external
data. The name may imply that this is external
to the device, but in the case of the
P89LPC900 it is definitely inside. The impli-
cations for the code are that the MOVX-
instructions are required for access. A recent
type, such as the P89LPC932, has, for exam-
ple, 758 bytes, of which 256 bytes are
direct/indirect and 512 are ‘external’.
The code memory, based on flash technol-
ogy, is not only repeatedly programmable, but
can also be programmed In System (ISP) and
even In Application (IAP). For this purpose,
Philips provides a bootloader which can be
easily activated and communicates via the
UART by default. An RS232 level shifter is all
Figure 1. Complete overview of the clock distribution of the P89LPC900. that is required to download the code from a
PC. Esacademy provide the necessary soft-
ware (Flash-Magic), which uses a simple user
suring the frequency at the clock when performance is not that impor- interface or command line (for production pur-
output and fine-tune it with the aid tant, but current consumption plays poses, for example) to send the hex file to the
of the TRIM register. Note that a a more significant role. Figure 1 processor.
nominal frequency of 7.3728 MHz gives a complete overview of the The internal bootloader consists partly of
was selected, which is a very appro- clock circuitry. built-in, low-level code that takes care of the
priate value in order to generate all interaction with the memory, and partly of a
the known baud rates. program in flash that deals with the commu-
To be able to trade off perfor- The memory nications aspect and the translation of the
mance and current consumption, the The P89LPC900 is a complete hex file. The programmer can quite easily use
user can switch ‘on the fly’ to embedded controller, which means the low-level subset of the bootloader by
another frequency by changing the that no external memory can be writing to a few registers and executing a
prescaler. Even the separate oscilla- addressed (unless this is done via ‘call’ to a specific address. In this way you
tor for the watchdog can serve as SPI or I2C, of course). can write your own implementation of a boot-
the clock source during moments The data memory (RAM) of the loader, which, for example, does not commu-
nicate with the UART, but uses some other
method chosen by the programmer. This new
bootloader can replace the standard one. Fig-
ure 2 shows how a call to the IAP subset is
realised in practice.
The memory consists of pages of 64 bytes
each. The pages assemble into 1k sectors.
Pages and sectors can be individually erased,
with an impressive erase time of only 2 ms.
Also note that when programming the flash
memory, no additional programming voltages
are required. The second article will treat the
subject of programming the flash memory in
more depth. It may not be necessary to men-
tion this, but the code memory can be pro-
grammed with a parallel programmer as well.
In addition to the usual data and code
memories, the P89LPC900 also has an EEP-
ROM memory (64 to 512 bytes). The EEPROM
is accessed via a number of registers (pointer,
data and status), so that it is not necessary
to write specific communications code, as
required for some controllers when the EEP-
ROM is accessed via the I2C bus.
The P89LPC900 also has a number of spe-
Figure 2. Here you can see how a ‘call’ has been realised to the IAP subset. cial memory locations: the bootvector, the sta-

10/2003 Elektor Electronics 43


GENERALINTEREST
Power management
We mentioned before that the speed
of the processor can be changed
dynamically. For circuits that require
even lower power consumption,
there is the option of placing the
processor in either Idle or Power-
down mode. In both modes, the core
itself is halted. The difference is that
in Idle mode the peripherals con-
tinue to run, while in Power-down
mode everything is stopped. The
sources that can re-activate the
processor differ for each mode. In
Figure 3. The user of the P89LPC932 can make use of 4 compare outputs and 2 Idle mode a timer can re-activate the
capture inputs. processor, but in Power-down mode
only an external/keypad or compara-
tor interrupt can do this. Note that
tus byte and the configuration byte. The which ensures that an interrupt (or a the watchdog can continue to run in
bootvector determines the starting location wake-up) is generated only when a Power-down mode, although this
when the chip is in boot mode. This vector is specific pattern appears. will increase the power consumption
initially factory programmed to point to the Five pins have, in addition to the somewhat.
internal bootloader. The status byte deter- digital I/O, an analogue comparator
mines whether after reset the user code or function. Two comparators with a
the boot code is activated. In this case the ini- selectable reference (internal or Timers and counters
tial value is again such that the boot code will external) and switchable inputs can The P89LPC900 has the well-known
be executed. be used to compare signals and use timer/counter 0 and timer/counter 1,
the results to generate an interrupt. which are more or less standard on
The last byte in this category is the con- There are also versions with an 8- or every 80C51. New is the fact that the
figuration byte. It is used to select the 10-bit ADC. timers have an additional operating
desired clock source, the function of the When using the reset pin, take mode, which can be used as a ‘poor
reset pin and the system supervisory set- note of the alternative function of man’s PWM’. Registers THx and TLx
tings. The locations can also be accessed via this pin. Even though the pin is together determine the frequency
ISP and IAP. defined as an input after power up, and duty cycle. There are, inciden-
this pin is still sampled during reset. tally, versions (the P89LPC932 for
In the event that this pin is perma- example) that have a very compre-
In- and outputs nently ‘low’ the processor will not hensive capture/compare unit with
Because the P89LPC900 has an internal start up properly. In contrast to pre- 16-bit resolution and a 32xPLL (refer
RC-oscillator and a Power-On-Reset circuit, vious 80C51 controllers, the Figure 3). This provides the user
the basic rule is that the number of pins P89LPC900 has an active low reset! with 4 compare outputs, which per-
available for I/O is equal to the number pins mit all kinds of wave shapes, and
on the package minus 2 for the power sup- two capture inputs. This module can
ply. In almost every case all the port pins System supervisory be used to drive a stepper motor, for
can be programmed as Input, Open-drain, The P89LPC900 is provided with all example, or control an H-bridge. A
Push-pull or Quasi-bidirectional. Excep- the features with regards to ‘System (noise filtered!) Brake input allows
tions are the pins for the I2C bus and reset Supervisory’ functions. In the past the option of hardware intervention
input. These have a different configuration a significant additional expense had in the event there is a need to imme-
because of their dual functionality. Once the to be made for external components diately stop a stepper motor, for
processor has started, all pins are set to that perform the same functions. instance.
input. Two registers for each port (PxM1 Fortunately, they are now built in. In addition to the timer/counters,
and PxM2) together define the desired con- The P89LPC900 has a Power-On- the P89LPC900 is also provided with
figuration. For the analogue functions there Reset/Detect, a Low-Voltage an RTC. This is a convenient way to
is a third register to ensure that the digital Detect and a Watchdog. The latter keep track of elapsed time, without
circuitry is completely decoupled from the can, because of its separate oscilla- sacrificing another timer. Figure 4
relevant pin. tor, also function as an Oscillator illustrates its operation.
Naturally, a number of pins have more than Fail Detect. The activation of any of
one function (for communications, among oth- these functions does not necessar-
ers) and a few are suitable for interrupts. A ily result in a reset, but can gener- Communications
group of eight port pins is available that can ate an interrupt instead. A soft- The P89LPC900 has also acquired a
be used as a keyboard-interrupt. This mech- ware-reset can then perform this range of new features in the area of
anism is also provided with a Pattern Match, task, if appropriate. communications. One of the more

44 Elektor Electronics 10/2003


GENERALINTEREST
notable new features is the presence
of a separate baud-rate generator
for the UART. In the past it was nec-
essary to sacrifice a timer for this
purpose, which limited further use of
this timer to whatever frequency it
had to run at.
The UART also has a break-detect
mechanism. This makes it possible
to, for example, activate the boot-
loader in a very simple manner. The
user can now, without any effort,
program the processor from within
the programming environment. The
Flash-Magic software has a facility
to make this happen. Figure 4. The standard RTC peripheral keeps track of elapsed time.
The I2C-interface complies with
the 400-kHz standard and is byte-
wide implemented, which greatly package or, alternatively, you can with unusual peripherals such as CAN and
simplifies the code for the various easily write one yourself. USB have been planned.
I2C-modes and makes it less critical. On the Esacademy web site you Noteworthy are the 8-pin versions. Philips
A state machine can make use of should be able to find ‘Code-Archi- has decided to release a range of 8-pin
the codes that are returned by the tect’ by the time this issue of Elek- devices into the market. It is simply the case
I2C hardware. This is an easy way to tor Electronics is published. This that with 8 pins you don’t get a great deal of
determine the progress of the I2C- tool can generate online code for choice regarding the peripherals. The various
transfer and decide what the next various peripherals, without having devices will therefore feature different com-
step should be. Philips provides a to consult the data sheet. The code binations of peripherals.
detailed description in the user man- can then be processed further in a C Philips has done well to introduce a range of
ual as to which states belong with compiler. products on the market that have the same or
which mode (Master transmit/ Although the entire P89LPC900 greater functionality and are pin-compatible
receive, Slave transmit/receive). By family is available with flash mem- with the popular P87LPC76x, for example,
the way, the I2C-interface is compat- ory and code is readily repro- which are only available in OTP versions.
ible with earlier devices such as the grammed, an ‘in-system-emulator’ The P89LPC900 are available in several
P8xC554. can drastically reduce the develop- different packages, but the emphasis will be
Even the SPI interface hasn’t ment time and generally make life on smaller packages such as the TSSOP (only
been forgotten. Communications at much easier. There are a number of 9.8 × 6.6 mm for the 28-pin version). The
a speed of 3 Mbit is possible with a manufacturers that offer emulators smaller technology (0.35 micron) and the fact
wide range of SPI devices. The SPI for these controllers (Philips, ESS and that they are in-circuit programmable con-
interface can be configured for either Keil). the Keil emulator is remarkable. tribute to this. Fortunately, there are more
master or slave operation. For the amount of only 199.00 euro practical package options for experimental
(approx. £140), Keil supplies a fully- work. In the project to be described in Part 2,
fledged emulator, including a C com- the PLCC28 version has been used.
Interrupts piler with a 4 K limit. These tools all (030161-1)
A large number of interrupts (15 on have a USB connection, so that, up to
the P89LPC932) can be utilised to a point, an external power supply
facilitate the smooth operation of the can be omitted. For hobbyists who
program. The interrupts have, by do not want to spend this much Useful websites
default, a pre-determined priority, money, the design to be described in
but the user can divide them into Part 2 of this article will provide an www.philipsmcu.com
four different levels. The interrupts alternative solution. Philips 80C51-controllers and additional infor-
can be activated or deactivated indi- mation such as application-notes and entry to
vidually as well as globally. the forum.
The family www.esacademy.com
Tools for the 80C51 such as Flash-Magic and
The number of P89LPC900-deriva-
Development tools tives is growing at a great pace. At
Code-Architect.
www.altium.com
Because the P89LPC900 still has an the time of writing, it appears that C-compiler, demo software limited to 2 K
80C51 core, an assembler or com- Philips has chosen to fill the cate- code can be downloaded.
piler from the early days can still be gory of up to 28 pins first with the www.keil.com
used to write software for this fam- P89LPC900, (there are, after all, sev- C-compiler, demo software limited to 2 K
ily. The only thing that has changed eral flash-controllers in the higher code can be downloaded.
is the required register file. This may category already) before producing www.pds51.com
be part of the assembler/compiler the larger devices. Even controllers Hardware tools for 80C51.

10/2003 Elektor Electronics 45


MICROPROCESSOR

The P89LPC900 (2)


Part 2 (final): practical application
M. Stottelaar Eurodis Texim Electronics

In this second instalment we will look at the actual application of this


microcontroller in greater detail. Notably the ‘in system programming’
functionality is described in detail. In addition, a practical design is
presented that not only functions as a programmer for the controller, but
as a prototyping board as well. As an example project, guided by an
application note from Philips, a very good ADC can be built without
requiring any additional peripherals.

Addition to Part 1 (October 2003)


Hitex are the sole distributor of the
Keil/Philips LPC kits the UK. The kits are
available from www.hitex.co.uk/shop.
We thank Mr. Chris Hills of Hitex UK for
bringing this to our attention.

Flash memory
Many of you will recognise the
ceramic microcontroller with a glass
window. These are the UV erasable
versions that were (and sometimes
still are) used during the debugging
stage of the application software. An
expensive solution indeed, but the
alternative, the burning of one-time
programmable (OTP) devices was
often more costly and far from flexi-
ble. The arrival of multi-time pro-
grammable flash (MTP) has made
the UV-erasable type mostly obso-
lete. With that, the relatively long UV
erasure time is now also a thing of
the past.
Despite this large step forward,
there is another highly desirable fea-
ture: it would be very nice if the
microcontroller could be pro-
grammed and erased while it

30 Elektor Electronics 11/2003


MICROPROCESSOR
VDD voltage during programming, so there is no
need for an additional programming voltage.
t RH The next few paragraphs provide more detail
t VR
about the inner workings of the various ele-
RST
ments.
t RL 030161 - 12

In System Programming (ISP)


Figure 1. Three specific pulses at the Reset pin put the chip in boot-mode. When it leaves the factory, the P89LPC900
has been pre-programmed with an enabled
boot loader. When power is applied the
remains in the application circuit. In essary are a PC running a small microcontroller is ready to receive the appli-
particular with SMD packages this application and a level shifter to con- cation code. After the code has been sent, the
very desirable of course. And if it vert the RS232 signal levels to TTL microcontroller is switched to user-mode, so
were also possible to replace the logic levels. All the programming that the application code will be executed fol-
code ‘in the field’, then all of our functionality is controlled by two lowing the next reset.
wishes would have come true. pieces of code that reside in the There is, of course, a method to return the
microcontroller. The low-level part microcontroller to boot mode again. The
takes care of the actual reading and P89LPC900 actually has multiple methods to
Two pieces of code writing of the memory, while the do this, two of which will be described here.
All the recent versions of microcon- high-level part (boot-loader) provides A third method is outside our scope; it is also
trollers from Philips Semiconductors for the communications via the possible to put the processor in boot mode
have the option of being (re)pro- UART. The low level functions are using a parallel programmer.
grammed while fitted in the circuit, available to a programmer and can The first method of putting the chip in
and this includes the P89LPC900 be used to write your own boot boot mode is to apply three specific pulses to
series. Because nearly all versions loader, which would be able, for the reset pin of the processor. In practice, the
have at least one UART, this is an example, to reprogram the micro- serial port of a PC can be used to generate
eminently suitable method to pro- controller via a CAN-network. these pulses. In addition to the usual RxD and
vide the microcontroller with code. The P89LPC900 is incidentally quite TxD signals a third line is required to gener-
The only other things that are nec- happy with only one power supply ate these pulses (refer to Figure 1).
The second, possibly even simpler,
method uses the Break Detect function of the
microcontroller. If this function has been
enabled, the TxD line from the PC can put the
microcontroller in boot mode. This means that
the Break Command has to be sent to the
microcontroller. This is certainly a very con-
venient method during the debugging stage of
the software development cycle, particularly
if the UART is accessible to the world via a
sub-D connector. However this method also
has its risks. The wave shape for the Break
signal is rather simple and there is a signifi-
cant risk that the controller will inadvertently
enter boot mode. It is therefore recommended
to disable this feature when the project has
been completed. Software examples for
enabling the break detect feature can be
found in the application notes from Philips.
In part 1 we mentioned that Flash Magic
(refer to Figure 2) is the name of the PC soft-
ware used to program the microcontroller.
This software is maintained by ESACADEMY
(www.esacademy.com) and is periodically
updated with a new list of microcontrollers to
be programmed. The design is very simple
and the environment has the look and feel of
a typical programmer (note that Flash Magic
is also suitable for other derivatives from the
80C51 family from Philips).
The circuit described below is suitable for
Figure 2. Menu structure of Flash Magic. use with Flash Magic and includes all the fea-

11/2003 Elektor Electronics 31


MICROPROCESSOR
+UCC code needs to remain active
JP1
D3 R9 during this process in order to
maintain the communications

1k
RUN
channel. However, using seg-
R13 R8
C2 C15 C16
D2
mentation, all the code can be
4k7

1k
+UCC 100n 100µ 100n replaced in two or more steps
25V
(in many cases the system soft-
K4 IC4
21 9
DS
K1
V+
ware can be left unaltered
26
P0.1 P2.6
27 1
I1 O1
16 because it is generally sub-
25 5 2 15 +UCC
ADC 24
P0.2
P0.3 IC1
P1.6
P1.7
4 3
I2
I3
O2
O3
14 jected to fewer changes than
output
23
P0.4 P2.1
2
20
4
5
I4 O4
13
12
the actual application code).
P0.6 I5 O5 R2 R3
P0.7
19 6
I6 O6
11
K2
A practical description of

10k

10k
16 7 10
P2.5 I7 O7 I2 C the IAP operation may be found
K5 GND
28
P2.7 8 SCL
on the Elektor Electronics web-
1 ULN2003
input 15
P2.0
12
SDA site under Free Download file
P2.4 P1.2/SCL
P1.3/SDA
11 number 030161-2 (November
10
K3
P1.4
P2.3/MISO
14 2003) on www.elektor-electron-
R1
3
P0.0 P2.2/MOSI
13
ics.co.uk.
P89LPC932BA
100k

18
P1.0
17
P1.1
22
P0.5 P1.5
6

JP2
SPI The hardware
X1 X2
7 8
X1
9
+UCC That was enough theory for
S1 RESET
now. The circuit shown in Fig-
C1 C3 C4
R7 13
+UCC ure 3 makes it possible to get
IC3.D
47k

33n 22p 22p ≥1 started with the P89LPC900


11.0592MHz

+UCC
11 12
T1 family in a practical way. The
R10
C7
R6
10k design supports the previously
47k

R4
100n
+UCC
IC3.C
BC557 mentioned ISP and IAP facili-
47k

3 8
K6 2 V+ 17 9 ≥1 10 ties, so that the testing of your
C1+ +UCC
1
C5
18
4 D1
IC5 own programs can be realised
6 4 SHDN
1N4001
2
100n C1–
IC2
≥1
IC3.B
LM317T very easily. A C compiler, for
15 12
7
14
T1 T1I
13 5 6
+UCC
R12 example, can be used for the
270Ω

3 R1 R1O
8 5
C2+
K8 development of the software. If
C6
4
MAX3222
C9 C14
R11
you don’t have a compiler, one
9 RTS 100n 6
C2–
100n 10µ C11 C10 C12 C13
can easily be downloaded from
270Ω

5 R5 14
1 16 16V C17
EN IC3
47k

V-
7
100µ 100n
16V
100n 100µ
16V
the Internet (for example Task-
SUB D9 IC3.A 100n P1
2
1
7
C8 100Ω ing or Keil). In general these are
3 ≥1
100n IC3 = 74HC02 ‘full featured’ demo versions,
030161 - 11 but limited with respect to the
maximum generated code size.
Figure 3. The schematic for the programmer and prototyping board. However, a 2k limited version is
often adequate to write a realis-
tic application. Also, the ‘Code
tures for putting the microcontroller in boot- troller without replacing the IC itself. Architect’ from Esacademy can be
mode. Flash Magic can also be operated from Of course, the ISP method is a possi- very helpful when first treading in
the command line. This makes enables you to ble solution in these situations. But 80C51 territory. Using this tool, you
use this tool as part of an automated produc- what about an environment where can interactively write code for the
tion process. there is no technical know-how or P89LPC932 that has been used in
It is also possible, of course, to write your nobody is actually present? this design. This member of the fam-
own programming environment to suit your In all these situations, the IAP- ily is part of a whole range of con-
own unique requirements. For this purpose, method can be used to replace the trollers with 8 to 28 pins and also
the Intel Hex strings are supplemented with code using a method chosen by the available in PLCC packages.
additional instructions. It is beyond the scope application programmer. The com- To maximise the functionality of
of this article to describe all these instruc- munications method can be selected the board, all the I/O from the micro-
tions in detail, but the P89LPC932 user man- to suit the environment (telephone controller has been brought to the
ual provides all the necessary information. line, Internet, RF, etc.). The principle outside and is available for use. The
is very simple. The programmer combination of the serial interface
defines the communication method and analogue and/or digital I/O can
In Application Programming and makes use of the so-called IAP easily be put to practical use to col-
(IAP) calls in the microcontroller to carry lect measurements with a PC or con-
In some high-end applications, there may be out the actual erasing and writing trol some outputs.
a need to replace the code in the microcon- operations. Obviously, part of the In order to program the microcon-

32 Elektor Electronics 11/2003


MICROPROCESSOR
troller, the simplest connection
T T

SCL
SDA
030161-1 SPI output

+
V+
D2
between the PC and P89LPC932

H2
H3

R9
K6 K2 K3 K1 D3
could consist of a single RS232 level I2C R8
C7 C15
shifter that we have used on many C9 C14 C4 C3
C5
previous occasions in Elektor Elec- S1
IC4

1-161030
tronics designs. The RXD and TXD X1 C16

IC2
lines from the PC and P89LPC932 are C8 JP2
K5 T
C6
simply connected via the level

R13
R3
R2

input
shifter. In this design we have cho-

R4
IC1
sen for a slightly more elaborate C17

JP1
R10
setup. Not only are the RXD and +

3002 rotkelE )C(

R5
TXD lines connected, but some addi- K8 C10 C1 C2

T1
D1
tional signals as well, to provide a 0 R1

IC3
K4
T
safe method of switching the pro- C11 ADC +

R6
R7
grammer on and off, and for generat- P1

ing the clock pulses at the reset pin C12

R12
R11
(for reboot).

H4
H1

C13
IC5

COMPONENTS LIST
Resistors:
R1 = 100kΩ
(C) Elektor 2003

R2,R3,R10 = 10kΩ
R4...R7 = 47kΩ
R8,R9 = 1kΩ
R11 = 390Ω
R12 = 270Ω
R13 = 4kΩ7
P1 = 100Ω preset V

Capacitors:
030161-1

C1 = 33nF
C2,C5-C10,C12,C16,C17 =
100nF
C3,C4 = 22pF
C11,C13,C15 = 100µF 25V radial
C14 = 10µF 16V radial

Semiconductors:
D1 = 1N4001
D2,D3 = low-current LED
T1 = BC557
IC1 = P89LPC932BA
IC2 = MAX3222CPN
IC3 = 74HC02
IC4 = ULN2003
IC5 = LM317T

Miscellaneous:
JP1,JP2 = jumper
K1 = 8-way SIL pinheader
K2,K5 = 4-way SIL pinheader
K3 = 5-way SIL pinheader
K4 = 6-way SIL pinheader
K6 = 9-way sub-D socket
(female), PCB mount
K8 = 2-way PCB terminal block,
lead pitch 5mm
S1 = pushbutton, one make
contact
X1 = 11.0592MHz quartz crystal
PCB, available from The PCBShop
Figure 4. There is plenty of room on the PCB for your own applications.

11/2003 Elektor Electronics 33


MICROPROCESSOR
signal levels if they do not conform
to the input requirements of some
optional external chips.
The power supply of the circuit is
a very simple design. We chose an
LM317 (IC5) with a trimpot, because
it is more readily available than a
fixed 3.3V-regulator. Before placing
the processor in its socket check that
the power supply voltage is around
3.3 V, adjustable with P1.

Construction
Figure 4 shows the (double sided)
PCB designed for the prototyping
board. The layout is quite spacious
and conveniently arranged, so that
even less experienced hobbyists
will have no problem with the con-
struction, provided you stick to the
component overlay and parts list.
Microcontroller IC1 is fitted in a
special PLCC socket. The various
Figure 5. The construction of the prototyping board is a relatively simple job. connecters have been placed near
the edge of the PCB as much as is
possible.
IC2 converts the signal levels and is pro- sigma-delta converter to be A section beside the controller
vided with an enable input, which causes the described later on. P0.1 through P0.4 has been deliberately designed as
chip to go completely off-line when the DTR are used as analogue inputs for this prototyping board. This provides an
signal is no longer active. The DTR line is also purpose, so that a four-channel ADC easily accessible space for your own
used, via IC3 and T1, to switch the power sup- is created. Fitting C3, C4 and X1 is applications. In this way you can
ply voltage to the P89LPC932 on and off dur- not strictly necessary, because the carry out a lot of different experi-
ing the programming session. The three pulses processor has a sufficiently accurate ments without immediately having
that are required to put the microcontroller in RC oscillator built in. These connec- to make another PCB.
boot mode are generated using the RTS line tions can be used as digital I/O. The A standard 9-VDC mains adapter
from the PC, combined with the TXD signal. signals for both I2C and SPI are also can be used to power the entire cir-
brought out to pins so that many cuit. There are no specific require-
popular chips can be connected ments for the adapter, since IC5 pro-
A few more schematic details directly. vides voltage regulation and the cur-
R1 and C1 form the circuit that’s used for the The four compare outputs (pins 2 rent consumption of around 20 mA is
through 5 of K1) and another three not very large. Diode D1 prevents an
ports are buffered and made avail- incorrectly connected adapter caus-
able via IC4, allowing relays or sim- ing damage to the circuit.
VCC
ilar to be controlled directly. Port P2.6
(pin 2 on K1) is fitted with an LED
(D3) that can be useful during soft- The programming
CHANNEL 1
CHANNEL 2
ware development. The remaining After everything has been put
ports, including P2.7, P2.0 and P2.4 together and carefully checked, the
are available as general-purpose I/O PCB can be connected to the power
(on K5). supply and serial port. Use the fol-
CHANNEL 3
Note that P1.5 can never be con- lowing jumper settings:
CHANNEL 4
figured as an output and in this
application is only used as Reset. During Flash During Run-
R A pushbutton (S1) is connected to Magic mode
P0.0
C port 1.4. This could be used, for JP2 Fitted Removed
example, to test the software exam-
ple of boot-mode via IAP. Even JP1 Removed Fitted
030161 - 14
though the processor is a 3-V type, Reset and
User-reset and
all the inputs and outputs are toler- power con-
N.B. uncontrolled
trolled with
Figure 6. The switchable comparator inputs ant of 5-V signals. It may be neces- power
Flash Magic
provide the option of four ADC channels. sary in some cases to convert the

34 Elektor Electronics 11/2003


MICROPROCESSOR
Although Flash Magic is a program reset pin. With these devices you Note AN10187Ω1, available from the Philips
that’s self-explanatory to a large will always have to make use of website provides all the necessary informa-
extent, it is worthwhile to take a either the Break Detect or IAP tion. But, briefly, the circuit operation is
quick look at the settings related to method. So be careful and convince essentially as follows: C1 on the reference
Start Bootrom in the ISP menu. A yourself that your code is correct. input is charged via R1 until the level is equal
number of things depend on The only method of escape once to the input of the comparator. From then on,
whether Break Detect or Pulses on you’re stuck is by using a parallel the charge/discharge cycle is controlled by
Reset Pin is used. The latter option programmer to clear the chip after a the result from the comparator. The number
will always work, provided the reset mistake. Fortunately only a small of charge cycles is proportional to the com-
jumper is fitted and in the menu number of these devices have been parator input voltage. By counting the num-
‘Options/Advanced Options/Hard- manufactured. ber of charge cycles during a predetermined
ware Config’ the tickbox ‘Use DTR number of cycles (charge and discharge) the
and RTS to enter ISP-mode’ has been level of te input voltage can be determined.
ticked. The other method will only ADC For a more detailed description and back-
work when the (running) code has As already mentioned, the above ground theory we refer you to the aforemen-
provision for this option, as design has a feature that allows an tioned application note.
described earlier. ADC to be realised even though the
Ex factory, the boot-loader is P89LPC932 does not have an on-
already enabled so that loading the board ADC. The principle of opera- In conclusion
first program will succeed even tion is based on the Sigma-Delta It would go too far to describe all the details of
without explicitly enabling the boat method. The two analogue compara- the P89LPC932. Fortunately, there is plenty of
loader. Consult the accompanying tors that are standard peripherals on code available for the 80C51 (often well doc-
PDF-file for more instructions with this controller are employed for this umented in application notes). In addition,
regard to Flash Magic. purpose. Because each comparator new application notes frequently appear on
Attention: up to version C of the has a selectable input (refer to Fig- the Philips website, explaining the details of
P89LPC932 it was not possible to ure 6), it becomes possible to make specific peripherals.
activate the boot loader using the a four-channel ADC. Application (030161-2)

11/2003 Elektor Electronics 35


APPLICATIONNOTE
The content of this note is based on information received from manufacturers in the electrical and electronics industries or
their representatives and does not imply practical experience by Elektor Electronics or its consultants.

TinyLogic ICs Type


NC7SZ57/58
Configurable logic gates
Source: Fairchild Semiconductors

The thing about these TinyLogic integrated circuits from Fairchild’s UHS
series is that they allow up to five different gate combinations to be
created, including versions with two identical inputs, or an inverting and
a ‘true’ input.

Fairchild’s ‘TinyLogic’ family was very high switching speeds. Com-


originally introduced about five years pared with ‘ordinary’ HC logic the
ago. The series comprises a wide speed of the NC7SZ devices is more
range of single and dual gate logic than twice as high at just 2.8 ns typ-
functions in a number of small SMD ical (at 5 V supply voltage). Another
enclosures (hence ‘tiny’). Compared extremely welcome characteristic of
with the commonly seen ‘small out- these ICs is that their outputs can
FIGURE 1. 2-Input AND Gate
line’ cases of similar CMOS ICs, supply a current of up to 32 mA.
TinyLogic devices offer considerable This makes them suitable for direct
space savings on printed circuit driving of LEDs, optocouplers and
boards. low-power relays.
All members of the TinyLogic
family are marked by high speed and
low power consumption. These fea- One IC, five functions
tures, in combination with their Notwithstanding the great value of
small size, make the devices emi- the above mentioned specifications,
nently suitable for application in undoubtedly the most striking thing
FIGURE 2. 2-Input NAND with inverted A Input
portable equipment like portable about the NC7SZ57 and –58 is that
CD-players, GSM phones, PDAs and each of these can be configured for
laptop computers, where space is at five different logic functions. Simply
a premium. by ‘rearranging’ the connection of
Within the family, a number of the output pins, the IC allows all
sub-series may be identified: HS, HT, standard logic functions with two
UHS and, recently, the ULP series. inputs to be implemented. The inset
The respective acronyms stand for table and the associated Figures 1
‘high speed’, ‘high-speed TTL com- through 10 illustrate how this may
patible’, ‘ultra-high speed’ and ‘ultra- be achieved in practice.
FIGURE 3. 2-Input NAND with inverted B Input
low power’. The devices discussed Figures 1 through 5 cover the
in this article belong in the UHS NC7S57 and Figures 6 through 10,
Figures 1-10. Overview of TinyLogic series which is marked by a supply the NC7SZ58. All inputs feature hys-
configuration options. voltage range of 1.65 V to 5.5 V and teresis.

46 Elektor Electronics 10/2003


APPLICATIONNOTE

Table 1. Configurations
2-Input Logic Function Type Circuit
2-Input AND NC7SZ57 Figure 1
2-Input AND with one inverting input NC7SZ58 Figure 7, 8
2-Input AND with two inverting inputs NC7SZ57 Figure 4
FIGURE 4. 2-Input NOR Gate
2-Input NAND NC7SZ58 Figure 6
2-Input NAND with one inverting input NC7SZ57 Figure 2, 3
2-Input NAND with two inverting inputs NC7SZ58 Figure 9
2-Input OR NC7SZ58 Figure 9
2-Input OR with one inverting input NC7SZ57 Figure 2, 3
2-Input OR with two inverting inputs NC7SZ58 Figure 6
2-Input NOR NC7SZ57 Figure 4
2-Input NOR with one inverting input NC7SZ58 Figure 7, 8
2-Input NOR with two inverting inputs NC7SZ57 Figure 1 FIGURE 5. 2-Input XNOR Gate

2-Input XOR NC7SZ58 Figure 10


2-Input XNOR NC7SZ57 Figure 5

User friendly the print on the device tells us the


location of pin 1. If the print is legi-
The TinyLogic ICs come in an ‘SC70’ ble, pin 1 is below at the left.
SMD case which is only 2 mm long! When designing a PCB and con- FIGURE 6. 2-Input NAND Gate
The pin connections are shown in structing a circuit, there are certain
Figure 11, while the pin states are advantages to having just one gate
listed in a separate table. in one integrated circuit. For exam-
Remarkably, and in contrast with ple, the logic gate may be inserted
what we would expect, each Tiny- directly in the signal line, without
Logic gate has its own case. It is having to run tracks up and down
also unusual that the case does not the board to a central IC containing,
have a mark to identify pin 1. Here, say, four such gates. The result is
FIGURE 7. 2-Input AND with inverted A Input

Table 2. Electrical Data


Absolute Maximum Ratings
DC Electrical Characteristics
Supply Voltage (VCC) –0.5 V to +7.0 V
DC Input Voltage (VIN) –0.5 V to +7.0 V
FIGURE 8. 2-Input AND with inverted B Input
DC Output Voltage (VOUT) –0.5 V to +7.0 V
DC Input Diode Current (IIK)@ VIN ≤ 0.5 V –50 mA
DC Output Diode Current (IOK) @ VIN ≤ –0.5 V –50 mA
DC Output Source/Sink Current (IOUT) ±50 mA
DC VCC or Ground Current (ICC / IGND) ±50 mA
Storage Temperature Range (TSTG) –65°C to +150°C
Max Junction Temperature under Bias (TJ) 150°C
Lead Temperature (TL) (Soldering, 10 seconds) 260°C
Power Dissipation (PD) @ +85°C SC70-6 180 mW FIGURE 9. 2-Input OR Gate

Recommended Operating Conditions


Supply Voltage Operating (VCC) 1.65 V to 5.5 V
Supply Voltage Data Retention (VCC) 1.5 V to 5.5 V
Input Voltage (VIN) 0 V to 5.5 V
Output Voltage (VOUT) 0 V to VCC
Operating Temperature (TA) –40°C to +85°C
Thermal Resistance (θJA) SC70-6 350°C/W
FIGURE 10. 2-Input XOR Gate

10/2003 Elektor Electronics 47


APPLICATIONNOTE
shorter connections with all the well-known
benefits for the actual operation of the circuit. SC70
Besides, PCB designers have more freedom in
doing the board layout, which does not Pin Descriptions
require a total redesign following every minor Pin Name Description
change to the circuit. I0, I1, I2 Data Inputs
Y Ou tput

(Top View)
Conclusion Function Table
Inputs NC7SZ57 NC7SZ58
Summarizing, we can say that these Tiny- I2 I1 I0 Y (I0) (I2) (I1) (I2) Y (I0) (I2) (I1) (I2)
Logic gates are a useful addition to the usual L L L H L
collection of logic components. TinyLogic L L H L H
L H L H L
devices are small, fast, economical and their L H H L H
ease of configuration makes them really ver- H L L L H
AAA Product Code Top Mark - see ordering code
satile. H L H L H Note: Orientation of Top Mark determines Pin One location. Read the top
H H L H L product code mark left to right, Pin One is the lower left pin (see diagram).
To close off this short article, we should
H H H H L
not forget to mention the main electrical H HIGH Logic Level L LOW Logic Level Pad Assignment for MicroPak
specifications of the NC7SZ57 and –58; see
the second table.
Those of you with a deeper interest in these
unusual but useful ICs are referred to the
TinyLogic datasheets published by Fairchild.
These may be downloaded free of charge 020353 - 12
(Top Thru View)

from this url:


www.fairchildsemi.com

(020353-1) Figure 11.Case, pinout and pin states.

48 Elektor Electronics 10/2003


COMPUTER

Wireless RS232 Link


Using licence-exempt Short Range Devices (SRDs)
Design by D. Langwald, P. Groppe and B. vom Berg

As we show in this article, off the shelf radio modules called Short Range
Device (SRDs) with an integrated microcontroller are here, making home
construction of a wireless RS232 link a reality for DIY constructors.

Wireless transmission of ‘information’, be it are not only easy to add to existing involving RF components is sure to
digital data, music or video, is sure to find equipment, but also certified and demand a lot of expertise, time and
wide application areas. Today, those of you complete with a manufacturer’s money, mostly due to three aspects:
with an active interest in ‘over-the-air’ tech- product warranty, not forgetting a
nology have a large number of options to suitable driver for the software link. – Developing an RF front end and
choose from, ranging from transmission of The alternative road is a bit more transmitter for the relevant fre-
infrared light pulses (remote controls, IrDA) exacting. For example, if an automa- quency range, observing the legal
right up to more challenging fields like RF tion component or a measurement limits for bandwidth, spurious radi-
applications called DECT, Bluetooth, Wireless system (sporting just about any ation and output power.
LAN and so on. For ‘large’ Windows comput- microcontroller) is to be upgraded – Certification or type approval of the
ers you can buy ready-made modules which with a radio link, a custom solution RF parts by an appointed national
or international regulating author-
ity, and paying the bill for the
paperwork.
– The design of a suitable data trans-
mission protocol to make sure that
interference due to external noise
and interference, moving objects,
reflections, indirect paths etc., can
be overcome by the system itself
— the requirements in this
respect are much higher than
with, say, an RS232 link using the
traditional cable.

An interesting alternative to the


above is available in the form of
cheap, off the shelf, type approved
and multi-purpose radio modules
operating in one of the allocated ISM
band (Industrial / Scientific / Medical)
and having a UART interface. In the
case of the module used in our pro-
ject, the ‘firmware’ for the data trans-
mission process is available from the
SRD manufacturer. Admittedly, con-
trolling the SRD in software using the
available firmware is not child’s play,
but it’s not rocket science either!

12 Elektor Electronics 12/2003


COMPUTER
Within the boundaries of the ISM IC1

bands (for example the pan-Euro- D1 7805 +5V

pean 433.05 – 434.79 MHz band) it is 1N4148 R1


possible (in many, but not all coun- K1

1K8
C1 C2 C3 C4
tries) to employ, licence-free, a type- > 7V
approved SRD with an ERP (effective 100n 10u 100n 10u D5
16V 16V
radiated power) not exceeding
POWER
10 mW.
As a matter of course, the manu-
facturer (but also the end user) of ANT
SRDs has to ensure that the product +5V
K4 K3
is compliant with rather strict regu-
RSSI
lations. In the Europe, for example, 2 1
C7
the standards for unlicensed use of RF GND ANT D2 D3
1u
8
SRDs in the 433/434 MHz band are VCC
2
16V
TxD RxD
laid down in EN300-220-3 and R2 R3 V+ 1
K2
IC3 16 C1+ C5 JP1
EN301489-3. Those of you interested 1

1K8

1K8
IC2
in the legal/technical aspects of SRD RSSI
3
C1–
3 1u 6
4 10 7 16V 2
type approval standards are referred BUSY
5 11
T2IN T2OUT
14 7
DATA OUT T1IN T1OUT
to the Low Power Radio Association 6 12 13 3
DATA IN R1OUT R1IN
(LPRA) which excels in supplying HOST RDY
7 9
R2OUT R2IN
8 8
4 4
information on SRDs at all levels as C9 D4 C2+ C6
9
well as in publishing a magazine ER400TRS JP2 15 MAX232
5 1u 5
100n BUSY C2–
and a website, the latter being 9 V- 16V
GND R4
posted at www.lpra.org. 6
RS-232
1K8

C8
Most SRD-based radio systems SUB D9
1u
employed in remote controls convey 16V

data, telemetry or alarm information


030204 - 11
across relatively small distances
(usually limited to a few hundred
metres ‘line of sight’ — LOS). In Figure 1. The external circuitry around the radio module comprises just a few parts, really.
some ISM bands, the transmission of
audio and video signals is allowed,
too. In everyday life, SRDs are used be able to build this interesting pro- BUSY (output)
in appliances like vehicle central ject. The four low-power (diagnostic) This signal indicates that the module is pro-
locking systems, outdoor wireless LEDs in the circuit indicate its main cessing commands (reception of data, error
thermometers, cordless mice and functionality: checking) and not capable of loading trans-
keyboards for the PC, wireless head- mitter data. In RS232 parlance, this corre-
phones, security cameras, and so on. LED D1: supply voltage sponds to the CTS (clear to send) signal.
The internationally used abbrevia- LED D2: data transfer: transmit The following states apply:
tion for such radio systems used to LED D3: data transfer: receive
be LPD (low-power devices) but that LED D4: state of BUSY line BUSY = 1: the ER400TRS is busy and no
seems to have evolved into the more transmit data should be conveyed to it on
modern SRD (short range device). The ER400TRS is driven with TTL penalty of being ignored (= lost).
signals, which forces us employ a
The UK-based firm Low Power level translator (here, a MAX232) if BUSY = 1: The ER400TRS is ready to accept
Radio Systems (LPRS) has a number the radio module is to be connected data and actually transmit them.
of ‘embedded-software’ SRDs in its to the COM port of an ordinary PC.
impressive range of licence-exempt The MAX232 (IC2) is not required in Jumper JP2 allows the BUSY signal to be
radio modules. One of these, the a microcontroller system if you are applied to the RS232 converter and from
ER400TRS ‘Easy Radio’ transceiver, absolutely sure the system UART there, to the host for processing by the PC
is used in our project — its main operates with TTL levels only. The software. Alternatively, the signal may be just
specifications and internal organisa- transmitted and received data are visually signalled by LED D4. If this control
tion are given in the inset. quite ordinary UART characters as signal is not actually processed by software
they occur in a standard serial asyn- or hardware, then provision must be made to
chronous (V24) interface like a COM ensure the ER400TRS is really ready to load
Little more port on a PC or a UART in a micro- and subsequently transmit data. In some
than the module controller system. cases, this means that delays following trans-
The circuit diagram of a complete mission and reception should be built into the
wireless data transmission system The ER400TRS offers two additional software, and be strictly maintained until the
as shown in Figure 1 proves that no hardware handshake control signals, next data block is sent.
special RF experience is required to whose use is not mandatory: Jumper JP3 enables the BUSY signal to be

12/2003 Elektor Electronics 13


COMPUTER
Easy Radio
ER400TRS Quick Data embedded software
Datasheet at: http://www.lprs.co.uk/main/viewdatasheet.php?datasheetref=112 The firmware running inside the
– Half-duplex FM transceiver ER400TRS module, and in particular
– 10 programmable channels the routines that look after the data
within 433.25 MHz and transmission protocols, are propri-
434.35 MHz(70 cms pan-Euro- etary, i.e., have been developed by
pean ISM allocation) LPRS themselves for their own prod-
– 50-Ω antenna connection ucts, hence do not reflect any kind of
– RF output power programmable international standard. The software
in 10 steps between 1 mW and that does it all is remarkably simple,
10 mW as well as easy to use from the out-
– Range 250 m line of sight (LOS) side. After all, when you are looking
or 30 m in buildings at ‘just’ a fast connection using sim-
– Data speed on host link: 2.4 to ple microcontroller systems, no com-
38.4 kbits/s, adjustable in five steps plex memory-hungry protocol stack
– Fixed 19.2 kbits/s data speed on RF link is required like the one required by
ER400TRS
– Two hardware handshaking signals RSSI
TCP/IP.
– RSSI (received signal strength) analogue output voltage
VCC
The embedded software of the
regulator
– Supply voltage 3.3 V to 5.5 V GND
ER400TRS is dubbed ‘Easy Radio’. It
– Current consumption at 5.5 V supply; RF
handles three important functions:
transceiver
– transmitting (10 mW): 23.0 mA
– receiving: 17.0 mA Ser. Data IN

micro-
Ser. Data OUT
1. parameter setting on the interface
– standby: 2.0 mA controller Host Ready
BUSY to the host (PC);
– Dimensions: 37.5 x 14.4 mm
030204 - 16
2. parameter setting on the RF parts;
3. executing the data transmission
protocol.
removed from the sub-D plug pin, which may interface and jumper JP1 in accor-
be necessary to prevent signal conflicts or dance with its timing requirements. The various parameters are loaded
contention. using ASCII command sequences
Finally, the ER400TRS puts analogue listed in the Easy Radio software
Host Ready (input) information regarding received sig- documentation. For example, the
This signal tells the module whether or not nal strength at your disposal. transmitter output power is stepped
the host is ready to load data from the receive down to 5 mW by sending the com-
buffer in the ER400TRS. Again, in RS232 RSSI mand string ER_CMD#P5 to the
terms this equates to an RTS (ready to send) (received signal strength indicator) radio module. An overview is given
signal, with the following logic states: The transceiver has a built-in RSSI in the text box ‘Easy Radio Function-
(Received Signal Strength Indicator) ality’. On www.lprs.co.uk/download/
Host Ready = 0: Host CPU is ready to load that provides an analogue output LPRS kindly supply a Windows-
and process the data that was just received. voltage that is inversely proportional savvy software tool that allows all
The module should respond by releasing the to the RF energy present within the ER400TRs parameters to be given
data to the host. pass band of the receiver. It ranges the desired values, and convey them
from 0 V (maximum signal, –50dBm) to the transceiver module.
Host Ready = 1: Host CPU not ready to load to 1.2 V (minimum signal, –105 dBm)
and process the data that was just received. In and has a slope of approximately Host interface parameters
this case the radio module should keep the 50 dB/Volt. This analogue output sig- The serial asynchronous interface
data in its internal receive register, taking nal should only be connected to a may be used at one of five different
into account that the data are erased no high impedance load (>100 kΩ) and (but very common) baud rates (2,400
sooner than 2.5 seconds after their reception. can be used to provide a measure of to 38,400 bits/s). Characters are
Within that period, the host must have the signal strength and any interfer- invariably transmitted and received
fetched the data (i.e., pulled Host Ready to ing signals (noise) within band dur- in UART format. This is only applic-
‘0’), else they are lost. ing the installation and operation of able to the relevant host, with the
When the host can be relied on to imme- systems. ER400TRS running at a factory-
diately fetch and process the received data, determined speed of 19,200 bits/s.
or if it has a sufficiently large receive buffer, The hardware links between the Hence the data speed on the radio
it is safe to permanent tie the Host Ready host(s) and the radio modules are link will always be 19.2 kbits/s.
input to ground using jumper JP1. In this way depicted in Figure 2. Because the
the ER400TRS is encouraged to immediately ER400TRS operates in half-duplex bi- RF section parameter
transmit received data. If, on the other hand, directional mode, both Host A and Here users have the opportunity to
the host is not quick to process received data, Host B can alternately transmit and select one of ten available radio
it may control this module input via its serial receive. channels (frequencies) between

14 Elektor Electronics 12/2003


COMPUTER
some more additional information (for exam-
ple, the number of data bytes). Next, all bytes
are Manchester-encoded and finally trans-
data transmission variable
between 2400 and 38400 baud mitted. During these activities, the BUSY line
of the ER400TRS is logic High.
Data IN At the receiver side the data are Man-
Data OUT chester-decoded, the extra information is sep-
arated and an error check is performed. Dur-
host radio module ing these activities, the BUSY line of the
computer with ET400TRS is logic High. In case data corrup-
ER400TRS tion is detected, all data is rejected and the
BUSY
receiving host does not get any data.
Host Ready
However, the transmitting host also does
RSSI
not get acknowledge information about the
rejected ‘telegram’. If it is required for the
only if
necessary host to have confirmation that all data has
been correctly received, then an acknowledge
9...12V 030204 - 12 process has to be implemented using the
max. 50mA
ER400TRS firmware.
If all data has been received okay, the data
Figure 2. Basic configuration of a radio station for data transmission and reception. are copied to the transmit/receive buffer in
the receiving ER400TRS. Next, the chip waits
for the receiving host to pull Host Ready Low
433.25 MHz and 434.35 MHz, where mission, until the ER400TRS flags (= RTS in RS232 terms). Following this the
the transmit and receive frequencies that it has finished its internal tasks, data are automatically and continuously fed
are always equal (i.e., no offset or thus allowing the host CPU to to the host via the serial link. If this type of
shift). release its data. Next, the data are handshaking is not required, the Host Ready
The transmitter output power can written into the module’s internal input may be permanently tied to ground
be adjusted between 1 mW and buffer, where they remain latched. using jumper JP2.
10 mW in ten steps. This may be The data are transmitted when In case the Host Ready signal is not pulled
useful to conserve battery energy either the buffer is full after continu- low within 2.5 s from reception of the data, all
when the module is used to cover a ous reception of 128 bytes (if more received data are wiped from the buffer and
relatively small distance. are sent to the chip on one go, the the ER400TRS is ready for transmission or
excess ones are discarded), or if a reception.
Data transmission pause occurs in the datastream after The data processing inside ER400TRS
protocol execution a byte is conveyed where the pause modules is invisible to the two hosts — all
The ER400TRS comprises a shared length is greater than two byte they need to do is supply and receive data via
128-byte transmit/receive buffer, via lengths. In this way, individual bytes their RS232 ports.
which the traffic is handled as fol- may be ‘broadcast’.
lows: Before the data leave the trans-
First, the Host transmitter CPU mitter a CRC (cyclic redundancy Antennas
checks if BUSY (= CTS on an RS232 check) is run to generate a CRC byte No specialist knowledge is required on RF
link) is Low. Alternatively, it should which is added to the ‘message’ technology if you want to set up SRD-based
idle a fixed time after the last trans- bytes, together with a preamble and data link like the one described in this article.
There’s one exception, though: the antenna.
The transceiver can be used with the var-
ious common types of antenna that match the
Easy Radio Functionality 50 Ω RF Input/Output such as a whip, helical
The embedded microcontroller looks after the following Easy Radio functions: or PCB/Wire loop antennas — see Figure 3.
Whip antennas are resonant with a length
– processing input and output data using a standard UART format (1 start bit, 8
corresponding to one quarter of the electrical
databits, no parity, 1 stop bit)
wavelength (λ/4). They are very easy to
– Manchester encoding/decoding of data for/from radio link
implement and can simply be a ‘piece of wire’
– Calculation and comparison of CRC checksum
or PCB track, which at 433 MHz should be
– Radio protocol monitoring and control: transmission of preamble and sync
about 15.5 cms in length. This should be
bytes, removal of these bytres when receiving
straight, in ‘free space’ (kept well away from
– Programming of receive/transmit synthesizer for channel selection
– RF output power programming
all other circuitry) and should be connected
– Operation of the external host interface at the desired baud rate directly to the Antenna pin of the transceiver.
– Storage of up to 128 bytes for receive/transmit buffer If the antenna is remote, it should be con-
– Operation of the two handshaking signals nected via a 50-Ω coaxial feeder cable
– Operational parameter back up in on-board EEPROM (RG58U, RG174U). The quarter-wave antenna
has the widest range of the three types dis-

12/2003 Elektor Electronics 15


COMPUTER
cussed here, but only if it ‘sees’ a sufficiently nance using a small (1.5-5 pF) capac- operate most efficiently when there
large ground plane beneath it. Its disadvan- itor. The PCB track acting as the loop is a substantial ground plane for
tage is mainly mechanical vulnerability and may be as narrow as 1 mm. The them to radiate against. For our pro-
sensitivity to large metal objects or surfaces feeder point should be at 15-25% of ject, a helical antenna can be made
in its vicinity. It is also rather cumbersome in the overall length of the loop. from 0.5-mm dia. (26 SWG) enam-
semi-portable equipment. Helical antennas are also reso- elled copper wire (ECW). Suitable
PCB Loop antennas are the most compact nant and generally chosen for their dimensions are:
antennas but are less effective than the other more compact dimensions. They are 17 turns, 5 mm internal diameter,
types. They are also more difficult to design more difficult to optimise than quar- stretch to 34 mm length;
and must be carefully ‘tuned’ for best perfor- ter wave antennas and are critical 24 turns, 3.2 mm internal diameter,
mance. At 433 MHz the loop should cover an with regard to surrounding objects stretch to 19 mm length.
area of 400-1000 mm2 and be tuned to reso- that can easily ‘de-tune’ them. They As to range and susceptibility to

An Application using the


Elektor 80C537 Board A
development
PC host computer A

Two built up radio modules are needed to realise the example


serial interface
application depicted in Figure A. At one side we find Host A, an SS20
serial interface
8051 controller system based on the 1997 Elektor Electronics SS20

80C537 Microcontroller Board connected to an SRD radio mod- 80C537 Lite Board,
ule via the second serial interface of the 80C537 micro. A Motherboard Type radio
module
MAX232 level converter is not required here. On the radio
module, the relevant pins are simply interconnected with wires
(pin 11 to pin14; pin 12 to pin 13). The development PC allows Analog IN
Digital IN / OUT
the software for the 80537 to be set while also acting as a display
device for the received characters. sensors/
LCD
actuators
The other party is formed by Host B, a regular PC connected
to a radio module via its serial port. At this side of the radio
link, a MAX232 level converter is required. The PC initially host computer B
runs an ordinary terminal emulation program (like HyperTer-
minal) just to display received characters and to send out (indi-
COM X radio
vidual) characters. PC module

Different applications were realised using this configuration, and 030204 - 14

the relevant software (C51 for the 80537 and Visual BASIC for Figure A. A PC and a microcontroller system communicating over a radio link.
the PC/Notebook) may be downloaded free of charge from the
Elektor Electronics webserver at www.elektor-
electronics.co.uk/dl/dl.htm (select this issue).

1. Individual key presses are transmitted by Host B, received by


the 80C537 system and get displayed on the monitor of the
development PC.

2. Host A sends individual characters or whole text strings —


these appear on the monitor connected to Host B.

3. The 80C537 system is turned into a small weather station by


extending it with sensors and/or actuators and an LC display. It
employs the radio link to convey to Host B meteorological data
like air pressure, temperature, relative humidity, etc. complete
with time stamps. Host B runs a small Visual BASIC program dis-
playing received data and writing an Excel compatible (log) file
for inspection/evaluation at a later time. The system also allows
texts to be sent from Host B to the LC display connected to the
80C537 system. Figure B shows a screendump of the program
B
running on Host B. The hardware should also allow the control
(by radio) of just about any actuator at the ‘remote’ site. Figure B. Screendump of the weather station software running on Host B.

16 Elektor Electronics 12/2003


COMPUTER
1/
Literature and Internet addresses: a 4 -wave

[1] LPRS: www.lprs.co.uk


155 mm
[2] ER400TRS hardware manual:
http://www.lprs.co.uk/main/viewdatasheet.php?datasheetref=112
[3] Easy Radio software manual: b loop
http://www.lprs.co.uk/pdf_directory/23861055851852.pdf
[4] 80C537 Microcontroller Board, Elektor Electronics June 1997.
[5] Portal website for the SRD industry and radio regulation authorities: 400 ... 1000 mm2
www.lpra.org

1.5 ... 5 pF

noise, the performance of the helical PCB and practical use c helical
antenna lies roughly between that of
the whip and the loop. It is, however, The printed circuit board for one
the least space consuming of the radio module (Figure 4) is double- 19 mm
three. Moreover, it is easily tuned by sided hence very compact. Populat- i = 3.2 mm 030204 - 13
24 turns
stretching and compressing the coil ing the board should not present
until the greatest range is obtained. problems if you pay due attention to
Figure 3. Pick your antenna.

COMPONENTS LIST IC1 = 7805CP


IC2 = MAX232CP the correct fitting of the polarized parts.
Resistors: IC3 = ER400TRS from LPRS (see text) To close off this article, we should reiter-
R1-R4 = 1kΩ8 ate that the use of SRDs is governed by strict
Miscellaneous: regulations. On request, LPRS supply cus-
Capacitors: JP1 = jumper with 2-way pinheader tomers with a copy of the CE compliance doc-
C1,C3,C9 = 100nF JP2 = jumper with 3-way pinheader ument for their SRD modules, as well as
C2,C4 = 10µF 16V radial K1,K3 = 2-way pinheader pointers to legal information relevant to the
C5-C8 = 1µF 16V radial K2 = 9-way sub-D socket (female),
use of SRDs in several countries.
angled pins, PCB mount
(030204-1)
Semiconductors: K4 = BNC socket, 50 Ω, PCB mount
D1 = 1N4148 (Farnell # 365-0558)
D2,D3,D5 = LED, green, 3mm, low RS232 cable (non crossing)
current PCB, order code 030204-1 (see
D4 = LED, red, 3mm, low current Readers Services page)
T

PIJL
HOEK1

HOEK2
K4
C9

K3

IC3

(C) ELEKTOR
030204-1
RxDTxD D5

D3 D2POWER

R3
JP2
R4

R2
C8

C6

R1
C5
C4 C1
BUSY
D4
030204-1

IC2
IC1
C3

HOEK4
D1
+
JP1

C7

C2
K1
0
K2

HOEK3

Figure 4. The PCB for the Wireless RS232 Link project is double-sided and easy to build up (board available ready-made).

12/2003 Elektor Electronics 17


SMALL CIRCUITSCOLLECTION

Universal Keypad 025


H. Kraus

Keypads are needed for a variety of applications and DIY pro- * voir texte * siehe Text
jects. Particularly for selecting the measurement range of an * see text * zie tekst
instrument or setting the output voltage of a laboratory power
supply, as well as for many other uses, potential-free relay out-
puts are desirable. In addition, break-before-make switching R12
should be used to avoid short circuits. This cannot be guar-
* D5
*
RE3.A
anteed by simple relay circuits, since the pull-in speed of most
D6
relays is greater than the dropout speed! S3

In many cases, an expensive or hard-to-obtain special-purpose 1N4148

IC is used for this purpose, but most such ICs limit the num-
ber of keys that can be used, and break-before-make switch- R9 R10 * T3

ing is often an unheard-of luxury! The circuit shown here, 10k 10k
C3 RE3.B
which is about as simple as possible and can be built using

100k
R11
only a handful of parts from your ‘junk box’, shows that that 10µ
there are other ways to solve this problem.
This design has the following advantages:
– break-before-make operation
R8
– potential-free relay outputs *
– any desired number of keys * D3 RE2.A

– any desired operating voltage S2


D4

– well-defined initial state (all relays disengaged) 1N4148


– only one stage switches if multiple keys are pressed
R5 R6 * T2

Each of the relays must have a spare working contact for the 10k 10k
changeover function. The pushbutton switches must have C2 RE2.B
100k

R7
changeover (double-throw) contacts that can switch the coil
10µ
currents of the relays. If the current rating of the pushbutton
switch contacts is insufficient (particularly with high-power
circuitry), a small relay can be connected in series with the
switch to supply power to the load relay. R4

Operating power is supplied to the switching stages via a * D1


*
RE1.A

series connection of the normally-closed (nc or ‘break’) con- D2


S1
tacts of all of the pushbutton switches. When any one of the
1N4148
switches is actuated, the supply voltage to all stages is inter-
rupted, causing all of the relays to drop out, and the base
capacitor associated the actuated switch is charged. When the R1 R2 * T1

10k 10k
switch is released, power is again applied to all of the relay C1 RE1.B
100k

R3
stages, but only the capacitor of the selected switching stage
provides sufficient energy to drive the connected transistor 10µ

into conduction and engage the relay. The working contact of


the relay latches the relay. LEDs with series resistors con- +U B
020193 - 11
nected in parallel with the relay coils indicate their switching
states.
When a different key is pressed, the above process is repeated. in the series. This ensures that only one stage can switch.
First, the supply voltage is disconnected from all of the relays, The values of the components marked with a * must be cho-
which ensures break-before-make operation. When the key is sen to match to the supply voltage used or the required
released, the relay whose capacitor has been charged is actu- switching current. If power relays are used, Darlington tran-
ated. sistors with suitable power ratings should be used. The num-
If several keys are pressed at the same time, only one capaci- ber of switching stages can be extended to almost any desired
tor receives a charging voltage. This is the capacitor for the limit to allow you to fit your equipment with a convenient, reli-
only pushbutton switch in the series circuit that is still con- able keypad.
nected to the positive terminal, which means the first switch (020193-1)

7-8/2003 Elektor Electronics


TECHNOLOGY MICROCONTROLLERS

Universal USB Device


Michael Odenwald, Michael Keller and Paul Goossens

Designing your own USB device can be an enjoyable task for electronics hobbyists.
The main stumbling block is often the driver for the device.
Writing this piece of software can be a bit too difficult for many people.
A universal USB device driver, which is also open source, presents the solution!

Figure 1.
These are the steps
you’ll come across when
creating the INF file for the
universal USB driver.

When designing USB devices you also need to write an device driver, as expected. And this doesn’t exist (yet)
associated device driver. For many designers this is a very for our hardware.
tricky task and many won’t even attempt such a project To help us out we made use of ‘libusb-win32’, a universal
because of this. This is now all set to change! With the help open source USB device driver [1]. This comes as a DLL
of our AVR USB board we’ll show you how we tackle this and lets Windows applications communicate directly with
driver problem, using an existing universal open source a USB device. With this we can deal with the (device
device driver program. dependent) data stream in a Windows application and
there is no need for a specially written device driver.
Unlike the way a ‘normal’ device driver functions,
Connections libusb-win32 lets us use an API (Application Programming
Everything went smoothly as far as the hardware for Interface) instead of having to communicate via a so-called
our AVR USB board was concerned, until we connected IOCTL (Input/Output ConTroL).
it to the PC. Windows (XP) then politely asks us for a

40 elektor - 3/2007
Driver Say goodbye to
connection problems
Let’s get busy!
First we have to download libusb-win32 and extract all
files from this ZIP file in their own folder. Before we can Listing 1
use this driver we first have to create an INF file. This file Globale variabele:
tells Windows which driver belongs to which device. usb_dev_handle *usbIODevice; /* The usb device handle */
The creation of this INF file is made very easy by the
inclusion of a program in libusb-win32 (‘inf-wizard.exe’). Funktie:
The INF file is created as follows: Power up the AVR USB
board and connect it to the PC. Windows will now ask int searchUSBDevice(int vendorID, int productID)
for the driver. Click on ‘Cancel’. Start the program {
‘inf-wizard.exe’. In the first window click on ‘Next’, after struct usb_bus *busses;
which the second window appears. This contains a list struct usb_bus *bus;
of all the connected USB devices. Select our AVR USB struct usb_device *dev;
board, with a VendorID of 0x0C7D and a ProductID of
0x0006, and click on ‘Next’. In the third window we can if (usbIODevice != NULL)
give the device a different name, if required. This isn’t {
necessary, so we click on ‘Next’ again. The program now usb_close(usbIODevice);
reports that it has generated an INF and a CAT file. Click }
on ‘Finish’ to close the program. (See Figure 1.)
usbIODevice=NULL;

Initial test /* Find the device for the given vendorID and
We now have to disconnect the AVR board from the PC productID*/
and then reconnect it again. Windows will ask for the usb_init();
driver program once more. This time, select the option usb_find_busses();
‘Specify a location’ and browse to the INF file that we usb_find_devices();
created with ‘inf-wizard.exe’. busses = usb_get_busses();
If everything goes to plan, Windows will install the device
driver. From the Device Manager in Windows you should for (bus=busses; bus; bus=bus->next) {
now be able to see the AVR USB board. for (dev=bus->devices; dev; dev=dev->next) {
if (dev->descriptor.idVendor == vendorID &&
dev->descriptor.idProduct == productID) {
usbIODevice=usb_open(dev);
Applications if(usb_set_configuration(usbIODevice, 1)) return 0;
We can now use the AVR USB board in our applications. if(usb_claim_interface(usbIODevice, 0)) return 0;
On the Elektor Electronics website are a few downloads return 1;
for this project, which contain several applications (in- }
cluding the source code) for controlling the AVR USB }
board. These applications have been written in C, . }
NET and a few other languages. You can use the source return 0;
code as the basis for your own applications. }
The testing of all functions of the AVR USB board is very
easy with the program ‘AVR-USB-Windows1.exe’. With
this you can test all I/O capabilities of the hardware. the required values the program tries to ‘open’ this
device. The ‘handle’ for this device is stored in the global
variable ‘usb_dev_handle’. The last step is to configure
the device according to the USB standard and claim
A closer look at the source code exclusive rights to the use of this device.
To give you an idea how we can control our USB device When no unexpected errors occur the function will return
from within an application, we’ll show you a few parts of the value ‘1’ to indicate that everything went well. If any-
the source code. The saying ‘a picture is worth a thou- thing went wrong the function will return the value ‘0’.
sand words’ also applies to source code!
In Listing 1 you can see how the application searches
for a specific USB device. If it is found, a connection with
this device is initiated. Hardware control
In a for-next loop all of the available USB busses of the Controlling the hardware is also very simple. In Listing
computer are interrogated. The VendorID and Produc- 2 you can see how the status of the digital inputs is read.
tID of every USB device connected to each bus are This assumes that the function ‘searchUSBDevice’ (from
requested. When both the VendorID and ProductID have listing 1) has previously been called to assign a valid

3/2007 - elektor 41
TECHNOLOGY MICROCONTROLLERS

With the many examples available, you should be able to


write applications for the AVR USB board in other deve-
lopment environments under Windows as well.

And finally ...


For ideas or help when you get stuck you should take a
look at the forum for the open source driver [4]. In here
you’ll find many enthusiastic programmers who pass on
useful information, and you can also ask questions.
You can of course also use our own forum on the Elektor
Electronics website to share your experiences with other
readers. For those of you with a grasp of foreign langua-
ges it would also be useful to visit the forums of our
French, German or Dutch websites. Here you’ll undou-
btedly find other electronics hobbyists who’ll make worth-
handle to ‘usb_dev_handle’. while contributions to this project and who in turn would
With the help of ‘sendUSBVendorCmdIn’ we send the be interested in your experiences.
command ‘AVR_USB_READ_DIGITAL’. This command can (060226-I)
also be found in the source code of the firmware. With
this we also specify from which port we want to read (the
second parameter). The result is put into the array ‘iodata’.
The application can then use these returned values to
determine what the status of the relevant digital input is.
Weblinks
[1] http://libusb-win32.sourceforge.net/
[2] http://www.elektor-electronics.co.uk/

Experimenting [3] gcc.gnu.org

The best way to familiarise yourself with this software is [4] http://sourceforge.net/forum/?group_id=78138
to go through the examples. The examples avr-usb1 to
avr-usb4 (which can be downloaded from [2]) can all be
compiled using GCC [3]. (GCC stands for GNU Compi-
ler Collection, a free ANSI-C compiler with support for
K&R C, C++, Objective C, Java, and Fortran.)
The other examples have been written in C#.

Listing 2
int digiportTest(void)
{
int i;
int result;
unsigned char iodata[8];

printf(“digiport: AVR-USB get value from digital input Port:\n\r”);

for (i=0; i<=1000; i++)


{
if((result = sendUSBVendorCmdIn( AVR_USB_READ_DIGITAL, AVR_USB_DIGITAL_P1, 0, iodata, 8)) < 0)
printf(„Error sendUSBVendorCmd %d“, result);
printf(„digital in status P1 is %s\n\r“, (iodata[0]) ? „close“ : „open“);
if((result = sendUSBVendorCmdIn( AVR_USB_READ_DIGITAL, AVR_USB_DIGITAL_P2, 0, iodata, 8)) < 0)
printf(„Error sendUSBVendorCmd %d“, result);
printf(„digital in status P2 is %s\n\r“, (iodata[0]) ? „close“ : „open“);
if((result = sendUSBVendorCmdIn( AVR_USB_READ_DIGITAL, AVR_USB_DIGITAL_P3, 0, iodata, 8)) < 0)
printf(„Error sendUSBVendorCmd %d“, result);
printf(„digital in status P3 is %s\n\r“, (iodata[0]) ? „close“ : „open“);
if((result = sendUSBVendorCmdIn( AVR_USB_READ_DIGITAL, AVR_USB_DIGITAL_P4, 0, iodata, 8)) < 0)
printf(„Error sendUSBVendorCmd %d“, result);
printf(„digital in status P4 is %s\n\r“, (iodata[0]) ? „close“ : „open“);
Sleep(500);
}
return 0;
}

42 elektor - 3/2007
MICROCONTROLLER

USB Analogue
Converter
With two analogue inputs and four digital outputs
Design by E. Brador

This circuit is based on the PIC16C765, a recent addition to the large


Microchip PIC family. It can be used to measure two analogue voltages
(0–5 V) via two analogue inputs and send the results to a PC via a USB
connection. There are also four digital outputs whose levels can be set
using the PC.

Due to its ease of use, applications for the USB inter-


face continue to proliferate. This time we present a
USB analogue converter that has two A/D inputs that
can be used to sample analogue voltages (ranging
from 0 to 5 V), as well as four digital outputs to which
data can be written.
This circuit is based on the Microchip PIC16C765
microcontroller, whose pinout is shown in Figure 1.

12 Elektor Electronics 11/2003


MICROCONTROLLER
can visit the manufacturer’s website at
http://www.microchip.com/

Any electronic technician or hobbyist who


wants to keep abreast of new developments
can hardly avoid the USB port. Here we use
USB Type 1 (USB 1.1), which is more than fast
enough for sampling signals whose levels
change relatively slowly, such as tempera-
ture, pressure, etc.

The electronics
A glance at the schematic diagram in Fig-
Figure 1. PIC16C765 pinout (source: Microchip). ure 2 clearly shows that our circuit is almost
unbelievably simple. The microcontroller is
surrounded by only a handful of components,
consisting primarily of the quartz crystal and
The PIC16C765 ory. It also features eight analogue the usual capacitors connected to inputs
inputs, a variety of digital inputs and OSC1 and OSC2, which collectively ensure
Together with its little brother, the outputs, a UART and a USB con- that the program runs at 24 MHz inside the
PIC16C745 (28 pins), the PIC16C765 troller, among other things. IC, despite the fact that a 6-MHz crystal is
was the first PIC processor to have Microchip provides assembler used. This is because an integrated PLL
an on-board USB interface. This RISC files for this microcontroller in order causes the basic frequency generated by the
processor (with only 35 instructions) to simplify the essential communi- crystal to be multiplied by a factor of four.
has 8 Kwords of 14-bit program cations between the USB PIC and Pushbutton switch S1 can be used to reset
memory and 256 bytes of data mem- the PC. For more information, you the processor in the event of problem. The
presence of a device on the USB port is
detected via resistor R1 (1k5). The rest of the
circuit consists of various connectors for the
+5V inputs and outputs.
One of the advantages of USB can already
be seen here: the circuit draws its power
R2
C3 C4
directly from the USB port.
10k

100n 100n

11 32
The circuit board
K4
1 24 3 Although a printed circuit board has been
MCLR D+
D–
23 2 designed for this circuit (Figure 3), it is natu-
40 18 1
RB7 VUSB R1 rally not much larger than the IC. Consider-
39 15
38
RB6
IC1
RC0
16
1k5
4
ing the small number of components (a micro-
RB5 RC1 USB-B
C5
K1 37
RB4 RC2
17 controller, a USB chassis-mount connector, a
36
RB3 RC6
25 220n crystal, two resistors and five capacitors),
35 26
34
RB2 RC7 instructions for assembling the circuit board
RB1
33 8 are actually unnecessary, except that we rec-
RB0 RE0
RE1
9
K2 ommend using a good-quality socket for the
19 PIC16C765 10
RD0 RE2 microcontroller.
20
21
RD1
2
If you cannot program the PIC16C765 used
RD2 RA0
22
RD3 RA1
3 in this circuit, a pre-programmed version can
27
RD4 RA2
4
K3 be ordered form Readers Services under order
28 5
29
RD5 RA3
6
number 020374-41.
RD6 RA4
30 7
RD7 RA5
OSC1 OSC2
12 13 14 31
Installation
X1
After the USB cable (which also provides the
power) has been connected, the circuit will
C2 6MHz C1
be recognised as a Human Interface Device
22p 22p (HID). However, this only works properly
020374 - 11 under Windows 98 SE, Windows ME, Win-
dows XP or Windows 2000. After the device
Figure 2. Except for IC1, there’s not a lot of electronics in the USB analog has been recognised, the proper driver will be
converter. installed.

11/2003 Elektor Electronics 13


MICROCONTROLLER
HOEK3

HOEK1

K2

R2
1-473020
K3 ROTKELE )C(
K4

C3 C4
K1
T IC1

C2 020374-1
C5
R1

C1

X1
HOEK2

HOEK4

(C) ELEKTOR
020374-1

Figure 3. Printed circuit board and component Figure 4. Windows recognises the interface as an HID (Human Interface Device).
layouts for the USB converter circuit. This screendump is taken from Windows XP.

COMPONENTS LIST The microcontroller identifies USB protocol.


itself to the PC by specifying its ven- Some of the important portions of
Resistors: dor ID (VID) and product ID (PID). As the program are printed in Listings 1
R1 = 1kΩ5 this is a hobbyist circuit, we have & 2, so you can see what is involved
R2 = 10kΩ
retained the default settings from
Microchip. If you consider that up to
256 different devices can be con-
Capacitors:
nected to a single USB port, you can
C1,C2 = 22pF
understand the need for unambigu-
C3,C4 = 100nF
ous identification.
C5 = 220nF After being installed, the circuit
should be visible as a USB device in
Semiconductors: the Device Manager window (see
IC1 = PIC16C765, programmed, the screen dump in Figure 4).
order code 020374-41

Miscellaneous: The assembler program


X1 = 6MHz quartz crystal At the Microchip website, you can
K1 = 4-way PCB terminal block find a variety of programs that illus-
K2,K3 = 2-way PCB terminal block trate how to program this microcon-
K4 = USB socket, PCB mount, type B troller for USB communications,
PCB, order code 020374-1 which means for data traffic via the
Disk, contains hex-code and Windows- USB port. Figure 5. The program window shows
software, order code 020374-11 or Free If you want to write programs for the values measured on the two
Download this microcontroller, we advise you to analogue inputs and the levels of the
first become quite familiar with the four digital outputs.

14 Elektor Electronics 11/2003


MICROCONTROLLER
in making an analogue measurement Listing 1. Analogue measurement subroutine (one channel).
and sending the measured values.
Assembling the program is more acqudat
complex than with a PIC16F84, since banksel PIE1 ;memory bank selection
several files from Microchip are nec- bcf PIE1,ADIE ;don’t use interrupt for conversion
essary for this purpose. The program
can be compiled using MPLAB, the banksel ADCON0
well-known PIC development envi- bcf ADCON0,CHS2 ;input selection
ronment that Microchip makes avail-
bcf ADCON0,CHS1 ;microprocessor’s
able free of charge.
bcf ADCON0,CHS0 ;RA0
The microcontroller program is
available in the form of a hex file
(Elk.hex) and is available on diskette
from Readers Services (order number bsf ADCON0,ADON ;set internal converter
020374-11) or from the Elektor Elec-
tronics website.
pagesel Pdelay
call Pdelay ;call delay for conversion
Operation
The PC software for the PIC is writ- banksel ADCON0
ten in Delphi, and some of its sub- bsf ADCON0,GO ;start new conversion
routines are suitable for use with
USB. loop
It is necessary to install the file btfsc ADCON0,GO_DONE ;loop
port.dll in the same directory as the
main program.
goto loop ;conversion not yet finished
The compiled PC program, which
is called Acq_usb, has been tested
banksel PIR1
under Windows XP, Windows ME
and Windows 98 SE, and it works BCF PIR1,ADIF ;reset end of conversion flag
perfectly under these three operat-
ing systems. banksel ADRES ;fetch conversion result
Using this program, voltages movf ADRES,w
between 0 and 5 V can be cyclically banksel buffer
sampled on two channels (see the movwf buffer ;and move to buffer for transmission to PC
screen dump in Figure 5). The pro-
gram automatically starts sampling.
To test the circuit, you can use a
power supply or battery with a Listing 2. Subroutine for transmitting measured values to the PC.
potentiometer to allow the voltage to
be adjusted over the range of 0–5 V. SendData ;subroutine for transmission of values to PC
The arrow buttons can be used to pagesel PutEP1
write ‘1’ of ‘0’ values to the four out- bankisel buffer ;place buffer address into FSR
puts by clicking on the up arrow (for movlw buffer
‘1’) or the down arrow (for ‘0’). movwf FSR
movlw 0x4 ;send 4 bytes
Although this is a ‘bare bones’ call PutEP1
circuit, it can be used for a wide vari- btfss STATUS,C ;stay in this loop until data transmission complete
ety of measurements by connecting goto sendData
various types of converters or trans-
ducers to the inputs (via an interface banksel buffersFilled
if necessary). In this way, you can clrf buffersFilled
use it to measure temperatures or bankisel buffer
pressures. clrf buffer
(020374-1) clrf buffer+1
clrf buffer+2
clrf buffer+3
clrf buffer+4

pagesel acqudat
goto acqudat

11/2003 Elektor Electronics 15


COMPUTER

USB Audio Recorder


A fully-featured sound card for the Universal Serial Bus
Design by G. Kronauer and T. Zepf

Many motherboards these days only offer limited space for expansion
cards, and integrated sound chips are generally not so well suited to high-
quality recording. If a sound card is fitted in the PC, it is exposed to
enormous levels of interference which does nothing for the audio quality.
The solution is an external sound card, connected over USB.

Installing an add-in sound card into a system audio using the CD-ROM drive. If PCMCIA sound card.
is generally a lot of fuss. In order to transfer you want to make recordings using All more recent PCs offer a pow-
audio data digitally to the PC, either you will a notebook computer, you will have erful interface in the form of the Uni-
need an S/PDIF interface on the sound card to be content with the microphone versal Serial Bus, which can also be
or else you will be reduced to ‘grabbing’ the input or purchase an expensive used for transferring audio data. The

36 Elektor Electronics 5/2003


COMPUTER
circuit described here is a fully-fea- When the PLL is in lock, the sample
tured sound card, capable of full-
duplex operation, that runs under
rate of the received data is indicated
by the three LEDs D1 to D3. The I2S
Features
Windows 98SE, MacOS or Linux. The output then carries the digital audio – compatible with USB specification 1.0 and
UDA1335 and UDA1325 are ICs from signal which is taken to the above
Philips that include a USB interface, UDA1325 on pins DA, DS and BCK. – compatible with USB Audio specification
A/D and D/A converters, I2C inter- The device also has an analogue 1.0
face and an 8052-compatible micro- input on pins VINR and VINL, which – analogue input (adjustable from –3 dB to
controller. The chip is available in is connected via coupling capacitors +27 dB)
various versions: the UDA1335 (with- C28 and C29. Input selection is con- – coaxial S/PDIF phono input
out ROM), the UDA1325 (with N106 trolled in software under Windows: – optical digital input (TOSLink)
firmware) and the UDA1325 (with more about this later. – analogue output (adjustable over a 60 dB
N104 firmware). In this application, The digital audio data for record- range)
the microcontroller is always used in ing are carried to the PC via a USB – analogue sample rates from 8 kHz to
the ROM-less (EA=0) mode, and so ‘In Pipe’ and playback data are car- 48 kHz
it does not matter which firmware ried back from the PC to the sound – digital sample rates of 32 kHz, 44.1 kHz
version is present. card over a USB ‘Out Pipe’. The vol- and 48 kHz
The ROM-less mode of operation ume can be adjusted using the – full-duplex operation supported
has been chose here because the UDA1325’s built-in DSP. After D/A – Plug & Play compatible
firmware in the ROM version has conversion, the signal is made avail-
been found to be so full of bugs that able at K4 via coupling capacitors
it is not suitable for serious use. The C37 and C38 at a level of 0 dBu. This
author has had the chip under the can be connected to a line input or to provision of a suitable reset pulse for the
microscope since shortly after it high-impedance headphones such microcontroller but also the reference voltage
came onto the market and, after as those supplied with portable CD for the D/A converter. T2 is used to switch
much detailed work, has analysed players. R10 into the D+ circuit of the USB. The host
the multitude of bugs and developed The address and data bus of the recognises this as a ‘USB connect’ and will
workarounds for them. The trouble 80C52 CPU integrated into the respond by beginning the process of enu-
has been worthwhile: this USB UDA1325 is, as usual with such meration.
sound card is by a clear margin more CPUs, connected to EPROM IC5 via The circuit can be powered from the USB
reliable than generally-available USB latch IC4. PSEN is used as the read itself or powered from its own power supply.
sound cards using the UDA1325. strobe signal for the EPROM. ALE Since the configuration descriptor data need
The TDA1315H is used to convert selects between data and address to differ between the bus-powered and self-
the S/PDIF data into I2S format: this information on P0. In order to allow powered cases, JP1 is used to switch address
device offers two S/PDIF inputs. This either type 27C256 or type 27C512 pin A14 (but not while the circuit is pow-
allows the circuit to switch between EPROMs to be used, A15 is con- ered!).
S/PDIF phono (or Cinch) and nected permanently to the positive
TOSLink (optical) connections supply: note therefore, when using a
directly in the UDA1325 without 27C512 EPROM, that the code must Firmware
requiring extra hardware. This be stored from location 0x8000 The software provided by Philips does not
means we can connect to older CD onwards. Since RD and WR are not support either switching of the input source
players, that only have an phono out- externally accessible it is not possi- or increasing the sensitivity level of the input
put, as well as to more recent mod- ble to connect other peripherals to in analogue operation. This is a further rea-
els that have only an optical output. the CPU bus. Internally to the chip son to develop our own firmware. Because of
An EPROM, with the obligatory the RD and WR signals are used in a fault in the Windows 98 audio driver,
address latch, and a 3.3 V voltage addressing hardware registers. switching between audio inputs only works
regulator to supply the UDA1325 There is little point in going into from Windows 98SE onwards. It is a simple
complete the design. great detail here about the internals matter to check which version of Windows
of the chip. Copious information is you have under System Properties. Earlier
provided in the data sheets available versions of Windows 98 only allow you to
The circuit on the Internet at switch off the analogue signal. In this case
The S/PDIF receiver is operated in www.semiconductors.philips.com/ you will need to update to Windows 98SE,
‘hardware mode’. It receives the data acrobat/datasheets/UDA1325_N_1.pdf and suitable (even legal!) software is readily
directly from K1 (phono) or IC1 and /TDA1315H_5.pdf. available on the Internet for a small fee.
(TOSLink), connected straight to
pins IECIN0 and IECIN1 respec- A 48 MHz crystal is used as the The four main jobs of the firmware are as fol-
tively, as shown in Figure 1. If a sig- clock source, which means that the lows:
nal is present at either of these two CPU is clocked at 24 MHz. C32 and
inputs, the PLL in the receiver will L1 ensure that the crystal oscillates – Controlling the USB core;
attempt to lock on to it. The level on at 48 MHz and not at 16 MHz. The – Processing USB 1.0 standard requests (for
pin 7 of IC2 (IECSEL) determines capacitor at pin 40 (VREFDA) of the example GetDescriptor);
which of the two inputs is used. UDA1325 looks after not only the – Processing USB Audio Class 1.0 requests

5/2003 Elektor Electronics 37


5/2003
Figure 1. Circuit diagram showing TDA1315 S/PDIF receiver, and the UDA1325, which includes the USB interface, converters and a DSP.
+5V +5V

Elektor Electronics
IC1 L2
R4
TORX173 L3 C8 C9
+5V +5V
1Ω

VDDE VDDX VDDI VDDO VDDA1 VDDA2 VDDA3


3 47µH +3V3
100n 10µ
1 25V
C41 20
C5 C6 C7
IC4 C42
R8 R12 R13 R19 R14
2 4 5 6 100n 10
100n 100n 100n
22k

22k

22k

22k
1Ω

100n
3 42 17 T2
VDDD1

VDDD2

12 28 9 32 38 42 52 28
VDDA

S/PDIF IC4
C1 6 22
K1 IECIN0 LADDR

VDDE

VDDX

VDDA1

VDDA2

VDDA3
10n

VDDO
VDDI
5 23 R5 R7 R6 R9 2 56 AD0 AD0 2 19 A0 A0 10
IECIN1 LMODE C10 BC557B BCKO/GP4 P0.0 1D A0
4k7

4k7

4k7

22k

32 24 1 58 AD1 AD1 3 18 A1 A1 9
MUTE LCLK R10 WSO/GP3 P0.1 A1
75Ω

R1 12 25 60 AD2 AD2 4 17 A2 A2 8
UNLOCK LDATA P0.2 A2
1k5

31 34 100n 27 62 AD3 AD3 5 16 A3 A3 7


DEEM SDAUX CLK P0.3 A3
D1 30 21 T1 64 AD4 AD4 6 15 A4 A4 6 11 AD0
INVALID CTRLMODE R11 P0.4 A4 IC5 D0
29 39 15 3 AD5 AD5 7 14 A5 A5 5 12 AD1
COPY SYSCLKI 22k GP5/WSI P0.5 A5 D1
13 40 17 5 AD6 AD6 8 13 A6 A6 4 13 AD2
R3 D2 FS32 SYSCLKO GP0/BCKI P0.6 A6 D2
14 IC2 19 13 IC3 7 AD7 AD7 9 12 A7 A7 3 EPROM 15 AD3
680Ω FS44 RESET GP1/DI P0.7 A7 D3
15 20 A8 25 16 AD4
+5V FS48 TDA1315H PD UDA1325H A8 D4
D3 16 7
BC547B 63 14 A8 A9 24 17 AD5
CHMODE IECSEL DO/GP2 P2.0 A9 27C512 D5
8 35 57 16 A9 11 1 A10 21 18 AD6
IECO SD DA P2.1 C1 EN A10 D6
9 36 59 18 A10 A11 23 19 AD7
IECOEN WS DS P2.2 A11 D7
37 61 20 A11 74HC573 A12 2
SCK BCK P2.3 A12
44 22 A12 A13 26 +U A14
RCINT R16 P2.4 A13
1 USB-B 8 23 A13
RCFIL 22Ω D+ P2.5
R2 27 K2 3 29 1 27
C3 UDAVAIL R15 P2.6 A15 A14
470Ω

2 26 2 6 30
VREF STROBE 22Ω D– P2.7 +5V OE CE R28
43 1
2n2 CLKSEL +5VUSB 22 14 20

10k
L4 C12 C11
28 50
TESTA ALE
10 33 4 31
TESTB I2SSEL 22p 22p PSEN
L5
VSSD1

VSSD2

11 38
VSSA

TESTC I2SOEN
C2 C4
R26
K3 C28 47µ 47 37 C37 47µ K4
4 41 18 VINR VOUTR 100Ω
10µ 100n LINE 25V 25V LINE
25V R27
C29 47µ 43 34 C38 47µ
VINL VOUTL 100Ω
25V 25V
+5V VDDE
51 54
VRP XTAL1A
L8 +5VUSB 19 53
SCL/GP6 XTAL2A
21 4
IC6 SDA/GP7 SHTCB
C26 C27 +5V VDDX VDDI C13 C14 35 VDDO VDDA1 VDDA2 VDDA3
JP1 LE33CZ TC
36
100n 100n POWER USB +3V3 100n
RTCB +3V3
10µ 25V

VSSA1
VSSA2
VSSA3
49 48

VSSO
VSSE

VSSX
VRN EA

VSSI
EXT L6 L7 XTAL2B XTAL1B VREFDA VREFAD R21 R20 R23 R22
D4 IC7

1Ω

1Ω

1Ω

1Ω
26 25 10 11 33 24 39 44 55 40 41
1N4002 7805 +U A14
X1
> 9V C32
R17 R18 10n R24 R25
C47 C46 C45 C44 C43 C15 C16 C17 L1 C31 48MHz C30 C36 C35 C33 C34 C39 C40 C20 C21 C18 C19 C24 C25 C22 C23

10k

10k
220k

220k
1µH5
470µ 100n 10µ 100n 100n 100n 100n 100n 10p 10p 10µ 100n 100n 47µ 10p 10p 10µ 100n 10µ 100n 10µ 100n 10µ 100n
25V 63V 25V 25V 25V 25V 25V 25V
COMPUTER

L3...L8 = BLM31A601S 012013 - 11

38
COMPUTER
(for example volume control); be installed. In this way it is very
The configuration descriptor for a USB
– Driving the on-chip hardware, such simple to add extra devices (for
audio device is formed as follows:
as the A/D converter, and setting example human interface devices) to
the sample rate. the list of descriptors.
Config
In order for a USB device to be recog-
Interface0 pipe (control)
The digital audio data are nised by the operating system as an
AC Control audio (Topologie)
autonomously transferred by DMA audio device, a list of descriptors for
....
hardware and so this does not audio class (AC) specific interfaces
Interface (alt0) pipe
require any software intervention. and endpoints must be given in the
Interface (alt1) pipe (waveout)
USB audio devices are so-called configuration descriptor. Depending
ACInterface audio (stream format)
‘compound devices’, which means on the scale of the topology and the
Endpoint ISO
that they are composed of several number of alternate interface set-
ACEndpoint audio (sample rates)
interfaces. In this case we have tings this can easily add up to a kilo-
….
three interfaces: control, wave out, byte of data. The characteristics of
Interface (alt0) pipe
and wave in. Under Windows, each the sound card (inputs, outputs, con-
Interface (alt1) pipe (wave in)
device requires a separate driver to nections, controller) are specified in
ACInterface audio (stream format)
Endpoint ISO
ACEndpoint audio (sample rates)
R28 C39
L1
R21
C31
H2

C32
H1

R24
C20 K4 the AC control descriptor. The Microsoft dri-
OUT1

R27
C38
R20

C42 C30 X1
C15 L6 C37
ver development kit includes a tool called
C21 C18 C36 grapher.exe, which allows simple display of
IC5

C27
IC4

C19

C26
the USB topology. Each audio pipe must offer
C17

R26 an ‘Alternate Setting 0’ which releases all


IC3

C40

C35
C34

L8
C33 R25
L7 C25 R18 possible bandwidth on the USB when the
C16 C13 pipe is closed.
C24

C41 C29
R23

C14

K2 C12 C28
R12
R14
R13

C23
R11

R16 012013-1 R19 R17 K3 Construction


L5 R15 C22 R22
K1 A glance at the double-sided layout for the
C11 R5
R10 R2 C2
R1

T1 C9
C3
printed circuit board in Figure 2 will reveal
USB

L4 JP1
0 C44
C43 C4 that IC2 and IC3, as well as a few passive
R8
EXT

R9
R6

C6
C45
T2 IC2 C1 components, are SMDs. The two ICs have
C47 C8 L3 C5 IC1 rather a large number of pins, and so con-
IC6
+ C10 R7 struction cannot exactly be described as a
C46
R4
IC7 L2 straightforward task. If you have not had pre-
H4

R3
H3

C7
D4 D3 D2 D1 1-310210
ROTKELE )C( vious experience with SMDs, you should get
expert advice: it is all to easy to destroy
(C) ELEKTOR
012013-1

Figure 2. Printed circuit board layout and component mounting plan.

5/2003 Elektor Electronics 39


COMPUTER
COMPONENTS LIST
Resistors:
R1 = 75Ω
R2 = 470Ω
R3 = 680Ω
R4,R19-R23 = 1Ω
R5,R6,R7 = 4kΩ7
R8,R9,R11-R14 = 22kΩ
R10 = 1kΩ5
R15,R16 = 22Ω
R17,R18 = 220kΩ
R24,R25,R28 = 10kΩ
R26,R27 = 100Ω

Capacitors:
C1,C32 = 10nF ceramic, lead pitch 5mm
C2,C9,C13,C18,C20,C22,C24,
C36 = 10µF 25V radial, lead pitch 5mm
C3 = 2nF2 ceramic, lead pitch 5mm
C4,C6,C7,C14-C17,C19,C21,C23,C25,
C26,C27, C33,C35 = 100nF
(SMD shape 1206)
C5,C8,C10,C41-C44,C46 = 100nF
ceramic, lead pitch 5mm
C11,C12 = 22pF
C28,C29,C34,C37,C38 = 47µF 25V radial
C30,C31,C39,C40 = 10pF
C45 = 10µF 63V radial
C47 = 470µF 25V radial

Inductors:
L1 = 1µH5 miniature choke
L2 = 47µH miniature choke
L3-L8 = BLM31A601S (Murata, SMD shape
1206, Farnell # 581-094)

Semiconductors:
D1,D2,D3 = LED, 3mm dia.
D4 = 1N4002
T1 = BC547B
T2 = BC557B
IC1 = TORX173
IC2 = TDA1315H/N2 (Philips)
IC3 = UDA1325H/N106 (Philips)
IC4 = 74HC573
IC5 = 27C512-10, order code 012013-21
IC6 = LE33CZ (ST, Farnell) or LP2950CZ-
3.3 (National Semiconductor)
IC7 = 7805

Miscellaneous:
JP1 = 3-way pinheader with jumper
K1 = Cinch socket, PCB mount (e.g., T-
709G from Monacor/Monarch)
K2 = USB-B socket, PCB mount
K3,K4 = 3.5-mm stereo jack socket, PCN
mount (Conrad Electronics # 732893)
X1 = 48MHz quartz crystal, 3rd overtone,
parallel resonance
PCB, order code 012013-1
Disk, order code 012013-11

40 Elektor Electronics 5/2003


COMPUTER
expensive components, especially
when using an ordinary soldering
iron. A specially-designed SMD sol-
Performance A +1

+0.5

dering station, as we have recently curves -0

-0.5

discussed in Elektor Electronics -1

(‘SMDs? Don’t panic!’ in the January The first performance curve, curve A, d
-1.5

2003 issue) is extremely useful here. shows the amplitude response of the B
r -2

Purchasing such apparatus is how- system when the A/D and D/A con- -2.5

ever rather expensive and only rec- verters are connected in series. To -3

ommended to those who plan to carry out this measurement a special -3.5

ASIO multimedia driver for Cubase -4

make extensive use of SMDs in their


VST/32 was used (see www.usb- -4.5

hobby. audio.com), which allows full-duplex


-5
20 50 100 200 500 1k 2k 5k 10k 20k
Hz 012013 - 12

As usual, one the two ICs have operation, to briefly delay the output
been neatly soldered and the 21 from a signal generator. The peak at B 10

SMD capacitors and coils fitted, turn the end of the curve is probably 5

the circuit board over and start on caused by the digital output filter: the 2

the leaded components. After sweat- data sheet is silent on this point. If the 1

ing over the SMDs this should pre- D/A converter is measured on its 0.5

sent no difficulty, as long as care is own, the peak is at most 0.5 dB high. 0.2

% 0.1

taken with the polarity of the elec- 0.05


Curve B shows distortion plus noise
trolytic capacitors. The DIL ICs (the
as a function of frequency. Again the 0.02

EPROM and the latch) should be fit- converters are connected in series,
0.01

ted in sockets, and the LEDs should and the distortion is chiefly caused by
0.005

only be fitted once you have decided the A/D converter. The values (digi-
0.002

0.001
how they should appear in the enclo- tally measured) are about a factor of 20 50 100 200 500
Hz
1k 2k 5k 10k 20k
012013 - 13

sure. Finally fit the large connectors: two higher than the maximum figures
two mini-jack sockets, the TOSLink, given in the data sheet. C +0

-10

the phono and the USB sockets. -20

Once the printed circuit board looks Curve C shows the frequency -30

like our photos, give it a thorough response of the D/A converter when -40

-50

visual inspection for solder bridges driven at full amplitude (0 dB), mea- -60

sured with a 997 Hz signal sampled at -70


and other problems: and then the job d

48 kHz. The output signal level is B


-80

is done. approximately 0.66 V. Over a band-


-90

-100

width of 22 kHz the total distortion -110

plus noise is approximately 0.008 %.


Operation There are no harmonics within the
-120

-130

-140

Fit jumper JP1 in position ‘EXT’ and audio band above –90 dB. Despite the -150
20 50 100 200 500 1k 2k 5k 10k 20k 50k 90k

apply power from an external mains rise in the noise level above 20 kHz Hz 012013 - 14

power supply. The current consump- (typical of delta-sigma converters with


tion should be around 110 mA. In noise shaping) the distortion figure is still only 0.03 % when the measurement bandwidth is
contrast to the USB Audio Codec increased to 80 kHz.
published in the December 2002
issue of Elektor Electronics this cir- Measured values (bus-powered unless otherwise noted)
cuit can also be supplied from a USB Current consumption (bus-powered) 96 mA
hub, if JP1 is fitted in the appropri- Current consumption (self-powered) 109 mA
ate position. A signal at 4 MHz DAC
should be found at pin 11 of IC4; if Nominal output amplitude (0 dB) 0.66 V
not, check the oscillator circuit Bandwidth (-3 dB) 23.9 kHz (fs = 48 kHz)
around X1 for soldering or other Amplitude (20 kHz) +0.38 dB (fs = 48 kHz)
assembly errors. Output impedance 110 Ω
Users of Windows 98SE or Win- Signal-to-noise ratio >96 dBA
dows ME should install the relevant THD+N (1 kHz) 0.008 % (B = 22 kHz)
patches from Microsoft before pro- 0.03 % (B = 80 kHz)
Channel separation >100 dB (1 kHz)
ceeding. The reasons for doing this
>87 dB (20 kHz)
and how to go about it are explained
in the text box. Installing the audio ADC
Maximum input sensitivity 58 mV
recorder is considerably simplified
Minimum input sensitivity 1.42 V
by Plug and Play. Once the device is Input impedance 12 kΩ
connected, Windows recognises it THD+N (1 kHz, –0.5 dBFs) 0.02 % (B = 24 kHz)
automatically and installs the USB Channel separation >69 dB (1 kHz)
audio recorder drivers: >47 dB (20 kHz)
SNDREC10.INF for the self-powered

5/2003 Elektor Electronics 41


COMPUTER

Free Downloads Windows bug fixes


– PCB layout. File number: 012013-1. USB audio playback and recording devices are not correctly dealt with in the dri-
– EPROM-Hex code (no source!). ver (SNDVOL32.EXE), since it cannot distinguish between two devices with the
File number: 012013-11. same name. This can have various consequences. Once the USB device is
www.elektor-electronics.co.uk/dl/dl.htm, installed and the system rebooted, the CD volume control no longer works. The
select month of publication. volume slider is not displayed with the correct name, there is more than one
input selector, both are labelled ‘USB Audio Device’, and they cannot be individu-
ally selected. Hardware such as this sound card, which supports full-duplex
recording and playback, is also not correctly displayed. The Line In and Mic
mode and SNDREC11.INF for the bus-pow- options are displayed as a USB Audio Device, but neither of the input selectors
ered mode (these files are stored in the INF can be chosen. The master playback volume control is displayed as a USB Audio
directory). The operating system CD is Device.
required for this operation. After installation Bug fixes for these problems are available as files Q269601.EXE and
of these files and restarting the machine, the Q280127.EXE at the sites
audio device will be recognised and the hard- www.media-assistance.com/English/index_english.html
and
ware manager should be opened again. This
www.pcsound.philips.com/driverfiles/patch269601usa8/269601usa8.exe (only for
time the USB audio drivers are installed. If the Windows 98SE).
patches have been installed, the PnP man- On Microsoft’s website at http://support.microsoft.com/?scid=KB;en-us:280127
ager will point out that there are newer ver- you can also find the patch for Windows ME.
sions of WDM Audio in the driver list. These If these bug fixes are applied after the USB Audio Recorder has been installed, or
newer versions should not be overwritten. if you experience other problems with the display of audio devices, it can help to
After a successful installation the USB audio remove the USB Audio Device from the registry using RegEdit. This requires a lit-
device will be found under ‘Audio/Video/ tle experience, since an erroneous addition to or deletion from the registry can
Game controller’ in the Control Panel. Now have fatal consequences for the system.
any sound software that supports the Win- First search for the key HKEY_LOCAL_MACHINE\Enum\USB. If multiple USB
dows Multimedia Driver can record and play devices have been or are connected, you will find them categorised according to
back audio data. their Vendor ID and Product ID. The entry for the USB Audio Recorder starts
‘VID_0C7D...’. Now disconnect the USB cable and delete all the keys relating to
An advantage of the USB audio recorder
the device from the registry. Close RegEdit and reconnect the USB Audio
over the USB Audio Codec is that the input Recorder. All the drivers will be installed afresh. In contrast, installation under
selection is under menu control. The recorder Windows XP, MacOS and, of course, Linux, should present no problems.
Wave In menu allows the user to select
between three inputs: S/PDIF digital audio
over the coaxial input, S/PDIF over the opti- course be adjusted. The level control Audio Codec the choice was fixed in
cal input, and the analogue line input. If a for the line input covers the gain hardware between two levels.
digital input is selected the LEDs indicate the range of the internal preamplifier (012013-1)
sample rate, and the input level cannot of from –3 dB to +27 dB; on the USB

42 Elektor Electronics 5/2003


USB Converter
Jörg Schnyder

Does this sound familiar: you buy a small


piece of equipment, such as a programming
& debugging interface for a microcontrol-
ler, and you have to use a clunky AC wall
adapter to supply it with power? It’s even
worse when you’re travelling and there’s no
mains socket anywhere in sight. Of course,
you can use the USB bus directly as a
power source if the supply voltage is 5 V. If
you need a higher voltage, you can use the
USB converter described here. This small
switch-mode step-up converter can gener-
ate an output voltage of up to 15 V with a
maximum output current of 150 mA.
The LM3578 is a general-purpose switch-
mode voltage converter. Figure 1 shows its
internal block diagram. Here we use it as
a step-up converter. The circuit diagram
in Figure 2 shows the necessary compo-
nents. Voltage conversion is achieved by
switching on the internal transistor until it
is switched off by the comparator or the
current-limiting circuit. The collector cur-
rent flows through coil L1, which stores
energy in the form of a magnetic field.
When the internal transistor is switched
off, the current continues flowing through
L1 to the load via diode D1. However, the
voltage across the coil reverses when this
happens, so it is added to the input volt-
age. The resulting output voltage thus con-
1
sists of the sum of the input voltage and
the induced voltage across the coil. The
output voltage depends on the load cur- in the circuit board for this purpose.
rent and the duty cycle of the internal tran- As we haven’t been able to invent a device R5 and R6 for other
output voltages:
sistor. Voltage divider R5/R6 feeds back a that produces more energy than it con-
portion of the output voltage to the com- sumes, you should bear in mind that the R5 = 47k,
6V:
parator in the IC in order to regulate the input current of the circuit is higher than R6 = 9,1k
output voltage. C5 determines the clock the output current. As a general rule, you R5 = 110k,
12V:
frequency, which is approximately 55 kHz. can assume that the input current is equal R6 = 10k
Network R4, C2 and C3 provides loop to the product of the output current and R5 = 130k,
15V:
R6 = 9,1k
compensation. The current-sense resistor the output voltage divided by the input
for the current-limiting circuit is formed by
three 1-Ω resistors in parallel (R1, R2 and
R3), since SMD resistors with values less
than 1 Ω are hard to find. The output volt- L2 L1

age ripple is determined by the values and 47µH 820µH

internal resistances of capacitors C11, C8, 8


D1
C7 and C6. The total effective resistance is K2 R4 1 UIN 6
1 -IN C
reduced by using several capacitors, and +5V R5 K1
220k

2 C3 IC1 SK34SMD
D– 2 7
this also keeps the construction height of
82k

3 +IN I LIM
D+ C2 22p
the board low. L2, C1, C9 and C10 act as GND
4
3
LM3578AM
5
OSC E
an input filter. Ensure that the DC resist- USB 2n2

ance of coil L2 is no more than 0.5 Ω. Use 4

a Type B PCB-mount USB connector for R1 R2 R3 R6


C9 C10 C11 C8 C7 C6
connection to the USB bus. A terminal strip C1 C5 C4
1Ω

1Ω

1Ω

10k

with a pitch of 5.08 mm can be used for 100n 47µ 47µ 1n5 68µ 68µ 68µ 68µ
100n
16V 16V 20V 20V 20V 20V
the output voltage connector. Of course,
070119 - 11
you can also solder a cable directly to the
2
board. Two additional holes are provided

 elektor elector - 7-8/2007


components list C10 = 47µF 16V
C11 = 68µF 20V
(for UO = 9 V)

Resistors Inductors
R1,R2,R3 = 1Ω L1 = 820µH (SMD CD105)
R4 = 220kΩ
3 L2 = 47µH (SMD 2220)
R5 = 82kΩ
R6 = 10kΩ
voltage and divided again by 0.8. Specifi- Semiconductors
cally, with an output current of 100 mA at Capacitors
D1 = SK34SMD (Schottky)
9 V, the input current on the USB bus is (SMD 1206)
IC1 = LM3578AM (SMD SO8)
approximately 225 mA. C1 = 100nF
Finally, Figure 3 shows a small PCB lay- C2 = 2nF2
C3 = 22pF
out for the circuit. All of the components C4 = 100nF
Miscellaneous
except the connector and the terminal strip C5 = 1nF5 K1 = 2-way PCB terminal block, lead pitch
are SMDs. (tantalum SMD 7343) 5mm (optional)
(070119-I) C6 = 68µF 20V
K2 = USB-B connector
C7 = 68µF 20V
Web link C8 = 68µF 20V PCB layout, free download from Elektor
Author’s homepage: www.systech-gmbh-de C9 = 47µF 16V website, 070119-1.pdf

7-8/2007 - elektor elector 


COMPUTER

USB-RS232 Interface
A compact solution for missing ports
Design by L. Lemmens

Thanks to a special integrated circuit from FTDI Chip, computer


peripherals with an RS232 interface are easily connected to a USB port.
This simple solution is ideal if a peripheral does not have a USB port, your
notebook PC has no free RS232 port available, or none at all!

After a slow and faltering start, the USB port


has become commonplace on PCs, to the
extent that the latest GHz machines have
just one RS232 port left, or none at all. The
compact USB-RS232 interface described in
this article allows your good old RS232
peripherals (printer, programmer system,
etc.) to be hooked up to a USB port. The free
driver programs for Win98/ME/2000/XP,
Linux and Apple Macintosh make the inter-
face virtually transparent, enabling the USB
port to behave like a regular COM interface.
The driver and the conversion chip from
Glasgow-based FTDI Chip allow a full serial
data link to be set up on a 9-way RS232 con-
nector, including all handshaking signals.
The UK representative for FTDI Chip is Alpha
Micro Components Ltd. in Basingstoke
(www.alphamicro.net). International distrib-
utors for FTDI Chip products may be found register), which is controlled by the ingly they contain the same drivers
on the ‘Sales Network’ page which may be computer by way of a virtual COM in the relevant section. At the input
accessed via www.ftdichip.com. FTDI Chip port. The difference between these side, an USB Transceiver forms the
has representatives in most parts of the two components is that the link with the USB cable and its two
world and hosts a very useful website. FT232AM contains a UART which in signal wires called D+ and D– for
turn comprises an RS232 interface the USB 1.1 Full-Speed mode. The
(using TTL levels). The FT245AM, on 3.3-V reference voltage needed for
Function and architecture the other hand, features a 8-bit inter- the USB Transceiver is supplied by
Although it is not necessary to know all the face with handshake lines that allow an internal low-drop voltage regula-
ins and outs of the converter chip if you just direct access to the on-chip FIFO. tor whose output is available at pin
want to use the circuit we’re about to This makes the ’245 IC particularly 6 of the chip. This is done not only to
describe, it is still useful to have an idea of interesting if an existing microcon- enable the reference voltage to be
what is going on inside the black box. troller system is to be upgraded with applied to an external decoupling
The simplified block diagram of the a serial interface. Note, however, capacitor but also to allow the USB
FT232AM is shown in Figure 1 and the pin that you will need to provide the Full-Speed mode to be defined. With
assignment, in Figure 2. Like its family mem- necessary software ‘glue’ yourself! reference to the circuit diagram
ber the FT245AM, the FTDI Chip FT232AM is At the side of the USB, the two shown in Figure 3, that is achieved
essentially a serial USB FIFO (first in, first out chips are identical and not surpris- using resistor R6 which pulls the D+

60 Elektor Electronics 4/2003


COMPUTER
VCC
48MHz Baud Rate
Generator

3.3 Volt
3V3OUT Dual Port TX
LDO
Buffer
Regulator
128 bytes TXD
RXD
RTS#
CTS#
DTR#
DSR#
USBDP DCD#
Serial Interface RI#
USB USB UART UART
Engine
Transceiver Protocol Engine FIFO Controller
USBDM ( SIE )
TXDEN
USBEN

TXLED#
RXLED#

Dual Port RX
Buffer
USB DPLL
384 Bytes

EECS
EEPROM EESK
Interface EEDATA

XTOUT 48MHz GND


6MHZ x8 Clock RESET#
Oscillator Multiplier SLEEP#
XTIN 12MHz TEST
PWRCTL

RCCLK
020375 - 13

Figure 1. Simplified block diagram of the USB/RS232 converter type FT232AM (courtesy FTDI Chip).

line to +3.3 V. This level causes the functional parameters. between 300 bits/s and 2 Mbits/s (actually,
USB Host (i.e., the USB controller in Buffers for ‘receive’ and ‘transmit’ up to 920 kbits/s for RS232 and 2 Mbits/s for
the PC) to recognise our interface as (‘Dual-Port TX Buffer’ with 128 bytes RS422/485).
a Full-Speed device and arrange for capacity and a 384-byte ‘Dual-Port The ‘EEPROM Interface’ on board the
the appropriate addressing. In the RX Buffer’) arrange for the exchange FT232AM chip is intended for the connection
case of a Low-Speed device, the D– of data in both directions (between of an external 93C46 EEPROM chip. Although
line is held at +3.3 V with the aid of Serial Interface Engine and the UART the FT232AM will work happily without the
a resistor. Behind the USB Trans- registers). The block identified as addition of a non-volatile data memory, the
ceiver we find a functional block ‘UART FIFO Controller’ is responsible interface will then ‘report’ as a standard ser-
identified as ‘Serial Interface Engine’ for the exchange process between ial device. The small EEPROM allows specific
which handles the parallel-to-serial the two buffers and the transmit and data like manufacturer and product identifier
and serial-to-parallel conversion of receive registers of the UART.
USB data. Next, the ‘USB Control Functionally, the ‘UART’ proper is
Engine’ processes the USB control not unlike the one found in the PC.
RCCLK

XTOUT
AGND
AVCC
EECS

information and looks after the com- Its task is to supply all relevant sig-
XTIN

VCC
TXD

munication with the USB Host Con- nals to the RS232 interface and in
troller (in accordance with the USB addition, for RS422 and RS485.
Low Level protocol), as well as the The ‘Baud Rate Generator’ allows 32 25

commands that define the UART’s the serial data speed to be set EESK 1 24 RXD

FTDI
EEDATA RTS#
VCC CTS#
RESET# DTR#
FTDI Chip contact details TEST
FT232AM DSR#
3V3OUT DCD#
Future Technology Devices International Ltd., USBDP RI#
St. George’s Studios, 93-97 St George’s Road, Glasgow G3 6JA, United Kingdom. USBDM 8 XXYY 17 GND
Tel.: (+44) (0)141 353 2565, Fax: (+44) (0)141 353 2656. 9 16
URL: www.ftdichip.com

UK distributor:
VCC

TXDEN
GND

RXLED#

PWRCTL
USBEN
TXLED#
SLEEP#

Alpha Micro Components Ltd, Springfield House, Cranes Road, 020375 - 14

Sherbourne St. John, Basingstoke, Hants RG24 9LJ, United Kingdom.


Tel : (+44) (0)1256 851 770, Fax: (+44) (0)1256 851 771.
URL: www.alphamicro.net Figure 2. Pin connections of the FT232AM in
QFP case (7 x 7 mm) (courtesy FTDI Chip).

4/2003 Elektor Electronics 61


COMPUTER
+5V +5V +5V

R3 C6 R9 R11 R10
C1

470Ω

470Ω
10k
100k
8
100n
10n
T1
3 4 AVCC
DI DO
7 IC2 6 RCCLK
PRE PE
2 1
BC857 SK CS C4 C5
93C46
R2 R1 R12
100n 100n

2k2
470k

100k

5
RESET +5V

C13 C14
+5V
100n 10µ
16V
C8
D1 D2
C11
100n
L1
R7 R8 3 13 26 100n
C7 13
1k

1k

2 30 11 V+ 12
EEDATA AVCC C1+ C9
10µ 16V 1 32 24
EESK EECS EN K1
11 31 IC3 14
RXLED RCCLK C1– 100n
12
IC1 19 26 27 DCD 1
TXLED DCD R3OUT R3IN
4 20 5 4 DSR 6
RESET DSR R2OUT R2IN
15 24 22 23 RXD 2
USBEN RXD R4OUT R4IN
R5 16 23 20 1 RTS 7
D+ TXDEN RTS T3IN T3OUT
10Ω 25 7 2 TXD 3
K2 FT232AM TXD T1IN T1OUT
3 7 22 8 9 CTS 8
R4 USBDP CTS R1OUT R1IN
2 D– 8 21 6 3 DTR 4
10Ω USBDM DTR T2IN T2OUT
1 6 18 19 18 RI 9
3V3OUT RI R5OUT R5IN
R6 5 10 21 28 5
C3 TEST SLEEP T4IN T4OUT
1k5

USB-B 4 14 29 15
PWRCTL AGND MAX213 C2+ C10
10n 25
XIN XOUT SHDN SUB-D9
10 16 100n
9 27 28 17 C2–
X1 V-
C2
17
C12
33n 6MHz
100n
020375 - 11

Figure 3. Circuit diagram of the USB/RS232 Interface.

codes (VID, vendor ID; PID, product ID), ser- tor (K2). A sufficient amount of sup- mode while booting. The other R-C
ial numbers, etc., to be permanently stored ply noise decoupling is afforded by a combination, R11-C4, only decouples
and made known to the operating system. small choke (L1) and capacitor (C7). the voltage at the AVCC (analogue
Note that the EEPROM is obligatory when In addition all integrated circuits supply) pin which powers the inter-
several USB/RS232 converters using FTDI have their own supply decoupling. nal 8x clock multiplier.
chips are connected to a PC. This is because As already mentioned, resistor R6 The MAX213 and its external
the drivers will only install virtual COM ports pulls the USB D+ line to +3.3 V, in charge pump capacitors only serve
for converters with unique serial numbers. order to tell the USB host that the to convert the 5-V signals at the
Without the serial number (i.e., without the interface is a ‘Full-Speed’ device. The RS232 side of the FT232AM into true
EEPROM) only one virtual COM port can be same resistor also triggers the recog- RS232 signals (i.e., having a polar-
installed. nition of an USB device when the ized swing). Normally, that would
interface cable is plugged into the mean approximately ±12 V, but in
USB port on the PC or on a hub. practice only ±8 V is achieved, with
Circuit diagram Very conveniently, the FT232AM a maximum of up to ±10 V.
The circuit diagram shown in Figure 3 looks features two LED driver outputs that
rather uncomplicated. In the top left-hand cor- allow active data transmission (D1)
ner we find the power-up reset circuit com- and reception (D2) to be visualised. Circuit board
prising T1 and the customary R-C network. Although the two R-C networks Even if the circuit diagram is unclut-
Right beside it is the (optional) EEPROM. In R11-C4 and R10-C5 are identical in tered and fairly straightforward, that
the next lower ‘row’ we find, from the left to value, their functions are quite dif- does not necessarily apply to the
the right, the USB-B connection, the FT232AM, ferent. The combination R10-C5 at printed circuit board (Figure 4). The
a MAX213 and finally the RS232 header. the RCCLK pin is a timing network main reason for the discrepancy is
The circuit receives its +5 V supply volt- to ensure clock stability when the found in the use of SMD parts. Also,
age from the PC via pin 1 of the USB connec- FT232AM wakes up from Sleep the PCB is double-sided and

62 Elektor Electronics 4/2003


COMPUTER
D2 D1C14
COMPONENTS LIST

K2
C10

C11
Inductors:

C9
All resistors and capacitors C12
L1 = BLM31A601S (Murata) (e.g., C7
SMD shape 1206

R1
IC3

L1
R2
T1

C13
Farnell # 581-094) R3
C1
Resistors: C2
R1,R3,R10 = 100kΩ Semiconductors:

K1
C5
R2 = 470kΩ D1,D2 = LED, 3mm dia. 020375-1 R10
X1
R4,R5 = 10Ω T1 = BC857
R6 = 1kΩ5 IC1 = FT232AM or FT232BM (FTDI
R7,R8 = 1kΩ Chip order code FT8U232AM)
R9 = 10kΩ IC2 = 93C46 (optional)
R11 = 470Ω IC3 = MAX213ECWI
R12 = 2kΩ2

(C) ELEKTOR
020375-1
Miscellaneous:
Capacitors: K1 = 9-way sub-D plug (male), PCB
C1,C3 = 10nF mount, angled pins
C2 = 33nF K2 = USB connector, type B, PCB
C4,C5,C6,C8-C13 = 100nF mount
C7,C14 = 10µF 16V radial X1 = 6MHz ceramic resonator
C4 R11

R9
R12

C6
IC1

IC2

(C) ELEKTOR
020375-1
R6
R5

C8
R4
C3

R8
R7

Figure 5. Our finished and fully working prototype board seen from above… Figure 4. Copper track layout and component
overlay of the PCB designed for the interface.

through-plated, and has components fitted at


both sides! Those of you who have experi-
ence in dealing with SMDs will not be
deterred by the extremely compact board lay-
out. Fortunately, for those with less know-
how in this area, Elektor Electronics recently
published a number of useful articles on the
subject of SMD soldering (see ‘References’ at
the end of this article). Beginners are advised
to prepare themselves by first reading the
articles and then acquire practical experience
from some (defective) boards and SMD parts
to prevent disappointment with the present
project.
The bare board is first populated with the
SMDs and then with the ‘leaded’ components
and sockets. One of the sockets is a USB Type
Figure 6. … and from below. ‘B’, for which the pinout is shown in Figure

4/2003 Elektor Electronics 63


COMPUTER
7. The other variant of the socket, called USB 2 3 4 1 = +5V
1
‘A’, is always at the PC or hub side, while type USB-A 2 = D-
3 = D+
‘B’ should always be inside the equipment 4 = GND

reporting to the PC. Via the USB cable, the 1


2
type ‘A’ socket supplies current to the ‘B’ 3
socket at the equipment side. In our case, this 4

current is used to power the USB-RS232 con-


verter board. USB cables always contain 1-to-
1 wire connections. 3 2 4
USB-B 1 = +5V
2 = D-
3 = D+
Ready-made modules 4 = GND

3 2
Those of you who dislike DIY constructing on
PC boards, and SMDs in particular, will be 4 1
glad to know that FTDI chip also supply
ready-made USB-RS232 interface modules
020375 - 12
under part number DLP-USB232M, see their
website for further details. These modules
have all connections brought out to pins of a Figure 7. USB-A and USB-B socket pinouts.
standard 0.6-inch wide DIP plug.

Once finished, you will have a new Figure 8a.


Software serial port on your system, just check During the installation, two dri-
Before connecting your circuit to the PC’s USB it using Start → Settings → Control vers are actually installed that are
port, give your soldering work a last, thor- Panel → System → Device Manager. linked with one another. One of
ough, visual inspection, for which a magnify- If you open the ‘Ports (COM & LPT)’ these provides the virtual COM port
ing glass will prove very useful. folder you should see a new ‘USB you just found as the new device in
Next, download the necessary drivers from Serial Port (COMx)’ as illustrated in the Device Manager. The other driver
the FTDI Chip website. Drivers are available
for all popular Windows versions, as well as
for the Macintosh and Linux platforms.
Regarding the Windows drivers, versions are
available with and without PNP (Plug & Play) Installation
support. The latter are called ‘non-PNP’. The As is well known, USB devices may be ‘hot plugged’ to the PC. The operating
difference is small but essential. The drivers system will recognise the interface and request the associated driver. This may be
with PNP support should only be used when downloaded from the Drivers and Utilities page on the FTDI Chip website. The
the peripheral connected to the PC via the so-called Virtual COM Port (VCP) drivers arrange for the interface to behave like
USB/RS232 interface also installed its drivers an ordinary serial port. There are drivers for Windows, MacOS and Linux. Here,
using Windows PNP. In other words, in case we will assume the Windows drivers are used.
of doubt, resort to the non-PNP drivers first to
prevent problems. Typical problems you may Having installed the driver, the simulated COM port may be addressed by applica-
encounter with the PNP supporting drivers tions just like any regular serial port on the system. Higher programming lan-
include slow booting and erroneous identifi- guages like Delphi and C++ allow ‘components’ like Tcomport to be employed
cation of an USB/RS232 converter as a for the communication with the serial interface. If you do your own programming
‘pointer device’ which will result in failure of anyway, we’d recommend using the ‘D2XX ‘Direct’ Drivers’ for Windows
the mouse to operate as expected! For Win- instead of the VCP ones. A Direct Driver must be employed to be able to pro-
dows XP, there’s an additional XPNPNP tool gram the external EEPROM!
that allows the Plug & Play function to be
switched off for serial FTDI interfaces. The Windows VCP drivers copied form the FTDI website come in two flavours:
With the right driver securely stored in a with and without PNP. This has nothing to do with the interface proper (which is
subdirectory , you may start the installation always recognised automatically by Windows). But only concerns the hardware
process by connecting the USB/RS232 inter- connected to the interface (see the subheading ‘Software’).
The VCP driver download comes as a zip file containing drivers for Windows98,
face to a USB port on the PC. After a short
ME, 2000 and XP. The zip archive file is unpacked on the hard disk. The FTDI
delay, Windows will report that a USB device
Chip website supplies extensive documentation, all the latest on the software and
has been found. If there is no reference to a
the installation process.
USB device, then there is a problem on our lit-
tle board. In some cases, all you have to do is
Windows will automatically launch its New Hardware Wizard when the interface
unplug the USB connector, wait a few seconds is connected to the USB port on the PC. Next it will prompt you to point to the
and insert it again, so try this first. When location where the drivers may be found. Browse and navigate to the folder con-
everything goes well, all you have to do is taining the unpacked files. After a short delay, the Wizard will find FTDIBUS.INF
browse the system and click on FTDIBUS.INF and install the drivers and associated software for the interface.
to make the rest of the installation proceed.

64 Elektor Electronics 4/2003


COMPUTER
ensures that the USB side of the FT232AM
appears as a USB device in the sub-folder
‘Universal Serial Bus Controllers’ (see Figure
8b).
Figure 9 shows the programming win-
dow of the tool available for programming the
EEPROM connected to the FT232AM. This lit-
tle tool may also be downloaded from the
FTDI website. OEMs (original equipment
manufacturers) may want to use this tool to
program their own VID or PID. If you do not
a have a VID or PID, you may either omit them
or omit the entire EEPROM. Yet another pos-
sibility is to simply resort to the PIDs and
VIDs reserved by FTDI Chip. For the
FT232AM, VID = 0403 and PID = 6001. A
more extensive description of the actual uses
b of this option may be found in the program-
ming instructions supplied by FTDI in the
form of yet another free download.
Finally, we should mention that there are,
of course, limits to the performance of a con-
verter acting as a simulated RS232 port. Con-
trol of the data flow is essential to ensure
trouble-free conversion between RS232 and
USB, in order to prevent overruns occurring
on the two buffers inside the FT232AM (128
and 384 bytes). Such situations would cause
bytes to be lost in the conversion process and
Figure 8. After the installation you should find a new ‘USB Serial COM Port’ under are most likely to occur at high data speeds
‘Ports’ in the Device Manager (8a) and a new ‘USB High Speed Serial Converter’ when no handshaking is used.
under ‘Universal Serial Bus Controller’ (8b). (020375-1)

Note: since writing this article we have been advised by FTDI Chip that the FT232AM chip
has been superseded by the FT232BM.
Literature:
– USB Driver Programming, Elektor Electronics
October and November 2002.
– USB UART, Elektor Electronics December 2001
and January 2002.
– USB Interface, Elektor Electronics September
2000.
– SMD’s? Don’t Panic!, Elektor Electronics January
and February 2003.

Free Downloads
– PCB layout (pdf file), on
www.elektor-electronics.co.uk/dl/dl.htm.
Select file number 020375-11.zip, month
of publication.
– FT232AM datasheets, drivers, info on
ready-made modules, etc.,
Figure 9. Utility program for (optional) programming of PID and VID information www.ftdichip.com
into the 93C46 EEPROM.

4/2003 Elektor Electronics 65


MICROPROCESSOR

Xilinx PROM Programmer


Parallel port serial PROM burner
By Müller & Müller

The programmer described here reads and writes to the Xilinx family of
serial PROMs. The PC software is written in Turbo Pascal and the
programmer plugs into a free printer (Centronics) port.

When it comes to PROM burning tools the


most common model available is the univer-
sal type of PROM programmer. These are
capable of handling the majority of chips cur-
rently on the market. The cost of such a
burner is relatively high so the average elec-
tronics enthusiast has a hard job justifying
his/her purchase especially if the programmer
will only be used occasionally. If you do man-
age to scrape the funds to buy a programmer,
regular software updates are fairly painless
but it can be frustrating to find that a whole
new model of programmer is introduced
shortly after you make your purchase.
One solution to the problem is to build a low
cost programmer and write (and update) the
necessary programming software yourself. A
disadvantage of choosing this path is that the
programmer will not be so ‘universal’ as a
commercial unit. The programmer described
in this article is designed to burn serial PROMs
produced by Xilinx but it should also be possi-
ble to adapt it for other manufacturers devices.
These serial PROMs are used in conjunction
with FPGAs (Field Programmable Gate
Arrays). At boot-up the serial PROM loads
configuration data to the FPGA. Together lines. For a more complete descrip- sary to configure it with the correct
these devices are typically used to implement tion of the devices refer to [1]. Figure bit pattern. These patterns are
large complex digital systems (e.g., PCI bus 1 shows the timing waveform spec- described under the heading Pro-
designs). ification for programming the gramming but for more detailed
The PROM burner described here plugs into XC17VXX-Family of PROMs. information see reference [2]. The
a parallel printer port on a PC and the pro- As the name suggests, data to and timing diagram indicates the pattern
grammer software is written in Turbo Pascal from the PROM is transferred serially and sequence of signals necessary
and runs under DOS so even aged PCs should through a single pin (DATA) of the for programming the PROM. Data is
have no problem using it. PROM. Writing begins at address shifted into a 64 bit long latch in the
‘0000’ with the data presented not in PROM on the rising edge of the clock
bits but in words. Most Xilinx when both CE and OE are high.
Burning Serial PROMs PROMs have a 64-bit word length. Once all 64 bits have been shifted
The circuit diagram and PCB layout (Figure 3) In order to switch the PROM into into the register the voltage on pin
are designed to accept PROMs with DIP out- reading or writing mode it is neces- Vpp is raised to Vpp1 and the data is

30 Elektor Electronics 10/2003


MICROPROCESSOR
latched. To read data from the PROM VPP2
VPP1

CE is now pulled Low and OE High. VPP

Data is shifted out of the PROM on


every rising edge of the clock.
Address incrementing occurs via the CLK

RESET/OE pin. TSDP TCAC THIC


TSIC
In addition to simple data transfers THDP TOH

to the PROM there are also special DATA Ø 1 2 Last Bit 1 2 Last Bit

features that allow the RESET polar-


TSCC
ity to be inverted and also some
internal information to be read-out, CE
for example the PROM type and
manufacturers code (MfG code).
RESET / OE

The Hardware Load PROM Internal


Data Latches
Program
Pulse
Verify Current Device Word Increment
Word
Counter
010109-12
The programmer circuit diagram is
shown in Figure 2. Printer port out-
puts IN00 to IN07 are used along Figure 1. Programming cycle timing diagram for the XC17VXX type PROM.
with the two inputs ACK (Acknowl-
edge) and PE (Paper Empty). A stan- D1
+15V
dard printer extension lead connects IC4
1N4148
a PC to the 25-way plug K1 on the +15...18V D2 7805 +5V
LM317T
programmer. Outputs from the PC 1N4148 IC2
are used to switch the voltages in C3 C5 R3
C2
the programmer and also to provide

120Ω
100n D3
100µ 25V
the data, clock and reset signal to 1µ
25V
1N4148
the PROM. The two inputs to the PC P1 P2 P3
LM317T
carry the PROM output data and the IC6 +VCC
2k5 2k5 2k5

status signal CEO. R13


R4
10k

T1
Signals on the printer port from the
120Ω

T4
T2
PC are terminated by 4.7 kΩ pull-up R14
2k2
resistors (R5) and buffered by the
BC557B 2x +VCC
74HC245 bus driver IC1. This IC car- P4 BS170
R1
ries the signals that switch voltages C4 D4 2k5 K2
1k

PROM
within the programmer so it is 1µ
DATA 1 8
VCC
25V
important to ensure that its supply T5 R2 JP1
CLK 2 7 VPP
RST/OE 3 6 CEO
voltage is derived from a separate
680Ω

P5
3V3/5V CE 4 5
2k5
(unswitched) 5 V regulator (IC4). Ser- GND
BS170 DIP8
ial data for the PROM also passes T3

through IC1 and IC3. The supply for


IC3 comes from the switched Vcc. BS170
This ensures that voltage thresholds +5V +5V +VCC
of the PROM signals correspond to IC1 IC3
R5 1 8x 4k7 74HC245 74HC245
Vcc and that the signals DATA, CLK,
3EN1 3EN1
OE and CE (and the acknowledge 1
3EN2
1
3EN2
19 19
signals ACK and PE) will only be dri- G3 G3
2 3 4 5 6 7 8 9
K1
ven when the supply voltage Vcc is 1 1
1
switched on. To be absolutely sure 14
2 D0 2 2 18 2 2 18
15
that Vcc cannot be pulled high via 16
3 D1 3 17 3 17
4 D2 4 16 4 16
the input protection diodes of IC3, 17
5 D3 5 15 R7 5 15
18 330Ω
transistor T5 switches the supply to 19
6 D4 6 14 R8
330Ω
6 14
7 D5 7 13 R9 7 13
ground via the 1 kΩ resistor when 20
8 D6 8 12 R10
330Ω
8 12
21 330Ω R12
Vcc is switched off. 22
9 D7 9 11 R11
330Ω
9 11
10k
10 ACK
The programmer can handle both 23
11
R15
24 560Ω
3.3 V and 5 V PROMs so it’s impor- 25
12 PE
R6
13
tant to use an HC type of driver for 560Ω +5V +VCC

IC3. The LS or ALS family of devices


DB25 20 20
do not provide suitable output signal C1
IC1
C6
IC3
100n 10 100n 10

0101
Figure 2. The circuit diagram.

10/2003 Elektor Electronics 31


MICROPROCESSOR
COMPONENTS LIST IC4 + 0
K1 D2
C4

H4
H1

C3
010109-1
Resistors: C1 T4 C5 D4

R13
R14
R1
R2

R5
R1 = 1kΩ C6

JP1
R2 = 680Ω

K2
R3,R4 = 120Ω

R12
R5 = 8-way 4kΩ7 SIL array

IC1

IC3
T3 T5
R6,R15 = 560Ω R7
R8
R7-R11 = 330Ω R9 IC6
P5
R12,R13 = 10kΩ R10

R4
R11
R14 = 2kΩ2

D3
R15 C2
P1-P5 = 2kΩ5 preset R6

T1
T2
Capacitors: P4
1-901010

R3

D1
C1,C5,C6 = 100nF ROTKELE )C(

H2
H3

C2,C4 = 1µF 25V radial


P1 P2 P3 IC2
C3 = 100µF 25V radial

Semiconductors:
D1,D2,D3 = 1N4148
D4 = LED, red (C) ELEKTOR
010109-1
IC1,IC3 = 74HC245
IC2,IC6 = LM317T
IC4 = 7805
T1,T2,T3,T5 = BS170
T4 = BC557B

Miscellaneous:
JP1 = 2-way SIL header with jumper
K1 = 25-way sub-D plug (male), PCB mount
K2 = 8-way DIL socket with turned pins
PCB, order code 010109-1, available from
The PCBShop
Disk, project software, order code 010109-
11 or Free Download

levels and the HCT family cannot operate at Figure 3. The Xilinx programmer uses a single sided PCB.
the necessary supply voltages. HC devices
can operate with a supply of between 2 V
and 6 V. The series resistors in the data derived on-board. To be on the safe is given in the software. The pro-
inputs of IC3 limit the input current when Vcc side all PROM voltages are switched gram also indicates the correct volt-
< 5 V. by signals via the printer port. age levels necessary depending on
The DATA pin of the PROM can be configured The programmer can use PROMs the type of PROM selected so it’s not
as either an input or output. Resistor R12 is with either a 5 V or 3.3 V supply volt- necessary to wade through piles of
used to effectively increase the output imped- age (Vcc), jumper JP1 selects data sheets for this information. The
ance of IC3 pin 11, this ensures that when- between these two supply levels LED indicates that reading and pro-
ever the PROM drives data out from pin 1 it and gives a simple visual indication gramming voltages are available.
will always be available as an input to the PC of the supply voltage selected: with
via line PE irrespective of the state of the out- JP1 fitted the supply voltage is 3.3 V,
put of IC3 pin 11. It is only when writing to with JP1 not fitted the supply volt- Software features
the PROM (when the DATA pin will be an age will be 5 V. Pin 7 (Vpp) requires The programmer software is written
input and therefore high impedance) that the three different voltage levels in Turbo Pascal and runs under DOS
output of IC3 pin 11 (write data) will appear depending on the operation that the using command line options. Among
on the DATA pin. An important parameter of PROM is performing: Vpp1 for pro- the software downloads for this arti-
the data transfer is the slope of the signal gramming, Vpp-nom for reading the cle a free version of DOS is included,
edges of the PE connection to the PC. Resistor data and Vpp2 for verification of the this enables a boot disk to be made
R6 is used to reduce the effects of reflections writing procedure. Transistors T1 so that the programmer software
in the cable that may otherwise corrupt the and T2 switch these three voltage will run even if you do not have DOS
signal. levels from data signals D1 and D2. available on your machine.
The circuit requires a single external input With Vcc switched on and D1 and D2 Using the command spb /? gives an
voltage in the range of 15 to 18 V; all other low the level on this pin will be Vpp1. overview of all the available options
voltages required for programming are The programmer voltage sequencing such as selection of chip type and

32 Elektor Electronics 10/2003


MICROPROCESSOR
the type of access required of the checked to determine if the chip is of the eight printer port output bits is held in
PROM (eg reading, writing or reset blank but to be sure the program the eight bit wide global variable dat. As an
bit reading etc). The program always performs a blank check on the entire example if we wanted to switch on the sup-
asks if the chip is plugged into the PROM, the extra time needed is not ply voltage to the programmer we would
socket before it attempts to switch excessively long. need to set bit D0 (connector K1 pin 2) to a 1.
the supply voltage to the PROM. The This could be accomplished with the line:
program checks if the PROM in the /b dat := dat or $01
socket corresponds with type of chip Burn, the data held in the brenn- This will set the bit in software and then with
selected and also documents the dat.bin file is programmed into the an output instruction to the printer port this
programming process. PROM, this operation will not pro- new value of D0 will be output to the pro-
The program options are described gram the polarity of the reset signal. grammer leaving bits D1 to D7 unchanged. To
below in the same order that they The file name is stored as the con- turn off the supply voltage we just need to do
are used in the program: stant BrenndatenFileName and can the reverse procedure:
be changed in the program at this dat := dat and $fe
/? point. The size of the data in the file or alternatively:
Overview of the program options. must always be smaller or equal to dat := dat and (not $01)
the available space in the PROM. If And again write it to the printer port. The
/d? the file size is bigger than the PROM hexadecimal value of each bit of the LPT port
The printer port where ‘?’ is the size given in ‘Size’ an error message (and its inverse hex value) is given below:
number of the LPT port connected to is generated and the burning
the programmer. process will not start. $01 ($FE) Vpp - Relay (REL)
$02 ($FD) Vpp-nom
/av /r $04 ($FB) Vpp2
This command is used to setup the This command reads all the data in $08 ($F7) CE
different programming voltages the PROM and stores it in the file $10 ($EF) RESET/OE
required for the specified PROM. An data.bin. This feature will execute $20 ($DF) CLK
oscilloscope or DVM can be used to differently depending on whether $80 ($7Ff) DATA
test voltage levels. The program the reset bit has already been pro-
indicates the required voltage and grammed. The reset polarity should
on which pin of the PROM socket the always be read before this command Chipinfo.dat
voltage should be measured. It also is used. All the data relating to the chip are stored in
indicates which preset needs to be this file. The information required by the pro-
adjusted. The chip name is only used /cp grammer is:
here for the sake of appearance. Changes the reset polarity. First the
polarity of the reset is tested using Mm This byte in the identification code iden-
/m /rp and if necessary the reset polar- tifies the chip manufacturer (Xilinx = $C9).
This function reads the chips MfG ity is changed. Lastly the reset sta-
code. A chip name must be entered tus will be read and displayed. IDCLK This is the number of clock pulses
here. When the MfG code is correct needed to read out the manufacturers code.
then the message Chip identified will Two examples
be displayed; if not the MfG code In order to read a XC17S10 type of ID is the second part of the MfG code indi-
read from the chip will be displayed. PROM connected to port LPT1 the cating the chip series and type.
If it is necessary to enter a new chip following command line is used: spb
into the chip information file (chip- /r s10 /d1 Size is the size of the PROM in bits.
info.dat), all the displayed values Where s10 specifies the PROM type.
must first be converted to hexadeci- Using the command spb /av /cp /b RSTClk This is the number of clock pulses
mal. s200a /d2 indicates that the PROM needed to program the Reset bit.
All further functions are specific to type has changed and the program-
each chip type and will only be car- ming voltages will be set up and Vcc gives the PROM operating voltage.
ried out if the MfG code read from adjusted before the PROM is inserted
the chip corresponds to the selected into the socket. The reset polarity will Vpp1 gives the PROM programming voltage.
chip type. The MfG code is always then be changed and Data will be
tested first. programmed into the XC17S200A via Vpp2 This voltage on pin 7 used to test/fix the
the LPT2 printer port. data written into the PROM. This voltage
/rp level is only slightly higher than the supply
Reads the polarity of the reset bit. voltage and is not implemented at present
In and out since verification at this slightly raised volt-
/bc In order to be able to switch all the age is not essential.
Blank Check, this tests if all the voltages and signals in the program-
PROM bits are blank (=1). The pro- mer hardware each bit of the printer Vppnom The voltage on the pin VPP during
gramming specification suggests port byte must be individually pro- reading. It will be at least as high as the
that only a few bits need to be grammable. In the software the state chips supply voltage VCC.

10/2003 Elektor Electronics 33


MICROPROCESSOR
The Reset Bit D2 ensures that no damage occurs if
Bugfix The polarity of the serial PROMs
you accidentally mix up the power
supply polarity. First check that 5 V
The program is written in Turbo Pascal and reset signal can be programmed. is available on pin 20 of IC1, LED D4
uses a system unit called Crt, this unit When the PROM is used together should also light to indicate that the
includes a bug which causes a run time error with a Xilinx FPGA it is useful to be supply voltage is available.
in Windows if the PCs processor is a Pen-
able to reset the PROM from the INIT The software can now be installed
tium type running faster than about
signal from the FPLA. This means and run to drive the programmer.
200MHz. The program runs without prob-
that the polarity of the PROM reset Jumper JP1 allows the supply volt-
lem in DOS.
pin needs to be changed so that age of the PROM to be quickly
A patch is included in the software package
RESET = 0. Changing the polarity of changed between 5 V and 3.3 V
010109-11 for this article. The patch pro-
the reset signal is a one-way opera- depending on the type of PROM
gram (TPPATCH.EXE) is able to locate and
correct the failure in this unit. If you need to
tion so once the polarity has been used. This supply can also be
make any changes to the source code for programmed to negative reset it can- adjusted to suit PROMs using other
this project it is therefore important to run not be changed back. For trials it is supply voltages. Xilinx are currently
this patch program once you have recom- best to test the chip with an unpro- offering three PROMs families each
piled spb.exe. grammed reset (RESET = 1). with a different supply voltage. The
supply voltage data for the PROMs is
stored in the Chipinfo.dat file and can
Programming be read using the /av option so the
The Burning procedure switches the voltage levels can be quickly
Name This is an abbreviated name identify- PROM into programming mode. Both adjusted.
ing the type of PROM used in the command CE und OE must be high for at least After installation the PCB can be
line to call the program. The same name must two positive clock edges and the plugged into the printer socket of the
not be used for PROMs from other manufac- voltage on Vpp must be at Vpp1 [1]. PC. The LED will go out and com-
turers even if the PROM has the same mem- In this mode the manufacturer and mands can be entered to the pro-
ory capacity. chip information can be read and grammer software. For example
The four voltages Vcc, Vpp1, Vpp2 and Vppnom also data can be written to the using the command line spb /av /d1
are used to simplify the voltage settings PROM. The data is shifted serially s10 calls the program where /av indi-
when different types of PROMs are used. The into the PROM in 64 bit chunks and cates the voltage test and /d1 is for
levels are displayed by the /av function. The latched by a Vpp1 pulse on pin Vpp. printer port LPT1 (d2 would be
file can be expanded to incorporate other ser- The XC17S05D Xilinx PROM is the entered here if LPT2 was used) and
ial PROMs that have compatible program- only type with 32 bit long latches; it s10 indicates the PROM type.
ming algorithms. The maximum number of is not widely used and is not sup- Next it is necessary to adjust the
entries is given by the maxdats constant ported by this programmer. Accord- two-level supply voltage to the
defined in spb.pas and will need to be ing to the specification after pro- PROM. Firstly fit jumper JP1 and
changed if new devices are added. All the gramming the voltage level on Vpp with a DVM connected to the output
data in chipinfo.dat is taken from [2]. should be set to VPP2 but this is not of IC6 (VCC) adjust the preset P4
implemented in the program. Lastly until VCC reaches 3.3 V, once this has
the programmer switches out of pro- been achieved remove JP1 and
Reading the MfG code gram mode and both supply volt- adjust preset P5 until VCC is 5 V.
Each PROM contains its manufacturers iden- ages VCC and Vpp are switched off. Finally the program indicates adjust-
tification code that enables it to be recog- ment of the programming voltages
nised by the programmer. The code consists on pin 7. These settings are best
of two bytes: the first byte identifies the man- Build and operation made when you need to change to a
ufacturer (Xilinx uses the code $C9). The sec- The single-sided PCB has a board different type of PROM.
ond byte comprises four bits indicating the area of 72⋅63 mm2, this gives enough (010109-1)
density of the PROM and four bits for infor- space for the components to be
mation on the programming algorithm. This mounted quite easily. The five wire
is contained in the second column of chip- links need to be fitted first (one of
info.dat. these runs under the 8 pin DIP pro-
The PROMs manufacturer code is read in the gramming socket).
ReadMfGCode procedure. The PROM must first
be set to program mode with CE = 1 and
Once you are sure that all the
polarised components have been fit-
References:
OE= 0. Next a defined number of clock pulses ted the correct way round (including [1] Programmer Specification
is sent to the PROM these are described as the SIL resistor network) and double- www.xilinx.com/support/
the NIDCLK or also the IDCLK (see the first col- checked your soldering the circuit programr/specs.htm
umn of the chipinfo.dat). Now with OE = 1 can be powered up. The first test
and CE = 0 the MSB of the MfG-Code is out- should take place without a PROM [2] PROM Specification
put on the DATA pin. The code is now read by fitted to the programming socket. www.xilinx.com/isp/
the LeseByteMfG function as each bit is Connect 15 V to 18 V between the csapps.htm
shifted out by the clock signal. supply solder pins on the PCB. Diode

34 Elektor Electronics 10/2003

You might also like