Professional Documents
Culture Documents
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.
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)
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.
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
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
proper-
ty of reduc-
ing reflections
on the data lines,
which helps reduce
errors.
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).
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).
C Compilers
for the PIC Micro
Efficiency from a higher programming language
By O. Beckman Lapré
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
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
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
1 DCD DCD 1
K6 K7
1 DCD DCD 1
K8
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).
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
+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
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.
T1
BC557B
cases, the only remedy is to reinstall
U+
T2 the software.
R4
R1
R2
2k7 The solution presented here does not
15k
R3 BC547B
1k
R9
10k
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-
HOEK3
K4 C1
R1
D2
D1
R2
IC1
S1
034050-1
R6
R3
R7
T3 T1
R8
T2
R5
R9
T4
HOEK4
R4
HOEK2
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
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…
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+
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
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’.
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
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.
R1 R6 R7 R16
C1 C2
Martin Valle
330 Ω
10k
10k
10k
100n 100n
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.
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)
• w
ide range of on-chip peripherals:
brown-out detector, watchdog timer,
comparators, A/D converter;
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
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
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.
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.
10k
3k9
10k
10k
unwittingly connecting a cheap input cable R12 R13 R16 R15 R18
6k8
10k
3k9
10k
10k
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.
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)
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.
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
100n 8 7 100n
470µ 100n 100n 1µ
25V 63V E B C E
C B
IC6 = 74HC125 030313 - 11
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.
#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
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.
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.
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
2
that it is best to connect 15
3
20
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
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
.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
K2 T1 D2
R6
030030
R2
R4
R5
R7
R3
C5
IC1
D3
D4
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
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.
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
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
10k
10k
D7
100n
collectors of the driver transistors to +12V
16 1N4148
the +12-V line, as shown on the R6
T3
10k
to take apart the power bar. Cheap
BC547
power bars, which are usually hot- 020298 - 11
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
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)
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.
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Ω
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
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
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
The P89LPC900
Part 1: the architecture
By M. Stottelaar Eurodis Texim
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
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
+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-
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 +
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
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.
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
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.
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
(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)
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.
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
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
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
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.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.
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).
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
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
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
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µ
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
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];
42 elektor - 3/2007
MICROCONTROLLER
USB Analogue
Converter
With two analogue inputs and four digital outputs
Design by E. Brador
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.
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.
pagesel acqudat
goto acqudat
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
Elektor Electronics
IC1 L2
R4
TORX173 L3 C8 C9
+5V +5V
1Ω
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
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
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
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
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
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
+0.5
-0.5
(‘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
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
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
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
-100
-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
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
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
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
USB-RS232 Interface
A compact solution for missing ports
Design by L. Lemmens
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
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#
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
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
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.
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.
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.
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.
to the PROM there are also special DATA Ø 1 2 Last Bit 1 2 Last Bit
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
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
0101
Figure 2. The circuit diagram.
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
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