17.11.2012 Views

Blockbusters - Allt om Elektronik

Blockbusters - Allt om Elektronik

Blockbusters - Allt om Elektronik

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

5<br />

Elektor<br />

<strong>Blockbusters</strong><br />

Top-15 articles fr<strong>om</strong> Elektor<br />

Elektor blockbusters Artikeltitel • 1


Contents<br />

Elektor RFID Reader ........................................................................................................3<br />

Stand Alone OBD-2 Analyser.........................................................................................11<br />

ElekTrack .......................................................................................................................18<br />

Making Waves at C ........................................................................................................24<br />

Digital Inspector ............................................................................................................27<br />

Profiler ..........................................................................................................................31<br />

ECIO PLC ........................................................................................................................36<br />

Universal JTAG Adaptor .................................................................................................41<br />

GBECG............................................................................................................................47<br />

Tilt Gamepad .......................................................................................................57<br />

Micro Webserver ..................................................................................................60<br />

Software Defined Radio ................................................................................................68<br />

Wireless USB in miniature .............................................................................................74<br />

A 16-bit T<strong>om</strong> Thumb ......................................................................................................82<br />

USB Flash Board ............................................................................................................89<br />

Elektor blockbusters Contents • 2


HANDS-ON MICROCONTROLLERS<br />

ELEKTOR RFID Reader<br />

For MIFARE ®<br />

Gerhard H. Schalk<br />

RFID cards are bec<strong>om</strong>ing<br />

increasingly popular in<br />

many fields where<br />

previously barcodes and chip<br />

cards were used. They open<br />

up many new possibilities, such<br />

as applications in travel cards or<br />

even banknotes. As befits a<br />

premier electronics magazine,<br />

Elektor Electronics is offering its<br />

readers with this issue not only a<br />

free RFID card but also a professional<br />

RFID reader for your own applications.<br />

The design described here can both read<br />

fr<strong>om</strong> and write to all types of RFID card<br />

that are c<strong>om</strong>patible with the MIFARE and<br />

ISO 14443-A international standards.<br />

In developing the Elektor Electronics<br />

RFID reader we have aimed to make<br />

the device as universal as possible. So,<br />

for example, the reader can be used in<br />

26<br />

and ISO 14443-A cards<br />

conjunction with a PC over a USB connection,<br />

or in stand-alone mode using<br />

its liquid crystal display. It is very simple<br />

to use the free PC-based program<br />

‘MIFARE Magic’ to read and write all<br />

kinds of MIFARE cards without<br />

installing special software in the<br />

reader.<br />

Elektor blockbusters Elektor RFID Reader • 3<br />

elektor electronics - 9/2006


Specifications<br />

Elektor Electronics RFID reader:<br />

• Near-field reader for 13.56 MHz RFID cards<br />

• C<strong>om</strong>patible with MIFARE and ISO 14443-A cards<br />

• Allows both reading and writing<br />

• USB interface for connection to PC<br />

• Ready for immediate use without programming<br />

• Free PC-based software available<br />

• Stand-alone (including portable) operation using LCD<br />

module<br />

• Dedicated MF RC522 reader IC<br />

• Dedicated microcontroller on reader board<br />

• SPI and I2C interfaces<br />

• Spare 8-bit microcontroller port<br />

• Buffered switching output<br />

MIFARE Magic directly supports a<br />

range of contactless 13.56 MHz<br />

MIFARE cards, including the Philips<br />

MIFARE UltraLight, MIFARE 1K and<br />

MIFARE 4K. The MIFARE Magic window<br />

(Figure 1) also offers the facility<br />

to send individual c<strong>om</strong>mands to the<br />

card with a click of the mouse. This<br />

allows you to determine the characteristics<br />

of different cards very easily.<br />

Examples of c<strong>om</strong>patible cards include<br />

the MIFARE UltraLight RFID card supplied<br />

with this issue, and described in<br />

more detail in a separate article, and<br />

smart cards used on many public<br />

transport systems all over the world —<br />

for example, the London Underground<br />

Oyster card<br />

In stand-alone operation, for example<br />

in an access control application, the<br />

reader can be used directly with the<br />

firmware we have developed. On<br />

switch-on the reader immediately<br />

looks for cards within the range of the<br />

antenna (a few centimetres) and reads<br />

any cards it finds in that area. The LCD<br />

(if connected) then shows the card<br />

type along with its serial number, and<br />

the switching output of the reader is<br />

activated.<br />

The reader is constructed around the<br />

newest Philips reader IC type<br />

MF RC522 and a type LPC936 microcontroller.<br />

Since the reader IC is only<br />

available in an HVQFN32 package, we<br />

have decided to solve the problems of<br />

mounting and soldering by making<br />

available ready populated and tested<br />

reader boards fitted with pre-programmed<br />

microcontrollers.<br />

The Elektor Electronics RFID reader is<br />

naturally ideal for experimenting with<br />

the free MIFARE UltraLight card. The<br />

system includes a powerful microcontroller<br />

and I 2 C, SPI, UART and USB<br />

interfaces, and free development tools<br />

• Available as ready populated and tested SMD circuit<br />

board<br />

• Can be modified for user applications<br />

• Programming tools available<br />

MF RC522 reader IC:<br />

• Highly-integrated single-chip reader for ISO 14443-A and<br />

MIFARE cards<br />

• Supports contactless data transmission at 106 kbit/s,<br />

212 kbit/s and 424 kbit/s<br />

• 50 mm approx. read/write range (depending on antenna)<br />

• Integrated MIFARE Classic cryptography<br />

• Programmable over UART, I 2 C or SPI<br />

• 64 byte transmit and receive FIFO buffer<br />

• Programmable reset and power-down modes<br />

• Programmable timer<br />

• Internal oscillator allows direct connection of 27.12 MHz<br />

crystal<br />

are available. This makes it suitable for<br />

developing dedicated applications<br />

such as door and gate openers, membership<br />

card systems, storing passwords<br />

and configuration data, payment<br />

systems, security for d<strong>om</strong>estic<br />

appliances such as televisions, video<br />

recorders and PCs, monitoring battery<br />

Figure 1. The MIFARE Magic program developed for the Elektor Electronics RFID reader allows MIFARE and<br />

ISO 14443-A RFID cards to be read, written and programmed.<br />

Elektor blockbusters Elektor RFID Reader • 4<br />

9/2006 - elektor electronics 27


HANDS-ON MICROCONTROLLERS<br />

packs and much more besides. The<br />

c<strong>om</strong>bination of secure identity, data<br />

storage and contactless interface<br />

opens up many opportunities for novel<br />

applications.<br />

Reader hardware<br />

Figure 2 shows the block diagram of<br />

the reader. The basic reader functions,<br />

including the creation of the HF magnetic<br />

field, modulation and demodulation,<br />

and the generation of the<br />

ISO 14443 data stream, are carried out<br />

in the MF RC522. It is simplest to think<br />

of the MF RC522 as a contactless<br />

UART driven directly by the microcontroller.<br />

In the Elektor Electronics reader<br />

we have used an 8051-c<strong>om</strong>patible<br />

LPC936 microcontroller fr<strong>om</strong> Philips.<br />

The CPU takes only two cycles per<br />

instruction and is clocked at 16 MHz.<br />

This speed and the 16 kbyte Flash<br />

Elektor blockbusters<br />

28<br />

RFID Reader<br />

Analog<br />

Interface<br />

Antenna<br />

Matching<br />

MFRC5222<br />

MF RC522<br />

Voltage<br />

Regulator<br />

I 2 C<br />

Optional Power Supply<br />

5V<br />

LCD<br />

I /O<br />

�C / Philips<br />

LPC 935<br />

RS232<br />

FT232R<br />

USB / UART<br />

I 2 C<br />

060132 - 13<br />

Figure 2. Block diagram of the Elektor Electronics RFID reader.<br />

Contactless<br />

UART<br />

USB<br />

memory are sufficient for an enormous<br />

range of possible applications. Programs<br />

for the microcontroller can be<br />

simply written using any 8051 c<strong>om</strong>piler.<br />

C<strong>om</strong>munications with the PC are<br />

handled by an FT232R USB/RS232<br />

interface chip fr<strong>om</strong> our friends at<br />

Future Technology Devices (FTDI).<br />

The full circuit diagram is shown in<br />

Figure 3. When connected to a PC,<br />

power is taken fr<strong>om</strong> the USB via miniconnector<br />

K1. The FT232R USB interface<br />

chip is configured to report the<br />

reader as a high-power device when<br />

the bus is initialised (during ‘enumeration’).<br />

As a bus-powered device the<br />

reader can then draw a current of up to<br />

500 mA. When enumeration is c<strong>om</strong>plete<br />

the /PWRNEN signal on pin 11 of<br />

IC1 changes state, making P-channel<br />

MOSFET T2 conduct. The 5 V supply is<br />

then passed through to voltage regulator<br />

IC5. The output of the LM2937 pro-<br />

Register Bank<br />

FIFO Serial UART<br />

SPI<br />

I<br />

Host<br />

2C Figure 4. Block diagram of the Philips MF RC522 reader IC.<br />

060132 - 14<br />

vides the 3.3 V supply for the LPC<br />

microcontroller (IC3) and the<br />

MF RC522 (IC4). Red LED D6 shows<br />

when the 3.3 V supply is present. If 5 V<br />

power is not provided via the USB connector<br />

Schottky diode D4 allows an<br />

external power supply to take over<br />

aut<strong>om</strong>atically. Either four AA-size cells<br />

(the enclosure suggested in the parts<br />

list will accept these) or a 5 V mains<br />

supply capable of delivering at least<br />

300 mA can be used.<br />

Figure 4 shows an overview of the<br />

internal functions of the MF RC522<br />

reader IC in the form of a (greatly simplified)<br />

block diagram. The output drivers<br />

of the device allow direct connection<br />

of transmit and receive antennas<br />

without external active amplification<br />

circuitry. A few passive c<strong>om</strong>ponents<br />

provide the essential matching to the<br />

antenna characteristics. The analogue<br />

interface handles demodulation and<br />

decoding of the reply data sent by the<br />

card. The digital block is responsible<br />

for constructing the ISO 14443A or<br />

MIFARE protocol frames and acc<strong>om</strong>panying<br />

error detection (parity and CRC).<br />

The FIFO buffer allows 64-byte blocks<br />

to be sent and received in ISO 14443<br />

mode (‘T=CL’ protocol). In MIFARE<br />

mode the largest data blocks<br />

exchanged are at most 16 bytes long,<br />

and so there is no need for the microcontroller<br />

to split up the c<strong>om</strong>mand<br />

packets. The registers of the MF RC522<br />

can be programmed over the SPI, asynchronous<br />

serial or I 2 C interfaces. Since<br />

the LPC936 microcontroller only has<br />

one asynchronous serial interface, and<br />

this is required for c<strong>om</strong>munications<br />

with the PC, the I 2 C interface is used<br />

to talk to the MF RC522.<br />

If desired an LCD module can be connected<br />

to port P0 of the LPC936 via<br />

connector K2. P0.0 is buffered by a<br />

transistor and provides a switched output,<br />

and the SPI and I 2 C interfaces of<br />

the microcontroller afford plenty of<br />

opportunities to expand the reader by<br />

adding extra hardware. For example, a<br />

real-time clock could easily be added<br />

to allow for time monitoring, and the<br />

switched output could control a door<br />

opener; see also the pages about the<br />

RFID reader on the Elektor Electronics<br />

website.<br />

Get started<br />

The double-sided printed circuit board<br />

for the Elektor Electronics RFID reader<br />

is shown in Figure 5. It is only possible<br />

to reflow solder the reader IC, and<br />

so we are making the board available<br />

Elektor RFID Reader • 5<br />

elektor electronics - 9/2006


Elektor blockbusters<br />

060132 - 11<br />

LC DISPLAY<br />

LCD1<br />

VSS<br />

VDD<br />

VO<br />

RS<br />

R/W<br />

D7<br />

E<br />

D0<br />

D1<br />

D2<br />

D3<br />

D4<br />

D5<br />

D6<br />

D7<br />

K<br />

A<br />

1k<br />

R17<br />

BC517<br />

K2<br />

10k<br />

1 2 3 4 5 6<br />

7 8 9<br />

10 11 12 13 14 15 16<br />

R14<br />

T3<br />

P1<br />

10k<br />

10�<br />

16MHz<br />

27.12MHz<br />

2�2<br />

R10<br />

10�<br />

12p<br />

12p<br />

12p<br />

12p<br />

100n<br />

see text *<br />

voir texte *<br />

siehe Text *<br />

zie tekst *<br />

C29<br />

R11<br />

C7<br />

C8<br />

C13<br />

C14<br />

C16<br />

+5V<br />

100n 47p<br />

47p<br />

4<br />

GND<br />

MINI USB-B<br />

C3<br />

C1<br />

C2<br />

TEST<br />

GND GND GND<br />

17 20 24<br />

OSC<br />

IN OUT<br />

21 22<br />

X2<br />

*<br />

1n<br />

C24<br />

C15<br />

560nH<br />

27<br />

28<br />

OSCI<br />

OSCO<br />

26<br />

27p<br />

4�7<br />

L3<br />

5<br />

FT232RQFN<br />

220p<br />

*<br />

C23<br />

68p<br />

*<br />

R9<br />

Ant.<br />

3<br />

4<br />

15<br />

14<br />

USBDM<br />

USBDP<br />

C19<br />

9/2006 - elektor electronics 29<br />

1<br />

2<br />

DCD<br />

CTS<br />

8<br />

220p<br />

*<br />

C20<br />

C27<br />

68p<br />

*<br />

C28<br />

Ant.<br />

L5<br />

K1<br />

RTS<br />

DSR<br />

6<br />

7<br />

2<br />

3<br />

�1<br />

C17<br />

1<br />

P89LPC935<br />

P0.0<br />

P2.0<br />

P0.1<br />

P2.1<br />

P0.2 P2.2/MOSI<br />

P0.3 P2.3/MISO<br />

P0.4<br />

P2.4/SS<br />

P0.5 P2.5/SPICLK<br />

P0.6<br />

P2.6<br />

P0.7/T1<br />

P2.7<br />

VSS P3.1/X1 P3.0/X2<br />

7 8 9<br />

X1<br />

4<br />

18<br />

DVSS<br />

AVSS<br />

D6<br />

D7<br />

20<br />

19<br />

3<br />

26<br />

25<br />

24<br />

1<br />

2<br />

13<br />

14<br />

15<br />

16<br />

27<br />

28<br />

5<br />

D4<br />

D5<br />

23<br />

22<br />

EA<br />

MFRC522<br />

PVSS<br />

TX2<br />

13<br />

24<br />

32<br />

ALE SDA<br />

TXD<br />

RS<br />

R/W<br />

E<br />

30<br />

31<br />

D7 SCL<br />

TVSS<br />

D6 A0<br />

14<br />

8<br />

29<br />

D5 A1<br />

TVSS<br />

10<br />

IC2 = 74HC02<br />

9<br />

560nH<br />

IC2.A<br />

L2<br />

100n<br />

BAT54<br />

C31<br />

D5<br />

1k<br />

1k<br />

9<br />

8<br />

�1<br />

10<br />

R1<br />

R2<br />

19 1<br />

VCC VCCIO<br />

RESET 3V3OUT<br />

IC1<br />

CBUS0 TXLED TXD<br />

CBUS1 RXLED DTR<br />

CBUS2<br />

RXD<br />

CBUS3 PWRNEN RI<br />

CBUS4 SLEEP<br />

32<br />

27<br />

28<br />

D3 A3<br />

D4 A2<br />

27p<br />

C18<br />

C25<br />

C26<br />

RXD<br />

4�7<br />

L4<br />

10<br />

11<br />

2<br />

3<br />

C21<br />

R8<br />

22<br />

21<br />

31<br />

*<br />

30<br />

1k<br />

2k2<br />

C22<br />

R6<br />

R7<br />

18<br />

16<br />

5<br />

6<br />

�1<br />

4<br />

IC2.C<br />

IC2.B<br />

12<br />

11<br />

�1<br />

JP2<br />

21<br />

VDD<br />

4<br />

P1.7<br />

6 5<br />

P1.5/RST P1.6<br />

17<br />

10<br />

P1.1/RXD P1.4/INT1<br />

11<br />

P1.3/SDA/INT0<br />

18<br />

12<br />

P1.0/TXD P1.2/SCL<br />

IC3<br />

D1 A5<br />

D2 A4<br />

TX1<br />

25<br />

26<br />

VMID<br />

16<br />

11<br />

IC4<br />

1<br />

6<br />

23<br />

NRSTPD<br />

IRQ<br />

SVDD<br />

AUX1<br />

AUX2<br />

19<br />

20<br />

I2C<br />

PVDD<br />

DVDD<br />

AVDD<br />

TVDD<br />

RX 17<br />

15 12<br />

13<br />

GR<br />

YE<br />

100n<br />

100n<br />

IC2.D<br />

D1<br />

D2<br />

C4<br />

C5<br />

L1<br />

10k<br />

100n<br />

1k<br />

100n 100n<br />

100n 100n<br />

JP1<br />

4k7<br />

R16<br />

C6<br />

CPU PWR<br />

R15<br />

4k7<br />

4k7<br />

C9<br />

C10<br />

C11<br />

C12<br />

R5<br />

R3<br />

R4<br />

100k<br />

2�2<br />

1k<br />

R13<br />

R12<br />

D6<br />

C30<br />

14<br />

C32<br />

IC2<br />

2�2<br />

7<br />

Figure 3. C<strong>om</strong>plete circuit diagram of the reader, which can operate either in stand-alone mode, using the LCD module, or in conjunction with a PC using the USB interface.<br />

7<br />

9<br />

2 3<br />

RE<br />

T1<br />

IRLM6402<br />

BAS19<br />

T2<br />

IRLM6402<br />

D3<br />

+4V8...+6V<br />

D4<br />

+3V3<br />

+5V<br />

IC5<br />

LM2937<br />

Elektor RFID Reader • 6


HANDS-ON MICROCONTROLLERS<br />

30<br />

T<br />

R17<br />

D7<br />

K2<br />

(C) ELEKTOR<br />

C6<br />

T3<br />

C7<br />

060132-1<br />

C8<br />

060132-1<br />

C9<br />

C10<br />

C29<br />

14 1<br />

R14<br />

X1<br />

IC3<br />

D6<br />

R15<br />

R4<br />

R3<br />

R5<br />

IC4<br />

R11 R10<br />

-<br />

X2<br />

C12<br />

C17<br />

L2<br />

C11<br />

L3<br />

C19<br />

C16<br />

R7<br />

R6<br />

C15<br />

C18 C20<br />

C21C25<br />

C27C23<br />

C22C26<br />

C28C24<br />

R8 R9<br />

C13C14<br />

JP2<br />

D3<br />

P1<br />

JP1<br />

IC2<br />

C32<br />

R12<br />

IC5<br />

T1<br />

R16<br />

D2<br />

R2<br />

R1<br />

C30 T2<br />

D1<br />

C3<br />

C5<br />

IC1<br />

C1<br />

C2<br />

C4<br />

R13 L1<br />

C31 D4<br />

+ +<br />

Figure 5. The double-sided printed circuit board incorporates the antenna. The reader IC is not suitable for<br />

hand soldering and so the board is available ready populated and tested.<br />

Elektor blockbusters<br />

K1<br />

D5<br />

-<br />

ready populated and tested. Instructions<br />

are also provided for building the<br />

unit into the suggested enclosure,<br />

which we can also supply.<br />

The two jumpers on the reader board<br />

(JP1 and JP2) are not fitted for normal<br />

operation. Assuming the LCD module<br />

is connected to the reader board, the<br />

unit is ready for operation as soon as<br />

power is applied, and the serial number<br />

of any RFID card within range of<br />

the reader’s antenna will appear on<br />

the display. If the display appears<br />

blank, the contrast should be adjusted<br />

using P1.<br />

To use the reader with a USB connection<br />

to a PC, the free CMD-FDTI-USB<br />

driver must be downloaded fr<strong>om</strong> the<br />

Elektor Electronics website. This particular<br />

driver is required because the<br />

FT232R contains the Elektor Electronics<br />

Vendor ID and Product ID.<br />

When the RFID reader is connected to<br />

the PC using the supplied USB cable<br />

Windows will aut<strong>om</strong>atically detect the<br />

new USB device. The freshly-downloaded<br />

driver should be selected for<br />

the unit. If problems arise, the ‘Installation<br />

Guide’ on the FTDI website<br />

(www.ftdichip.c<strong>om</strong>) can be consulted<br />

for assistance: this guide is also applicable<br />

to the modified driver.<br />

Installing the CMD-FTDI driver installs<br />

both the ‘D2XX’ (direct) and ‘VCP’ (virtual<br />

COM port) drivers. The VCP driver<br />

allows the USB link to be treated fr<strong>om</strong><br />

the point of view both of the PC and of<br />

the microcontroller as an ordinary<br />

RS232 connection.<br />

The D2XX driver is required if it is<br />

desired to modify the unit in a way<br />

that requires changes to the internal<br />

configuration data stored in EEPROM<br />

in the FT232R. This can be done using<br />

the PC-based program MPROG, available<br />

as a free download fr<strong>om</strong> the FDTI<br />

website: MPROG will work only with<br />

the D2XX driver.<br />

MIFARE Magic<br />

Once the driver has been installed,<br />

MIFARE Magic, a specially-written PCbased<br />

program for the Elektor Electronics<br />

RFID reader, can be run. This is<br />

also available as a free download, fr<strong>om</strong><br />

www.elektor-electronics.co.uk. After<br />

downloading the program the contents<br />

of the ZIP file must be copied into a<br />

subdirectory of your choice. Start the<br />

program with a double-click on<br />

MifareMagic.exe, with the reader<br />

already connected to the USB port.<br />

This allows MIFARE Magic to find the<br />

reader aut<strong>om</strong>atically. There is no need<br />

Elektor RFID Reader • 7<br />

elektor electronics - 9/2006


Elektor blockbusters<br />

COMPONENTS<br />

LIST<br />

Resistors<br />

(all SMD case 0805, 5%)<br />

R1,R2,R6,R12,R15,R17 = 1k�<br />

R3,R4,R5 = 4k�7<br />

R7 = 2k�7<br />

R8,R9 = 4�7<br />

R10 = 270�<br />

R11 = 10�<br />

R13 = 100k�<br />

R14,R16 = 10k�<br />

P1 = 10k�-preset, SMD, 4 mm SQ<br />

Capacitors<br />

(all SMD case 0805, 16 V, ceramic)<br />

C1,C2 = 47pF NP0<br />

C3,C4,C5,C6,C9,C10,C11,C12,C16,<br />

C31 = 100nF<br />

C7,C8,C13,C14 = 12pF NP0<br />

C15 = 1nF NP0<br />

C17,C19 = 220 p NP0<br />

C18,C20 = not fitted<br />

C21,C23 = 27pF NP0<br />

C22,C24 = not fitted<br />

C25,C27 = 68pF NP0<br />

C26,C28 = not fitted<br />

C29,C30, C32 = 2μF2<br />

Semiconductors<br />

D1 = SMD LED (0805) green,<br />

low-current<br />

D2 = SMD LED (0805) yellow,<br />

low-current<br />

D3,D6,D7 = SMD LED (0805), red,<br />

low-current<br />

D4 = BAS19 (200 mA; SOT23)<br />

D5 = BAT54S (30V / 300 mA; SOT23)<br />

T1,T2 = 6402 (p-channel MOSFET, 20V /<br />

3.7A; SOT23)<br />

T3 = BC517 (npn Darlington; TO92 case)<br />

IC1 = FT232RQFN (QFN32 case, FTDI)<br />

IC2 = 74HC02 (TSSOP14 case; NOR<br />

gate)<br />

IC3 = P89LPC936FDH-S (SSOP28 case;<br />

Philips)<br />

IC4 = MFRC52201HN1 (HVQFN32case;<br />

Philips)<br />

IC5 = LM2937 (low-drop, 3V3, SOT223<br />

case)<br />

Miscellaneous<br />

X1 = 16MHz quartz crystal (18pF parallel<br />

capacitance; 5·3.2mm)<br />

X2 = 27.12MHz quartz crystal (18pF<br />

parallel capacitance; 5·3.2mm)<br />

K1 = miniature USB-B socket, SMD,<br />

5-way<br />

L1 = SMD ferrite (1.5 A; 0805 case)<br />

L2,L3 = 560nH SMD inductor (0805 case)<br />

JP1,JP2 = 0.1-in. jumper (see text)<br />

LCD1 = LCD module with 2x16 characters<br />

and backlight<br />

Enclosure, dim. 146x91x33 mm with LCD<br />

window and battery c<strong>om</strong>partment for 4<br />

AA bateries<br />

PCB, order code 060132-91 (populated<br />

and tested, including USB cable; see<br />

Elektor SHOP pages and<br />

www.elektor.c<strong>om</strong>)<br />

C<strong>om</strong>patible LC display (see Elektor SHOP<br />

pages and www.elektor.c<strong>om</strong>)<br />

89LPC936 source & hex code files; free<br />

download fr<strong>om</strong> www.elektor.c<strong>om</strong><br />

Mifare Magic PC software incl. source<br />

code; free download fr<strong>om</strong><br />

www.elektor.c<strong>om</strong><br />

Elektor RFID Reader • 8<br />

9/2006 - elektor electronics 31


HANDS-ON MICROCONTROLLERS<br />

32<br />

Figure 6. The ‘Terminal’ view of MIFARE Magic shows all the characters sent by the reader<br />

over the USB interface.<br />

Figure 7. The ‘MIFARE UltraLight’ and ‘Mifare Standard‘ windows allow<br />

simple programming of the RFID card.<br />

Figure 8. The free PC-based Flash Magic program can program the LPC microcontroller over the USB interface<br />

of the Elektor Electronics RFID reader.<br />

Elektor blockbusters<br />

to select a COM port, as MIFARE<br />

Magic uses the D2XX driver internally.<br />

Figure 6 shows the ‘Terminal’ view of<br />

MIFARE Magic. This mode emulates a<br />

VT100 terminal and displays all the<br />

characters sent by the LPC microcontroller<br />

over the FTDI interface.<br />

The firmware in the LPC microcontroller<br />

defaults to ‘terminal’ mode on<br />

power-up. As soon as the reader<br />

detects a new card within its field it<br />

activates the card. The reader determines<br />

whether the card is a MIFARE<br />

UltraLight, MIFARE 1K or MIFARE 4K.<br />

The entire memory contents of the<br />

card are read out and displayed on the<br />

MIFARE Magic terminal. For MIFARE<br />

1K and 4K cards the standard MIFARE<br />

key is used. If the card uses a different<br />

key the data stored in certain sectors<br />

will not be readable. To use a different<br />

terminal program instead of MIFARE<br />

Magic (such as HyperTerminal or the<br />

built-in terminal in the LPC Flash<br />

Magic programming tool), the VCP<br />

driver must be used and the terminal<br />

program must be told the number of<br />

the relevant COM port. The parameters<br />

for the port are as follows: 115200<br />

baud, no parity, 8 data bits and one<br />

stop bit.<br />

The ‘Window’ menu allows MIFARE<br />

Magic to be switched between the<br />

‘Terminal’ view, the ‘MIFARE Ultra-<br />

Light’ and the ‘Show All Cards’ views.<br />

The ‘MIFARE UltraLight’ window (see<br />

Figure 7) allows various card c<strong>om</strong>mands<br />

to be executed with a click of<br />

the mouse. This makes it easy to program<br />

a MIFARE UltraLight card, such<br />

as the sample supplied free with this<br />

issue. When this window is opened<br />

the firmware in the LPC microcontroller<br />

on the reader board switches<br />

fr<strong>om</strong> terminal mode into PC reader<br />

mode. Here the microcontroller waits<br />

for a card c<strong>om</strong>mand fr<strong>om</strong> the PC and<br />

calls the corresponding function in its<br />

software. This mode is useful when<br />

developing applications on the PC.<br />

The ‘Show All Cards’ window displays<br />

the serial numbers of all cards currently<br />

detected by the reader. This is<br />

useful for testing reader range and the<br />

capacity of the reader to deal with multiple<br />

cards simultaneously.<br />

Program-it-yourself<br />

For dedicated applications it is possible<br />

to modify or c<strong>om</strong>pletely rewrite<br />

both the firmware in the LPC936 and<br />

the software running on the PC. Any<br />

updates to the reader firmware will<br />

also require reprogramming the<br />

Elektor RFID Reader • 9<br />

elektor electronics - 9/2006


LPC936. The most up-to-date software<br />

will always be available on the Elektor<br />

Electronics website for free download.<br />

Updates will be reported on the news<br />

pages of the website and in the magazine<br />

under ‘Corrections and Updates’.<br />

The LPC on the reader board can be<br />

programmed directly over the USB port<br />

using the free PC program ‘Flash<br />

Magic’ (see Figure 8). This program,<br />

fr<strong>om</strong> Embedded Systems Academy<br />

(www.esacademy.c<strong>om</strong>) and sponsored<br />

by Philips (www.semiconductors.c<strong>om</strong>)<br />

supports a range of Philips microcontrollers.<br />

Both jumpers JP1 and JP2 must be fitted<br />

on the reader board before the LPC<br />

microcontroller can be programmed.<br />

Interested readers will find a detailed<br />

discussion of how to program the<br />

device on the Elektor Electronics website<br />

along with a list of all the MIFARE<br />

UltraLight reader and card c<strong>om</strong>mands.<br />

The reader firmware was developed<br />

using the Keil mVision3 C c<strong>om</strong>piler for<br />

the LPC microcontroller. All the c<strong>om</strong>mands<br />

necessary for developing dedicated<br />

applications are made available<br />

as functions and so it is not necessary<br />

to deal directly with the individual registers<br />

of the MF RC522.<br />

The listing shows the code necessary<br />

to activate a MIFARE UltraLight card<br />

and read a data block. The data will be<br />

transmitted using the serial interface<br />

of the microcontroller.<br />

As mentioned above, the PC<br />

reader mode of the LPC<br />

firmware allows a<br />

PC application<br />

to<br />

invoke<br />

card functions.<br />

Using<br />

this mode<br />

function invocation<br />

is done<br />

using a very simple<br />

serial protocol<br />

to c<strong>om</strong>municate with<br />

the program running<br />

in the microcontroller.<br />

When the function has<br />

been executed the<br />

response is returned to the<br />

PC. The naming and parameters<br />

of the functions are identical<br />

in the PC software and in<br />

the microcontroller firmware.<br />

The source code for the PC-based<br />

MIFARE Magic program and for the<br />

microcontroller software can be<br />

downloaded for free fr<strong>om</strong> the Elektor<br />

Electronics website.<br />

(060132-1)<br />

Listing<br />

while(1)<br />

{<br />

status = ISO14443_Request(WUPA, &bATQ);<br />

if(status != STATUS_SUCCESS)<br />

continue;<br />

}<br />

status = ISO14443_Anticoll(Level1,0,&abSNR[0]);<br />

if(status != STATUS_SUCCESS)<br />

continue;<br />

status = ISO14443_Select(Level1, &abSNR[0], &bSAK);<br />

if(status != STATUS_SUCCESS)<br />

continue;<br />

// Check if UID is c<strong>om</strong>plete<br />

if((bSAK & 0x04) == 0x04)<br />

{<br />

// UID not c<strong>om</strong>plete<br />

status = ISO14443_Anticoll(Level2,0,&abSNR[4]);<br />

if(status != STATUS_SUCCESS)<br />

continue;<br />

}<br />

status = ISO14443_Select(Level2, &abSNR[4], &bSAK);<br />

if(status != STATUS_SUCCESS)<br />

continue;<br />

// Read UltraLight Block 0..3<br />

status = Read(0,abDataBuffer);<br />

Elektor blockbusters Elektor RFID Reader • 10<br />

9/2006 - elektor electronics 33


PROJECTS VEHICULAR TEST EQUIPMENT<br />

Stand Alone OBD-<br />

Interpret<br />

‘trouble<br />

codes’<br />

without a PC<br />

Folker Stange and Erwin Reuss<br />

This handy analyser makes a simple job of rummaging through the information stored by the client–<br />

accessible part of your car’s c<strong>om</strong>puter. It works with all current OBD-2 protocols and can read and erase<br />

trouble codes stored in the vehicle and reset the MIL display. All this without the help of a PC or a visit<br />

to a service station.<br />

Since the turn of the millennium more<br />

and more new car models have been<br />

fi tted with the latest version of the on<br />

board diagnostic interface OBD-2. With<br />

the increasing sophistication of modern<br />

engine management many new<br />

owners have seen the benefi ts of an<br />

OBD analyser such that it is fast bec<strong>om</strong>ing<br />

an essential part of the garage<br />

tool kit along with the torque wrench<br />

and spark plug spanner.<br />

It has been reported that s<strong>om</strong>etimes<br />

when owners fi t a new car radio or satnav<br />

system to their car the vehicle<br />

management system unnecessarily<br />

registers a fault, similarly s<strong>om</strong>e owners<br />

who have modifi ed the engine to accept<br />

an alternative fuel have noticed<br />

that the engine management can incorrectly<br />

interpret the engine condition<br />

Elektor blockbusters<br />

and trigger an error. In s<strong>om</strong>e cases the<br />

engine management can even be<br />

switched into an emergency condition.<br />

Whatever the cause the outc<strong>om</strong>e is the<br />

same; a dashboard mounted MIL (malfunction<br />

indicator light) c<strong>om</strong>es on, a<br />

fault condition is stored and it is necessary<br />

to make an (expensive) visit to the<br />

nearest garage to have the ‘trouble’<br />

put right and the MIL reset. With the<br />

OBD analyser described here in your<br />

glove box it is a simple job to connect<br />

to the OBD socket, fi nd out what the<br />

trouble is, reset the error and continue<br />

on your journey. On cost grounds alone<br />

the price of the analyser will be more<br />

than repaid by avoiding just a single<br />

unnecessary visit to a dealership<br />

garage.<br />

A number of OBD analysers have been<br />

featured in the electronics press (including<br />

Elektor Electronics) describing<br />

an interface between the OBD connector<br />

and a laptop. The approach we<br />

have adopted here is however far less<br />

cumbers<strong>om</strong>e, this stand-alone unit<br />

does not require a notebook or battery,<br />

recognises all the usual OBD-2 or EOBD<br />

protocols and is small enough to stow<br />

in your car’s glove box. Operation is<br />

quite straightforward using just two<br />

buttons, 580 of the c<strong>om</strong>monest trouble<br />

codes can be recognised and described<br />

on its running text display.<br />

The Circuit<br />

The OBD-2 analyser employs an AT-<br />

90CAN128 microcontroller fr<strong>om</strong> the ATmega128<br />

family fr<strong>om</strong> Atmel. This par-<br />

Stand Alone OBD-2 Analyser • 11<br />

46 elektor electronics - 6/2007


2 Analyser<br />

socket<br />

ticular model has an on-board CAN<br />

bus interface as shown in Figure 1.<br />

The controller is supplied pre-programmed<br />

with the AGV4900 fi rmware<br />

which handles the user-interface including<br />

push buttons, buzzer, LEDs<br />

and LCD.<br />

Pin assignments the OBD-2 connector<br />

are given in Figure 2. In order to support<br />

all the current OBD-2 protocols<br />

the analyser needs to be able to interface<br />

to several bi-directional<br />

interfaces:<br />

6/2007 - elektor electronics<br />

ISO/KWP<br />

PWM<br />

VPWM<br />

CAN<br />

16 x 3 LCD DISPLAY<br />

A<br />

Key<br />

AGV4900<br />

B<br />

handheld scanner<br />

070038 - 12<br />

Figure 1. Block diagram of the OBD-2 analyser.<br />

K-Line<br />

CAN-H<br />

S-GND<br />

C-GND<br />

PWM+<br />

VPWM<br />

8 7 6 5 4 3 2 1<br />

16 15<br />

14 13 12 11 10 9<br />

+12 V<br />

L-Line<br />

CAN-L<br />

PWM-<br />

070038 - 14<br />

Figure 2. Pin defi nitions of the OBD-2/EOBD connector.<br />

Elektor blockbusters<br />

Specification<br />

• Aut<strong>om</strong>atic or manual selection of OBD-2 protocol<br />

• Very fast aut<strong>om</strong>atic protocol scan (0.1 to 2.6 s per protocol)<br />

• Fast software boot sequence (ready to go around a second after switch on)<br />

• Read and display important vehicle information (depending on the vehicle)<br />

• Real-time sensor reading (selectable)<br />

• Vehicle chassis number display (if supported by the vehicle manufacturer)<br />

• Readout and display of the trouble code memory<br />

• Read out and display of Freeze-Frame data<br />

• Erasure of trouble code memory<br />

• Language selection (English or French)<br />

• 580 trouble codes with description in running text<br />

• All existing OBD protocols for private vehicles are supported:<br />

ISO9141-2<br />

ISO14230-4 (KWP2000)<br />

J1850 PWM<br />

J1850 VPWM<br />

ISO15765-4 (CAN, 11/29 Bit, 250/500 kbits/s)<br />

• Power for the analyser is supplied fr<strong>om</strong> the vehicle’s OBD-2 connector (12 V)<br />

• Backlit 3-line LC display with adjustable contrast<br />

• Acoustic signal gives audible feedback and beeps when trouble codes recognised<br />

• LED Indicators for connection status and data traffi c fl ow<br />

• Simple operation using just two push buttons<br />

• Connection for a standard OBD-2 cable<br />

• Handheld format: 80x135x30 mm (wxhxd), weight 150 g (approx.)<br />

• Supplied as a kit through Elektor SHOP<br />

��K/L interface<br />

��PWM interface<br />

��VPWM interface<br />

��CAN interface<br />

Points to note<br />

The fi rst three of these in the circuit<br />

diagram (Figure 3) have been implemented<br />

using transistors and c<strong>om</strong>parators<br />

confi gured to meet the interface<br />

standards. The specifi ed pull up resistors<br />

for the K and L signals have a rela-<br />

The OBD analyser is only suitable for vehicles fi tted with an OBD-2/EOBD connector.<br />

EOBD is fi tted to vehicles sold in the EU:<br />

- after 01.01.2001, for petrol engine vehicles.<br />

- after 01.01.2004, for diesel engine vehicles.<br />

Before the analyser is plugged into any vehicle manufactured before these dates, it is<br />

important to check c<strong>om</strong>patibility with the OBD-2 standard. The website of Florian Schäffer<br />

[3] contains a databank of vehicles where you check to see if yours is OBD-2 c<strong>om</strong>patible.<br />

Stand Alone OBD-2 Analyser • 12<br />

47


PROJECTS VEHICULAR TEST EQUIPMENT<br />

K-Line<br />

L-Line<br />

Q4<br />

2x<br />

BS170<br />

+12V<br />

6<br />

7<br />

8<br />

9<br />

Q8<br />

BS250 D5<br />

1N4148<br />

PWM-<br />

D1<br />

+12V<br />

+12V+5V<br />

560 �<br />

560 �<br />

6k8<br />

6k8<br />

+5V<br />

8 RN1<br />

10k<br />

7<br />

VPWM<br />

PWM+<br />

R6<br />

1N4004<br />

K2<br />

Q3<br />

1<br />

2<br />

3<br />

4<br />

5<br />

RN1<br />

10k<br />

9<br />

RN1<br />

10k<br />

5<br />

Q5<br />

7<br />

10<br />

6<br />

6<br />

IC2.B<br />

BS170<br />

8 RN2<br />

tively low impedance so MOSFETs<br />

have been used here as drivers. The<br />

CAN bus driver IC type PCA82C250<br />

takes care of the CAN interface.<br />

The user-interface software is logically<br />

designed such that just two push buttons<br />

are required to operate the analyser<br />

and select all possible menu options.<br />

Connections for the buzzer, the<br />

‘connect’ and ‘Data Traffic’ LEDs<br />

should not require any further explanation.<br />

Control of the three-line LCD is a<br />

little more c<strong>om</strong>plex, a fi ve wire SPI interface<br />

connects the display to the controller.<br />

LED backlights ensure that the<br />

display is night time readable. The relatively<br />

low controller clock speed<br />

(8 MHz) is a good c<strong>om</strong>pr<strong>om</strong>ise, producing<br />

a low level of EMI emissions while<br />

still giving ample operating speed for<br />

this application.<br />

Elektor blockbusters<br />

3 RN1<br />

10k<br />

4<br />

R11<br />

R4<br />

100k<br />

R3<br />

100k<br />

RN3<br />

6k8<br />

6<br />

K/L-Interface<br />

5<br />

8 RN3<br />

7<br />

5<br />

4<br />

2 RN1<br />

10k<br />

1<br />

IC2.A<br />

PWM-Interface<br />

IC2 = LM339N<br />

CAN-H<br />

CAN-L<br />

1<br />

7<br />

2<br />

10k<br />

100 �<br />

2 RN3<br />

1<br />

R7<br />

CAN-Interface<br />

3<br />

100 �<br />

Q7<br />

BS250<br />

D4<br />

R8<br />

C6 C7<br />

470p 470p<br />

10 RN2<br />

10k<br />

9<br />

13<br />

7<br />

CANH<br />

6<br />

CANL<br />

8<br />

RS<br />

+5V<br />

S1 S3<br />

KL IN<br />

K OUT<br />

L OUT<br />

IC4<br />

Q6<br />

BS170<br />

PWM+ OUT<br />

PWM- OUT<br />

PWM IN<br />

+8V +5V<br />

VPWM-Interface<br />

RN2<br />

11 5<br />

IC2.D<br />

10<br />

1N4148<br />

8<br />

RN2 IC2.C<br />

2<br />

10k<br />

9<br />

1<br />

14<br />

4 RN2<br />

10k<br />

TXD<br />

1<br />

RXD<br />

4<br />

5<br />

VREF<br />

2 PCA82C250<br />

The Firmware<br />

3<br />

10k 6<br />

3 RN3<br />

6k8<br />

4<br />

VPWM<br />

OUT<br />

VPWM<br />

IN<br />

51<br />

(AD0)PA0<br />

50<br />

(AD1)PA1<br />

49<br />

(AD2)PA2<br />

48<br />

(AD3)PA3<br />

47<br />

(AD4)PA4<br />

46<br />

(AD5)PA5<br />

45<br />

(AD6)PA6<br />

44<br />

(AD7)PA7<br />

35<br />

(A8)PC0<br />

36<br />

(A9)PC1<br />

37<br />

(A10)PC2<br />

38<br />

(A11)PC3<br />

39<br />

(A12)PC4<br />

40<br />

(A13)PC5<br />

41<br />

(A14)PC6<br />

42<br />

(A15)PC7<br />

9<br />

8<br />

7<br />

6<br />

5<br />

4<br />

3<br />

2<br />

62<br />

The heart of the OBD-2 analyser is the<br />

pre-programmed microcontroller with<br />

the designation AGV4900 [1] available<br />

solely fr<strong>om</strong> Stange Distribution [2]. The<br />

software was developed by co-author<br />

Erwin Reuss. Like similar OBD projects<br />

the fi rmware for this analyser is only<br />

available pre-programmed into the microcontroller<br />

where it is copy protected.<br />

The source fi les are not available<br />

for download. Without this software<br />

copy protection is would not be possible<br />

to offer the analyser in kit form.<br />

There is no possibility for the h<strong>om</strong>e<br />

constructor to assemble a low-cost version<br />

of this design unless of course all<br />

the necessary software is written fr<strong>om</strong><br />

scratch.<br />

A menu option switches all display information<br />

between either English or<br />

French (for the convenience of our Ca-<br />

nadian readers). Stange Distribution<br />

are specialists in OBD related equipment<br />

and produce several OBD-2 controllers<br />

for applications in the fi eld of<br />

OBD development.<br />

All the OBD analyser functions can be<br />

selected fr<strong>om</strong> the menu using just two<br />

keys. One feature of the software is the<br />

very quick boot procedure which ensures<br />

that the device is ready for use in<br />

little more than a second after switchon.<br />

The most important 580 trouble<br />

codes have a plain text description of<br />

the fault which is displayed in running<br />

text (in the language chosen). This feature<br />

helps pr<strong>om</strong>ote a quick and effective<br />

diagnosis of the problem. In the<br />

vast majority of cases there will be no<br />

need to look up the code in an OBD<br />

trouble code book.<br />

48 elektor electronics - 6/2007<br />

C10<br />

100n<br />

(IC3/INT7)PE7<br />

(T3/INT6)PE6<br />

(OC3C/INT5)PE5<br />

(OC3B/INT4)PE4<br />

(OC3A/AIN1)PE3<br />

(XCK0/AIN0)PE2<br />

(TXD/PDO)PE1<br />

(RXD/PDI)PE0<br />

AREF<br />

29<br />

(IC1)PD4<br />

30<br />

(XCK1)PD5<br />

31<br />

(T1)PD6<br />

32<br />

(T2)PD7<br />

AGND<br />

63<br />

C5<br />

22p<br />

AVCC<br />

+5V<br />

64 52 21<br />

IC3<br />

PB7(OC2/OC1C)<br />

17<br />

PB6(OC1B)<br />

16<br />

PB5(OC1A)<br />

15<br />

PB4(OC0)<br />

14<br />

PB3(MISO)<br />

13<br />

PB2(MOSI)<br />

12<br />

PB1(SCK)<br />

11<br />

PB0(SS)<br />

10<br />

AT90CAN128<br />

AGV4900<br />

XTAL1 XTAL2<br />

Q1<br />

8MHz<br />

VCC<br />

VCC<br />

24 23<br />

PG4(TOSC1)<br />

19<br />

PG3(TOSC2)<br />

18<br />

PG2(ALE)<br />

43<br />

PG1(RD)<br />

34<br />

PG0(WR)<br />

33<br />

1<br />

C4<br />

22p<br />

20<br />

RESET<br />

PEN<br />

GND<br />

GND<br />

PF7(ADC7/TDI)<br />

54<br />

PF6(ADC6/TDO)<br />

55<br />

PF5(ADC5/TMS)<br />

56<br />

PF4(ADC4/TCK)<br />

57<br />

PF3(ADC3)<br />

58<br />

PF2(ADC2)<br />

59<br />

PF1(ADC1)<br />

60<br />

PF0(ADC0)<br />

61<br />

PD0(SCL/INT0)<br />

25<br />

PD1(SDA/INT1)<br />

26<br />

PD2(RXD1/INT2)<br />

27<br />

PD3(TXD1/INT3)<br />

28<br />

53 22<br />

1k<br />

R1<br />

1k5<br />

R12<br />

LED1 LED2<br />

+12V<br />

red green<br />

+5V<br />

VCC<br />

RST<br />

38<br />

CSB<br />

39<br />

RS<br />

Figure 3. The AVR microcontroller with on-board CAN interface is the main part of the circuit diagram.<br />

3<br />

IC2<br />

12<br />

GND<br />

R5<br />

33�<br />

1N4148<br />

R/W<br />

E<br />

VIN<br />

D2<br />

BZ1<br />

F/CM12P<br />

26 40 37 36 25 24 35 34 33 32 31 30 29 28<br />

VOUT<br />

D0<br />

D1<br />

D2<br />

D3<br />

D4<br />

D5<br />

D6<br />

D7<br />

LCD<br />

EA DOG-M163E<br />

PSB<br />

27 23<br />

C1<br />

100n<br />

IC5<br />

7805<br />

CAP1N CAP1B<br />

21<br />

+5V<br />

C2<br />

100n<br />

3<br />

IC1<br />

78L08<br />

+5V<br />

33�<br />

A1<br />

1<br />

A2<br />

20<br />

C1<br />

2<br />

C2<br />

19<br />

R9<br />

+8V<br />

C3<br />

100n<br />

070038 - 11<br />

Stand Alone OBD-2 Analyser • 13


Putting all the bits together<br />

Attention has been paid to the PCB<br />

layout (Figure 4); SMD c<strong>om</strong>ponents<br />

have not been used for this design to<br />

COMPONENTS<br />

LIST<br />

Resistors<br />

RR1 = 1k�<br />

R3,R4 = 100k�<br />

R5,R9 = 33�<br />

R6,R11 = 560�<br />

R7,R8 = 100�<br />

R12 = 1k�5<br />

RN1,RN2 = 10k� SIL-10 array<br />

RN3 = 6k�8 SIL-8 array<br />

Capacitors<br />

C1,C2,C3,C10 = 100nF<br />

C4,C5 = 22pF<br />

Elektor blockbusters<br />

6/2007 - elektor electronics<br />

Figure 4. The PCB is an SMD-free zone.<br />

simplify c<strong>om</strong>ponent mounting. The<br />

PCB is produced to industry standard<br />

using FR4 type board with gold plating.<br />

Gold is chemically inert and gives<br />

C6,C7 = 470pF<br />

Semiconductors<br />

D1 = 1N4004<br />

D2,D4,D5 = 1N4148<br />

IC1 = 78L08<br />

IC2 = LM339N<br />

IC3 = AT90CAN128 (Atmel; QIL case),<br />

programmed as “AGV4900” (Stange<br />

Distribution)<br />

IC4 = PCA82C250 (Philips)<br />

IC5 = 7805<br />

LED1 = 3mm, red<br />

LED2 = 3mm, green<br />

Q3-Q6 = BS170 (TO92)<br />

Q7,Q8 = BS250 (TO92)<br />

Miscellaneous<br />

Q1 = 8MHz quartz crystal (HC49/S)<br />

the board almost unlimited shelf life.<br />

The plating also ensures that there<br />

should be no problems of corrosion<br />

which have been reported when lead-<br />

LC-Display 3x16 lines, type EA DOGM163E;<br />

with background light: EA LED55X31-A<br />

S1,S3 = PCB mount pushbutton type 40-XX<br />

B3F (Omron) with matching aluminium cap<br />

DC buzzer<br />

X2 = 9-way sub-D plug (male), PCB mount<br />

IC socket 14-way<br />

IC socket 8-way<br />

QIL socket (4 segments of 16 pins)<br />

PCB<br />

Case with front panel foil<br />

Mounting materials<br />

Note: Kit of parts no. 070038-71 contains<br />

all c<strong>om</strong>ponents, the case (with front panel<br />

foil fi tted), mounting materials and OBD-<br />

2 cable, see Elektor SHOP advert or www.<br />

elektor-electronics.co.uk<br />

Stand Alone OBD-2 Analyser • 14<br />

49


PROJECTS VEHICULAR TEST EQUIPMENT<br />

free solder is used on unplated boards.<br />

Gold has excellent tinning properties<br />

and allows the use of either lead-free<br />

or lead/tin solder. Apart fr<strong>om</strong> the need<br />

to take care with c<strong>om</strong>ponent placement<br />

and soldering, no special electronic<br />

skills or programming c<strong>om</strong>petence<br />

is needed to c<strong>om</strong>plete this<br />

project.<br />

Except for the two LEDs ‘connect’ and<br />

‘data-traffi c’, the two pushbuttons and<br />

the LC display all other c<strong>om</strong>ponents<br />

are mounted on the PCB side printed<br />

with the c<strong>om</strong>ponent outlines and identification<br />

(Figure 5). Mounting the<br />

c<strong>om</strong>ponent starts with soldering each<br />

of the individual resistors into place<br />

followed by the diodes, capacitors,<br />

crystal, IC sockets, resistor networks<br />

(make sure they are the right way<br />

round), voltage regulator and then the<br />

transistors. The 7805 should fi rst be<br />

mechanically secured before the leads<br />

are soldered in place. Once the buzzer<br />

Elektor blockbusters<br />

Figure 5. The PCB c<strong>om</strong>ponent side. Figure 6. The two push buttons, LEDs and LCD are mounted on the other side of the PCB.<br />

and the sub-D connector are fi tted the<br />

board can be flipped over and the<br />

pushbuttons, display and LEDs soldered<br />

into place.<br />

The AT90CAN128 chip fr<strong>om</strong> Atmel<br />

Figure 7. The controller board connector<br />

is made up of four sections.<br />

used in this project is unfortunately<br />

only available in either the TQFP or<br />

MLF/QFN outline and neither of these<br />

are really suitable for a self-build<br />

project. The controller is therefore supplied<br />

(in MLF outline) already mounted<br />

on a small carrier board. It is only necessary<br />

to fi t an intermediate pin/socket<br />

arrangement to connect the carrier<br />

board to the main PCB. The pin layout<br />

of this connector is the same as a<br />

QIL64 package (Quad in line, 64 Pins).<br />

All the c<strong>om</strong>ponents for this connector<br />

are included in the kit, to ensure success<br />

it will be necessary to follow the<br />

instructions carefully, a mistake here<br />

will be diffi cult to correct.<br />

The c<strong>om</strong>plete socket is made up of four<br />

strips (Figure 7) fi tted to the main PCB,<br />

each strip is fi xed in place initially by<br />

soldering just one pin of each of the<br />

strips, this allows the fi nal layout of the<br />

c<strong>om</strong>plete socket to be easily adjusted<br />

until it exactly matches the layout.<br />

Stand Alone OBD-2 Analyser • 15<br />

50 elektor electronics - 6/2007


Once you are sure that the four strips<br />

are accurately aligned (check that they<br />

are also all at the same height on the<br />

board) all the remaining pins can be<br />

carefully soldered to c<strong>om</strong>plete the<br />

socket.<br />

The carrier board can now be fitted<br />

with the pins. The supplied pin strips<br />

must be carefully separated<br />

into 8-pin lengths. Any rough<br />

corners can be smoothed<br />

down with a fine file. The<br />

strips are pushed fully into<br />

the socket Figure 8a (They<br />

only fit one way round: the<br />

thinner tapered pins go into<br />

the socket).<br />

The controller board can now<br />

be positioned onto the pins<br />

(Figure 8b) ensuring that<br />

pin 1 is correctly aligned (to<br />

the left by C10). The 64 pins<br />

can now be carefully soldered<br />

onto the controller board<br />

(Figure 8c).<br />

Once all the c<strong>om</strong>ponents have<br />

been fi tted a short test can be<br />

carried out by connecting a<br />

12-V supply to the sub-D connector<br />

(pin 9 = +12 V, pin 1 or<br />

2 = 0 V). The current drawn<br />

by the analyser should not exceed<br />

about 150 mA. The display<br />

backlight will be lit and<br />

the boot loader version<br />

number will appear on the<br />

display followed by the greeting<br />

message. The short selftest<br />

is now c<strong>om</strong>plete.<br />

The fi nished PCB can now be<br />

mounted in the case: Fit the<br />

pushbutton caps and the sub-<br />

D cover, remove the protective<br />

fi lm fr<strong>om</strong> the display and with<br />

the display facing downwards<br />

Elektor blockbusters<br />

6/2007 - elektor electronics<br />

a<br />

b<br />

Figure 8. The three steps to mount the controller board.<br />

position the PCB into the front cover of<br />

the case. The small countersunk<br />

screws can now be carefully screwed<br />

in and tightened. Lastly, fi t the remaining<br />

half of the case and the OBD-2-Analyser<br />

is now ready for action!<br />

Figure 9. Displays: (a) Contrast setting, (b) Start menu, (c) Status display,<br />

(d) MIL/DTC PID Menu, (e) DTC trouble code number.<br />

Analyser operation<br />

The fi rst requirement before the OBD-2<br />

analyser can be used is that the car is<br />

fi tted with the corresponding OBD-2<br />

connector (see the advice given in<br />

‘points to note’ elsewhere in this article).<br />

If it is, the supplied OBD-2 cable<br />

is inserted into the OBD-2 connector in<br />

the car. The connector<br />

shouldn’t be too diffi cult to locate,<br />

regulations insist that it<br />

must be mounted in the vehi-<br />

a<br />

b<br />

c<br />

d<br />

e<br />

c<br />

cle within 1 metre of the driver’s<br />

seat. A concise operating<br />

manual for the analyser is<br />

available to download fr<strong>om</strong><br />

www.elektor-electronics.co.uk. A<br />

shortform manual is also supplied<br />

in the kit of parts so we<br />

will not delve too deeply into<br />

the fi ner points here. An online<br />

simulator is also available<br />

on our website so you can familiarise<br />

yourself ‘virtually’<br />

with the analyser operation.<br />

At switch-on it is possible to<br />

alter the display contrast (Figure<br />

9a). This is achieved by<br />

holding down keys A and B<br />

and plugging the analyser into<br />

the OBD-2 socket. The contrast<br />

changes each time key A<br />

is pressed. Once you are happy<br />

with the setting release<br />

key A and press B to store it.<br />

This basic method is used to<br />

control the analyser: Key A cycles<br />

you through the menu options<br />

while key B confi rms a<br />

selection or provides a response<br />

fr<strong>om</strong> the equipment.<br />

The display now shows the<br />

greeting ‘ELEKTOR OBD2 1.4’<br />

with the start menu (Figure<br />

9b) following shortly after-<br />

Stand Alone OBD-2 Analyser • 16<br />

51


PROJECTS VEHICULAR TEST EQUIPMENT<br />

wards with the options: Start Diag,<br />

Protocol and Language. When the analyser<br />

is regularly used on the same vehicle<br />

and you are sure of the correct<br />

protocol then it can be selected otherwise<br />

option code 0 tells the analyser to<br />

aut<strong>om</strong>atically fi nd the correct protocol.<br />

A press on key B begins the scan (if the<br />

vehicle interface is not c<strong>om</strong>patible with<br />

OBD protocol the test ends with a failure<br />

message). When the scan has run<br />

the display will show the state of the<br />

MIL/DTC indicating if any troubles<br />

were present (Figure 9c). Selecting the<br />

option Live Data with button B will<br />

show the actual value of a parameter.<br />

The chassis number or vehicle ID can<br />

be read and the c<strong>om</strong>munication Protocol<br />

displayed as well as the option to<br />

rescan.<br />

The current reading of a sensor (live<br />

data) is given in the PID (parameter<br />

identifi er) menu. The example shown<br />

in Figure 9d is a reading of the intake<br />

Mass Air Flow (MAF in g/s). Pressing<br />

key B takes you back to the previous<br />

menu. When a failure has been detected<br />

by the engine management system<br />

the analyser will indicate that the MIL<br />

is on (MIL:ON), and the number of<br />

stored DTCs (Diagnostic Trouble Code)<br />

is given (Figure 9e) .There is now a<br />

choice between displaying the trouble<br />

codes or freeze frame data. For trouble<br />

codes the code number is displayed<br />

Elektor blockbusters<br />

errors found:<br />

2 of 4<br />

error code 2<br />

error 2<br />

description<br />

select error 3<br />

with button B<br />

070038 - 13<br />

Figure 10. Trouble code menu showing a description of the trouble in running text.<br />

Figure 11. The Freeze frame menu (PID select).<br />

along with (in most cases) a detailed<br />

description of the fault (see Figure<br />

10).<br />

When the trouble codes are displayed,<br />

pressing key A brings up an option to<br />

clear the codes fr<strong>om</strong> the vehicle’s<br />

memory.<br />

More information about the failure can<br />

be gleaned by selecting Freeze Frame.<br />

When an error is detected by the engine<br />

management system the on<br />

board c<strong>om</strong>puter will take a snapshot<br />

or freeze frame of all sensor<br />

readings and store them<br />

in the vehicle’s memory. A<br />

check of this data can provide<br />

a valuable insight<br />

into the cause of the<br />

failure. In selecting<br />

freeze frame trouble<br />

codes it is possible<br />

to select successive<br />

sensor values<br />

stored<br />

around the<br />

time that<br />

the failureoccurred.<br />

The example in Figure 11 indicates a<br />

sensor reading when trouble was<br />

logged; trouble F000 a PID 0D (speed)<br />

of VSS = 33 km/h measured. Button A<br />

takes you through successive parameters<br />

while button B returns to the previous<br />

menu.<br />

The downloadable user’s manual contains<br />

overviews of all the menu options,<br />

selections and display messages.<br />

When you want to get more familiar<br />

with its operation, try the online simulator<br />

mentioned earlier, or better still<br />

put your order in and build your own<br />

OBD-2 Analyser! An extra fi le containing<br />

soldering and assembly hints can<br />

also be downloaded fr<strong>om</strong> the Elektor<br />

Electronics website.<br />

52 elektor electronics - 6/2007<br />

(070038-I)<br />

Literature<br />

[1] Datasheet for the AGV4900-Controller:<br />

www.obd-diag.de<br />

[2] Source of the AGV microcontroller: www.<br />

stange-distribution.de<br />

[3] http://www.blafusel.de/misc/OBD-2_<br />

scanned.php<br />

Stand Alone OBD-2 Analyser • 17


PROJECTS GPS<br />

ElekTrack<br />

Tracking & tracing<br />

with GPS<br />

Chris Vossen<br />

Position determination is all the rage. The manufacturer of the well-known T<strong>om</strong>T<strong>om</strong><br />

navigation system has bec<strong>om</strong>e a publicly traded c<strong>om</strong>pany, and the alarm systems of<br />

expensive cars and other vehicles often c<strong>om</strong>prise positioning systems so they can report<br />

where the vehicle is located. However, such systems are rather expensive, so we decided to<br />

take the DIY approach and develop our own version, dubbed ElekTrack.<br />

Nowadays we want to know the current<br />

position of everything. Where’s<br />

that package I ordered? Is the book I<br />

want already back in the library? Has<br />

my nephew’s train arrived already?<br />

Technology has advanced so much in<br />

recent years that there’s almost no situation<br />

we can imagine that doesn’t already<br />

have a solution. And otherwise<br />

we provide a solution!<br />

Big Brother<br />

People are often a bit nervous about<br />

organisations that keep track of everything,<br />

but in s<strong>om</strong>e cases this is exactly<br />

what we want. For example, consider<br />

car security and alarm systems. Those<br />

of us who can afford the latest Maybach<br />

or Mercedes SLR will doubtless<br />

encounter stringent security requirements<br />

when they take out insurance<br />

for their vehicles. Quite often these<br />

cars must be fitted with security systems<br />

that include vehicle tracking and<br />

tracing capability in addition to standard<br />

anti-start and alarm functions. This<br />

means that they have a built-in GPSbased<br />

positioning system that reports<br />

Elektor blockbusters<br />

the vehicle location to a message centre.<br />

Stolen vehicles are indicated by red<br />

spots on a map in the control ro<strong>om</strong>.<br />

Passenger cars are not the only vehicles<br />

being fitted with tracking systems.<br />

Lorries and boats can also benefit<br />

fr<strong>om</strong> such systems. More and more<br />

excavating machines are also being<br />

fitted with security systems, because<br />

they are stolen by the truckload. With<br />

a built-in track & trace module, these<br />

pricy machines can be tracked down<br />

and recovered.<br />

Of course, not everybody has an excavating<br />

machine or a Bentley in the garage,<br />

but it’s still possible to find other<br />

interesting uses for a GPS tracker. For<br />

example, on a scooter or motorcycle.<br />

And if you’re a private detective, such<br />

a system is bound to make your eyes<br />

light up.<br />

We developed the ElekTrack to give<br />

our readers an opportunity to experiment<br />

with GPS tracking. Due to the<br />

large number of SMD c<strong>om</strong>ponents<br />

and the difficulty of soldering such<br />

c<strong>om</strong>ponents, we decided to supply<br />

this module fully assembled only.<br />

Objective of the design<br />

What must a tracking aid be able to<br />

do in its simplest form? Naturally, you<br />

want to be able to track the unit’s location.<br />

We chose the most obvious solution<br />

for the position determination<br />

part: GPS. With this, the system can<br />

identify its position nearly everywhere<br />

in the world. In addition, GPS is presently<br />

very accurate, and as long as the<br />

European Galileo system [1] is not yet<br />

operational, it is the best ‘alternative’.<br />

We decided on SMS for data transmission.<br />

Although data transmission is<br />

not actually live with this approach,<br />

it is possible almost everywhere and<br />

at all times. The GPRS network would<br />

have been another good option for data<br />

transmission. GPRS works with a direct<br />

link via the Internet, so data can<br />

Figure 1. As you can readily see fr<strong>om</strong> the schematic,<br />

everything revolves around the GSM modem.<br />

ElekTrack • 18<br />

36 elektor - 10/2007


R7<br />

3V3<br />

56R2<br />

C15<br />

be displayed live on a c<strong>om</strong>puter<br />

with Internet access. The location<br />

could thus be queried<br />

without any time delay,<br />

and the data could be<br />

stored ‘live’ in a database.<br />

However,<br />

we gave the preference<br />

to the<br />

simpler SMS<br />

system.<br />

The design<br />

T3 MMBT3906 2x<br />

T4<br />

4k7<br />

T1<br />

T2<br />

GND<br />

R10<br />

Vbat<br />

100k<br />

10R<br />

R5<br />

10/2007 - elektor<br />

D6 L4<br />

BLM21P300S<br />

RS3K<br />

D7<br />

R3<br />

IRLML6402<br />

BC848<br />

1N4148<br />

K1<br />

GND<br />

4k7<br />

D4<br />

R11<br />

100n SM8S33A<br />

250V<br />

VCC 1<br />

GND 2<br />

RST 3<br />

VPP 4<br />

CLK 5<br />

IO 6<br />

10<br />

9<br />

Simcard Holder<br />

K4<br />

5<br />

4<br />

3<br />

2<br />

Elektor blockbusters<br />

1<br />

1k<br />

L3<br />

100nH<br />

C7 C8<br />

100n 18p<br />

R4<br />

R6<br />

1k<br />

T5<br />

1V8<br />

GND<br />

C16 C17 C18<br />

4u7<br />

50V<br />

22n 220p<br />

BOOST 6<br />

1<br />

GND<br />

8<br />

GND<br />

9<br />

GND<br />

16<br />

GND<br />

17<br />

GND<br />

C1<br />

100n<br />

SW 2<br />

3<br />

VIN<br />

4<br />

VIN<br />

SW 5<br />

BIAS 10<br />

11<br />

VC<br />

FB 12<br />

15<br />

SHDN<br />

IC5<br />

680n<br />

L5<br />

47uH<br />

R12<br />

LT3430<br />

R13<br />

3k3<br />

10k<br />

R8<br />

MMBT3904<br />

10k<br />

R9<br />

1<br />

3<br />

4<br />

6<br />

2<br />

5<br />

ESDA6V1SC6<br />

D1<br />

1<br />

GND<br />

2<br />

GND<br />

4<br />

GND<br />

13<br />

GND<br />

14<br />

GND<br />

15<br />

GND<br />

27<br />

GND<br />

28<br />

GND<br />

GND<br />

3V3<br />

VCC 12<br />

3<br />

RF-IN<br />

5<br />

LNA<br />

7<br />

OPEN<br />

SHORT<br />

10<br />

BOOT<br />

11<br />

XRESET<br />

TXD-B<br />

8<br />

24<br />

TXD-A 23<br />

RXD-A 21<br />

RXD-B 20<br />

PPS 19<br />

XSTANDBY 16<br />

9<br />

RESERVED<br />

IC4<br />

Copernicus GPS Receiver<br />

14<br />

SYNC<br />

C11<br />

D8<br />

1<br />

3<br />

4<br />

6<br />

D5<br />

1N4148<br />

30BQ060<br />

thus consists of two main modules: a<br />

GPS module and a GSM module.<br />

The GSM module is a type Q2686 fr<strong>om</strong><br />

Wavec<strong>om</strong>. This module can be controlled<br />

using Wavec<strong>om</strong> OpenAT c<strong>om</strong>mands,<br />

and it has a built-in microcontroller.<br />

The main advantage of this is<br />

shorter development time c<strong>om</strong>pared<br />

with using a separate modem, since<br />

it is not necessary to implement a microcontroller<br />

or any peripheral logic.<br />

Everything is located in a single module.<br />

This also keeps the overall design<br />

nicely c<strong>om</strong>pact.<br />

For the GPS module, we decided on the<br />

Copernicus fr<strong>om</strong> Trimble. This is a successor<br />

to the Lassen iQ, which already<br />

showed what it could do in the USB<br />

12k7<br />

4k99<br />

2<br />

5<br />

C10<br />

100n<br />

GND<br />

R14<br />

D2<br />

DALC208<br />

4V3<br />

C12<br />

100u<br />

10V<br />

8<br />

IVCC1<br />

1<br />

OVCC2<br />

C19<br />

C2<br />

470p<br />

1V8<br />

VL 3<br />

2<br />

100k<br />

GND<br />

R1<br />

4V3<br />

6<br />

THREE-STATE<br />

1<br />

VIN<br />

3<br />

ON/OFF NC 4<br />

VOUT 5<br />

LP2985<br />

2<br />

GND<br />

4V3 1V8 2V8<br />

9<br />

SIM_VCC<br />

11<br />

SIM_IO<br />

12<br />

SIMPRES<br />

13<br />

SIM_RST<br />

14<br />

SIM_CLK<br />

VBATT 1<br />

VBATT 2<br />

VBATT 3<br />

VBATT 4<br />

19<br />

ON_OFF<br />

17<br />

FLASH LED<br />

15<br />

BUZZ_OUT<br />

16<br />

BOOT<br />

18<br />

/RESET<br />

20<br />

BAT_TEMP<br />

21<br />

AUX_ADC<br />

22<br />

SPI1-CS<br />

23<br />

SPI1-CLK<br />

24<br />

D12 SPI1-I<br />

25<br />

SPI1-IO<br />

28<br />

SPI2-CS<br />

27<br />

SPI2-IO<br />

SPI2-I<br />

29 SPI2-CLK<br />

26<br />

34<br />

MIC2N<br />

35<br />

SPK1P<br />

36<br />

MIC2P<br />

37<br />

SPK1N<br />

38<br />

MIC1N<br />

39<br />

SPK2P<br />

40<br />

MIC1P<br />

41<br />

SPK2N<br />

30<br />

RXD2<br />

TXD2<br />

31<br />

32<br />

CTS2<br />

33<br />

RTS2<br />

42<br />

GPIO0<br />

43<br />

GPIO44<br />

4V3 IC6<br />

3V3<br />

C13<br />

VCC 7<br />

100n 1u<br />

16V<br />

IC3<br />

K5<br />

C9<br />

100n<br />

GND<br />

IVL2 4<br />

OVL1 5<br />

MAX3375E<br />

GND<br />

470R<br />

R25<br />

470R<br />

R2<br />

D3<br />

1V8<br />

C14<br />

10u<br />

10V<br />

101<br />

GND<br />

102<br />

GND<br />

IC2<br />

VCC_1V8 5<br />

CHG_IN 6<br />

BAT_RTC 7<br />

CHG_IN 8<br />

VCC_2V8 10<br />

Wavec<strong>om</strong> Q2686<br />

K2<br />

103<br />

GND<br />

Vbat<br />

GND<br />

GND<br />

PCM_SYNC 77<br />

PCM_IN 78<br />

PCM_CLK 79<br />

PCM_OUT 80<br />

RI1/GPIO42 69<br />

DCD1/GPIO43 70<br />

TXD1/GPIO36 71<br />

RTS1/GPIO38 72<br />

RXD1/GPIO37 73<br />

DSR1/GPIO40 74<br />

CTS1/GPIO39 75<br />

DTR1/GPIO41 76<br />

COL0/GPIO4 59<br />

COL1/GPIO5 60<br />

COL2/GPIO6 61<br />

COL3/GPIO7 62<br />

COL4/GPIO8 63<br />

ROW4/GPIO13 64<br />

ROW3/GPIO12 65<br />

ROW2/GPIO11 66<br />

ROW1/GPIO10 67<br />

ROW0/GPIO9 68<br />

104<br />

GND<br />

EXT_INPUT1<br />

EXT_INPUT2<br />

EXT_INPUT3<br />

TXD_OUT<br />

RXD_IN<br />

GPIO22 57<br />

GPIO24 58<br />

VPAD-USB 52<br />

GPIO2 53<br />

USB-DP 54<br />

GPIO23 55<br />

USB-DM 56<br />

SCL 44<br />

GPIO19 45<br />

SDA 46<br />

GPIO21 47<br />

GPIO20 48<br />

INT1 49<br />

INT0 50<br />

GPIO1 51<br />

GPS receiver design published in the<br />

May 2005 issue of Elektor Electronics.<br />

Schematic diagram<br />

A glance at the schematic diagram in<br />

Figure 1 quickly shows that everything<br />

is built around the GSM modem. The<br />

GPS module is connected to UART2 of<br />

the modem via a logic-level converter<br />

(IC3). The circuitry around T3, T4 and<br />

T5 detects whether the antenna circuit<br />

is shorted, open, or connected normally.<br />

The GPS module supplies power to<br />

the active antenna via T1 and T2.<br />

Two supply voltages are necessary for<br />

proper operation of the circuit: 4.5 V<br />

and 3.3 V. They are provided by IC5 and<br />

IC6. IC5 (a LT3430) is a buck convert-<br />

GND<br />

R21<br />

82k<br />

R20<br />

82k<br />

K3<br />

4k7<br />

R16<br />

82k<br />

T6<br />

MMBT3904<br />

R24<br />

C22 D9<br />

10n 1N4148<br />

10k<br />

DI0<br />

DI1<br />

DI2<br />

R17<br />

3V3<br />

2<br />

C1+<br />

4<br />

C1-<br />

5<br />

C2+<br />

6<br />

C2-<br />

11<br />

T1IN<br />

9<br />

R1OUT<br />

1<br />

EN<br />

FORCEON 12<br />

FORCEOFF 16<br />

R1IN<br />

10<br />

INVALID<br />

8<br />

T1OUT 13<br />

V- 7<br />

V+ 3<br />

C4<br />

100n<br />

C5<br />

C3<br />

100n<br />

100n<br />

L1<br />

BLM21B102<br />

MAX3221E<br />

R15<br />

L2<br />

BLM21B102<br />

C6<br />

100n<br />

10k<br />

2V8<br />

T7<br />

MMBT3904<br />

R23<br />

C21 D10<br />

10n 1N4148<br />

10k<br />

VCC 15<br />

IC1<br />

14<br />

GND<br />

2V8<br />

4k7<br />

GND<br />

GND<br />

R18<br />

4k7<br />

T8<br />

MMBT3904<br />

R22<br />

C20 D11<br />

10n 1N4148<br />

10k<br />

TXD_OUT<br />

RXD_IN<br />

R19<br />

040161 - 11<br />

ElekTrack • 19<br />

37


PROJECTS GPS<br />

er operating a frequency of 200 kHz.<br />

Resistors R12 and R14 determine the<br />

output voltage, which is set to approximately<br />

4.5 V.<br />

IC6 provides the supply voltage for the<br />

GPS module. It generates a fixed 3.3-V<br />

output voltage fr<strong>om</strong> a 4.5-V input voltage.<br />

Three identical level converters<br />

are formed using T6, T7 and T8. They<br />

convert the relatively high input voltages<br />

to logic levels that c<strong>om</strong>ply with<br />

the specifications of the GSM modem.<br />

IC1 is a standard RS232 converter,<br />

which among other things can be used<br />

for connecting the unit to a PC in order<br />

to program the modem. You can also<br />

use IC1 as a port for your own applications.<br />

D1 and D2 protect the input<br />

of the GSM module against static discharges<br />

that can occur when the SIM<br />

card is inserted in the socket.<br />

LED D3 shows the status of the GSM<br />

link. If it is continuously on, the modem<br />

is not logged in to the network. It<br />

starts blinking as soon as the modem<br />

logs in successfully. LED D12 shows<br />

the status of the GPS module.<br />

External connections<br />

The power supply can work with an<br />

external 12-V or 24-V system. Based on<br />

tests, the ElekTrack requires an external<br />

supply voltage of at least 8 V for<br />

proper operation. The external power<br />

source must also be able to supply<br />

sufficient current. Relatively high peak<br />

currents occur when the GSM modem<br />

is transmitting data. The average power<br />

consumption of the unit is around<br />

500 mW, so a 9-V battery would only<br />

last for approximately 2 hours. A scooter<br />

or motorcycle battery will hold out<br />

for a lot longer. Naturally, it would always<br />

be possible to modify the soft-<br />

Elektor blockbusters<br />

ware in order to reduce the current<br />

consumption. For instance, you could<br />

implement a function to place the GPS<br />

module in sleep mode with an SMS<br />

c<strong>om</strong>mand and awaken it with another<br />

c<strong>om</strong>mand.<br />

Naturally, the unit also has antenna<br />

connectors: one for the GPS module<br />

and one for the GSM module. The modem<br />

also has several logic inputs. They<br />

can be used for purposes such as connecting<br />

an alarm to the ElekTrack. A<br />

voltage above approximately 8 V will<br />

cause the digital input of the GSM modem<br />

to be triggered. When this happens,<br />

a text message can be sent to<br />

one of two previously programmed telephone<br />

numbers. You will have to implement<br />

this in the software yourself,<br />

since this function is not yet included<br />

as standard. Perhaps it will be implemented<br />

in a firmware update.<br />

The GPS module can be configured<br />

using various c<strong>om</strong>mands. For this purpose,<br />

the module must be linked to a<br />

PC by a cable. A program such as HyperTerminal<br />

for Windows must be used<br />

to configure the ElekTrack unit. The serial<br />

port of the PC must be configured<br />

as shown in Figure 2.<br />

Startup<br />

The first thing you have to do is to<br />

check whether the SIM card is protected<br />

by a PIN code. Use the following<br />

c<strong>om</strong>mand for this:<br />

at+cpin?<br />

If the modem responds with ‘+CPIN:<br />

READY’, the SIM card does not need a<br />

PIN code. If you receive the response<br />

‘+CPIN:SIM PIN’ instead, the SIM<br />

card needs a PIN code, and this will<br />

first have to be eliminated. The current<br />

firmware does not yet support<br />

aut<strong>om</strong>atic PIN code use. This may be<br />

implemented in a future version of the<br />

firmware. Check our website for the<br />

latest version.<br />

If you enter the c<strong>om</strong>mand<br />

at+cpin=xxxx<br />

(where ‘xxxx’ is the pin code of the<br />

SIM card), you will receive ‘OK’ in<br />

response.<br />

Next you have to request disabling of<br />

PIN checking by entering the following<br />

c<strong>om</strong>mand:<br />

at+clck=”SC”,0,xxxx (where<br />

‘xxxx’ is again the PIN code of the SIM<br />

card). The modem will again respond<br />

with ‘OK’.<br />

In order to check whether the modem<br />

can now log into the network aut<strong>om</strong>atically,<br />

you have to reset it with<br />

ElekTrack • 20<br />

38 elektor - 10/2007


at+cfun=1<br />

If everything goes well, the upper LED<br />

(D12) will start blinking after a bit less<br />

than a minute. This means that the mo-<br />

Better than GPS<br />

The Global Positioning System (GPS) was originally<br />

developed for military use. In response to<br />

steadily increasing demand for accurate position<br />

determination, the GPS system was released for<br />

civilian use a bit at time. At first, the accuracy of<br />

the satellite signals was intentionally degraded<br />

by the US authorities who originally established<br />

the system. This restriction was removed a few<br />

years ago, so consumers can now use the full<br />

resolution of the system. This allows GPS to be<br />

used to determine positions with an potential<br />

error of up to three metres. The positioning accuracy<br />

depends on the number of ‘visible’ satellites<br />

and whether a WAAS or EGNOS signal is<br />

received.<br />

The terms WAAS and EGNOS relate to systems<br />

that can be used in c<strong>om</strong>bination with GPS to<br />

increase positioning accuracy. WAAS stands for ‘<br />

Wide Area Augmentation System’, while EGNOS<br />

stands for ‘European Geostationary Navigation<br />

Overlay Service’. The EGNOS and WAAS<br />

systems do the same thing, but the former is for<br />

Europe and the latter for North America. Each<br />

system consists of a network of satellites and<br />

ground stations that generate a GPS correction<br />

signal that can be used to increase positioning<br />

accuracy by a factor of up 5 on average. A receiver<br />

that supports WAAS or EGNOS generates<br />

positions that differ fr<strong>om</strong> true positions by less<br />

Elektor blockbusters<br />

10/2007 - elektor<br />

dem has successfully logged in to the<br />

network. If you wish, you can check<br />

this by entering the c<strong>om</strong>mand<br />

at+cops?<br />

The modem will respond with<br />

+COPS: 0,2,20408<br />

OK<br />

(here ‘20408’ is the operator number,<br />

than 3 metres in more than 95% of all cases.<br />

EGNOS currently consists of three geostationary<br />

satellites and several ground stations distributed<br />

over Europe. The ground stations collect information<br />

fr<strong>om</strong> each other and generate a correction<br />

signal. The ground stations know their own<br />

locations with high accuracy, and they c<strong>om</strong>pare<br />

their positions with the signals received fr<strong>om</strong><br />

the satellites, since the paths of the satellite signals<br />

can be distorted by atmospheric conditions<br />

and other causes. The correction signal is then<br />

transmitted to the geostationary satellites. This<br />

data has the same format as the standard GPS<br />

signal, so it can be read by any GPS receiver<br />

that supports WAAS.<br />

EGNOS is as joint project of ESA, Eurocontrol<br />

and the European C<strong>om</strong>mission, and it works<br />

with the American GPS navigation system and<br />

the Russian Glonass navigation system. The EG-<br />

NOS satellite number for Europe is 33. Many<br />

GPS systems indicate whether they are receiving<br />

a correction signal. The term ‘differential’ is<br />

also used for this.<br />

The MSAS system, which operates the same<br />

way, is used in Asia.<br />

ElekTrack • 21<br />

39


PROJECTS GPS<br />

Figure 2. The settings shown here must be used for serial<br />

c<strong>om</strong>munication.<br />

which depends on the provider.)<br />

Now the modem will log into the network<br />

aut<strong>om</strong>atically as soon as power<br />

is applied to the module.<br />

Security<br />

The first thing you have to do is to<br />

change the password. The default<br />

password is ‘elektor’. To change the<br />

password, first enter the following<br />

c<strong>om</strong>mand to request the password:<br />

at+password?<br />

The modem will respond with ‘+PASS-<br />

WORD:: elektor’. To change the password,<br />

use the c<strong>om</strong>mand:<br />

at+password=”gpsmodule”<br />

Note: you must enter the quotation<br />

marks as shown; otherwise you will receive<br />

an error message. The maximum<br />

password length is 20 characters.<br />

GPS status<br />

The GPS module is connected to the<br />

serial port of the modem. Two c<strong>om</strong>mands<br />

for requesting data fr<strong>om</strong> the<br />

GPS module are implemented in the<br />

first version of the firmware. The first<br />

c<strong>om</strong>mand is<br />

at+gpshealth?<br />

The following is an example of a possible<br />

response fr<strong>om</strong> the modem:<br />

Rcvr status code = 0x01<br />

(Don’t have GPS time yet)<br />

Receiver health byte = 0x11<br />

Battery backup: BBRAM not<br />

available at start-up<br />

Antenna feedline fault: An-<br />

Elektor blockbusters<br />

tenna line open/short<br />

Type of fault: Open detected<br />

OK<br />

Fr<strong>om</strong> this, you can deduce that the GPS<br />

module does not have any valid coordinates<br />

at present. The antenna status<br />

indicates a fault situation. The fault<br />

type indicates that the antenna connection<br />

is open-circuited. The antenna<br />

is probably not connected.<br />

If the c<strong>om</strong>mand is issued again after<br />

the antenna has been connected, you<br />

might receive the following response:<br />

Rcvr status code = 0x00 (Doing<br />

position fixes)<br />

Receiver health byte = 0x01<br />

Battery backup: BBRAM not<br />

available at start-up<br />

Antenna feedline fault: OK<br />

OK<br />

Here you can see that the antenna<br />

status is ‘OK’. If the antenna input is<br />

short-circuited, a ‘Short circuit’ status<br />

message will appear. The receiver<br />

status code reports that the receiver<br />

Figure 3. ElekTrack knows exactly where to find Elektor’s new head office!<br />

was able to determine a valid position.<br />

When the module is first enabled,<br />

the receiver status code indicates the<br />

number of satellites being received.<br />

When the receiver has managed to determine<br />

a valid position, the lower LED<br />

(D3) starts blinking. If this LED is on<br />

continuously, s<strong>om</strong>ething is wrong. It<br />

could mean that the module is not receiving<br />

enough satellites, but it could<br />

also mean that the antenna is connected<br />

incorrectly.<br />

Normal use<br />

Now that you have determined that a<br />

link has been established, you would<br />

like to know the latitude and longitude<br />

coordinates. Enter the following c<strong>om</strong>mand<br />

for this:<br />

at+gpsposition?<br />

The modem will return a set of coordinates<br />

in response, such as<br />

Long: 5.803043 E;<br />

Lat: 50.941492 N;<br />

OK<br />

ElekTrack • 22<br />

40 elektor - 10/2007


Practical problems<br />

Anyone who writes software knows that little bugs always<br />

find a way to creep into the code. When were first developing<br />

the software, we had problems with sending SMS<br />

messages. It seemed like the SMS service of the modem<br />

s<strong>om</strong>ehow didn’t want to work. After spending several<br />

hours looking for the source of the problem and reading<br />

through documentation, we came up with the simple but<br />

brilliant idea of trying a different SIM card. That meant<br />

a quick trip to the shop to pick up a new SIM card. And<br />

just imagine our surprise when we discovered that there<br />

were no problems at all with the new card!<br />

Of course, we found it rather remarkable that everything<br />

worked OK with the new SIM card, so we contacted the<br />

supplier. It turned out that there was indeed a bug in the<br />

modem firmware. Logging in to the SMS service evidently<br />

did not work properly with s<strong>om</strong>e types of SIM cards.<br />

This problem has been corrected in the latest version of<br />

the firmware.<br />

Another problem that is probably familiar to most software<br />

developers is the difference between little-endian<br />

and big-endian memory organisation. The GPS module<br />

outputs latitude and longitude coordinates as doubles in<br />

radians. The GPS module operates in little-endian mode,<br />

while the GSM module operates in big-endian mode.<br />

When you import the data (as ASCII values), the order<br />

of the bytes must therefore be reversed. If you convert<br />

little-endian radian data in a big-endian processor, the<br />

results are naturally all over the map. We overlooked this<br />

detail at first. Your first impulse is to think that you made<br />

a mistake in the code that performs the conversion. In<br />

retrospect it’s all pretty obvious, but in the midst of the<br />

fray it’s a hard nut to crack.<br />

Of course, you want to be able to request<br />

the coordinates via SMS so you<br />

can request the position of the module<br />

remotely. To prevent unauthorised<br />

persons fr<strong>om</strong> receiving a reply<br />

fr<strong>om</strong> the module if they send a text<br />

message to it, the module must have<br />

a password. Send the following message<br />

to the module via SMS to assign<br />

it a password:<br />

info::<br />

or<br />

INFO::<br />

Note: ‘info’ must be written either<br />

entirely in upper case or entirely in<br />

lower case. The password you configured<br />

using the at+password c<strong>om</strong>mand<br />

must be entered here in place of<br />

.<br />

The parameter is option-<br />

Elektor blockbusters<br />

10/2007 - elektor<br />

al. The reply is returned to the sender<br />

by default. If you want to have the reply<br />

be sent to a different number, you<br />

can use this parameter to specify the<br />

desired number.<br />

After a few seconds, the ElekTrack will<br />

send a text message via SMS with the<br />

longitude, latitude and altitude data,<br />

which can be used to determine the location<br />

of the ElekTrack unit. For example,<br />

you can do this online at [2] (Figure<br />

3) or [3].<br />

The ElekTrack is supplied as fully assembled<br />

unit, and you can order it via<br />

our webshop at www.elektor.c<strong>om</strong>.<br />

The latest version of the software is<br />

also available on our website. And of<br />

course, we always appreciate hearing<br />

fr<strong>om</strong> our readers about interesting ideas<br />

and applications.<br />

(040161-1)<br />

Web Links<br />

[1] en.wikipedia.<br />

org/wiki/Galileo_positioning_system<br />

[2] www.gpscoordinates.eu<br />

[3] http://boulter.c<strong>om</strong>/gps<br />

ElekTrack • 23<br />

41


TECHNOLOGY E-BLOCKS<br />

Making Waves<br />

John Dobson<br />

In last month’s article on making a sound waveform we used the E-blocks SPI bus D/A and<br />

memory board to generate a sound waveform of around 400 Hz. In using Flowcode I read that<br />

the flowchart is first converted into C and then into assembly code, and that you can embed C<br />

into your Flowcode programs to speed the operation up. In this article I describe my attempts to<br />

use C to speed up the sound waveform generator. At the same time I<br />

discovered how you can use Flowcode to learn C programming.<br />

To generate code for the PIC microcontroller,<br />

Flowcode processes a flow<br />

chart in a number of steps. Let’s have a<br />

look at how this works:<br />

Step 1<br />

Flowcode initially takes your flow<br />

chart and generates C fr<strong>om</strong> it. As an<br />

example of this let’s look at a simple<br />

counter program (COUNTER1.FCF) in<br />

Flowcode and its C equivalent.<br />

In Figure 1 you can see the counter in<br />

Flowcode: we declare the value of variable<br />

COUNT as 0; then we have a loop<br />

icon. The Loop WHILE 1 declares an<br />

endless loop as ‘1’ is always true.<br />

Elektor blockbusters<br />

56<br />

Inside the loop we have icons to<br />

increase the value of COUNT by 1, wait<br />

for one second and then output the<br />

value of COUNT to port C. I have a<br />

16F877 PIC micro with LEDs counting<br />

up in a binary sequence on port C.<br />

Step 2<br />

If you open Windows Explorer and look<br />

in the directory where the<br />

COUNTER1.FCF Flowcode file is saved<br />

you will find that Flowcode has generated<br />

a number of files one of which is<br />

COUNTER1.C. This is the C equivalent<br />

of the COUNTER1 flow chart program.<br />

If you open this file in Notepad you will<br />

see the program in Figure 2.<br />

Here we have shown the program in<br />

two parts, side by side – to save space<br />

on this page. Firstly, Flowcode has<br />

defined s<strong>om</strong>e of the constants the C<br />

c<strong>om</strong>piler needs with statements like<br />

‘char PORTC@0x07;’. This defines the<br />

C variable ‘PORTC’ as being hex<br />

(that’s what the ‘0x’ stands for)<br />

address 07. Similarly TRISC is defined<br />

as being hex 87. TRISC is the data<br />

direction register on the PIC micro and<br />

the TRISC register on the 16F877 I am<br />

using is at hex 87. Similarly, many of<br />

the other PIC micro and circuit specific<br />

functions – such as the clock speed,<br />

Making Waves at C • 24<br />

elektor electronics - 4/2006


at C<br />

Elektor blockbusters<br />

the pins for the internal USART etc. are<br />

defined. (Note that in C when a line<br />

begins ‘//’ this indicates that the line<br />

is a c<strong>om</strong>ment and not a line of code.)<br />

There are no macros or subroutines in<br />

our program so these sections are<br />

blank, but there is a variable defined<br />

as type CHAR called FCV_COUNT.<br />

This is our COUNT variable fr<strong>om</strong> the<br />

Flowcode program. This is the first<br />

hint in how you can use the C icon in<br />

Flowcode to embed code into a Flowcode<br />

program: all variables in Flowcode<br />

are prefixed by ‘FCV_’ when<br />

transferred to the C c<strong>om</strong>piler. This<br />

means that when referring to a Flowcode<br />

variable in a C icon you must also<br />

prefix the variable with ‘FCV_’. (incidentally,<br />

FCV stands for FlowCode<br />

Variable.)<br />

After the declaration of variables you<br />

see the first line of C:<br />

Void main()<br />

{<br />

This is a function declaration within C<br />

to indicate that this is our main program.<br />

This is the equivalent to the<br />

START icon in Flowcode. The pair of<br />

braces indicate that there are no variables<br />

passed to this function, and the<br />

‘open’ curly bracket ’{‘ indicates the<br />

start of the main function, and you can<br />

see a ‘close’ curly bracket ‘}’ at the end<br />

of the program.<br />

After this we have two more declarations<br />

– for the A/D converter – to<br />

declare these pins as analogue inputs –<br />

and to turn the timer interrupt on.<br />

These are declared inside the main<br />

program loop as they can be altered by<br />

the user within the Flowcode program.<br />

After this we have the main program:<br />

FCV_COUNT is declared as being 0,<br />

corresponding to our first flow chart<br />

icon, then there is a while (1) statement<br />

followed by further code inside<br />

curly braces: this means execute the<br />

routine inside the curly braces forever.<br />

Inside the braces we have the<br />

FCV_COUNT increment, and a delay of<br />

1 second. Note that these lines of C<br />

code end with a semicolon. Lines of C<br />

E-Blocks and Flowcode<br />

do your C programming<br />

Figure 1. A simple Flowcode counter.<br />

Figure 2. C equivalent of COUNTER1.FCF.<br />

Making Waves at C • 25<br />

4/2006 - elektor electronics 57


TECHNOLOGY E-BLOCKS<br />

code are always terminated with a ‘;’.<br />

Then we have the line ‘TRISC=0x00’.<br />

We saw earlier that TRISC is the data<br />

direction register. This line of code<br />

writes value 0 to TRISC which declares<br />

all of the port C pins as outputs. A<br />

value for hex FF would declare all the<br />

pins as inputs. Our last line of C code<br />

in the loop writes the value of our<br />

COUNT variable to port C.<br />

The last line here is a kind of safety<br />

net: in the case where we do not have<br />

an endless loop in our Flowcode program,<br />

then the C program will get<br />

stuck at this point and execute this<br />

line forever. This is the equivalent to<br />

the END icon in Flowcode. If you have<br />

a C program without an END loop like<br />

this then you get a curious effect: the<br />

program counter in the PIC micro<br />

device keeps incrementing until it rolls<br />

over back to address 0000, at which<br />

point your program will start to run<br />

again.<br />

Well, that was not as hard as I had<br />

expected: C is a mysterious language<br />

but it seems that if we start fr<strong>om</strong> a flowchart<br />

then, with a little explanation, the<br />

C bec<strong>om</strong>es readable. Admittedly all the<br />

declarations are difficult to understand<br />

but Flowcode seems to take care of<br />

them, so I won’t worry too much what<br />

they all mean. Besides, a good introduction<br />

to C was supplied free of charge<br />

with last month’s Elektor.<br />

Back to the plot<br />

So back to our original objectives of<br />

increasing the speed of the waveform<br />

generator program I wrote. Well, I duly<br />

c<strong>om</strong>piled my program ‘SINE WAVE<br />

GEN.FCF’ fr<strong>om</strong> last month’s instalment,<br />

and looked at the C produced.<br />

What I noticed was that every time<br />

Flowcode used a DAC_SEND_CHAR<br />

icon it went through a lot of lines of C<br />

to declare further variables and<br />

address references that the C c<strong>om</strong>piler<br />

needs. The reason Flowcode does this<br />

is that it has to assume that you don’t<br />

know what you are doing (thank goodness!)<br />

and it has to set all the parameters<br />

of Port C for serial c<strong>om</strong>munication,<br />

each time you use the SPI DAC macro<br />

icon, just in case you are using port C<br />

I/O pins for other functions. Well<br />

maybe we can take out s<strong>om</strong>e of these<br />

lines of C to speed things up? I<br />

decided to tackle this in two stages:<br />

firstly replace a DAC_SEND_CHAR<br />

icon with the C equivalent to make<br />

sure I had replicated the function of the<br />

program, and secondly to then start<br />

altering the C code to see if I could<br />

Elektor blockbusters<br />

58<br />

make it more efficient.<br />

Going back to the main program I simply<br />

replaced one of the<br />

DAC_SEND_CHAR icons with a C icon.<br />

Then I looked up the equivalent C of<br />

the DAC_SEND_CHAR icon and<br />

pasted it into the new C icon. Then I<br />

adjusted the variable declarations to<br />

make sure the C icon picked up my<br />

OUTVAL Flowcode variable, and<br />

rec<strong>om</strong>piled the program to make sure<br />

that it still worked. Eventually it did.<br />

Having got to first base I then c<strong>om</strong>mented<br />

out all the unnecessary lines of<br />

C – of the original 34 lines of C code,<br />

which a DAC_SEND_CHAR icon produces<br />

only 9 were actually needed!<br />

There was a certain amount of trial and<br />

error here – I just kept c<strong>om</strong>menting out<br />

lines until the program stopped working!<br />

The program produced is called<br />

SINC3.fcf and you can download it fr<strong>om</strong><br />

the Elektor Electronics website. The file<br />

number is 065032-11.zip and you can<br />

find it under Magazine � April 2006<br />

Unfortunately however I was unsuccessful<br />

in making the DAC go any<br />

faster – the speed limitation turned out<br />

to be the speed of the SPI but itself –<br />

let me explain!<br />

Within the code of the<br />

DAC_SEND_CHAR Flowcode c<strong>om</strong>mand,<br />

the 8-bit SPI data is sent in two<br />

bytes. The last four bits of the first byte<br />

contain the most significant data nibble,<br />

and the four most significant bits<br />

of the second byte contain the least<br />

significant nibble. Other bits in each<br />

SPI data byte are reserved for chip configuration<br />

etc. The DAC_SEND_CHAR<br />

Flowcode icon takes OUTVAL and<br />

processes it like this:<br />

dac_val = (FCV_OUTVAL & 0xF0) > 4;<br />

sspbuf = dac_val;<br />

delay_us(3);<br />

dac_val = (FCV_OUTVAL & 0x0F)<br />

4’), then we set the<br />

SSPBUF register in the chip with the<br />

result and wait 3 �s. Whatever gets<br />

placed in the SSPBUF register will be<br />

sent by SPI. The second routine is similar:<br />

take OUTVAL, shift left by four<br />

bits, set SSPBUF and wait 3 �s. The<br />

last statement is the key: SSPBUF is<br />

the serial buffer in the PIC device and it<br />

will take 3μs for the buffer to clear as<br />

the information is sent one bit at a<br />

time. If you write to the buffer again<br />

before 3 �s has elapsed you will overwrite<br />

the data mid way through the<br />

serial send operation which produces<br />

s<strong>om</strong>e very strange results, as the SPI<br />

bus ceases to function correctly.<br />

So, it turns out that the frequency of<br />

our oscillator is determined by the<br />

speed of the SPI bus. For those of you<br />

that want the maths: each sample<br />

takes 6 �s; 256 samples per waveform<br />

gives a theoretical minimum period of<br />

1.5 ms or around 650 Hz.<br />

Oh well…time to reduce the number of<br />

samples to 64…<br />

Programs available for<br />

download<br />

(065032-1)<br />

• COUNTER1.fcf<br />

• SINC3.fcf<br />

File number: 065032-11.zip<br />

Location: MAGAZINE � April 2006 �<br />

‘E-Blocks making Waves at C’<br />

Earlier in this series<br />

Electronic Building Blocks,<br />

November 2005.<br />

E-blocks and Flowcode,<br />

December 2005.<br />

E-blocks in Cyberspace,<br />

January 2006.<br />

E-blocks – now you CAN,<br />

February 2006.<br />

E-blocks Making Waves,<br />

March 2006.<br />

Articles may be downloaded individually<br />

fr<strong>om</strong> our website.<br />

For a c<strong>om</strong>plete overview of available<br />

E-blocks visit SHOP at<br />

www.elektor-electronics.co.uk<br />

Making Waves at C • 26<br />

elektor electronics - 4/2006


PROJECTS LOGIC ANALYSER<br />

Digital<br />

Inspector<br />

Four-channel<br />

logic analyser<br />

Ronald de Bruijn<br />

When checking digital signals a logic analyser is indispensable, especially since many circuits use<br />

microcontrollers these days. In this article we describe an easy to build circuit that can cope with most<br />

digital signals and also has a memory function.<br />

Specification<br />

Sample frequency: 200 Hz-2 MHz<br />

Channels: 4<br />

Range: 0 to 5 V<br />

Memory: 1024 samples per channel<br />

Trigger levels: +Ve and –Ve<br />

Trigger pattern: can be set for each input<br />

Dot matrix LCD: 64 x 128 pixels<br />

Supply: 9 V PP3 battery<br />

The best way to inspect digital signals<br />

is with a logic analyser. S<strong>om</strong>etimes it’s<br />

useful to be able to do this on-site, or<br />

you may have to take a ‘floating’ measurement.<br />

The four-channel logic analyser<br />

described here is suitable in both<br />

situations due to its c<strong>om</strong>pactness and<br />

because it can be battery powered.<br />

The maximum sampling rate is 2 MHz<br />

and the circuit has sufficient memory<br />

to store 1024 samples of the signal. The<br />

dot-matrix display with a resolution of<br />

64 by 128 pixels shows a clear representation<br />

of the digital signals.<br />

Schematic<br />

At the heart of the circuit is IC2 (a<br />

PIC18F4850, see Figure 1). This PIC<br />

controller samples the signals and<br />

Elektor blockbusters<br />

drives the display. It is<br />

controlled via five push<br />

buttons (S1 to S5). The<br />

crystal (X1, 10 MHz) determines<br />

what the maximum<br />

sampling rate is.<br />

The internal PLL of the<br />

microcontroller is used<br />

to give the controller an internal clock<br />

frequency of 40 MHz, which is the maximum<br />

frequency rec<strong>om</strong>mended by Microchip<br />

for this type of chip.<br />

Diodes D1 to D8 protect the inputs<br />

against too high or negative voltages.<br />

The input signals are fed to IC1, a<br />

74HC04N, which is used as a buffer.<br />

The fact that the signals are inverted<br />

doesn’t matter in this case, since we<br />

can easily convert the signals back via<br />

the software. The signals go directly<br />

fr<strong>om</strong> the buffers into the controller via<br />

RA1 to RA4, where the software takes<br />

over (see Control).<br />

Preset P1 is used to set the contrast<br />

of the display and T1 turns on the<br />

background light of the display. Bz1<br />

gives an audible warning when a new<br />

sampling cycle starts and when you<br />

change between run and hold mode.<br />

The five switches used to control the<br />

circuit don’t require a hardware debounce<br />

circuit, since this is taken care<br />

of by the software.<br />

The power supply for the circuit consists<br />

of two parts: a stabilised 5 V supply<br />

and a 9 V supply for the display<br />

light. The source for these voltages can<br />

either be a 9 to 12 V mains adapter or<br />

a 9 V rechargeable battery.<br />

A simple charging circuit for the battery<br />

is also included (T2, R1, R17, D12),<br />

which c<strong>om</strong>es into action whenever a<br />

mains adapter is connected. Assuming<br />

a standard LED with a forward voltage<br />

drop V f of 1.5 V is used, the charging<br />

current for the battery will be:<br />

(1.5 – 0.6) / 56 = 16 mA.<br />

A 9 V NiMH battery with a capacity C<br />

of 170 mAh is then charged at about 0.1 C,<br />

so no damage will occur if it is charged continuously.<br />

The battery will be fully charged<br />

in about 10 hours with this circuit. During<br />

the charging LED D12 will be on. If an<br />

ordinary (non-rechargeable) battery is<br />

Digital Inspector • 27<br />

38 elektor electronics - 9/2007


CH4<br />

CH3<br />

CH2<br />

CH1<br />

Elektor blockbusters<br />

R5<br />

330 �<br />

R6<br />

330 �<br />

R4<br />

330 �<br />

R3<br />

330 �<br />

9/2007 - elektor electronics<br />

D8<br />

D5<br />

4x<br />

4x<br />

+5V<br />

+5V<br />

D7<br />

D4<br />

14<br />

IC1<br />

7<br />

1N4148<br />

D2<br />

D1<br />

D6<br />

D3<br />

1N4148<br />

IC1 = 74HC04<br />

C6<br />

100n<br />

R9<br />

100k<br />

IC1.D<br />

9 8<br />

1<br />

R10<br />

100k<br />

IC1.C<br />

5 6<br />

1<br />

R8<br />

100k<br />

IC1.B<br />

3 4<br />

1<br />

R7<br />

100k<br />

IC1.A<br />

1 2<br />

1<br />

D10<br />

D9<br />

S5<br />

S1<br />

S2<br />

S3<br />

S4<br />

used, the circuit around T2 can be left<br />

out.<br />

Control<br />

Switch S1 is used to select the sampling<br />

frequency. The rates that can be<br />

selected are 5/10/20/50/100/200/500 �<br />

s/div and 1/2/5 ms/div. S2 selects the<br />

channel that is used to trigger the circuit.<br />

S3 is used to tell the PIC if it is to<br />

trigger on a rising or falling edge and<br />

S4 can arm and stop the circuit, or clear<br />

the display. One short press of S4 arms<br />

2x<br />

1N4148<br />

10k<br />

R15<br />

10k<br />

R14<br />

+9V<br />

R11<br />

10k 10k<br />

10k<br />

12V<br />

R12<br />

R13<br />

10k<br />

K3<br />

R16<br />

3<br />

2<br />

1<br />

C2<br />

22p<br />

D11<br />

1N4004<br />

680 �<br />

R1<br />

D12<br />

+5V<br />

11<br />

20MHz<br />

C1<br />

22p<br />

BC337<br />

R17<br />

56� T2<br />

C5<br />

100n<br />

1<br />

MCLR/VPP/RE3 RC0/T1OSO/T13CKI<br />

15<br />

RC1/T1OSI<br />

16<br />

2<br />

RA0/AN0/CVREF<br />

RC2/CCP1<br />

17<br />

3<br />

4<br />

RA1/AN1<br />

RA2/AN2/VREF-<br />

IC2<br />

RC3/SCK/SCL<br />

RC4/SDI/SDA<br />

18<br />

23<br />

5<br />

RA3/AN3/VREF+<br />

RC5/SDO<br />

24<br />

6<br />

RA4/T0CKI<br />

RC6/TX/CK<br />

25<br />

7<br />

RA5/AN4/SS/HLVDIN RC7/RX/DT<br />

26<br />

PIC18F4580-I/P<br />

RD0/PSP0/C1IN+<br />

19<br />

RD1/PSP1/C1IN-<br />

20<br />

RD2/PSP2/C2IN+<br />

21<br />

RD3/PSP3/C2IN-<br />

22<br />

RD4/PSP4/ECCP1/P1A<br />

27<br />

33<br />

RB0/INT0/FLT0/AN1 RD5/PSP5/P1B<br />

28<br />

34<br />

RB1/INT1/AN8<br />

RD6/PSP6/P1C<br />

29<br />

35<br />

RB2/INT2/CANTX RD7/PSP7/P1D<br />

30<br />

36<br />

RB3/CANRX<br />

37<br />

RB4/KBI0/AN9<br />

38<br />

RB5/KBI1/PGM<br />

RE0/RD/AN5<br />

8<br />

39<br />

RB6/KBI2/PGC RE1/WR/AN6/C1OUT<br />

9<br />

40<br />

RB7/KBI3/PGD RE2/CS/AN7/C2OUT<br />

10<br />

OSC1 OSC2<br />

12 13<br />

X1<br />

14 31<br />

BT1<br />

9V<br />

BZ1<br />

the circuit. After the trigger signal occurs<br />

it will take 1024 samples per channel<br />

and store them. Pressing S4 briefly<br />

again will make the circuit read in a<br />

new set of 1024 samples after the next<br />

trigger signal. When S4 is held down<br />

for longer the display is cleared. The<br />

last settings for the sampling frequency,<br />

the trigger channel and the trigger<br />

condition are stored inside the EEP-<br />

ROM of the microcontroller. These settings<br />

are then used as the initial state<br />

when the circuit is next turned on.<br />

S5 turns the backlight on or off. After<br />

Figure 1. Fr<strong>om</strong> the circuit diagram it is clear that the microcontroller takes care of just about everything.<br />

32<br />

220 �<br />

R21<br />

1k<br />

S6<br />

R19<br />

T1<br />

BC337<br />

+9V<br />

+5V<br />

P1<br />

20k<br />

C3<br />

100n<br />

11 10<br />

1<br />

+5V<br />

IC1.E<br />

IC1.F<br />

13 12<br />

1<br />

10k<br />

R2<br />

47�<br />

+5V +9V<br />

IC3<br />

7805<br />

R20<br />

C4<br />

K2<br />

+5V<br />

100n<br />

060092 - 11<br />

LC DISPLAY<br />

Digital Inspector • 28<br />

39


PROJECTS LOGIC ANALYSER<br />

I4<br />

I3<br />

I2<br />

I1<br />

I5<br />

about one and a half minutes, or when<br />

in a ‘Lo_Batt’ condition, the microcontroller<br />

aut<strong>om</strong>atically turns off the<br />

backlight.<br />

Operation<br />

D3<br />

D5 D4<br />

D1<br />

D2<br />

D7<br />

D8<br />

D6<br />

R8<br />

P1<br />

R10<br />

K2<br />

C5<br />

IC1<br />

S1<br />

R3<br />

R4<br />

R6<br />

R5<br />

R7<br />

R9<br />

R12<br />

C2<br />

C1<br />

In order to obtain the highest possible<br />

sampling rate we initially let the microcontroller<br />

store the samples in its RAM<br />

when the trigger event occurs. For this<br />

we use the following software instruction:<br />

movff port a, postinc0. This instruction<br />

copies the contents of port a<br />

to the RAM and increments the RAM<br />

address by one. This cycle is then re-<br />

X1<br />

R11 IC2<br />

S2<br />

R16<br />

R19<br />

R20<br />

R13<br />

R14<br />

C6 R1<br />

D10<br />

D9 R21<br />

R2<br />

peated 1024 times. At the end of this,<br />

128 samples are read fr<strong>om</strong> the RAM<br />

and shown on the display. This process<br />

is repeated once a second.<br />

If no new trigger event occurs for about<br />

three seconds (depending on the sampling<br />

rate), the circuit reads in 128<br />

samples and shows them on the LCD.<br />

In this way we can tell what condition<br />

(high or low) the inputs are.<br />

A quick press of S4 turns on the memory<br />

function. This is indicated by an ‘R’<br />

on the right of the screen. The circuit<br />

then waits for the trigger event. Once<br />

this has occurred and the 1024 samples<br />

have been stored the ‘R’ changes into<br />

an ‘S’ and the display shows the first<br />

128 samples of each channel. Switches<br />

S1 and S2 can now be used to scroll<br />

through the memory. A short press of<br />

S1 or S2 causes small jumps through<br />

the memory; a longer press of S1 or S2<br />

creates larger jumps. The cursor at the<br />

bott<strong>om</strong> of the display shows which<br />

area of memory is currently shown.<br />

Another quick press of S4 makes the<br />

circuit read in a new set of samples<br />

and store them in memory. The display<br />

keeps showing the same area of memory<br />

as for the previous samples. This<br />

is of course very useful when you’re<br />

studying the signals that follow a short<br />

40 elektor electronics - 9/2007<br />

R15<br />

S6 C3<br />

1<br />

3<br />

D11 2<br />

C4<br />

Figure 2. As can be seen fr<strong>om</strong> the c<strong>om</strong>ponent layout, the construction of the circuit isn’t difficult. Connector K2 is placed such that the display can be mounted directly above the double-sided PCB.<br />

Elektor blockbusters<br />

3<br />

1<br />

3<br />

1<br />

T2<br />

T1<br />

R17<br />

BZ1<br />

S3<br />

K3<br />

IC3<br />

D12<br />

S5<br />

BT1<br />

S4<br />

C<strong>om</strong>ponents<br />

list<br />

Resistors<br />

R1 = 680�<br />

R2,R11-R16 = 10 k�<br />

R3-R6 = 330�<br />

R7-R10 = 100k�<br />

R17 = 56�<br />

R19 = 1k�<br />

R20 = 47�<br />

R21 = 220�<br />

P1 = 20k� preset, multiturn, vertical<br />

mounting<br />

Capacitors<br />

C1,C2 = 22pF<br />

C3-C6 = 100nF<br />

Semiconductors<br />

D1-D10 = 1N4148<br />

D11 = 1N4001<br />

D12 = LED, 5mm diam.<br />

T1,T2 = BC337<br />

IC1 = 74HC04<br />

IC2 = PIC18F4580-I/P, programmed,<br />

Elektor SHOP # 060092-41<br />

IC3 = 7805<br />

Miscellaneous<br />

Bz1 = AC buzzer<br />

X1 = 10MHz quartz crystal<br />

Graphic LC display, 128 x 64 pixels,<br />

e.g. DEM128064A or NLC128x64<br />

(Conrad Electronics # 187429)<br />

Case 186 x 123 x 41mm with c<strong>om</strong>partment<br />

for 9V battery, e.g. Strapubox<br />

(Conrad Electronics # 522775)<br />

S1-S5 = pushbutton Multimec<br />

RA3FTL6 w. knob AQC09-24.2<br />

S6 = on/off switch<br />

9-V battery clip<br />

5 wander sockets, screw mount (for<br />

connection to I1-I5)<br />

Kit of parts incl. case: Elektor SHOP #<br />

060092-71<br />

PCB layout: free download fr<strong>om</strong><br />

www.elektor.c<strong>om</strong>, file # 060092-1<br />

Digital Inspector • 29


time after the trigger event.<br />

If you hold down S4 a bit longer, until<br />

the buzzer gives a beep, the circuit<br />

reads in a new set of samples and<br />

stores them in memory. But this time<br />

the display won’t show the same area<br />

of memory; instead it jumps right back<br />

to the beginning.<br />

If you hold down S4 longer still (until<br />

you’ve heard two beeps), the logic analyser<br />

c<strong>om</strong>es out of memory mode and<br />

returns to the standard mode where<br />

128 ‘live’ samples are always shown<br />

on the display.<br />

Construction<br />

In this design we haven’t used any<br />

SMDs. The layout is fairly sparse, with<br />

all c<strong>om</strong>ponents easily accessible. The<br />

soldering should therefore not cause<br />

any problems.<br />

We would like to c<strong>om</strong>e back to the connection<br />

between the display and the<br />

board. There is enough ro<strong>om</strong> above the<br />

board for the display. The easiest way<br />

to connect the display to the board is<br />

to first solder a single pin-header strip<br />

Elektor blockbusters<br />

9/2007 - elektor electronics<br />

to the display board. Next, plug a wirewrap<br />

socket into this pin-header and<br />

plug the other end into the main board.<br />

Check that the display is at the right<br />

height and then solder the wirewrap<br />

socket to the main board.<br />

When you use the rec<strong>om</strong>mended enclosure<br />

for this circuit you should first<br />

file off the corners of the board at the<br />

side of the input signals. The board<br />

will then fit perfectly.<br />

C<strong>om</strong>ments<br />

When you’re not using all of the channels<br />

it is advisable to connect the unused<br />

channels to ground. You’ll often<br />

find that open inputs can pick up interference,<br />

which results in a garbled<br />

display.<br />

It should be clear that this analyser is<br />

not suitable for use with very high frequencies.<br />

Applications for this device<br />

are found with ‘slower’ microcontrollers,<br />

serial c<strong>om</strong>munications, etc. Even<br />

so, this simple circuit can make your<br />

life a lot easier during the development<br />

of a digital (microcontroller) circuit.<br />

PIC Microcontrollers<br />

Silent alarm, RGB fader, poetry box,<br />

night buzzer and more!<br />

For this project we’re offering a c<strong>om</strong>plete<br />

kit of parts (order code 060092-<br />

71), which consists of the display, the<br />

main board, a programmed microcontroller,<br />

the c<strong>om</strong>ponents and the enclosure.<br />

All that’s left for you to do is solder<br />

the c<strong>om</strong>ponents to the board and<br />

mount it in the enclosure. After connecting<br />

a battery or mains adapter you<br />

can start analysing straight away.<br />

For those of you who want to etch<br />

the board yourselves, the layout can<br />

be downloaded fr<strong>om</strong> our website at<br />

www.elektor.c<strong>om</strong>, under file number<br />

060092-1.zip. And if you have the facility<br />

to program the PIC microcontroller,<br />

you can also download the source code<br />

fr<strong>om</strong> our site (file # 060092-11.zip).<br />

This hands-on book covers a series of exciting and fun<br />

projects with PIC microcontrollers. You can built more<br />

than 50 projects for your own use. The clear explanations,<br />

schematics, and pictures of each project on a breadboard<br />

make this a fun activity. You can also use it as a study<br />

guide. The technical background information in each<br />

project explains why the project is set up the way it is,<br />

including the use of datasheets. All software used in this<br />

book can be downloaded for free, including all of the<br />

source code, a program editor, and the JAL open source<br />

programming language.<br />

446 pages • ISBN 978-0-905705-70-5 • £27.00 • US$ 54.00<br />

Elektor<br />

Regus Brentford<br />

1000 Great West Road<br />

Brentford TW8 9HH<br />

United Kingd<strong>om</strong><br />

Tel. +44 20 8261 4509<br />

Order quickly and safe through www.elektor.c<strong>om</strong>/shop<br />

(060092-I)<br />

Publicité<br />

Digital Inspector • 30<br />

41


HANDS-ON MILLING<br />

Profiler<br />

Construction kit<br />

for a general-purpose<br />

milling machine<br />

Harry Baggen<br />

Have you always dreamed of having your own milling machine<br />

but found them just too expensive? If so, we have<br />

the perfect solution for you. Working in close<br />

collaboration with the Belgian manufacturer<br />

Colinbus, we have put together a construction<br />

kit for our readers that enables you to build a<br />

professional milling machine for a fraction of<br />

the cost of a ready-made model. This machine<br />

is suitable for a wide variety of jobs, ranging fr<strong>om</strong><br />

making parts for models to milling circuit boards.<br />

As an electronic hobbyist or professional,<br />

you have to work with more<br />

than just pure electronics, and you often<br />

have to deal with a lot of mechanical<br />

tasks. This includes jobs such as<br />

making printed circuit boards, routing<br />

wiring, and fashioning a suitable<br />

enclosure with a corresponding front<br />

panel. S<strong>om</strong>e of these jobs require<br />

suitable tools if you want to achieve<br />

good results – at least if you want to<br />

do it all yourself.<br />

Many hobbyists, as well as designers<br />

of prototypes and small development<br />

labs, would certainly be able to<br />

make good use of a small milling ma-<br />

Elektor blockbusters<br />

chine for this sort of work. Investing<br />

in such a machine may be affordable<br />

for c<strong>om</strong>mercial use, but the situation<br />

is a bit different for h<strong>om</strong>e use. A<br />

good, accurate milling machine can<br />

easily cost several thousand euros,<br />

and even then you only have a basic<br />

model without all the bells and whistles<br />

(such as vacuum swarf removal<br />

and a high-speed spindle motor).<br />

We launched this project especially<br />

for all electronics hobbyists and professionals<br />

who regularly pursue their<br />

job and/or hobby at h<strong>om</strong>e. The idea<br />

for this construction project arose<br />

spontaneously during a conversation<br />

with Frank Jacops of the Belgian<br />

c<strong>om</strong>pany Colinbus, which specialises<br />

in milling machines. When you<br />

talk with s<strong>om</strong>eone who not only sells<br />

milling machines but also designs<br />

them fr<strong>om</strong> the ground up, the conversation<br />

quickly turns to the fact that<br />

most electronics types have splendid<br />

ideas about all the nice things<br />

they could do with such a machine,<br />

but the price is an obstacle in most<br />

cases. Frank Jacops understood this<br />

immediately (he has been an avid<br />

reader of Elektor Electronics for many<br />

years), and he suggested offering a<br />

construction kit at a special price for<br />

a limited time, exclusively for readers<br />

of Elektor Electronics.<br />

������������<br />

14 elektor electronics - 1/2007


Naturally, we must<br />

admit that the kit is not exactly<br />

inexpensive at £ 1099 or � 1599 plus<br />

shipping costs, but this still represents<br />

a savings of nearly £ 1400 relative<br />

to a c<strong>om</strong>parable ready-assembled<br />

model. That’s an attractive reward for<br />

a day or so of assembly work.<br />

Of course, several small milling machines<br />

are also c<strong>om</strong>mercially available<br />

at a lower cost, but they are all<br />

quite small and have limited features.<br />

If you look at the photos in this article,<br />

you can see that we’re talking<br />

about a c<strong>om</strong>pletely different category<br />

here. Robust construction, high accu-<br />

Elektor blockbusters<br />

1/2007 - elektor electronics<br />

‘Profiler’ technical<br />

specifications<br />

Dimensions 453 (w) x 583 (d) x 468 (h) mm<br />

Max. working area 300 (X) x 400 (Y) x 100 (Z) mm<br />

Interface Serial<br />

Power 240 V, 50–60 Hz<br />

X/Y/Z linear transport MultiStab guideways<br />

X/Y/Z drive Stepper motors<br />

Positioning speed 60 mm/s<br />

Mechanical resolution 0.0075 mm<br />

Software resolution 0.025 mm<br />

Software Colinbus User Interface<br />

Conversion program for Gerber and Excellon files<br />

racy, and a generous working area of<br />

30 � 40 cm — now that’s s<strong>om</strong>ething<br />

you can sink your teeth into! This machine<br />

is suitable for all sorts of jobs,<br />

such as dispensing, potting, camera<br />

inspection, boring holes in boxes,<br />

milling front panels,<br />

and even<br />

3D<br />

modelling (using<br />

separate software). You can also<br />

mill circuit boards with this machine,<br />

although the manufacturer explicitly<br />

wishes to state that this model is not<br />

designed primarily for this purpose,<br />

since it requires even higher accuracy.<br />

However, based on our experience<br />

it yields excellent results for average<br />

PCBs, and the necessary software<br />

is included.<br />

Assembly of the machine is quite<br />

straightforward, and the clearly<br />

written instructions practically exclude<br />

any problems. The acc<strong>om</strong>panying<br />

circuit boards with the drive<br />

electronics are fully assembled and<br />

tested, so all you have to do is install<br />

and connect them.<br />

Design<br />

The ‘Elektor Profiler’, as we have<br />

christened the machine, is the smallest<br />

milling machine produced by Colinbus.<br />

Its construction is largely the<br />

same as the c<strong>om</strong>mercial CBR-40 model<br />

(see www.colinbus.c<strong>om</strong>).<br />

The machine is made fr<strong>om</strong> steel and<br />

aluminium parts. This c<strong>om</strong>bination of<br />

materials provides sufficient weight<br />

and stability to withstand the motion<br />

of the machine, while the accuracy<br />

of the guideways and the speed of<br />

travel are very high thanks to the use<br />

of aluminium extrusions.<br />

The MultiStab system, which uses<br />

three rollers per edge travelling along<br />

precision steel rods pressed into aluminium<br />

extrusions, provides good<br />

mechanical guidance with minimum<br />

play. This design is used for all three<br />

axes. One roller of each set of three<br />

for each guideway assembly can be<br />

manually positioned to adjust the<br />

amount of play as necessary. Each of<br />

the three axes is driven by a spindle<br />

with a special zero-backlash nut.<br />

The milling machine is controlled<br />

by a built-in processor board fitted<br />

with a Renesas H8/3003 and a driver<br />

board fitted with three ST L6208<br />

ICs, which look after driving the<br />

three stepper motors. This approach<br />

makes the timing independent of the<br />

connected PC. The c<strong>om</strong>puter simply<br />

sends c<strong>om</strong>mands and coordinates<br />

to the processor board, which processes<br />

and executes the c<strong>om</strong>mands<br />

independently.<br />

The processing power of the builtin<br />

microcontroller is not sufficient to<br />

drive all three stepper motors at the<br />

������������<br />

15


HANDS-ON MILLING<br />

same time (this trick is reserved for<br />

the larger and more expensive Colinbus<br />

models), so it can only drive<br />

two at the same time. The machine<br />

can thus execute smooth motions<br />

in a two-dimensional plane. For 3D<br />

motions, it switches rapidly back<br />

and forth between two axes, which<br />

Elektor blockbusters<br />

Figure 1. The mechanical parts of the construction kit.<br />

makes it appear that all three motors<br />

move simultaneously. This has little<br />

noticeable effect in practice, since<br />

the steps resulting fr<strong>om</strong> the interpolation<br />

are very small.<br />

The control board in the milling machine<br />

has a serial interface, but a<br />

standard USB to RS232 adapter can<br />

Figure 2. The assembled circuit boards and the spindle motor and bracket.<br />

You can order the construction kit<br />

for the Profiler milling machine<br />

by filling in the Order Form on<br />

the Elektor Electronics website at<br />

www.elektor.c<strong>om</strong> (click ‘Milling<br />

Machine’ under ‘Quick Service’).<br />

The price is 1099 pounds (1599<br />

euros) including VAT, plus<br />

shipping charges. The shipping<br />

charges depend on the country<br />

and are stated on the website<br />

Order Form.<br />

The kit is supplied and invoiced<br />

directly and exclusively by the<br />

manufacturer, i.e. not by Elektor.<br />

There are also several optional<br />

extras available for the machine.<br />

Consult the Colinbus website for<br />

information about these options.<br />

be used without any problems to operate<br />

the machine via the USB port<br />

of the PC.<br />

The spindle motor supplied with the<br />

milling machine is a fairly basic model<br />

fr<strong>om</strong> Ferm, which allows you to<br />

start using the machine right away.<br />

Naturally, you can also fit other types<br />

of motors, but we should remark here<br />

that a true professional-quality spindle<br />

motor can easily cost more than<br />

the entire construction kit.<br />

Construction kit<br />

What do you get for the price of £1099<br />

or 1599? The photos in Figure 1 and<br />

Figure 2 show almost all the parts<br />

included in the kit. They include all<br />

the mechanical parts, screws and<br />

bolts, guideway rollers, spindles,<br />

bearings, stepper motors, cables<br />

and so on, plus the drive electronics<br />

on the two pre-assembled circuit<br />

boards. The previously mentioned<br />

Ferm spindle motor (and associated<br />

bracket) is also included in the kit. A<br />

MDF panel (also included in the kit)<br />

serves as the base plate.<br />

The c<strong>om</strong>panion software for the<br />

milling machine consists of two programs:<br />

a user-friendly interface for<br />

configuring and operating the machine<br />

and a conversion program for<br />

PCB layouts (see below).<br />

The kit includes assembly instruc-<br />

������������<br />

16 elektor electronics - 1/2007


tions that provide a step-by-step description<br />

of how to put the machine<br />

together.<br />

There’s not much that can go wrong<br />

during assembly. The various parts<br />

fit together very accurately thanks to<br />

the c<strong>om</strong>bination of precision holes in<br />

the steel panels and the steel rods<br />

in the aluminium extrusions, so no<br />

further alignment is necessary. You<br />

have to provide the necessary wiring<br />

for the two circuit boards for the<br />

control and drive electronics, and the<br />

connectors and transformer must be<br />

soldered in place.<br />

All the assembly steps are clearly<br />

described in the instructions. However,<br />

we would like to clarify a few<br />

details here.<br />

Once the machine is partially assembled,<br />

the guideways must be adjusted.<br />

The accuracy of the entire milling<br />

machine depends entirely on this<br />

adjustment. The guideways for the<br />

bridge (on the sides) have of three<br />

rollers, of which one can be adjusted<br />

using an adjustment plate. It must<br />

be adjusted so there is very little<br />

play, but it should not be made too<br />

tight, since otherwise the rollers will<br />

jam. A similar construction is also located<br />

at the top of the bridge and in<br />

the motor column, but the latter part<br />

must be partially disassembled to<br />

access the rollers.<br />

The drives use spindles with trap-<br />

Elektor blockbusters<br />

Figure 3. Cross-section drawing of the boring head mount on the bridge. Figure 4. Detail of the plastic nut with the transverse pins, which provide a zero-play coupling.<br />

1/2007 - elektor electronics<br />

ezoidal threads that run in special<br />

plastic nuts (see Figure 4). These<br />

nuts are fitted with transverse pins<br />

that provide the coupling to the<br />

bridge or the boring column. The X<br />

and Y spindles must also be carefully<br />

aligned to achieve the specified<br />

accuracy and linearity. Note that the<br />

Figure 5. The boring column and the guideway in the bridge.<br />

special plastic nuts on these spindles<br />

must be lubricated using only<br />

the special grease included with the<br />

kit. Do not use normal grease!<br />

The rest of the assembly process is<br />

adequately described by the instructions<br />

included with the kit.<br />

������������<br />

17


HANDS-ON MILLING<br />

Software<br />

The user interface specially written<br />

for the Colinbus milling machine provides<br />

the operator interface for the<br />

machine (Figure 6). This program is<br />

designed such that even inexperienced<br />

users can work with it easily.<br />

Elektor blockbusters<br />

Figure 6. The user interface. The working surface of the machine is shown at the upper right.<br />

The screen is c<strong>om</strong>posed of several<br />

windows. The effective working surface<br />

of the machine is shown in the<br />

right-hand window. After loading a<br />

file, you can use the mouse to place<br />

the object to be machined in the desired<br />

location on this surface. The ma-<br />

Figure 7. Gerber and Excellon files can be read in with the PCB contouring program<br />

and converted into contour data for the milling machine.<br />

chine will then start working at exactly<br />

this position. You can also specify<br />

the values of all the settings and<br />

preferences for the machine. In addition,<br />

you can operate all machine axes<br />

manually using this program. Everything<br />

you can think of can be configured<br />

here, such as reading memory<br />

points, relative zero points and so on<br />

with micr<strong>om</strong>etre accuracy.<br />

The user interface includes a PCB<br />

contouring program (Figure 7), which<br />

you can use to edit and merge the<br />

Gerber and Excellon files generated<br />

by c<strong>om</strong>monly used PCB programs<br />

and then convert the coordinates in<br />

these files into the contours used by<br />

the milling machine. You can manually<br />

specify the reference points to be<br />

used on the circuit board and then<br />

use them to ensure that the data in<br />

the Gerber and Excellon files are registered<br />

exactly with each other (the<br />

Gerber file contains the data for the<br />

PCB tracks, while the Excellon file<br />

contains the hole data). The file generated<br />

by the program can then be<br />

imported into the user interface program<br />

so you can see the PCB layout,<br />

which you can drag to a specific location<br />

on the working surface.<br />

If you want to process 3D files (such<br />

as DXF files), you will need the separate<br />

RAMS3D program, which is not<br />

included in the construction kit due<br />

to the special price.<br />

Finally, there’s s<strong>om</strong>ething for diehard<br />

DIYers: the entire c<strong>om</strong>mand set for<br />

controlling the milling machine is<br />

freely available, so you can also write<br />

your own code.<br />

1001 jobs<br />

This robust, versatile milling machine<br />

opens up a world of opportunities<br />

for handy hobbyists and professionals<br />

who aren’t afraid to roll up their<br />

sleeves. With it, making rectangular<br />

openings in a box is a piece of cake<br />

and a machining a slot in a front panel<br />

for a slider is no sooner said than<br />

done. What’s more, this milling machine<br />

is a handy tool for things that<br />

have nothing to do with electronics.<br />

For instance, you can use it to make<br />

your own parts for a model airplane<br />

or toys for your kids (and donate your<br />

jigsaw to local charity!).<br />

In short, there are more than enough<br />

things you can do with this machine.<br />

Once you’ve used it, you won’t want<br />

to do without it.<br />

18 elektor electronics - 1/2007<br />

(060232-1)<br />

������������


PROJECTS PROGRAMMABLE LOGIC CONTROL<br />

Elektor blockbusters<br />

ECIO PLC<br />

Cheap, DIY and with CAN!<br />

Ben Rowland (Matrix Multimedia) & Luc Lemmens (Elektor Labs)<br />

Here’s the first real-life application of ECIO modules introduced in the October 2007 issue<br />

of Elektor. An ECIO acts as the brains of a PLC board that has relays, opto-isolators, CAN (!)<br />

connectivity and an LCD. All this I/O capacity together with Flowcode allows the board to<br />

act as a versatile, powerful PLC for quite c<strong>om</strong>plex control and aut<strong>om</strong>ation projects. The LCD<br />

module is used to display ASCII characters to the user as a means of troubleshooting during<br />

the software development stage or for monitoring the system.<br />

ECIO PLC Features<br />

• CAN bus connection<br />

• 4 optically isolated inputs<br />

• 4 relay driven outputs<br />

• 2x16 character alphanumeric LCD<br />

• Flowcode-programmed but will also take PIC18 hex files<br />

• Free Flowcode for ECIO<br />

• USB connectivity for programming<br />

A full PLC application board c<strong>om</strong>prising isolated outputs, inputs,<br />

LC display and CAN bus connectivity…sounds good!<br />

But you’d also like to hear that it’s low cost, based on an<br />

ECIO module and easy to program using Flowcode, the all<br />

graphics method of mastering PICs (and other micros, too).<br />

PLC<br />

A PLC (programmable logic control) is a device typically<br />

used as the central, intelligent, control element in a flowchart-designed<br />

industrial process, usually for mass manufacturing<br />

or quality checking and goods sorting. Conveyor<br />

belt controls will typically be PLCs.<br />

PLCs exist c<strong>om</strong>mercially and their (high level) programming<br />

languages have been standardized to a wide extent. Unfortunately<br />

the price tag of almost any c<strong>om</strong>mercial PLC puts it<br />

well out of reach of enthusiasts. A pity, because many Elektor<br />

readers have affinity with industrial control systems.<br />

PLC c<strong>om</strong>mand sequences are in a way like c<strong>om</strong>puter programs<br />

— they follow a predefined sequence of events with<br />

all the options for conditional loops, event timers, logic<br />

conditions, event counters, analogue values (temperature;<br />

liquid level; pressure) and simple result logs.<br />

If you have a slightly c<strong>om</strong>plex process you’d like to con-<br />

trol using electronics on a machine, then a PLC is a good<br />

choice because of its (electrical) robustness and flexibility<br />

when it c<strong>om</strong>es to connecting the real world through relays<br />

and optocouplers.<br />

To be able to program a PLC (i.e. define the sequence of<br />

events to happen in a process) you need to write a program.<br />

Once debugged and simulated on a PC, you can<br />

download the program to the PLC and fr<strong>om</strong> then on it’s<br />

fingers crossed.<br />

PLC programs can be edited, debugged, extended, optimized<br />

and of course stored and retrieved. Right, just like<br />

any PC or microcontroller program!<br />

Circuit description<br />

The circuit diagram of the ECIO PLC is shown in Figure 1.<br />

The circuit c<strong>om</strong>prises a number of distinct elements which<br />

we’ll discuss below.<br />

ECIO<br />

The ECIO module is the brain of the board. It is used to control<br />

all of the peripheral devices on the board. ECIO modules,<br />

introduced in the October 2007 issue of Elektor [1],<br />

represent an ultra low-cost way of entering the world of PIC<br />

microcontroller programming. ECIOs are available fr<strong>om</strong> the<br />

Elektor Shop with good discounts for volume orders. Here<br />

we use the 40-pin version called ECIO-40P.<br />

Relays<br />

The relays the PLC is using to switch electrical devices on<br />

and off are controlled via ECIO pins RB4–RB7. Outputting<br />

a logic Low to these pins will switch off the corresponding<br />

relay and outputting a logic High will switch on the corresponding<br />

relay coil. If a relay is enabled then the LED next<br />

to that particular relay will light to give a visual on/off representation.<br />

The relays are used to provide electrical isolation<br />

between the ECIO module and the external switched<br />

voltage (which could be the 230 V mains). This means that<br />

power devices running fr<strong>om</strong> high voltages like 48 VDC or<br />

ECIO PLC • 36<br />

64 elektor - 3/2008


K1<br />

K2<br />

K3<br />

K4<br />

OI0<br />

K6<br />

+9V - +20V<br />

3<br />

1<br />

2<br />

VDD USB<br />

230 VAC can be controlled safely via the ECIO module.<br />

Each set of relay contacts (NO and NC) is brought out to<br />

three pins of a PCB mount screw terminal block — the centre<br />

pin (C) is the pole.<br />

Opto-isolators<br />

The opto-isolated inputs are special in not having a plus (+)<br />

and a minus (–) input terminal. Inside IC1, the two diodes<br />

on each input are in fact LEDs so the polarity of the control<br />

Elektor blockbusters<br />

3/2008 - elektor<br />

T1<br />

D1<br />

+12V<br />

IC2<br />

VDD USB<br />

μA78M05CKC<br />

R7<br />

3<br />

B1<br />

1<br />

1 3<br />

VDD_EXT<br />

C1 C3<br />

C5 C6<br />

D5<br />

B40C1500<br />

10u<br />

25V<br />

100n<br />

100n 10u<br />

25V<br />

VDD USB<br />

OI1<br />

2<br />

4<br />

VDD USB<br />

T2<br />

9<br />

VSS<br />

8<br />

OSC1<br />

VDD 18<br />

7<br />

OSC2<br />

22p 20MHz 22p<br />

BC547<br />

BC547<br />

BC547<br />

BC547<br />

R2A R3A R2B R3B R2C R3C R2D R3D<br />

D2<br />

OI2<br />

2<br />

TXCAN 1<br />

RXCAN 2<br />

CLKOUT/SOF 3<br />

TX0RTS 4<br />

TX1RTS 5<br />

TX2RTS 6<br />

RX0BF 10<br />

RX1BF 11<br />

17<br />

RESET<br />

13<br />

SCK<br />

14<br />

SI IC3<br />

15<br />

SO<br />

16<br />

CS MCP2515<br />

12<br />

INT<br />

1<br />

TXD<br />

4<br />

RXD CANL 6<br />

VDD USB<br />

C7<br />

10u<br />

25V<br />

VDD USB<br />

K9<br />

IC1<br />

R1A<br />

R1B<br />

R1C<br />

R1D<br />

1<br />

2<br />

3<br />

4<br />

5<br />

6<br />

7<br />

8<br />

16<br />

15<br />

14<br />

13<br />

12<br />

11<br />

10<br />

9<br />

OI0<br />

OI1<br />

OI2<br />

OI3<br />

R4A<br />

R4B<br />

R4C<br />

R4D<br />

RA0<br />

RA1<br />

RA2<br />

RA3<br />

RESET<br />

R5A<br />

RB1<br />

R5B<br />

RC7<br />

R5C<br />

RB0<br />

R5D<br />

RB3<br />

R6<br />

RB2<br />

220R<br />

IC4<br />

MCP2551<br />

VDD USB<br />

R1 = 4x 4k7<br />

TLP620-4<br />

R4 = 4x 220R R5 = 4x 220R<br />

X1<br />

ECIO<br />

C2<br />

C4<br />

R2 = 4x 10k<br />

R3 = 4x 330R<br />

VDD USB<br />

T3<br />

D3<br />

OI3<br />

VDD USB<br />

T4<br />

D4<br />

390R<br />

2<br />

VDD 3<br />

VSS<br />

GND<br />

RESET<br />

RA0<br />

RA1<br />

RA2<br />

RA3<br />

RA4<br />

RA5<br />

RD0<br />

RD1<br />

RD2<br />

RD3<br />

RD4<br />

RD5<br />

RD6<br />

RD7<br />

VREF 5<br />

7<br />

CANH<br />

8<br />

RS<br />

1<br />

2<br />

3<br />

4<br />

5<br />

6<br />

7<br />

8<br />

9<br />

10<br />

11<br />

12<br />

13<br />

14<br />

15<br />

16<br />

17<br />

18<br />

19<br />

20<br />

CAN H<br />

CAN L<br />

R8<br />

120R<br />

40<br />

39<br />

38<br />

37<br />

36<br />

35<br />

34<br />

33<br />

32<br />

31<br />

30<br />

29<br />

28<br />

27<br />

26<br />

25<br />

24<br />

23<br />

22<br />

21<br />

JP1<br />

END<br />

NODE<br />

VDD_EXT<br />

RB7<br />

RB6<br />

RB5<br />

RB4<br />

RB3<br />

RB2<br />

RB1<br />

RB0<br />

RC7<br />

RC6<br />

RC2<br />

RC1<br />

RC0<br />

GND<br />

RE2<br />

RE1<br />

RE0<br />

RC6<br />

RC2<br />

RC1<br />

RC0<br />

RD7<br />

RD6<br />

1N4001<br />

R9A<br />

RB4<br />

1N4001<br />

R9B<br />

RB6<br />

D6<br />

D7<br />

2<br />

4<br />

6<br />

8<br />

10<br />

12<br />

14<br />

+12V<br />

D8<br />

T5<br />

+12V<br />

R10A<br />

K5<br />

BC547<br />

D9<br />

R10B<br />

T6<br />

BC547<br />

1<br />

3<br />

5<br />

7<br />

9<br />

11<br />

13<br />

Re1<br />

Re2<br />

VDD USB<br />

VDD USB<br />

P1<br />

10k<br />

CONTRAST<br />

RESET<br />

RA4<br />

RA5<br />

RE0<br />

RE1<br />

RE2<br />

K14<br />

NO<br />

C<br />

NC<br />

voltage you wish to apply to ECIO PLC does not matter! The<br />

opto-isolator outputs are connected to ECIO pins RA0–RA3.<br />

These input pins will be at logic zero for no input voltage<br />

and at logic one for a voltage of 3.5 V or more. The optoisolators<br />

are used to provide an isolation layer fr<strong>om</strong> input<br />

voltages. This means that relatively high voltages can be<br />

used to safely control the ECIO module. The signals you<br />

want to process in the ECIO PLC are applied to the circuit<br />

through PCB mounted 2-way screw terminal blocks. LEDs<br />

D1-D4 show the logic status of the opto-isolator inputs.<br />

K15<br />

NO<br />

C<br />

NC<br />

RD4<br />

RD5<br />

RD0<br />

RD1<br />

RD2<br />

RD3<br />

1N4001<br />

R9C<br />

RB5<br />

1N4001<br />

R9D<br />

RB7<br />

VDD USB<br />

R11<br />

33R<br />

D10<br />

D11<br />

R9 = 4x 2k2<br />

R10 = 4x 1k<br />

+12V<br />

D12<br />

T7<br />

+12V<br />

R10C<br />

BC547<br />

D13<br />

R10D<br />

T8<br />

LCD1<br />

1<br />

2<br />

3<br />

4<br />

5<br />

6<br />

7<br />

8<br />

9<br />

10<br />

11<br />

12<br />

13<br />

14<br />

15<br />

16<br />

BC547<br />

Re3<br />

Re4<br />

LC Display 2 x 16<br />

K18<br />

K19<br />

070786 - 11<br />

NO<br />

C<br />

NC<br />

NO<br />

C<br />

NC<br />

Figure 1.<br />

Circuit diagram of the<br />

ECIO PLC board. Minimal<br />

hardware — great<br />

potential in terms of I/O.<br />

ECIO PLC • 37<br />

65


PROJECTS PROGRAMMABLE LOGIC CONTROL<br />

Figure 2.<br />

The unstuffed ECIO PLC<br />

board is available<br />

fr<strong>om</strong> Elektor.<br />

Elektor blockbusters<br />

K6<br />

K1<br />

K2<br />

K3<br />

K4<br />

B1<br />

R11<br />

CAN<br />

The CAN (controller area network) interface is used for adding<br />

the ECIO PLC onto a CAN network. CAN is ‘hip’ and<br />

few PLCs we have seen offer this connectivity. Here we use an<br />

MCP2515 CAN controller chip and an MCP2551 line driver.<br />

The CAN controller chip is connected ECIO peripheral pins<br />

set up to do SPI c<strong>om</strong>ms. There is also an interrupt pin, which<br />

is connected to ECIO pin RB2 and a chip select pin, which is<br />

connected to ECIO pin RB3. The CAN controller has its own<br />

20 MHz clock derived fr<strong>om</strong> a quartz crystal, X1.<br />

The actual connection of the CAN bus to the ECIO is by<br />

way of K9, a 2-way PCB mount screw terminal block. Jumper<br />

JP1 has to be installed only if the MCP2551 is the end<br />

node of the bus.<br />

C1<br />

R1 R3<br />

IC1<br />

COMPONENTS LIST<br />

Resistors<br />

R1 = 8-pin SIL array 4 x 4k�7*<br />

R2 = 8-pin SIL array 4 x 10k�*<br />

R3 = 8-pin SIL array 4 x 330�*<br />

R4,R5 = 8-pin SIL array 4 x 220�*<br />

R6 = 220�<br />

R7 = 390�<br />

R8 = 120�<br />

R9 = 8-pin SIL array 4 x 2k�2*<br />

R10 = 8-pin SIL array 4 x 1k�*<br />

R11 = 33�<br />

P1 = 10k� preset<br />

* see text<br />

Capacitors<br />

C1,C6,C7 = 10μF 25V radial<br />

IC2<br />

C3 C5 C6<br />

D5 R7<br />

D1<br />

D2<br />

D3<br />

D4<br />

T1<br />

T2<br />

R2<br />

T3<br />

T4<br />

R4<br />

C2,C4 = 22pF<br />

C3,C5 = 100nF<br />

LCD<br />

The LCD module is used to display ASCII characters to the<br />

user as a means of troubleshooting during the software development<br />

stage, or for monitoring the system as it’s busy<br />

checking and controlling the events in the aut<strong>om</strong>ated process.<br />

The LCD is connected to ECIO pins RD0–RD5 with the<br />

four data bits taking up bits 0–3, the RS bit taking up bit 4<br />

and the Enable bit taking up bit 5. P1 is the LCD contrast<br />

adjustment.<br />

Power supply<br />

Nothing special in this department — the usual 7805 voltage<br />

regulator (IC2) and the traditional set of decoupling capacitors.<br />

A bridge rectifier is used ahead of the regulator to<br />

66 elektor - 3/2008<br />

14<br />

13<br />

R9<br />

T6 T7<br />

T5<br />

T8<br />

P1<br />

K5<br />

R10 D8<br />

Re1<br />

Re3<br />

D12<br />

Re2<br />

D9<br />

Re4<br />

D13<br />

R5<br />

Semiconductors<br />

D1-D5,D8,D9,D12,D13 = 3mm LED<br />

D6,D7,D10,D11 = 1N4001<br />

B1 = B80C1500 (round case; 80V piv @<br />

1.5A p )<br />

T1-T8 = BC547<br />

IC1 = TLP620-4<br />

IC2 = 7805<br />

IC3 = MCP2515-I/P<br />

IC4 = MCP2551-I/P<br />

Miscellaneous<br />

Re1-Re4 = 12V relay, SPDT, e.g. Omron<br />

G5LE-1<br />

X1 = 20MHz quartz crystal<br />

2<br />

1<br />

C7<br />

IC3<br />

R6<br />

X1<br />

C2<br />

R8<br />

IC4<br />

D10<br />

C4<br />

D6<br />

D7<br />

D11<br />

K11<br />

K8<br />

K10<br />

K7<br />

JP1<br />

K9<br />

K1,K4,K9 = 2-way PCB screw terminal<br />

block, lead pitch 5mm<br />

K5 = 14-way boxheader<br />

K6 = AC/DC low-V adapter socket,<br />

PCB mount, e.g. CUI Inc. # PJ-002B<br />

(Digikey # CP-002B-ND) or Cliff Electronic<br />

C<strong>om</strong>ponents # DC10B (Farnell<br />

# 224960)<br />

K7,K8,K10,K11 = 3-way PCB screw terminal<br />

block, lead pitch 5mm<br />

ECIO = ECIO-40P processor module<br />

(Elektor Shop)<br />

LCD1 = LCD, alphanumerical, 2x16<br />

characters, e.g. Displaytech 162<br />

JP1 = 3-way SIL pinheader with jumper<br />

PCB, order code 070786-1 fr<strong>om</strong><br />

Elektor Shop<br />

ECIO PLC • 38


The ECIO family of USB programmable microcontrollers provides<br />

a simple way of adopting microcontroller technology<br />

into your projects. The device behaves just like a normal microcontroller<br />

— but when you plug the USB lead in and press<br />

the reset switch you can send a new program to the device.<br />

This makes the ECIO<br />

one of the lowest cost<br />

USB-c<strong>om</strong>patible PIC<br />

programmers in the<br />

world.<br />

Currently there are two<br />

products in the range:<br />

ECIO-28P and ECIO-<br />

40P. These devices<br />

are based on PICmicro<br />

18 series devices;<br />

the 18F2455 and the<br />

18F4455 respectively.<br />

allow the ECIO PLC board to be powered by AC as well as<br />

DC wall warts with an output voltage between 9 and about<br />

20 volts. For the DC connection, polarity is irrelevant.<br />

Phew, that ECIO PLC board has a lot of connections to the<br />

outside world and to prevent losing track of all those I/O<br />

lines and associated devices we’ve made a summary in<br />

Table 1.<br />

Construction<br />

The c<strong>om</strong>ponent mounting plan of the PCB designed for<br />

ECIO PLC is shown in Figure 2. As usual the copper track<br />

layout may be downloaded fr<strong>om</strong> our website for those with<br />

the wherewithal to etch & drill their own circuit board at<br />

h<strong>om</strong>e. All others will like to hear that the bare board is<br />

available ready-made fr<strong>om</strong> the Elektor Shop.<br />

No SMD c<strong>om</strong>ponents are used in this project so stuffing the<br />

board should be mostly plain sailing if you use care and<br />

precision in handling and soldering the parts. The 8-pin resistor<br />

arrays containing four individually wired resistors<br />

(i.e. not top c<strong>om</strong>moned!) may prove difficult to get. Instead<br />

of arrays, you can also use four individual resistors mounted<br />

vertically side by side.<br />

Give your c<strong>om</strong>pleted board a good visual inspection before<br />

inserting ICs and powering up for the first time.<br />

ECIO hardware Testing — I/O and CAN<br />

To help you find your bearings we have written a simple<br />

and instructive ECIO test program, of which the Flowcode<br />

listing is shown in Figure 3. Download it, load it into Flowcode,<br />

run the simulation, c<strong>om</strong>pile and blow it into the ECIO<br />

module.<br />

Elektor blockbusters<br />

3/2008 - elektor<br />

ECIO – the cheapest USB PIC progger out there<br />

VDD USB<br />

GND<br />

/RESET<br />

RA0/AN0<br />

RA1/AN1<br />

RA2/AN2<br />

RA3/AN3<br />

RA4/AN4<br />

RA5/AN5<br />

RE0/AN5<br />

RE1/AN6<br />

RE2/AN7<br />

RD0<br />

RD1<br />

RD2<br />

RD3<br />

RD4<br />

RD5<br />

RD6<br />

RD7<br />

ECIO40 CONNECTIONS<br />

1<br />

2<br />

3<br />

4<br />

5<br />

6<br />

7<br />

8<br />

9<br />

10<br />

11<br />

12<br />

13<br />

14<br />

15<br />

16<br />

17<br />

18<br />

19<br />

20<br />

ECIO40P<br />

40<br />

39<br />

38<br />

37<br />

36<br />

35<br />

34<br />

33<br />

32<br />

31<br />

30<br />

29<br />

28<br />

27<br />

26<br />

25<br />

24<br />

23<br />

22<br />

21<br />

VDD EXT<br />

RB7<br />

RB6<br />

RB5<br />

RB4<br />

RB3/AN9<br />

RB2/AN8/INT2<br />

RB1/AN10/INT1/SCK<br />

RB0/AN12<br />

RC7/RX/SDO<br />

RC6/TX/CK<br />

RC2<br />

RC1<br />

RC0<br />

GND<br />

VDD USB<br />

GND<br />

/RESET<br />

RA0/AN0<br />

RA1/AN1<br />

RA2/AN2<br />

RA3/AN3<br />

RA4/AN4<br />

RA5/AN5<br />

The ECIO microcontrollers are pre-programmed with a bootloader<br />

program which allows you to send a new program to<br />

the microcontroller via USB, in principle as many times as you<br />

like. ECIO is c<strong>om</strong>patible with hex code fr<strong>om</strong> any appropriate<br />

c<strong>om</strong>piler. ECIO is directly c<strong>om</strong>patible with Flowcode — a<br />

graphical programming language which greatly simplifies the<br />

code generation process<br />

ECIO28 CONNECTIONS<br />

1<br />

2<br />

3<br />

4<br />

5<br />

6<br />

7<br />

8<br />

9<br />

10<br />

11<br />

12<br />

13<br />

14<br />

ECIO28P<br />

28<br />

27<br />

26<br />

25<br />

24<br />

23<br />

22<br />

21<br />

20<br />

19<br />

18<br />

17<br />

16<br />

15<br />

VDD EXT<br />

RB7<br />

RB6<br />

RB5<br />

RB4<br />

RB3/AN9<br />

RB2/AN8/INT2<br />

RB1/AN10/INT1/SCK<br />

RB0/AN12<br />

RC7/RX/SDO<br />

RC6/TX/CK<br />

RC2<br />

RC1<br />

RC0<br />

— but can also be used<br />

with any C c<strong>om</strong>piler or<br />

Microchip’s own development<br />

suite MPLAB.<br />

ECIO is well supported<br />

with a wide range of<br />

learning and development<br />

tools including (free)<br />

Flowcode and inexpensive<br />

E-blocks.<br />

The program includes a general PIC setup routine that does<br />

all the port and I/O pin configuring on the ECIO. For example,<br />

ECIO lines RB4-RB7 are set up as output lines (for<br />

the relay drivers). The test program is simple to use: if you<br />

drive the opto-isolator on RA0, the relay on RB4 will be energised.<br />

Similarly with the c<strong>om</strong>bination RA1/RB5, and so<br />

Table 1. ECIO connections overview<br />

Relay Output ECIO I/O Pin<br />

Relay Re1 (K14) RB4<br />

Relay Re2 (K15) RB5<br />

Relay Re3 (K18) RB6<br />

Relay Re3 (K19) RB7<br />

Opto-Isolator Inputs ECIO I/O Pin / LED<br />

K1 RA0 / D1<br />

K2 RA1 / D2<br />

K3 RA2 / D3<br />

K4 RA3 / D4<br />

CAN (fr<strong>om</strong> CPU) ECIO I/O Pin<br />

Serial Data Out RC7<br />

Serial Data In RB0<br />

Serial Clock RB1<br />

/Interrupt RB2<br />

/Chip Select RB3<br />

LCD ECIO I/O Pin<br />

D0 RD0<br />

D1 RD1<br />

D2 RD2<br />

D3 RD3<br />

RS RD4<br />

Enable RD5<br />

ECIO PLC • 39<br />

67


PROJECTS PROGRAMMABLE LOGIC CONTROL<br />

Figure 3.<br />

This Flowcode program<br />

runs a hardware test<br />

on the ECIO PLC.<br />

Elektor blockbusters<br />

on. The display will show: ‘Elektor ECIO PLC board’ (no?<br />

adjust that LCD contrast!). Neither family members nor PIC<br />

geeks may be too impressed but if this works then a whole<br />

lot of PIC code is being executed and you can safely assume<br />

that all hardware is functioning as it should.<br />

The CAN test utility discussed in the inset is also included<br />

in the free software download for this project. The two test<br />

programs provided are educational and certainly worth<br />

looking at even if you do not actually build the project (hint:<br />

use the free Flowcode version to begin with). The archive<br />

file number is 070786-11.zip.<br />

PLC programming<br />

All ECIO PLC programming bears great resemblance to Eblocks<br />

and Flowcode so if you have any experience with<br />

these you’re in luck. If not, there’s a mass of information<br />

out there on the Internet [1], in previous issues of Elektor<br />

and in the Flowcode package itself. Best of all, Flowcode<br />

for ECIO is free [1].<br />

Writing a process control program for the ECIO PLC underscores<br />

what Flowcode is all about: rather than worrying<br />

about syntax and PIC assembly code you are working at<br />

a fairly high level, setting up a full-blown flowchart of the<br />

program and let Flowcode arrange all the c<strong>om</strong>piling, initializing,<br />

error tracking and code downloading to the ECIO<br />

module. Of course you can simulate your PLC program so<br />

there’s a good chance of instant success when the ECIO<br />

PLC board is connected up to the real world.<br />

More advanced users may want to rely on their own methods<br />

of producing PIC18 code using C++ c<strong>om</strong>pilers or similar.<br />

The ECIO even accepts straight hex code fr<strong>om</strong> all you<br />

assembly code diehards out there. Simply use the free USB<br />

I/O drivers to connect ECIO to your PC.<br />

(070786-I)<br />

CAN interface testing<br />

CAN is essentially good for sending c<strong>om</strong>plex message structures<br />

between a number of ECUs (microcontrollers). The test<br />

program written for Flowcode simply looks for an echo of<br />

the outgoing CAN message. This could be used to see how<br />

many nodes are on the network or used to calculate the distance<br />

between nodes based on echo time, etc.<br />

Basically the ECIO test program is sending out a specific<br />

CAN message with an standard ID of 12. When the Multiprogrammer<br />

receives a CAN message it checks the ID and<br />

if it is equal to 12 then it resends the message ID 12. The<br />

ECIO continues to send out this message ID until it receives<br />

a CAN message back. Once it has received a message back<br />

it checks the ID and then confirms or denies if the echo was<br />

successful.<br />

For this test you will need another ECIO PLC board or an<br />

E-blocks Multiprogrammer connected to an E-blocks CAN<br />

module. One ECIO PLC board will send several messages<br />

over the CAN bus. The other one will ‘listen’ until a predefined<br />

message appears and then replies to the ECIO. When<br />

the CAN transmitter is started the display reads ‘Startup’,<br />

followed by ‘Done’ a bit later once the CAN controller is initialized.<br />

If the CAN connection is okay the display shows ‘Message<br />

returned’, if not, you’ll see ‘Message failed’.<br />

Web Link and reference<br />

[1] http://www.matrixmultimedia.c<strong>om</strong>/ECIO-X.php<br />

[2] EasyControl I/O, Elektor October 2007.<br />

ECIO PLC • 40<br />

68 elektor - 3/2008


PROJECTS JTAG ADAPTOR<br />

Universal<br />

JTAG Adaptor<br />

Marcel Cremmel<br />

For<br />

programming and emulation<br />

This adaptor was originally intended to allow programming of the memory and CPLD of the PSD813<br />

used in the GBECG Gameboy cartridge, which converts this games console into an electrocardioscope<br />

(see October 2006 issue). But it’s much more universal than that (see box entitled ‘In-Circuit JTAG’) Our<br />

adaptor connects to a PC parallel port and uses the JTAG IEEE 1149.1 protocol.<br />

Informed microelectronics amateurs<br />

will of course be aware that other ‘In-<br />

Circuit’ programmable devices use this<br />

same port (parallel) and an identical<br />

protocol. Unfortunately, the programmer/emulators<br />

intended for these devices<br />

are not c<strong>om</strong>patible — far fr<strong>om</strong> it<br />

in fact: so there’s no point hoping for a<br />

mixed marriage!<br />

However, closer examination of the circuit<br />

diagrams of certain programmers<br />

suggested by the IC manufacturers<br />

Elektor blockbusters<br />

shows that the differences are relatively<br />

minor and in fact concern the interconnections<br />

between the LPT port signals<br />

and the JTAG connectors. So a few multiplexing<br />

functions is all it takes to produce<br />

a ‘universal’ adaptor.<br />

Had it been achieved using conventional<br />

logic c<strong>om</strong>ponents, the circuit of our<br />

adaptor would have been quite c<strong>om</strong>plex,<br />

with different electronics for each<br />

of the sections for the different types<br />

of processor. Using an EP900 program-<br />

mable logic circuit (Altera, on free offer<br />

fr<strong>om</strong> Elektor) makes it possible to offer a<br />

very cheap and simple programmer.<br />

Many manufacturers have adopted the<br />

JTAG (Join Test Action Group) protocol<br />

for programming, debugging, and testing<br />

their ICs in situ on the board (IC for<br />

In Circuit). Fortunately, you don’t need<br />

to know all the details of this protocol<br />

to be able to use it: the PC software<br />

(usually free) and the target c<strong>om</strong>ponents<br />

each include a JTAG core that al-<br />

Universal JTAG Adaptor • 41<br />

56 elektor electronics - 5/2007


lows them to c<strong>om</strong>municate c<strong>om</strong>pletely<br />

transparently.<br />

The devices involved have special<br />

‘JTAG’ pins that you merely need to<br />

connect to the pins of the same name<br />

on the programmer connector. The size<br />

(number of contacts) and pinning of this<br />

connector differ fr<strong>om</strong> one manufacturer<br />

to another. This information is given in<br />

the various diagrams shown in the boxes<br />

of Figures 1–4, concerning respectively<br />

Altera CPLDs and EPLDs (Byteblaster<br />

II) (Figure 1), Xilinx CPLDs and<br />

EPLDs (Parallel Download Cable) (Figure<br />

2), MSP430 microcontrollers fr<strong>om</strong><br />

Texas Instruments (LPT IF 4 wire JTAG<br />

C<strong>om</strong>munication) (Figure 3) and the<br />

PSD, uPSD and DSM families (Flashlink<br />

FL101) fr<strong>om</strong> ST Microelectronics (Figure<br />

4). It should also be noted that there is<br />

a certain discrepancy in the naming of<br />

the signals between the different JTAG<br />

connectors.<br />

ADAPTOR CIRCUIT<br />

The heart of the circuit (Figure 5),<br />

which with its 44 pins could hardly go<br />

unnoticed, is an EP900 PLD. This PLD<br />

forms the link between the PC’s parallel<br />

port, K1, and the four DIL pin headers<br />

for the JTAG connections to the four targets,<br />

named respectively MSP430 (K2),<br />

FLASHLINK (K3), XILINX (K4) and AL-<br />

TERA (K5). SW, a dual-gang DIP switch<br />

c<strong>om</strong>prising contacts JP1 and JP2, allows<br />

selection of one of the 4 types of<br />

programmer recognized by the JTAG<br />

adaptor (see truth table in the circuit<br />

diagram, also given on the c<strong>om</strong>ponent<br />

overlay on the board). These four options<br />

appear in the form of the same<br />

number of HE-10 headers in the bott<strong>om</strong><br />

right-hand part of the circuit. Each option<br />

has its own logic structure within<br />

the EP900; all these various sub-assemblies<br />

using logic gates are shown<br />

in Figure 6.<br />

Each of these structures is drawn fr<strong>om</strong><br />

the manufacturers’ programmer circuits.<br />

For reasons of effi ciency, the EP900’s<br />

logic structure is described in Altera’s<br />

AHDL language. The circuit diagram is<br />

easier for an electronics technician to<br />

read, but the ‘AHDL’ form is more efficient<br />

here. Just for information, the<br />

‘source’ fi le (.tdf) for the contents of the<br />

EP900 is given in the inset.<br />

At the bott<strong>om</strong> left we fi nd the…<br />

POWER SUPPLY<br />

The EP900 PLD is quite an old IC already!<br />

It requires a 5 V supply, but as<br />

its consumption is quite high, the pro-<br />

Elektor blockbusters<br />

5/2007 - elektor electronics<br />

JTAG ‘In-Circuit’ –<br />

s<strong>om</strong>e applications<br />

– PSDs, uPSDs and DSMs fr<strong>om</strong> ST Microlectronics<br />

– MSP430 microcontrollers fr<strong>om</strong> Texas Instruments<br />

– EPLDs and CPLDs fr<strong>om</strong> ALTERA<br />

– EPLDs and CPLDs fr<strong>om</strong> XILINX<br />

TCK 1 2 GND<br />

TDO 3 4 VCC<br />

TMS 5 6<br />

7 8<br />

TDI 9<br />

10 GND<br />

VCC<br />

2<br />

4<br />

6<br />

8<br />

10<br />

1<br />

3<br />

5<br />

7<br />

9<br />

TCK<br />

TDO<br />

TMS<br />

Figure 1. CPLD and EPLD (Byteblaster II) fr<strong>om</strong> Altera: 10-pin DIL connector.<br />

Software: Quartus II Web Edition, Quartus II Programmer [1]<br />

1 2 VCC<br />

GND 3 4 TMS<br />

GND 5 6 TCK<br />

GND 7 8 TDO<br />

GND 9 10 TDI<br />

GND 11 12<br />

GND 13<br />

14<br />

1 2<br />

3 4<br />

5 6<br />

7 8<br />

9 10<br />

11 12<br />

13 14<br />

V CC<br />

TDI<br />

1k<br />

TMS<br />

TCK<br />

TDO<br />

TDI<br />

V CC<br />

1k<br />

1k<br />

XILINX<br />

Figure 2. CPLD and EPLD (Parallel Download Cable) fr<strong>om</strong> Xilinx: 14-pin DIL connector.<br />

Software: ISE WebPACK [2]<br />

TDO 1 2 VCC out<br />

TDI 3 4 VCC in<br />

TMS 5 6 TCLK<br />

TCK 7 8 TEST<br />

GND 9 10<br />

RST 11 12<br />

13<br />

14<br />

VCC TOOL 2<br />

VCC TARGET 4<br />

6<br />

TEST/VPP 8<br />

10<br />

12<br />

14<br />

J1<br />

J2<br />

1<br />

3<br />

5<br />

7<br />

9<br />

11<br />

13<br />

TDO/TDI<br />

TDI/VPP<br />

TMS<br />

TCK<br />

RST<br />

47k R1<br />

C1<br />

10n/2n2<br />

1k<br />

TMS<br />

TCK<br />

TDO<br />

TMS<br />

TDI<br />

060287 - 12<br />

V CC<br />

VCC<br />

GND<br />

VCC<br />

VCC<br />

Target<br />

Altera<br />

Device<br />

GND<br />

TDI TDO TDI TDO TDI TDO<br />

C2<br />

TCK<br />

C3<br />

100n<br />

TMS<br />

TCK<br />

060287 - 14<br />

TMS<br />

TCK<br />

060287 - 13<br />

V CC<br />

VCC /AVCC /DVCC<br />

TDO/TDI<br />

TDI/VPP<br />

TMS<br />

TCK<br />

RST/NMI<br />

MSP430Fxxx<br />

TEST/VPP<br />

VSS /AVSS /DVSS<br />

Figure 3. MSP430 microcontrollers (LPT-IF 4-wire JTAG C<strong>om</strong>munication) fr<strong>om</strong> Texas Instruments: 14-pin DIL connector. Software:<br />

IAR-Kickstart [3]<br />

Universal JTAG Adaptor • 42<br />

57


PROJECTS JTAG ADAPTOR<br />

About the author<br />

Marcel Cremmel, the author, has been a qualifi ed lecturer in Electrical Engineering, electronics<br />

option, since 1979 (state certifi ed by the French National Education system).<br />

After c<strong>om</strong>pleting his fi rst years of teaching in the School of Engineering in Rabat in Morocco,<br />

under the Co-operation scheme, in 1982 he was assigned to the Louis Couffi gnal College in<br />

Strasbourg, in the BTS SE section (Higher Technician’s Certifi cate, ‘electronics systems’).<br />

His job requires him to cover all fi elds of electronics, though his preference is for telec<strong>om</strong>munications,<br />

video, microcontrollers (MSP430 and PIC) and programmable logic devices<br />

(Altera).<br />

Alongside electronics, his other passion is motorbikes in all their forms: touring, c<strong>om</strong>petitions,<br />

etc. His personal website is at http://electronique.marcel.free.fr/<br />

1 2<br />

GND 3 4<br />

TDI 5 6<br />

VCC 7 8 RST<br />

TMS 9 10 GND<br />

TCK 11 12 GND<br />

TDO 13<br />

14<br />

RST<br />

1<br />

3<br />

5 TDI<br />

7<br />

9 TMS<br />

11 TCK<br />

13 TDO<br />

gramming adaptor can’t be powered directly<br />

fr<strong>om</strong> the outputs of the PC’s LPT<br />

port. To simplify implementation and allow<br />

us to dispense with a special dedicated<br />

power supply, we have decided<br />

to power the adaptor fr<strong>om</strong> the power<br />

rails in the target systems. But these<br />

are usually content – especially nowadays!<br />

– with 3 V or 3.6 V, which is not<br />

enough to power the EP900.<br />

So we’ve fi tted the adaptor with a very<br />

fl exible switched capacitor voltage converter<br />

that supplies a regulated 5 V output<br />

fr<strong>om</strong> an input voltage anywhere between<br />

2.7 and 5.5 V! Yes, that’s right:<br />

the converter works just as well with<br />

an input voltage either lower or higher<br />

than the output voltage, with an effi -<br />

ciency of around 90%! Bravo to the Burr<br />

Brown engineers (that c<strong>om</strong>pany since<br />

taken over by Texas Instruments, which<br />

explains why the spec. sheet has to be<br />

obtained fr<strong>om</strong> the TI website). However,<br />

the current is limited to 30 mA.<br />

10k<br />

2<br />

4<br />

6<br />

8<br />

10<br />

12<br />

14<br />

System Reset Circuity<br />

(connect directly to RST<br />

input on PSD)<br />

10n<br />

100k<br />

100k<br />

100k<br />

100k<br />

User I/O Signals<br />

Figure 4. PSD, uPSD and DSM families (Flashlink FL-101) fr<strong>om</strong> ST Microelectronics: 14-pin DIL connector.<br />

Software: among others, PSDsoft Express [3] for programming the PSD813 in the ECG cartridge for Game Boy.<br />

Elektor blockbusters<br />

The only awkward point for amateurs<br />

is the size of the regulator IC (it’s only<br />

available in an SM version), making it<br />

tricky to solder. But luckily it only has<br />

six pins. So its now or never, to try your<br />

hand with an SM device. Position IC2<br />

accurately on its pads. Apply a little solder<br />

to one of the pad + legs. Once the<br />

solder has set, solder the leg diametrically<br />

opposite the previous one. If everything<br />

is OK, now solder the remaining<br />

legs. If you create a solder bridge<br />

between two legs, remove it using desoldering<br />

wick.<br />

CONSTRUCTION<br />

USER<br />

PC BOARD<br />

PSD or PSD Port C<br />

TDI - PC5<br />

VSTBY or PC2<br />

TMS - PC0<br />

TCK - PC1<br />

TDO - PC6<br />

General I/O - PC3<br />

General I/O - PC4<br />

General I/O - PC7<br />

060287 - 15<br />

As shown in Figure 7, the board designed<br />

for this project is double sided;<br />

it uses only a very few SM c<strong>om</strong>ponents,<br />

mainly around the EP900. Naturally,<br />

these are to be fi tted on the track side<br />

of the board. So let’s get stuck in! For<br />

reasons of practicality, we rec<strong>om</strong>mend<br />

starting with the SM c<strong>om</strong>ponents.<br />

Watch out – certain of them, in particular<br />

capacitor C1, are tucked away at the<br />

centre of the board, right between the<br />

legs of the PLCC44 socket (into which<br />

the EP900 is going to be plugged, on<br />

the other side). Take care to solder the<br />

regulator IC2 carefully, as without this,<br />

nothing else will work. It’s surrounded<br />

by capacitors that are bigger than<br />

it is. Take care to identify the values of<br />

the SM c<strong>om</strong>ponents correctly (resistors<br />

often have coded value information:<br />

103 means 10 k�, 1203 means 120 k�;<br />

things are trickier with the capacitors,<br />

which are often not identifi ed or identifi<br />

able. Once the SM c<strong>om</strong>ponents are<br />

fi tted, you can fi t the row of resistors,<br />

the rest of the conventional c<strong>om</strong>ponents,<br />

the selector SW, the headers K2<br />

(MSP430) to K5 (ALTERA), the PLCC44<br />

socket, fi nishing off with the 25-pin sub-<br />

D connector K1. Make sure you pick the<br />

male version of the printer connector<br />

(LPT); the female version won’t make<br />

for a very good connection! One little<br />

note about the dual selector SW: it’s not<br />

always easy to get hold of a dual DIP<br />

switch, so we’ve left enough ro<strong>om</strong> to fi t<br />

a quad one, but you’ll need to cut off the<br />

spare legs before you fi t it.<br />

If you’re making your own board, it’s<br />

equally possible to make it single-sided<br />

– the second side of the double-sided<br />

board is in fact only used to avoid the<br />

need for the wire links that a single-sided<br />

version will require. Construction is<br />

the same, but in this case, it’s preferable,<br />

for reasons of practicality, to start<br />

off by fi tting various wire links, using<br />

tinned copper wire.<br />

Take care to avoid shorts with the wire<br />

links positioned between the ‘FLASH-<br />

LINK’ and ‘XILINX’ connectors, which<br />

are relatively close together.<br />

All that remains is to plug the EP900<br />

into its socket. Check the quality of your<br />

construction one last time (soldering,<br />

c<strong>om</strong>ponent values – luckily there’s only<br />

one value for the conventional resistors),<br />

as there is no way of testing the<br />

proper operation of this circuit except<br />

by trying it out for real!<br />

Note about the EP900 PLD (order<br />

code 060287-41): this is available programmed,<br />

free of charge (apart fr<strong>om</strong><br />

standard postage and packing charges)<br />

fr<strong>om</strong> the Elektor SHOP. If you order PCB<br />

# 060287-1, the programmed IC will be<br />

aut<strong>om</strong>atically supplied with it.<br />

TARGET CONNECTIONS<br />

Watch out – you must only use one<br />

connector at a time! In most cases, a<br />

Universal JTAG Adaptor • 43<br />

58 elektor electronics - 5/2007


K1<br />

SUB D25<br />

VCC IN<br />

5/2007 - elektor electronics<br />

1<br />

14<br />

2<br />

15<br />

3<br />

16<br />

4<br />

17<br />

5<br />

18<br />

6<br />

19<br />

7<br />

20<br />

8<br />

21<br />

9<br />

22<br />

10<br />

23<br />

11<br />

24<br />

12<br />

25<br />

13<br />

STROBE<br />

AUTOFDX<br />

D0<br />

ERROR<br />

D1<br />

INIT<br />

D2<br />

SLCTIN<br />

D3<br />

GND1<br />

D4<br />

GND2<br />

D5<br />

GND3<br />

D6<br />

GND4<br />

D7<br />

GND5<br />

ACK<br />

GND6<br />

BUSY<br />

GND7<br />

PE<br />

GND8<br />

READY<br />

100R<br />

R1<br />

100R<br />

R10<br />

100R<br />

R9<br />

100R<br />

R17<br />

100R<br />

100R<br />

R8<br />

R11<br />

100R<br />

100R<br />

R7<br />

R12<br />

100R<br />

R6<br />

100R<br />

100R<br />

100R<br />

100R<br />

100R<br />

100R<br />

100R<br />

C3<br />

R5<br />

R4<br />

R3<br />

R13<br />

R14<br />

R15<br />

R16<br />

220n<br />

6 4<br />

PUMP+ PUMP-<br />

100k<br />

5<br />

IN<br />

IC2<br />

OUT<br />

1<br />

REG710NA-5<br />

3<br />

EN<br />

R28 R29 R30 R31 R32<br />

100k<br />

+5V<br />

100k<br />

C5 C2 2<br />

C4 C7<br />

100k<br />

100k<br />

STRB<br />

AFDX<br />

D0<br />

ERR<br />

D1<br />

INIT<br />

D2<br />

SLCT<br />

D3<br />

D4<br />

D5<br />

D6<br />

D7<br />

ACK<br />

BUSY<br />

PE<br />

RDY<br />

2<br />

24<br />

C1<br />

CLK1<br />

CLK2<br />

20<br />

IN<br />

19<br />

IN<br />

21<br />

IN<br />

30<br />

IN<br />

25<br />

IN<br />

26<br />

IN<br />

27<br />

IN<br />

41<br />

IN<br />

32<br />

I/O<br />

31<br />

34<br />

33<br />

35<br />

37<br />

38<br />

40<br />

I/O<br />

I/O<br />

I/O<br />

I/O<br />

I/O<br />

I/O<br />

I/O<br />

100n<br />

+5V<br />

1<br />

IC1<br />

44<br />

EP900LC<br />

22<br />

23<br />

VCC IN<br />

K4<br />

XILINX<br />

1 2<br />

3 4 TMS TDI<br />

5 6 TCK TMS<br />

7 8 Nstat TDO<br />

9 10 TCK RST<br />

11 12<br />

13 14<br />

I/O<br />

10<br />

SEL0<br />

43<br />

SEL1<br />

42<br />

17<br />

NC 39<br />

NC<br />

IN<br />

IN<br />

IN<br />

I/O<br />

I/O<br />

I/O<br />

I/O<br />

I/O<br />

I/O<br />

I/O<br />

I/O<br />

I/O<br />

I/O<br />

I/O<br />

I/O<br />

I/O<br />

I/O<br />

3<br />

4<br />

5<br />

11<br />

12<br />

13<br />

14<br />

15<br />

16<br />

18<br />

28<br />

29<br />

36<br />

6<br />

7<br />

8<br />

9<br />

10k<br />

R35<br />

+5V<br />

10k<br />

R37<br />

JP1<br />

10k<br />

R20<br />

100R<br />

R24<br />

100R<br />

R25<br />

100R<br />

100R<br />

R19<br />

R21<br />

100R<br />

R22<br />

100R<br />

R23<br />

100R<br />

100R<br />

100R<br />

100R<br />

R26<br />

R18<br />

R27<br />

R36<br />

JP2<br />

VCC IN<br />

10k<br />

R33<br />

100k<br />

R34<br />

TDO<br />

TDO F<br />

Nstat TDO<br />

TMS TDI<br />

TCLK<br />

TCK TMS<br />

TDI TMS<br />

TCK RST<br />

TDO TCK<br />

TCK A<br />

VCC IN VCC IN K3<br />

K5<br />

FLASHLINK<br />

ALTERA 1 2<br />

TCK A 1 2<br />

3 4<br />

TDO 3 4<br />

TMS TDI 5 6<br />

TMS TDI 5 6 TCK TMS<br />

7 8 TDO TCK<br />

Nstat TDO 7 8 TDO TCK TDI TMS 9 10<br />

TDI TMS 9 10<br />

TCK RST 11 12<br />

TDO F 13 14<br />

+5V<br />

TDO<br />

TMS TDI<br />

TCK TMS<br />

TDO TCK<br />

TCK RST<br />

JP1 JP2<br />

ON ON ALTERA<br />

OFF ON XILINX<br />

ON OFF PSD<br />

OFF OFF MSP430<br />

VCC IN<br />

VCC IN<br />

K2<br />

MSP430<br />

1 2<br />

3 4<br />

5 6 TCLK<br />

7 8 TDI TMS<br />

9 10<br />

11 12<br />

13 14<br />

060287 - 11<br />

Figure 5. The EP900 takes pride of place in the centre of the circuit for the universal JTAG programmer. It’s available ready-programmed, free of charge, when you order the PCB 060287-I.<br />

Elektor blockbusters<br />

Universal JTAG Adaptor • 44<br />

59


PROJECTS JTAG ADAPTOR<br />

ALTERA<br />

TRI<br />

D0 TCK<br />

D1<br />

D2<br />

D3<br />

D6<br />

AFDX<br />

WIRE<br />

D4 ACK<br />

TDO<br />

PIN7<br />

TRI<br />

TRI<br />

TRI<br />

TRI<br />

WIRE<br />

WIRE<br />

WIRE<br />

TMS<br />

PIN8<br />

PIN6<br />

TDI<br />

BUSY<br />

READY<br />

ERROR<br />

D0<br />

D1<br />

D2<br />

D3<br />

D6<br />

D4<br />

TDO<br />

VCC<br />

XILINX<br />

TRI<br />

TRI<br />

TRI<br />

NOT<br />

WIRE<br />

WIRE<br />

WIRE<br />

WIRE<br />

AND2<br />

TDI<br />

TCK<br />

TMS<br />

BUSY<br />

PE<br />

ERROR<br />

ACK<br />

READY<br />

D0<br />

D1<br />

D2<br />

D3<br />

FLASHLINK<br />

TRI<br />

TRI<br />

TRI<br />

NOT<br />

TCK<br />

TMS<br />

TDI<br />

NOT<br />

D5 RSTN<br />

D6<br />

TDO<br />

WIRE<br />

NOT<br />

WIRE<br />

WIRE<br />

WIRE<br />

READY<br />

PE<br />

ACK<br />

BUSY<br />

ERROR<br />

simple 10- or 14-way ribbon cable, with<br />

a crimped connector at each end (watch<br />

out for the orientation!) is used to establish<br />

the electrical links between the<br />

target and the adaptor (see the circuit<br />

diagrams of Figures 1 through 4 and the<br />

pinning of the relevant connectors).<br />

If you have direct access to the rear of<br />

the PC, the adaptor can be inserted directly<br />

into the LPT port, without using<br />

an extender cable interconnecting the<br />

PC and the JTAG adaptor.<br />

USB adaptors<br />

The latest offi ce and notebook PCs no<br />

longer have parallel ports (LPT) – a<br />

highly regrettable decision, especially<br />

for this project! To make up for this,<br />

you can fi nd USB/LPT adaptors, but do<br />

make sure you check their c<strong>om</strong>patibility<br />

with our JTAG programmer; many of<br />

them will only accept printers. We can’t<br />

go into details of the programming procedures<br />

for all the possible targets, so<br />

we’re going to confi ne ourselves to one<br />

example, the…<br />

GameBoy ECG cartridge<br />

The cartridge uses an SMD connector<br />

with a pitch of 1.25 mm (K3). To make<br />

the cable, we rec<strong>om</strong>mend you follow<br />

the following procedure.<br />

1. Press a piece of 14-way ribbon cable<br />

to a female DIL14 connector;<br />

2. Use the Molex connector and the<br />

wires already prepared in the c<strong>om</strong>ponents<br />

list (see Elektor Electronics October<br />

2006) to make up the appropriate<br />

6-way connector for K3;<br />

3. Solder the four wires TCK, TDI, TDO<br />

and TMS and the two power supply<br />

wires to both connectors;<br />

4. Check the connections with a continuity<br />

tester and then insulate the soldering<br />

with heat-shrink sleeving.<br />

And there you go, all ready to program<br />

the PSD813s in the GameBoy ECG<br />

cartridge.<br />

One last remark: the adaptor is c<strong>om</strong>patible<br />

with Byteblaster II (Altera); it does<br />

not work with the fi rst version of the<br />

driver (Byteblaster on its own, without<br />

the II). This old driver was used by<br />

the MaxPlus II software, and has been<br />

replaced by Quartus for two or three<br />

years now).<br />

60 elektor electronics - 5/2007<br />

D0<br />

D1<br />

D2<br />

MSP430<br />

TRI<br />

TRI<br />

TRI<br />

NOT<br />

TDI<br />

TMS<br />

TCK<br />

TRI<br />

TDO PE<br />

SLCT<br />

WIRE<br />

INIT TEST<br />

TRI<br />

STRB RST<br />

Figure 6. Nothing like it to illustrate the fl exibility of a PLD like the EP900! A single device can fulfi l several c<strong>om</strong>plex logic functions.<br />

060287 - 16<br />

Figure 7. C<strong>om</strong>ponent overlay for the board designed for this project. The track layout is available for free download.<br />

Elektor blockbusters<br />

AFDX<br />

NOT<br />

WIRE<br />

WIRE<br />

WIRE<br />

WIRE<br />

ACK<br />

BUSY<br />

READY<br />

ERROR<br />

(060287-I)<br />

Universal JTAG Adaptor • 45


Bibliography and Internet links<br />

[1] https://www.altera.c<strong>om</strong>/support/software/<br />

download/sof-download_center.html<br />

[2] http://www.xilinx.c<strong>om</strong>/ise/logic_design_<br />

prod/webpack.htm<br />

[3] http://focus.ti.c<strong>om</strong>/docs/toolsw/folders/<br />

print/iar-kickstart.html<br />

[4] http://mcu.st.c<strong>om</strong>/mcu/modules.php?<br />

name=Content&pa=showpage&pid=57<br />

REF710-5 data sheet:<br />

http://focus.<br />

ti.c<strong>om</strong>/lit/ds/symlink/reg710-5.pdf<br />

Supplementary information, fi le # 060287-<br />

11.zip, free download fr<strong>om</strong>: www.elektorelectronics.co.uk<br />

C<strong>om</strong>ponents<br />

list<br />

Resistors<br />

R1,R3-R27 = 100�<br />

R28-R32,R34 = 100k� (SMD)<br />

R33,R35,R26,R37 = 10k� (SMD)<br />

(R2 not fi tted)<br />

Capacitors<br />

C1 = 100nF (SMD 1206)<br />

C2,C4 = 2μF2 (SMD 1206)<br />

C3 = 220nF (SMD 1206)<br />

C5,C7 = 47μF 10V radial<br />

(C6 not fi tted)<br />

Semiconductors<br />

IC1 = EP900LC (programmed, order<br />

code 060287-41) *<br />

IC2 = REG710-NA5<br />

Miscellaneous<br />

K1 (K_LPT) = 25-way sub-D plug, (male),<br />

right-angled pins, PCB mount<br />

K2 (FLASHLINK), K3 (MSP430), K4 (XI-<br />

LINX) = 14-way 2-row pinheader<br />

K5 (ALTERA) = 10-way 2-row pinheader<br />

J1,J2 (SW) = 2-way DIP switch<br />

PLCC-44 socket<br />

Project software, fi le # 060287-11.zip,<br />

free download fr<strong>om</strong> Elektor website<br />

PCB, order code 060287-1<br />

* Ready-programmed PLD supplied free<br />

when ordering PCB # 060287-1 fr<strong>om</strong><br />

the Elektor SHOP<br />

Optional<br />

Parts for the cable connection to K3 on<br />

the GBECG:<br />

- 14-way (2x7) press-on IDC socket<br />

- Molex socket, 6-way, 1.25mm lead<br />

pitch (RS C<strong>om</strong>ponents # 279-9178)<br />

- 6 wires with crimped contacts for<br />

Molex connector (RS C<strong>om</strong>ponents #<br />

279-9544)<br />

Elektor blockbusters<br />

5/2007 - elektor electronics<br />

‘AHDL’ source fi le for the EP900<br />

Contrary to fi rst impressions, an AHDL fi le can tell you a lot. Looking at this one a little more<br />

closely, it’s easy to spot the various options (->).<br />

subdesign prog_jtag_univers<br />

(<br />

TDO,Nstat_TDO,TDO_F : input;<br />

STRB,AFDX,INIT,SLCT : input;<br />

D[6..0] : input;<br />

SEL[1..0] : input; -- 0->ALTERA,1->XILINX,<br />

-- 2->FLASHLINK,3->MSP430<br />

ACK,BUSY,READY,ERROR: output;<br />

TCK_A,TMS_TDI,TCK_TMS,TDO_TCK,TDI_TMS,TCK_RST,PE : bidir;<br />

)<br />

variable<br />

TCK_A,TMS_TDI,TCK_TMS,TDO_TCK,TDI_TMS,TCK_RST,PE : tri;<br />

begin<br />

TCK_A.in=D0; TCK_A.oe=AFDX;<br />

case SEL[] is<br />

when 0 -- ALTERA<br />

=> TMS_TDI.in=D1 ; TMS_TDI.oe=AFDX;<br />

TCK_TMS.in=D3 ; TCK_TMS.oe=AFDX;<br />

TDO_TCK.in=D2 ; TDO_TCK.oe=AFDX;<br />

TDI_TMS.in=D6 ; TDI_TMS.oe=AFDX;<br />

TCK_RST.in=GND; TCK_RST.oe=GND;<br />

ACK =D4;<br />

BUSY =TDO;<br />

PE.in=GND; PE.oe=GND;<br />

READY=Nstat_TDO;<br />

ERROR=GND;<br />

when 1 -- XILINX<br />

=> TMS_TDI.in=D2 ; TMS_TDI.oe=!D3;<br />

TCK_TMS.in=D1 ; TCK_TMS.oe=!D3;<br />

TDO_TCK.in=GND; TDO_TCK.oe=GND;<br />

TDI_TMS.in=GND; TDI_TMS.oe=GND;<br />

TCK_RST.in=D0 ; TCK_RST.oe=!D3;<br />

ACK =GND;<br />

BUSY =D6;<br />

PE.in=D6; PE.oe=VCC;<br />

READY=Nstat_TDO & D4;<br />

ERROR=VCC;<br />

when 2 -- FLASHLINK<br />

=> TMS_TDI.in=D2 ; TMS_TDI.oe=!D3;<br />

TCK_TMS.in=GND; TCK_TMS.oe=GND;<br />

TDO_TCK.in=!D5; TDO_TCK.oe=VCC;<br />

TDI_TMS.in=D1 ; TDI_TMS.oe=!D3;<br />

TCK_RST.in=D0 ; TCK_RST.oe=!D3;<br />

ACK =GND;<br />

BUSY =GND;<br />

PE.in=!TDO_F; PE.oe=VCC;<br />

READY=D6;<br />

ERROR=GND;<br />

when 3 -- MSP430<br />

=> TMS_TDI.in=D0 ; TMS_TDI.oe=!SLCT;<br />

TCK_TMS.in=D1 ; TCK_TMS.oe=!SLCT;<br />

TDO_TCK.in=D2 ; TDO_TCK.oe=!SLCT;<br />

TDI_TMS.in=INIT; TDI_TMS.oe=VCC;<br />

TCK_RST.in=STRB; TCK_RST.oe=!AFDX;<br />

ACK =GND;<br />

BUSY =GND;<br />

PE.in=TDO; PE.oe=!SLCT;<br />

READY=GND;<br />

ERROR=GND;<br />

end case;<br />

end;<br />

For info: the ‘Jedec’ programming fi le (prog_jtag_univers.jed) is available fr<strong>om</strong> the Elektor<br />

website (www.elektor-electronics.co.uk).<br />

Universal JTAG Adaptor • 46<br />

61


HANDS-ON ELECTROCARDIOGRAPH<br />

GBECG<br />

Marcel Cremmel<br />

Lots of electronics hobbyist dream<br />

of recording an electrocardiogram<br />

(ECG) using a circuit built at h<strong>om</strong>e. Usually<br />

out of technical curiosity, as numerous problems have to be<br />

resolved in order to properly sample the heart’s electrical activity. Alternatively, s<strong>om</strong>e people<br />

require personal medical monitoring while under a cardiologist’s care. And then it’s great to be<br />

able to make your own ECG and show it to your GP or clinical staff.<br />

The idea of using a Nintendo Gameboy<br />

games console equipped with a special<br />

cartridge was inspired by the<br />

world-famous Elektor GBDSO [1] (a big<br />

thank you goes out to Steve Willis for<br />

his help with this project).<br />

Our electrocardiograph utilizes three<br />

electrodes: one on each wrist, the<br />

third on the left leg. The electronic<br />

device, built on a cartridge that slips<br />

into any Gameboy model, processes<br />

the sampled signals and produces a<br />

very high quality ECG scrolling across<br />

the LCD (see the various illustrations).<br />

The electrocardiogram implements<br />

the method of M. Einthoven (see the<br />

inset on the next page). It only uses<br />

two active electrodes, a third being<br />

used to set the no-signal level of the<br />

first two. All leads are single-ended.<br />

Despite this simplicity, the results are<br />

noticeable and even recognized as<br />

usable by a cardiologist. The electrocardiograph<br />

easily meets the initial<br />

specifications for which it was<br />

Elektor blockbusters<br />

32<br />

designed: to monitor tolerance to the<br />

anti-malaria medication.<br />

To do that, we measure the QT interval<br />

(see Figure 1) which should remain<br />

‘normal’. Figure 1 [2] matches up the<br />

electrical activity sampled and the cardiac<br />

cycle phases, as follows:<br />

P-Wave: Auricular contraction; the<br />

blood c<strong>om</strong>ing fr<strong>om</strong> the veins is<br />

pushed into the ventricles.<br />

QRS C<strong>om</strong>plex: Ventricular contraction;<br />

the blood contained inside is<br />

pushed into the arteries.<br />

Both of these waves produce the ‘lubdub’<br />

heartbeat sounds.<br />

T-Wave: Repolarisation of the ventricles;<br />

the ventricular muscle returns<br />

to rest.<br />

The electronics!<br />

After this little ‘dose’ of general knowledge,<br />

let’s deal with our favourite subject:<br />

describing the GBECG electronic<br />

structures and making the board.<br />

Just as with the GBDSO [1] (Elektor<br />

Electronics October and November<br />

2000), the specific electronics and software<br />

(in Flash memory) are grouped<br />

onto a cartridge that slips into the console’s<br />

connector. In this way, the<br />

Gameboy is transformed into a powerful<br />

electrocardiograph!<br />

The electronic device processes the<br />

very low voltages sampled between<br />

the two active electrodes. The singleended<br />

leads are designated DI, DII and<br />

DIII according to their localisation (see<br />

drawing in Figure 2).<br />

The most c<strong>om</strong>mon lead is DI.<br />

Due to its low peak-to-peak amplitude<br />

(of the order of one mV), the EMF (electr<strong>om</strong>otive<br />

force) measured is considerably<br />

amplified (about 1000�) before it<br />

can be converted to 8-bit digital. The<br />

sampling frequency selected is 477.84<br />

Hz, c<strong>om</strong>patible with the spectrum of<br />

an ECG signal.<br />

The digital signal is then taken care of<br />

by the console processor. It is then<br />

placed in an 8 kBytes cyclic buffer<br />

GBECG • 47<br />

elektor electronics - 10/2006


GameBoy<br />

ElectroCardioGraph<br />

Elektor blockbusters<br />

It is practically impossible to grasp the operation of this<br />

h<strong>om</strong>e-made electrocardiograph instrument without a minimum<br />

of medical knowledge. We deal with the heart of the<br />

subject. First of all...<br />

A bit of history…<br />

In passing, let us pay<br />

h<strong>om</strong>age to Willem<br />

Einthoven who discovered<br />

the relationship<br />

between electrical phen<strong>om</strong>ena<br />

and muscular<br />

contraction of the human<br />

heart about 100 years<br />

ago. He received the<br />

Nobel Prize in 1924 for<br />

that discovery.<br />

Willem Einthoven, inventor of<br />

the electrocardiograph.<br />

and a bit of biology…<br />

The heart is an auton<strong>om</strong>ous muscle: it is the only one not<br />

controlled by the brain. The ‘sinus node’, located in the right<br />

auricle, triggers nerve flows that control the heart muscles.<br />

These contract (‘depolarisation’ in medical lingo) and relax<br />

(‘polarisation’) in order to make up the blood pump that<br />

gives us life. The contraction is caused by a change in electrical<br />

polarity on each side of the cellular membranes.<br />

During the relaxation phases, the electrical charges find their<br />

state of equilibrium before being stimulated again.<br />

The resulting potentials are transmitted to the skin surface.<br />

They can then be sampled by cutaneous electrodes, as the<br />

human skin is sufficiently conductive.<br />

A wise placement of the electrodes allows a cardiologist to<br />

deduce the heart’s mechanical behaviour (and its defects!)<br />

by analysing the electrical activity.<br />

Characteristics:<br />

• Cartridge c<strong>om</strong>patible with Nintendo Gameboy consoles<br />

type Classic, Pocket, Colour or Advance<br />

• Single-ended connections using 3 electrodes<br />

• Sensitivity: 1.6 mV full scale<br />

• C<strong>om</strong>mon mode rejection: 100 dB<br />

• Trace memory : 68 s<br />

• Scrolling display<br />

• Temporal window: 2.6 s in acquisition mode (1.3 s or<br />

2.6 s in consultation mode)<br />

• Heartbeat indicator<br />

• Battery power supply required<br />

• Approx. 2 hours use fr<strong>om</strong> battery power<br />

The Electrocardiogram (ECG)<br />

Technology has greatly evolved since the 1920s. The first patients dipped their<br />

hands and feet in basins full of very salty water!<br />

String galvan<strong>om</strong>eter, The U-shaped magnet ends are enveloped in water cooling<br />

tubes (well before PCs!) Photos : Stichting Einthoven Foundation<br />

GBECG • 48<br />

10/2006 - elektor electronics 33


HANDS-ON ELECTROCARDIOGRAPH<br />

34<br />

ECG<br />

Elektor blockbusters<br />

P<br />

R<br />

Q S<br />

auricular contraction diastole<br />

(repolarisation)<br />

T<br />

ventricular contraction 050280 - 27<br />

Figure 1. Relationship between the measured electrical activity and the cardiac cycle phases.<br />

I<br />

EA<br />

EB<br />

EC<br />

F1<br />

differential<br />

amplification<br />

AD1<br />

F5<br />

K<br />

IC1.D<br />

IC1.A + IC1.B<br />

�<br />

F4<br />

1 /2<br />

summing<br />

IC1.C<br />

II<br />

Figure 2. These single-pole leads are used to implement the electrocardiograph.<br />

F2<br />

differential<br />

amplification<br />

AD2<br />

IC2.D<br />

F6<br />

auto-zero<br />

control<br />

IC2.A<br />

Figure 3. Block diagram of the analogue part of the circuit.<br />

III<br />

050280 - 12<br />

F3<br />

lowpass<br />

filter<br />

A3<br />

IC2.C<br />

reference:<br />

2V5<br />

050280- 13<br />

ECG<br />

memory and reread to show the ECG<br />

in real time on the screen, in ‘scrolling’<br />

mode.<br />

The analogue part<br />

Presenting an adequate signal to the<br />

input of the digital analogue converter<br />

presents a challenge to the electronics<br />

engineer because there are a number<br />

of technical problems to analyse and<br />

resolve.<br />

Differential amplifier<br />

The peak-to-peak amplitude of the signals<br />

sampled between the electrodes<br />

is very low at just 2 mV max.<br />

Also, both the human body and the<br />

connecting wires to the electrodes are<br />

strongly influenced by high noise levels<br />

radiated by mains wires and other<br />

power carrying leads inside buildings.<br />

Capacitive coupling, although very<br />

low, produces a relatively high voltage<br />

(often over 1 V) to appear with respect<br />

to ground, despite the relatively low<br />

frequency of just 50 Hz or 60 Hz.<br />

To begin with, it would seem difficult<br />

to isolate the useful signal because its<br />

amplitude is 1,000 times lower than all<br />

the interference around! Moreover, the<br />

mains frequency is included in the useful<br />

spectrum; so the filtering solution<br />

does not work here.<br />

However, considering the wavelength<br />

of the mains voltage (6,000 km!), it is<br />

safe to assume that that each point on<br />

the skin receives the same induced<br />

potential thanks to its conductivity.<br />

Therefore, a c<strong>om</strong>mon-mode voltage is<br />

developed with respect to the electrodes.<br />

In this case, the solution bec<strong>om</strong>es<br />

obvious: we’re going to use a differential<br />

instrumentation amplifier with an<br />

adequate c<strong>om</strong>mon-mode rejection ratio<br />

(CMRR):<br />

Sp<br />

S<br />

CMRR �<br />

SECG<br />

N<br />

dB dB<br />

� �<br />

� � �<br />

� �<br />

� �<br />

� �<br />

��<br />

��<br />

In this formula:<br />

S P = amplitude of the interference: 1 V<br />

S ECG = ECG amplitude: 1 mV<br />

S/N= signal to noise ratio: 40 dB<br />

Or : CMRR � 100 dB.<br />

In addition, the amplifier must be<br />

characterised by a very high input<br />

impedance (> 10 M�) and a low offset<br />

voltage.<br />

Numerous integrated instrumentation<br />

amplifiers exist (the AD624, for exam-<br />

GBECG • 49<br />

elektor electronics - 10/2006


Elektor blockbusters<br />

100n<br />

TP<br />

GND<br />

050280 - 11<br />

C14<br />

BAV99<br />

1<br />

BAV99<br />

AUDIOIN<br />

GND<br />

12<br />

3<br />

2<br />

RESET<br />

14<br />

IC1.D<br />

13<br />

11<br />

D3<br />

R21<br />

47k<br />

R22<br />

100k<br />

9<br />

19 46<br />

2n2<br />

RESET<br />

TP<br />

GND<br />

ADD<br />

TP<br />

2V5<br />

RESET<br />

RST<br />

C12<br />

TP<br />

41<br />

100n<br />

PA6/D6<br />

PA7/D7<br />

15<br />

14<br />

4<br />

5<br />

6<br />

7<br />

8<br />

9<br />

10<br />

D1<br />

D0<br />

1n<br />

R20<br />

390k<br />

100n<br />

D5<br />

100k<br />

D1<br />

D0<br />

8<br />

+5V<br />

1M<br />

C16<br />

D3<br />

D2<br />

R25<br />

1k<br />

R24<br />

3<br />

BC848B<br />

C13<br />

PSD813F2A<br />

-90M<br />

PA4/D4<br />

PA5/D5<br />

17<br />

16<br />

D3<br />

D2<br />

C10<br />

IC1.C<br />

D5<br />

D4<br />

R19<br />

1<br />

IC2.A<br />

5<br />

+5V<br />

2<br />

IC2.B<br />

D6<br />

7<br />

1�<br />

4<br />

IC2<br />

11<br />

JTAG<br />

IC4<br />

PA2/D2<br />

PA3/D3<br />

20<br />

18<br />

D5<br />

D4<br />

10<br />

9<br />

6<br />

100n<br />

TCK<br />

GND<br />

PC0/TMS<br />

PA0/D0<br />

PA1/D1<br />

D7<br />

BAV99<br />

1%<br />

1M<br />

T1<br />

C8<br />

C11<br />

100k<br />

100k<br />

210k<br />

12<br />

2M2<br />

R23<br />

BAV99<br />

12<br />

13<br />

22<br />

21<br />

PC1/TCK<br />

D7<br />

D6<br />

+5V<br />

TMS<br />

PC2/VSTBY<br />

A14<br />

A15<br />

470p<br />

10<br />

11<br />

PC3/TSTAT<br />

ADIO14<br />

ADIO15<br />

38<br />

39<br />

A14<br />

A15<br />

R17<br />

R18<br />

R10<br />

R16<br />

14<br />

13<br />

D2<br />

+5V<br />

+5V<br />

TDO<br />

TDI<br />

PC4/TERR<br />

K3<br />

A12<br />

A13<br />

C9<br />

6<br />

7<br />

PC5/TDI<br />

ADIO12<br />

ADIO13<br />

36<br />

37<br />

A12<br />

A13<br />

GND<br />

GND<br />

16<br />

15<br />

+5V<br />

P1<br />

22k<br />

D4<br />

A10<br />

A11<br />

K1<br />

ELECTRODES<br />

EA<br />

EB<br />

EC<br />

10/2006 - elektor electronics 35<br />

47k<br />

4<br />

5<br />

PC7/DBE<br />

PC6/TDO<br />

ADIO10<br />

ADIO11<br />

34<br />

35<br />

A10<br />

A11<br />

5<br />

1%<br />

+5V<br />

18<br />

17<br />

A9<br />

R15<br />

IC1.B<br />

47k<br />

220k<br />

1%<br />

ADIO9<br />

+5V<br />

ADIO8<br />

19<br />

A8<br />

7<br />

1%<br />

32<br />

33<br />

A8<br />

A9<br />

R13<br />

R14<br />

6<br />

20<br />

A7<br />

100k<br />

100n<br />

100n<br />

100n<br />

524.25kHz<br />

131.0625kHz<br />

45<br />

44<br />

PB6<br />

PB7<br />

ADIO6<br />

ADIO7<br />

29<br />

30<br />

A6<br />

A7<br />

21<br />

A6<br />

Gameboy Connector<br />

12k<br />

22<br />

A5<br />

1%<br />

R11<br />

C7<br />

C5<br />

C4<br />

4<br />

23<br />

A4<br />

R12<br />

48<br />

47<br />

PB4<br />

PB5<br />

ADIO4<br />

ADIO5<br />

27<br />

28<br />

A4<br />

A5<br />

24<br />

A3<br />

10k<br />

2<br />

6<br />

VIN+ D0<br />

IC3<br />

3<br />

7<br />

VIN- CLK<br />

ADC08831IM<br />

5 1<br />

VREF CS<br />

TP<br />

50<br />

49<br />

PB2<br />

PB3<br />

ADIO2<br />

ADIO3<br />

25<br />

26<br />

A2<br />

A3<br />

25<br />

A2<br />

33n<br />

5%<br />

26<br />

A1<br />

1%<br />

R9<br />

PB0<br />

PB1<br />

PB0<br />

PB1<br />

ADIO0<br />

ADIO1<br />

23<br />

24<br />

27<br />

A0<br />

C2<br />

TP<br />

52<br />

51<br />

A0<br />

A1<br />

100k<br />

10<br />

IC2.C<br />

4k7<br />

13<br />

1%<br />

PD2/CSI<br />

CNTL2/PSEN<br />

RAMCS<br />

8<br />

R7<br />

2<br />

1%<br />

IC2.D<br />

220k<br />

1%<br />

42<br />

22k<br />

PD1/CLKIN<br />

CNTL1/RD<br />

R8<br />

14<br />

9<br />

2<br />

1<br />

29<br />

28<br />

IC1.A<br />

47k<br />

R5<br />

R6<br />

8<br />

PD0/ALE/AS<br />

CNTL0/WR<br />

1<br />

12<br />

3<br />

40<br />

43<br />

WR<br />

RD<br />

30<br />

47k<br />

R4<br />

3<br />

100n<br />

ECLK<br />

WR<br />

RD<br />

2M2<br />

1%<br />

R2<br />

C1<br />

5%<br />

560p<br />

22k<br />

8<br />

31<br />

32<br />

31<br />

+5V<br />

C6<br />

262.125kHz<br />

Figure 4. The bulk of the work is handled by the ISP flash memory, IC4 and IC3, an A/D converter, Serial I/O. The Gameboy processor handles the processing.<br />

DO<br />

CLK CAN<br />

CS<br />

CLK<br />

R1<br />

R3<br />

100n<br />

K2<br />

C15<br />

+5V<br />

+5V<br />

+5V<br />

100n 10�<br />

BAV99<br />

4 C3<br />

IC1<br />

11 100n<br />

IC1 = TLV2254AID<br />

IC2 = TLV2254AID<br />

TP TP TP<br />

CS CLK DO<br />

TP<br />

ECG<br />

TP<br />

+5V<br />

C17<br />

C19<br />

D1<br />

1,0485MHz<br />

+5V<br />

+5V<br />

+5V<br />

GBECG • 50


HANDS-ON ELECTROCARDIOGRAPH<br />

Elektor blockbusters<br />

36<br />

255<br />

N ECG<br />

0<br />

1V75 4V25<br />

VECG 050280 - 14<br />

Figure 5. The transfer function is determined by divider bridge R3/R12.<br />

RAM_CS<br />

RD<br />

WR<br />

ECLK<br />

+5V<br />

1<br />

top view<br />

A0 - A15 D0 - D7<br />

GAME BOY<br />

32<br />

RESET<br />

AUDIO IN<br />

GND<br />

050280 - 15<br />

Figure 6. Connector pinout for the Gameboy cartridge (view fr<strong>om</strong> above).<br />

ple). These are very high-performance<br />

devices and need no adjustment. But<br />

quality c<strong>om</strong>es at a cost.<br />

We decided to make the differential<br />

amplifier using more econ<strong>om</strong>ical operational<br />

amplifiers. This also allows significant<br />

savings in cost and power consumption.<br />

Moreover, these opamps<br />

function perfectly with a single 5 V<br />

power supply (this is not the case for<br />

the AD624). The disadvantage is the<br />

presence of an adjustable potenti<strong>om</strong>eter<br />

to optimise the CMRR.<br />

Block diagram and wiring diagram<br />

Figures 3 and 4 respectively give the<br />

block diagrams for the analogue part<br />

and the c<strong>om</strong>plete circuit diagram. The<br />

references associated with each function<br />

(ICx.y) identify the operational<br />

amplifiers for the structural diagrams<br />

that show the functionality.<br />

The instrumentation amplifier is made<br />

up of functions F1 and F2. Function F3<br />

is a 2nd order low pass filter with a<br />

roll-off of 170 Hz and a damping factor<br />

m of 0.73 (i.e., near Butterworth). It will<br />

faithfully attenuate all unwanted c<strong>om</strong>ponents<br />

outside of the useful frequency<br />

spectrum and replaces the<br />

anti-aliasing filter for the DAC<br />

(digital/analogue converter) that follows<br />

it.<br />

The gain distribution in the circuit is as<br />

follows: A1 = 21�, A2 = 4.7� and A3 =<br />

10�. The total amplification is 987, in<br />

c<strong>om</strong>pliance with our objectives. The<br />

other functions (F4, F5 and F6) assist<br />

the instrumentation amplifier in order<br />

to ensure its proper operation. In fact,<br />

the operational amplifiers have a supply<br />

voltage of between 0 V and 5 V.<br />

The ideal no-signal voltage on each of<br />

the terminals is 2.5 V. Setting this level<br />

is not a problem in most cases: a<br />

divider bridge with two resistors is<br />

appropriate (R23 and R24). It is harder<br />

for the two input amps because we<br />

must take care not to c<strong>om</strong>pr<strong>om</strong>ise their<br />

input impedances.<br />

The problem is solved using the third,<br />

c<strong>om</strong>mon, ECG electrode (see Figure 3)<br />

and the functions of F4 and F5.<br />

It can be shown that the voltage S<br />

equals half the sum of the voltage (EA<br />

+ EB). It is c<strong>om</strong>pared to the ‘2.5-V’ setting,<br />

and the error voltage is amplified<br />

to produce an ECG signal that can be<br />

processed. As there is no current flow<br />

in the electrodes, voltages EA and EB<br />

are equal to EC (give or take a few<br />

mV). In this way, the human skin actually<br />

helps to keep EA and EB equal to<br />

the target level of 2.5 V. That is the goal<br />

GBECG • 51<br />

elektor electronics - 10/2006


Elektor blockbusters<br />

we are seeking: the no-signal voltage<br />

of the opamps is as desired without<br />

reducing the input impedance.<br />

Moreover, a natural, but very annoying<br />

phen<strong>om</strong>enon occurs when we place<br />

the electrodes: an electr<strong>om</strong>otive force<br />

(EMF) contact potential is produced<br />

between the skin and the electrode<br />

metal. This ‘micro-cell’ is very weak (a<br />

few mV) but it is not eliminated by the<br />

instrumentation amplifier. On the contrary,<br />

it is amplified!<br />

Functions F4 and F5 partially reduce<br />

this effect, but the offset in S1 and S2<br />

may still reach 1 V in differential mode.<br />

This value is unacceptable and is<br />

therefore c<strong>om</strong>pensated by function F6.<br />

F6 c<strong>om</strong>pares the average S3 signal<br />

value with the 2.5 V setting. The error<br />

voltage is integrated (time constant<br />

R16C8 = 2.2 s) in order to produce the<br />

ZERO signal. This continuous voltage<br />

offsets the S3 signal until its average<br />

value is stabilised at 2.5 V.<br />

To increase the amplitude of this c<strong>om</strong>pensation,<br />

two diode pumps C9-D4-<br />

C11 and C12-D5-C13 produce –3 V and<br />

+8 V supply voltages for IC2.<br />

The digital part<br />

The digital-analogue conversion is performed<br />

by IC3. It integrates a real differential<br />

amplifier, but requires an<br />

external reference voltage. This is simply<br />

derived fr<strong>om</strong> the 5 V power supply<br />

using a potential divider (R23/R24)<br />

buffered by T1. The precision and the<br />

stability are average at best, but still<br />

sufficient for this application. The<br />

divider R3/R12 determines the transfer<br />

function (see Figure 4).<br />

The asymmetry with respect to 2.5 V is<br />

justified by the asymmetrical shape of<br />

an ECG in relation to its average value.<br />

The DAC provides its NECG results in<br />

‘serial’ format. It is controlled by the CS<br />

and CLK signals — the first triggers<br />

the conversion (its frequency is 477.84<br />

Hz) and the second clocks the data<br />

output (on DO).<br />

The PSD813F2<br />

A Gameboy cartridge plugs into a connector<br />

which acc<strong>om</strong>modates the console’s<br />

microprocessor buses:<br />

• Addresses: A15 to A0<br />

• Data: D7 to D0<br />

• Check: ECLK, WR, RD and RESET<br />

The first Gameboy games consoles on<br />

the market fr<strong>om</strong> about 1989 had a<br />

microprocessor similar to the old Z80,<br />

which explains the size of the buses.<br />

The most recent consoles are equipped<br />

with much more powerful CPUs, but<br />

for c<strong>om</strong>mercial reasons the old cartridges<br />

(and even older than those) still<br />

operate on the current Gameboys. That<br />

is also the case for our electrocardiograph!<br />

The PSD813F2 is an integrated circuit<br />

that’s perfectly adapted for making a<br />

cartridge for a Gameboy console.<br />

Unfortunately, we do not have enough<br />

space in this article to describe its<br />

c<strong>om</strong>plete functionality (see [3]). In<br />

summary, the PSD813F2 includes:<br />

• a configurable microprocessor interface<br />

that can be adapted to all 8-bit<br />

microprocessors on the market,<br />

The<br />

author<br />

including the vintage Z80;<br />

• 128 kBytes of Flash memory (only<br />

32 kBytes are utilised by the electrocardiograph<br />

object code, which<br />

leaves space for extensions or other<br />

things...);<br />

• a c<strong>om</strong>plex programmable logic<br />

device (PLD) that takes care of the<br />

address decoding;<br />

• a 16-cell sequential C<strong>om</strong>plex Programmable<br />

Logic Device (CPLD). It<br />

is responsible for the serial-to-parallel<br />

conversion of the DAC frames to<br />

relieve the CPU and produce the<br />

squarewave signals required for the<br />

diode pumps;<br />

• 27 I/O configurable ports;<br />

• 2 kBbytes RAM (not used).<br />

Moreover, a JTAG interface is used to<br />

c<strong>om</strong>pletely configure the ‘on circuit’<br />

c<strong>om</strong>ponent via connector K3, which<br />

should not fail to interest all of you<br />

electronics hobbyists. The PSDSoftExpress<br />

development environment can<br />

be downloaded for free on the manufacturer’s<br />

website.<br />

As you can see fr<strong>om</strong> the diagram (Figure<br />

4), the connection between the<br />

console bus and the PSD813 is simple:<br />

the signals of the same name are connected.<br />

The only particularity that could be<br />

The author, Marcel<br />

Cremmel, has been a qualified<br />

teacher in Electrical<br />

Engineering (with<br />

Electronics option) since<br />

1979 (French National<br />

Education state dipl<strong>om</strong>a).<br />

After having initially taught<br />

at the Mohammedia de<br />

Rabat Engineering School<br />

in Morocco as a participant<br />

in the Cooperation program,<br />

he was assigned to<br />

the Louis Couffignal High<br />

School in Strasbourg in<br />

1982, in the BTS EL section<br />

(Certificate, Senior<br />

Electronics Technician).<br />

Although his profession forces him to deal with all d<strong>om</strong>ains of electronics<br />

Marcel has a preference for telec<strong>om</strong>munications, video, microcontrollers<br />

(MSP430 and PIC) and programmable logic circuits (Altera). In addition to electronics,<br />

his other passion is motorcycles in all forms: touring, races, etc.<br />

His personal website is at http://electronique.marcel.free.fr/<br />

interpreted as an error: the data bus<br />

connections are crossed! That enabled<br />

us to simplify the board layout and the<br />

binary file of the GBECG control program<br />

was changed to suit.<br />

The software<br />

The software is entirely written in<br />

assembly language. The author used<br />

the ‘Gameboy Assembler Studio’ environment<br />

by Nicklas Larsson (freeware<br />

available on the web [4]).<br />

The assembly language was necessary<br />

because the specifications require a<br />

‘scrolling’ display in real time. That<br />

GBECG • 52<br />

10/2006 - elektor electronics 37


HANDS-ON ELECTROCARDIOGRAPH<br />

occupies the CPU of the first consoles<br />

at a level of 80% due to the ‘old’ manner<br />

in which the screen memory is<br />

organised (separate screen memory<br />

and character memory).<br />

The software can be thought of as handling<br />

four tasks:<br />

1. Initialisations<br />

This task is executed at switch-on or<br />

after a reset,<br />

• Initial assignment of variables.<br />

• Configuration of I/O ports.<br />

• Initialisation of the LCD. The screen<br />

has 160 x 144 pixels, but for technical<br />

reasons, the useful part is reduced<br />

38<br />

EPS<br />

050280 - 1<br />

COMPONENT<br />

LIST<br />

(all SMD, except K1)<br />

Resistors<br />

(all 0805 case)<br />

R1 = 2M�2 1%<br />

R2,R15,R21 = 47k�<br />

R3 = 22k�<br />

R4,R13 = 47k� 1%<br />

R5,R14 = 220k� 1%<br />

R6 = 22 k� 1%<br />

R7 = 4k�7<br />

R8,R11 = 100k� 1%<br />

R9 = 10k�<br />

R10 = 210k� 1%<br />

R12 = 12k�<br />

R16 = 2M�2<br />

R17,R18,R22,R25 = 100k�<br />

R19 = 1k�<br />

R20 = 390k�<br />

R23,R24 = 1M�<br />

P1 = 22 k� preset (Bourns 3314G)<br />

Elektor blockbusters<br />

EPS<br />

050280 - 1<br />

Figure 7. Copper track layout and c<strong>om</strong>ponent mounting plan of the double-sided board designed for the GBECG.<br />

Soldering of IC3 is particularly difficult, so we’re supplying the board with all c<strong>om</strong>ponents pre-soldered.<br />

to 160 x 96 pixels. The lower part<br />

(160 x 48) is utilised for fixed messages.<br />

• Internal timer: this is programmed<br />

to produce interrupts at a rate of<br />

477.84 Hz (sampling frequency).<br />

• Sound generator: this is pre-programmed<br />

to produce a cardiac<br />

‘beep’ when required.<br />

2. Main loop<br />

The main loop simply detects the<br />

action of certain keyboard keys and<br />

modifies the operating mode:<br />

• Start: acquisition mode<br />

• Select : stop mode<br />

Capacitors<br />

(all 0805 case except C8 and C19)<br />

C1 = 560pF 5%<br />

C2 = 33nF 5%<br />

C3-C7,C11,C13-C17= 100nF<br />

C8 = 1μF (1208)<br />

C9 = 470pF<br />

C10 = 1nF<br />

C12 = 2nF2<br />

C18 = not fitted<br />

C19 = 10μF (1208P)<br />

Semiconductors<br />

IC1,IC2 = TLV2254AID<br />

IC3 = ADC08831IM (Analog Devices)<br />

or TLC0831CD (Texas Instruments)<br />

IC4 = PSD813F2A-90M<br />

(STMicroelectronics), programmed,<br />

order code 050280-41<br />

D1-D5 = BAV99<br />

T1 = BC848B<br />

Miscellaneous<br />

K1 = Molex connector, 5-way, Dubox<br />

EPS<br />

050280 - 1<br />

• �: zo<strong>om</strong> _1 in stop mode<br />

• �: zo<strong>om</strong> _2 in stop mode<br />

3. Timer interrupt program<br />

This task is executed a rate of 477.84<br />

times per second. It carries out the following<br />

functions:<br />

• Debounced readout of the keyboard<br />

state.<br />

In run mode:<br />

• triggers a new conversion;<br />

• acquisition of the last sample (result<br />

of the previous conversion);<br />

• all 4 samples (or 119.46 times per<br />

second);<br />

• calculation of the ‘average sample’<br />

89882-405, Digikey # 90148-1102-<br />

ND<br />

Programming connections:<br />

K3 = Molex connector, 6-way, 1.25mm<br />

lead pitch, type 53261-0671 (Digikey<br />

# WM7624CT-ND)<br />

Optionally: FlashLink programming<br />

connection:<br />

Molex 6-way connector, 1.25mm lead<br />

pitch, female (Digikey # WM1724-<br />

ND)<br />

6 wires with pin terminations for Molex<br />

connector (Digikey # WM1775-ND)<br />

Electrodes:<br />

Cutaneous probes or clips are available<br />

fr<strong>om</strong> medical supplies outlets<br />

5-way SIL pinheader<br />

4 mm plate (3x)<br />

6 m screened audio cable<br />

PCB, with all c<strong>om</strong>ponents ready fitted,<br />

tested, order code 050280-91<br />

GBECG • 53<br />

elektor electronics - 10/2006


Elektor blockbusters<br />

= average of the last 4 samples;<br />

• detection of the R-wave in order to<br />

trigger the cardiac ‘beep’;<br />

• loading the 8 kBytes cyclic buffer<br />

with the average sample.<br />

4. Interrupt program, V-Blank<br />

This interrupt is produced at the end<br />

of each LCD vertical sweep. The rate<br />

is: f v = 59.73 Hz; or every two averaged<br />

samples.<br />

The program also takes care of refreshing<br />

the display.<br />

• Run mode: the LCD shows the last<br />

samples (or 320 averaged sampled<br />

values on the cyclic buffer), which<br />

traces the last 2.68 s on the screen<br />

width.<br />

• Stop mode: depending on the zo<strong>om</strong><br />

value: �1 or �2, the LCD shows the<br />

last 320 or 160 samples, which<br />

traces the last 2.68 s or 1.34 s on the<br />

screen width.<br />

In stop mode, the program also detects<br />

action on the � or � keys allowing<br />

the use to move around within the<br />

screen memory.<br />

During the display of the ECG trace,<br />

the program draws the vertical and<br />

horizontal scales. The latter moves<br />

with the trace in order to improve readability.<br />

The source code file of the<br />

The electrodes<br />

A good ECG can only be obtained with good, well-placed<br />

and properly-wired electrodes.<br />

To limit the effect of undesirable signals, it is rec<strong>om</strong>mended<br />

that you use shielded cables. Electronically, ‘audio’ cables<br />

are perfectly suited to this function. In practice however they<br />

are much too fragile, We therefore propose making small<br />

adaptors on which the cable clasps eliminate practically all<br />

risk of breaking (see Figure F),<br />

You will see that the shielding is only connected at the cartridge<br />

side and that it is isolated on the electrode side in<br />

order to avoid any contact with the skin.<br />

A<br />

GBECG control program is available as<br />

a free download fr<strong>om</strong> the Elektor Electronics<br />

website, the file number is<br />

050580-11.zip, see under month of<br />

publication. Improvements and additions<br />

are welc<strong>om</strong>e.<br />

Building it<br />

The use of SMD c<strong>om</strong>ponents is<br />

unavoidable. In fact, the underside of<br />

the board must be perfectly smooth<br />

(therefore, no through wires or pins) so<br />

that it can slip into the cartridge case.<br />

To save you the trouble of struggling<br />

with (and losing) those tiny SMD parts,<br />

we are supplying the GBECG printed<br />

circuit board with all c<strong>om</strong>ponents<br />

already soldered in place, and the<br />

PSD813 programmed, all at an affordable<br />

price (see the inset). The order<br />

code is 050280-91.<br />

All that is left to do is find an old<br />

Gameboy cartridge case and clear out<br />

the two half-shells a little. Photo A<br />

illustrates the cutouts to make.<br />

The wider cutout in the upper halfshell<br />

is due to potenti<strong>om</strong>eter P1 which<br />

otherwise prevents closing the case.<br />

Adjustment<br />

The only adjustment consists in optimising<br />

the CMRR of the differential<br />

‘4 mm’ type plugs make it possible to use c<strong>om</strong>mercially available<br />

electrodes (Figure G).<br />

The clip is very practical and adapted for children. But the<br />

price of these two electrodes may discourage many readers<br />

(more than £6 each and you will need three off!)<br />

H<strong>om</strong>ebrew electrodes can be made fr<strong>om</strong> coins as illustrated<br />

in the opposite photo. The author used French Florin (FF)<br />

coins which are made fr<strong>om</strong> nickel. Solder a 4-mm socket and<br />

the electrode (Figure H is ready to use.<br />

Three rubber bracelets keep them in place on the wrists and<br />

the lower calf. These bracelets can be made by cutting ribbon<br />

for straps to the proper length and gluing them to the<br />

self-adhesive ‘Velcro’ tape at both ends. We can also use<br />

sections fr<strong>om</strong> air chambers fr<strong>om</strong> a motorcycle or a scooter.<br />

E F G H<br />

GBECG • 54<br />

10/2006 - elektor electronics 39


HANDS-ON ELECTROCARDIOGRAPH<br />

B<br />

C<br />

amplifier. For that, you need a function<br />

generator and an oscilloscope or an AC<br />

voltmeter. Begin by making the measurement<br />

circuit in Figure B (the capacitor<br />

has a capacitance of 10 μF). Top to<br />

bott<strong>om</strong>: EA, EB, EC, GND.<br />

Plug the device into the fixed connec-<br />

D<br />

Elektor blockbusters<br />

40<br />

tor K1, observing the orientation, and<br />

only then connect the generator. In this<br />

way, we inject a c<strong>om</strong>mon-mode test<br />

signal. Adjust the generator: 50 Hz<br />

sine wave with amplitude 1 V. Insert<br />

the cartridge in the Gameboy with the<br />

upper half-shell removed in order to<br />

access the ECG test point. Turn on the<br />

power and measure the AC c<strong>om</strong>ponent<br />

of the ECG signal. Then adjust P1 to<br />

minimise the peak-to-peak amplitude.<br />

It should be less than 25 mV in order to<br />

obtain an S/N ratio in excess of 40 dB.<br />

Final check<br />

This step is not strictly required. Its<br />

purpose is to ensure proper operation<br />

of the electrocardiograph by injecting<br />

a signal and by verifying the result on<br />

the screen.<br />

Most benchtop signal generators are<br />

incapable of reliably producing the<br />

very low levels required for this check.<br />

Therefore, we must greatly attenuate<br />

the GBF signal. That is what the<br />

device shown in Figure C does.<br />

The signal is effectively divided by<br />

100. In this way, we inject a 1 Hz sinusoidal<br />

signal and a 140-mV DC amplitude<br />

signal. These should result in an<br />

image on the LCD screen similar to<br />

that in Figure D.<br />

The sinewave is aligned with the first<br />

dotted line and has a DC amplitude of 7<br />

divisions, or 7�200 μV = 1.4 mV.<br />

The fixed connector K1 on the cartridge<br />

is not very sturdy. To limit the<br />

risk of deformation or of it being torn<br />

out, restrain the three shielded cables<br />

on the cartridge cover with two cable<br />

ties, as illustrated in photo E.<br />

The cable ties we used on our prototype<br />

of the GBECG do not touch the<br />

internal c<strong>om</strong>ponents. They require four<br />

2 mm holes to be drilled which do not<br />

significantly weaken the shell.<br />

(050280-1)<br />

We would like to extend our thanks to Professors<br />

Schalij and Maan, Leiden University Hospital, the<br />

Netherlands, for their valuable assistance.<br />

Bibliography<br />

[1] GBDSO — Gameboy Digital<br />

Storage Oscilloscope,<br />

Elektor Electronics<br />

October and November 2000.<br />

Internet<br />

references<br />

and links<br />

[1] http://chem.ch.huji.ac.il/<br />

~eugeniik/history/einthoven.html<br />

GBECG • 55<br />

elektor electronics - 10/2006


Operating<br />

instructions<br />

Placement of the electrodes<br />

It is absolutely necessary to clean the skin and the electrodes<br />

well with a cotton and ether or alcohol, In this way, the electr<strong>om</strong>otive<br />

force EMF on the contacts, which may saturate the<br />

amplifiers, are limited considerably.<br />

The standard lead is ‘DI’:<br />

• EA electrode: right wrist<br />

• EB electrode: left wrist<br />

• EC electrode: left foot (lower calf)<br />

Utilisation of ‘contact’ products based on potassium chloride<br />

considerably improve the quality of the measurements.<br />

The best ECGs are obtained when the patient is calm and<br />

lying down so that the only muscle in action is the heart.<br />

Operation<br />

• Live start-up: welc<strong>om</strong>e screen is displayed.<br />

• Go to the acquisition screen: press Start, A, B or Select.<br />

[2] http://www.e-cardiologie.c<strong>om</strong>/<br />

examens/ex-electro2.shtml<br />

[3] http://www.st.c<strong>om</strong>/stonline/products/<br />

[4] http://www.devrs.c<strong>om</strong>/gb/<br />

Additional documents and<br />

program sources on<br />

http://www.elektor.c<strong>om</strong><br />

http://www.infoscience.fr/histoire/<br />

biograph/biograph.php3?Ref=128<br />

PSD813 datasheet<br />

http://www.st.c<strong>om</strong>/stonline/<br />

products/literature/ds/7833.pdf<br />

ADC08831IM datasheet<br />

http://www.ortodoxism.ro/<br />

datasheets2/6/<br />

0rcoik1yuwhx1dj2ogg8wid7sfcy.pdf<br />

Attention<br />

The GBECG electrocardiograph described<br />

in this article has not received medical<br />

approval and is therefore not intended<br />

• ECG acquisition: if<br />

the electrodes are for professional use. The instrument<br />

properly placed must always be powered by batteries in<br />

and the patient is<br />

order to respect protection category III.<br />

calm, the reading<br />

should be stabilised<br />

in a few seconds and look like the one illustrated in<br />

Figure I.<br />

Do not use this ECG as a reference; the shapes may vary<br />

appreciably fr<strong>om</strong> one individual to another.<br />

If no trace appears after thirty seconds, clean the skin below<br />

the electrodes using a pad and ether or alcohol.<br />

Irregularity of the trace may be reduced by using a ‘contact’<br />

product.<br />

• Stop mode: pressing the Select button stops the acquisition.<br />

You can then analyse the memory which contains<br />

68.6 s worth of ECG.<br />

�: zo<strong>om</strong> x 1<br />

�: zo<strong>om</strong> x 2 (see below)<br />

�: Move ahead<br />

�: Move backwards<br />

I Scales (zo<strong>om</strong> 1x)<br />

A beep sound will be heard each time an R wave is detected.<br />

The volume can be adjusted with the volume button on<br />

the console.<br />

Attention: The screen memory is erased when power is<br />

removed.<br />

Elektor blockbusters GBECG • 56<br />

10/2006 - elektor electronics 41


PROJECTS GAMEPAD CONVERSION<br />

Tilt Gamepad<br />

Upgrade your Gamepad<br />

with acceleration sensors<br />

Xin Wang and Marko Westphal<br />

Users of the Nintendo Wii and Play station 3 ‘tilt’ controllers have raved about the more intuitive<br />

control these devices offer. Up until now there hasn’t been a c<strong>om</strong>parable gamepad available for the<br />

dedicated PC gamer but why should they be left out of all the fun? Join in by adding this two-axis<br />

tilt sensor to a standard gamepad, it is particularly good for vehicle and flight simulation as well as<br />

adventure games. Give those thumbs a rest and start waving your arms around!<br />

A tilt gamepad senses the angle<br />

at which the handheld controller is<br />

moved and converts that measurement<br />

into equivalent digital outputs<br />

which would be produced by pressing<br />

the up/down left/right buttons<br />

on the gamepad. It is not necessary<br />

to press any of the buttons<br />

to control direction; the<br />

on-screen object is controlled<br />

simply by tilting the gamepad.<br />

In this design the movement<br />

is detected by an acceleration<br />

sensor manufactured by Analog<br />

Devices and sensor values<br />

are processed by an Atmel<br />

ATmega8 microcontroller. The<br />

2<br />

entire circuit fits onto a small<br />

PCB which converts a standard<br />

gamepad into a tilt gamepad.<br />

The sensor<br />

The novel c<strong>om</strong>ponent in this<br />

design is the analogue acceleration<br />

sensor type ADXL322<br />

fr<strong>om</strong> Analog Devices. This 2axis<br />

device produces two independent<br />

output voltages<br />

proportional to the inclination<br />

of the sensor in the x and<br />

y planes. The supply voltage<br />

can be in the range of 2.4 V to<br />

Elektor blockbusters<br />

Vs 14<br />

6 V. The two analogue output signals<br />

have a sensitivity of 420 mV/90�. The<br />

sensor range is ±2 g and it is supplied<br />

in an SMD CP-16 package which cannot<br />

be soldered into place using a con-<br />

+5V<br />

C2<br />

GND<br />

100n<br />

ST<br />

Yout 10<br />

Xout 12<br />

IC2<br />

ADXL322<br />

GND<br />

GND<br />

GND<br />

GND<br />

3<br />

5<br />

6<br />

7<br />

GND<br />

Vs 15<br />

GND<br />

8<br />

20<br />

XTAL1<br />

9<br />

ventional soldering iron so the PCB is<br />

supplied with this c<strong>om</strong>ponent already<br />

mounted.<br />

Signal processing<br />

The output signals fr<strong>om</strong> the acceleration<br />

sensor are analogue<br />

so it is necessary to process<br />

them using a microcontroller<br />

with an on-board A/D converter.<br />

The Atmel ATmega8 is an<br />

8-bit microcontroller with six<br />

multiplexed analogue inputs<br />

which can be selected internally<br />

as an input to the 10-bit<br />

resolution A/D converter. Up to<br />

23 of its pins can be configured<br />

as general-purpose digital I/O<br />

pins.<br />

The two analogue signals representing<br />

the X/Y tilt fr<strong>om</strong><br />

the acceleration sensor are<br />

connected directly to the A/<br />

D converter inputs of the microcontroller.<br />

The signals are<br />

digitised, filtered and then<br />

converted into digital output<br />

signals which emulate the up/<br />

down, left/right function of the<br />

direction buttons on the original<br />

gamepad.<br />

The X and Y values are sam-<br />

42 elektor electronics - 9/2007<br />

7<br />

1<br />

PC6 (RESET)<br />

PD0 (RXD) 2<br />

PD1 (TXD) 3<br />

PD2 (INT0) 4<br />

PD3 (INT1) 5<br />

PD4 (XCK/T0) 6<br />

VCC<br />

PD5 (T1) 11<br />

PD6 (AIN0) 12<br />

PD7 (AIN1) 13<br />

PB0 (ICP) 14<br />

PB1 (OC1A) 15<br />

PB2 (SS/OC1B) 16<br />

PB3 (MOSI/OC2) 17<br />

PB4 (MISO) 18<br />

PB5 (SCK) 19<br />

AVCC<br />

IC1<br />

28<br />

PC5 (ADC5/SCL)<br />

27<br />

PC4 (ADC4/SDA)<br />

26<br />

PC3 (ADC3)<br />

25<br />

PC2 (ADC2)<br />

24<br />

PC1 (ADC1)<br />

23<br />

PC0 (ADC0)<br />

ATmega8-16PI<br />

21<br />

AREF<br />

C3<br />

100n<br />

C4<br />

22p<br />

+5V<br />

X1<br />

4MHz<br />

GND<br />

XTAL2 GND<br />

10<br />

C5<br />

22p<br />

22<br />

C1<br />

GND<br />

100n<br />

+5V<br />

GND<br />

K1<br />

070233 - 11<br />

Figure 1. Besides the acceleration sensor and microcontroller there are very<br />

few other c<strong>om</strong>ponents required.<br />

0<br />

Tilt Gamepad • 57


pled alternately, the 2.56 V reference<br />

for the A/D converter is produced onchip<br />

and decoupled by capacitor C3 on<br />

Pin 21 (AREF). The I/O pins have good<br />

sink/source current capability which<br />

together with selectable internal pullup<br />

resistors means that there is no requirement<br />

for additional drivers for the<br />

output signals.<br />

Simple circuitry<br />

It can be seen in the circuit diagram in<br />

Figure 1 that apart fr<strong>om</strong> the microcontroller<br />

and sensor there are very few<br />

additional c<strong>om</strong>ponents required. The<br />

layout of the double-sided PCB shown<br />

in Figure 2 is therefore quite simple.<br />

Figure 3 gives the flow chart describing<br />

the main software functions. The<br />

microcontroller ADC port is sampled<br />

every 10 ms, raw values of acceleration<br />

are converted into tilt values which are<br />

then filtered. The signals output by the<br />

gamepad depend on the direction of<br />

tilt and tilt angle.<br />

The 6-way pin header (K1) is fitted<br />

to the PCB for all the connections to<br />

the gamepad. The circuit is powered<br />

directly fr<strong>om</strong> the USB interface (+5 V<br />

and ground).<br />

Elektor blockbusters<br />

9/2007 - elektor electronics<br />

Putting it together<br />

The finished PCB can be fitted into the<br />

casing of a standard PC gamepad if<br />

sufficient space is available. In principle<br />

any gamepad can be used providing<br />

the direction buttons are ‘active<br />

Low’ i.e., when you press a button the<br />

output signal goes fr<strong>om</strong> a high to a low.<br />

The author used a ‘Firestorm Digital 3’<br />

while in the Elektor Electronics lab a<br />

‘MAXFIRE G-08X4’ fr<strong>om</strong> Genius happened<br />

to be available for conversion<br />

(it must have been used earlier by one<br />

of our team for s<strong>om</strong>e serious research<br />

work…).<br />

In addition to the gamepad and finished<br />

PCB a short length of 6-core cable<br />

is required and possibly a small<br />

plastic enclosure for the finished PCB<br />

if it will not fit in the gamepad case.<br />

Do not insert the programmed microcontroller<br />

in its socket yet. The microcontroller<br />

can be ordered ready-programmed<br />

fr<strong>om</strong> the Elektor Electronics<br />

website. Alternatively, the hex file<br />

(object code) can be downloaded fr<strong>om</strong><br />

the same website at no cost if you prefer<br />

to program the device yourself. The<br />

original source files are protected by<br />

licences and copyrights and are not<br />

freely available.<br />

Assembly begins by first dismantling<br />

the gamepad; undo the screws at the<br />

K1<br />

C5<br />

C1<br />

IC1<br />

C3<br />

C2<br />

IC2<br />

Figure 2. The double-sided PCB is supplied with the<br />

SMD-outline tilt sensor already mounted<br />

(near the bott<strong>om</strong> of the board).<br />

X1<br />

C4<br />

C<strong>om</strong>ponents<br />

list<br />

Capacitors<br />

C1,C2,C3 = 100nF<br />

C4,C5 = 22pF<br />

Semiconductors<br />

IC1 = Atmega8-16PI, programmed,<br />

Elektor SHOP # 070233-41*<br />

IC2 = ADXL322<br />

Miscellaneous<br />

K1 = 6-way SIL pinheader<br />

X1 = 4MHz quartz crystal<br />

PCB with ADXL322 sensor fitted, Elektor<br />

SHOP # 070233-91<br />

* hex code file: free download #<br />

070233-11.zip fr<strong>om</strong> www.elektor.c<strong>om</strong><br />

Tilt Gamepad • 58<br />

43


PROJECTS GAMEPAD CONVERSION<br />

back of the unit which hold the two<br />

parts of the shell together. Once inside<br />

it is necessary to find out which parts<br />

of the circuit are connected to +5 V<br />

and which are connected to ground.<br />

The simplest method is to trace wires<br />

fr<strong>om</strong> the USB connection, pin 1 (usually<br />

black) is ground and pin 4 (usually<br />

red) is +5 V. Similarly check out the<br />

wiring to the gamepad buttons; a close<br />

inspection reveals that each of the direction<br />

buttons have two contacts,<br />

one of which is usually connected to<br />

ground (as in the Thrustmaster gamepad<br />

but s<strong>om</strong>e use +5 V for this connection)<br />

the other contact goes to the microcontroller.<br />

This contact will be used<br />

later to solder wires to the new PCB<br />

connector K1 pins 2 to 5. If it is necessary<br />

to mount the PCB externally in a<br />

small plastic enclosure (as is the case<br />

with the “Firestorm Digital 3”), a hole<br />

will need to be drilled in the rear of<br />

the gamepad housing (5 mm diameter<br />

Elektor blockbusters<br />

System Init<br />

Reset Timer<br />

Start Timer<br />

Select<br />

ADC Channel<br />

Start ADC<br />

ADC<br />

Ready<br />

?<br />

yes<br />

Filter and<br />

Calculate<br />

Output<br />

Timer = 10 ms<br />

?<br />

yes<br />

no<br />

no<br />

070233 - 12<br />

Figure 3. The software flow diagram. The sensor<br />

is sampled every 10 ms.<br />

Gamepad/sensor board connections<br />

Wiring between the gamepad and K1 on the sensor PCB using 6-core colour<br />

coded cable.<br />

K1 GND Up Left Down Right +5 V<br />

Cable Black Orange Yellow Green Blue Red<br />

Gamepad Earth/Ground Up Left Down Right +5 V<br />

should be sufficient) to run the multicore<br />

cable through.<br />

Wiring between the tilt PCB connector<br />

K1 and gamepad can now begin by soldering<br />

the wires +5 V, ground and the<br />

four direction button contacts.<br />

The pin assignment for K1 is detailed<br />

on the circuit diagram in Figure 1.<br />

Pins 1 and 6 carry the power supply<br />

while 2 to 5 are the digital output<br />

signals wired to the direction button<br />

contacts (active low, the idle state is<br />

high).<br />

The Table below shows the wiring<br />

connections in detail and the cable colours.<br />

Printed arrows on the PCB next<br />

to connector K1 indicate the direction<br />

in which the PCB should be moved to<br />

produce an output at that pin.<br />

Once the wiring is c<strong>om</strong>plete the preprogrammed<br />

microcontroller can now<br />

be fitted in its socket on the PCB. The<br />

PCB can be secured in the gamepad<br />

using hot glue (roughen the internal<br />

surface of the housing for good adhesion)<br />

or if an external enclosure is used<br />

it can be attached externally to the rear<br />

of the gamepad again with hot glue.<br />

Screw the two halves of the gamepad<br />

together.<br />

The tilt gamepad is now finished! The<br />

PC has no way of knowing that the<br />

gamepad internals have changed so<br />

it’s not necessary to load any new software<br />

drivers. Revisit all your favourite<br />

games but this time experience a<br />

whole new level of intuitive control.<br />

44 elektor electronics - 9/2007<br />

(070233-I)<br />

Tilt Gamepad • 59


Jürgen Wickenhäuser<br />

Remote measurement and<br />

control is possible via<br />

the Internet.<br />

Unfortunately,<br />

webservers<br />

usually sit in<br />

large,<br />

humming<br />

grey<br />

cabinets.<br />

That’s not<br />

the ideal<br />

solution for<br />

keeping an<br />

eye on your<br />

refrigerator,<br />

coffee machine<br />

or central heating<br />

system. The Elektor<br />

Electronics Micro<br />

Webserver provides an<br />

alternative.<br />

Elektor blockbusters<br />

Web<br />

�� Micro<br />

Micro Webserver • 60


server<br />

Elektor blockbusters<br />

The Elektor Electronics Micro Webserver<br />

is a full-fledged node for Internet<br />

traffic, despite its quite modest<br />

dimensions and c<strong>om</strong>plexity. It consists<br />

of a microcontroller board<br />

with a network interface.<br />

Thanks to its c<strong>om</strong>pact construction<br />

and the versatility<br />

of the microcontroller<br />

board, the Micro Webserver<br />

is an ideal<br />

choice for measurement<br />

and control<br />

applications. Naturally,<br />

the fact<br />

that it can be<br />

read and operated<br />

fr<strong>om</strong> anywhere<br />

in the<br />

world via the<br />

Internet is a<br />

major bonus.<br />

Despite these<br />

unprecedented<br />

features, the<br />

necessary<br />

hardware is<br />

actually minimal.<br />

In principle,<br />

two ICs are all<br />

you need for a<br />

c<strong>om</strong>plete webserver.<br />

To avoid any<br />

misunderstanding,<br />

this is not s<strong>om</strong>e kind of<br />

demo or prototype, but a<br />

fully functional device<br />

suitable for industrial applications,<br />

and its potential uses<br />

extend far beyond what we can<br />

describe here.<br />

Basic design<br />

The underlying technology is rather<br />

c<strong>om</strong>plex. Consequently, in this article<br />

we must <strong>om</strong>it a large number of inter-<br />

esting details that are not essential for<br />

a ‘simple’ webserver. However, readers<br />

who want to know all the details<br />

will find what they’re looking for in the<br />

acc<strong>om</strong>panying software. The interface<br />

is without question unusually userfriendly.<br />

For example, the program<br />

variables can be used directly in websites.<br />

It’s hardly possible to make<br />

things any easier.<br />

The Micro Webserver is programmed<br />

using the C language. But don’t let<br />

yourself be discouraged if you aren’t<br />

familiar with C, since this project is certainly<br />

suitable for beginners as well.<br />

Connection<br />

control and regulation<br />

via the Internet<br />

Internet and Ethernet are closely<br />

related. Ethernet is a standard that<br />

defines the connection. The transmission<br />

speed is normally 10 or 100<br />

Mbit/s, and it is aut<strong>om</strong>atically configured<br />

when the connection is established.<br />

We use the 10-Mbit/s variant in<br />

this project, since it is more than adequate<br />

for an embedded webserver.<br />

We assume you already have an Ethernet<br />

network. The webserver can thus<br />

be connected directly to a hub or<br />

switch, so the Internet can be<br />

accessed via Ethernet. There are also<br />

agreed conventions regarding how<br />

Internet c<strong>om</strong>munication takes place<br />

(via Ethernet, for instance). All of this<br />

is specified in the TCP/IP protocol.<br />

Here we assume that the network to<br />

which the Micro Webserver is connected<br />

can also ‘speak’ this protocol.<br />

Fr<strong>om</strong> a technical perspective, there’s<br />

no reason why the Micro Webserver<br />

cannot also be directly connected to a<br />

PC using a crossover cable. However,<br />

describing this in more detail is<br />

beyond the scope of this article, since in<br />

s<strong>om</strong>e cases the PC settings must be<br />

changed for such a connection.<br />

Hardware<br />

After all these introductory diversions,<br />

it’s time to get down to brass tacks.<br />

The hardware platform is the by now<br />

well-proven MSC1210 board (originally<br />

described in the 2003 Summer Circuits<br />

issue). If you do not already own a<br />

copy of this outstanding board, you<br />

can obtain one fr<strong>om</strong> Elektor Electronics<br />

together with the extension<br />

described here (Figure 1).<br />

The extension is thus new. In principle,<br />

it’s simply a ‘cust<strong>om</strong>’ network card for<br />

the MSC board. This card is built<br />

around the CS8900A Ethernet driver IC<br />

(refer to the schematic diagram in Figure<br />

2). As usual with network cards,<br />

there are two LEDs (D1 and D2) to indicate<br />

the status of the network connection.<br />

D1 flashes for 6 ms each time a<br />

data packet is received or transmitted,<br />

or if there is a collision between two<br />

packets. The second LED indicates<br />

whether the CS8900A is receiving<br />

proper link pulses. These pulses are<br />

used in Ethernet networks to synchronise<br />

transmitters and receivers, and D2<br />

will be on if this synchronisation is<br />

successful.<br />

The network IC also has a c<strong>om</strong>plete<br />

10Base-T transceiver. 10Base-T is the<br />

standard for 10-Mbit/s Ethernet over<br />

twisted-pair cable. The circuit requires<br />

only a few external c<strong>om</strong>ponents. The<br />

transformer just ahead of the RJ54 connector<br />

provides electrical isolation fr<strong>om</strong><br />

the rest of the world.<br />

The printed circuit board (Figure 3)<br />

has a ‘prototyping’ area to provide<br />

extra space for user applications, in<br />

addition to the space on the MSC1210<br />

board. Several spare signal lines are<br />

available in the leftmost row of the prototyping<br />

area (see Figure 2). Two extra<br />

LEDs and a pushbutton switch are<br />

also placed on the LAN board. The<br />

Micro Webserver • 61<br />

13


Figure 1. The MSC1210 board with the network extension: a powerful pair!<br />

Figure 2. The network card is built around the CS8900 network IC.<br />

14<br />

VCC1<br />

DGND2<br />

P37<br />

P36<br />

INT1<br />

INT0<br />

P17<br />

P16<br />

P15<br />

P11<br />

P10<br />

DGND3<br />

VIN_D2<br />

VCC2<br />

P00<br />

P01<br />

P02<br />

P03<br />

P04<br />

P05<br />

PO6<br />

P07<br />

ALE<br />

DGND4<br />

P27<br />

P26<br />

P25<br />

P24<br />

P23<br />

P22<br />

P21<br />

P20<br />

VCC3<br />

DGND5<br />

K1<br />

Peripheral Bus<br />

Elektor blockbusters<br />

RD<br />

WR<br />

INT1<br />

INT0<br />

NET_RES<br />

P16<br />

P15<br />

P11<br />

P10<br />

AD0<br />

AD1<br />

AD2<br />

AD3<br />

AD4<br />

AD5<br />

AD6<br />

AD7<br />

ADR15<br />

ADR03<br />

ADR02<br />

ADR01<br />

ADR00<br />

USER<br />

LED1<br />

D4 D3<br />

1k<br />

INT1<br />

INT0<br />

P16<br />

P15<br />

R9<br />

USER PAD<br />

P11<br />

P10<br />

VCC4<br />

DGND6<br />

INT1<br />

INT0<br />

PORT1_6<br />

PORT1_5<br />

PORT1_1<br />

PORT1_0<br />

USER<br />

LED0<br />

1k<br />

R8<br />

1k<br />

R10<br />

LAN RESET<br />

(ACTIVE HIGH)<br />

DATA-<br />

BUS<br />

AD0<br />

AD1<br />

AD2<br />

AD3<br />

AD4<br />

AD5<br />

AD6<br />

AD7<br />

CS<br />

ADR00<br />

ADR01<br />

ADR02<br />

ADR03<br />

ADDRESS<br />

BUS<br />

S1<br />

USER<br />

C10 C4 C5 C6<br />

100n 100n 100n 100n<br />

X1<br />

DVDD1<br />

61<br />

IOR<br />

62<br />

IOW<br />

33<br />

IOCS16<br />

75<br />

RESET<br />

97<br />

XTAL1<br />

98<br />

XTAL1<br />

20MHz<br />

65<br />

SD0<br />

66<br />

SD1<br />

67<br />

SD2<br />

68<br />

SD3<br />

71<br />

SD4<br />

72<br />

SD5<br />

73<br />

SD6<br />

74<br />

SD7<br />

27<br />

SD8<br />

26<br />

SD9<br />

25<br />

SD10<br />

24<br />

SD11<br />

21<br />

SD12<br />

20<br />

SD13<br />

19<br />

SD14<br />

18<br />

SD15<br />

63<br />

AEN<br />

37<br />

SA0<br />

38<br />

SA1<br />

39<br />

SA2<br />

40<br />

SA3<br />

41<br />

SA4<br />

42<br />

SA5<br />

43<br />

SA6<br />

44<br />

SA7<br />

45<br />

SA8<br />

46<br />

SA9<br />

47<br />

SA10<br />

48<br />

SA11<br />

50<br />

SA12<br />

51<br />

SA13<br />

52<br />

SA14<br />

53<br />

SA15<br />

54<br />

SA16<br />

58<br />

SA17<br />

59<br />

SA18<br />

60<br />

SA19<br />

9<br />

DVDD2<br />

DVDD3<br />

DVDD4<br />

DVSS1<br />

DVSS1A<br />

DVSS2<br />

DVSS3<br />

DVSS3A<br />

U+<br />

22 56 69 90 85 95<br />

IC1<br />

CS8900<br />

DVSS4<br />

AVDD1<br />

AVDD2<br />

AVDD3<br />

DMA<br />

LED<br />

AUI<br />

10BT<br />

INT<br />

E2PROM<br />

C7 C8 C9<br />

100n 100n 100n<br />

16<br />

DMACK0<br />

14<br />

DMACK1<br />

12<br />

DMACK2<br />

15<br />

DMARQ0<br />

13<br />

DMARQ1<br />

11<br />

DMARQ2<br />

TEST<br />

36<br />

SBHE<br />

64<br />

IOCHRDY<br />

49<br />

REFRESH<br />

29<br />

MEMR<br />

28<br />

MEMW<br />

34<br />

MEMCS16<br />

77<br />

SLEEP<br />

CHIPSEL<br />

AVSS0<br />

AVSS1<br />

AVSS2<br />

AVSS3<br />

AVSS4<br />

LAN<br />

LINK<br />

100<br />

99<br />

HC1<br />

78<br />

IRQ0<br />

32<br />

IRQ1<br />

31<br />

IRQ2<br />

30<br />

IRQ3<br />

35<br />

RES<br />

EESK<br />

4<br />

EECS<br />

3<br />

EEDI<br />

6<br />

EEDO<br />

5<br />

ELCS<br />

2<br />

CSOUT<br />

17<br />

8 10 23 55 57 70 1 89 86 94 96<br />

76<br />

DO+<br />

83<br />

DO–<br />

84<br />

DI+<br />

79<br />

D1–<br />

80<br />

CI+<br />

81<br />

CI–<br />

82<br />

TXD+<br />

87<br />

TXD-<br />

88<br />

RXD+<br />

91<br />

RXD+<br />

92<br />

93<br />

7<br />

R2<br />

24�9<br />

R3<br />

24�9<br />

4k99<br />

LAN<br />

ACTIVITY<br />

R5 R6<br />

4k7<br />

C3<br />

68p<br />

100�<br />

R1<br />

C1<br />

100n<br />

R4<br />

D1<br />

1k<br />

8<br />

7<br />

6<br />

3<br />

2<br />

1<br />

R7<br />

1k D2<br />

T1<br />

HALO<br />

TG43-1406N<br />

C2<br />

100n<br />

LINK<br />

PULSES<br />

9<br />

10<br />

11<br />

14<br />

15<br />

16<br />

044026 - 11<br />

1<br />

2<br />

3<br />

4<br />

5<br />

6<br />

7<br />

8<br />

K3<br />

TX+<br />

TX-<br />

RX+<br />

RX-<br />

RJ45 LAN<br />

Micro Webserver • 62<br />

elektor electronics - 7-8/2004


Elektor blockbusters<br />

Applications The Micro Webserver is ideal for the following applications:<br />

Aut<strong>om</strong>atic online weather station:<br />

Access control and registration in c<strong>om</strong>bination<br />

– temperature<br />

with:<br />

– precipitation<br />

– badge readers<br />

– lightning detection<br />

– light barriers<br />

– wind strength and direction<br />

– door openers<br />

– relative humidity<br />

– RFID tags<br />

– rain barrel level<br />

– light intensity<br />

Web interface for h<strong>om</strong>e appliances and fixtures:<br />

– refrigerator or freezer temperature monitoring<br />

– remote control for coffee machine, central heating or lighting<br />

– controlling sun awnings or roller shutters<br />

– outside lighting<br />

– intruder detection<br />

– greenhouse climate control<br />

placement of the connector for the link<br />

to the ‘motherboard’ allows the extension<br />

card to be located next to the<br />

motherboard or underneath it. In the<br />

latter case, the two boards can sandwiched<br />

together using standoff<br />

bushes.<br />

Although the design of this project is<br />

especially simple, there is one thing<br />

that must be mentioned. The current<br />

consumption of the LAN IC is<br />

100–120 mA, which is relatively high<br />

c<strong>om</strong>pared with the current drawn by<br />

the microcontroller. The 5-V supply<br />

voltage is taken fr<strong>om</strong> the MSC1210<br />

board. To prevent the voltage regulator<br />

on that board fr<strong>om</strong> bec<strong>om</strong>ing overheated,<br />

we strongly rec<strong>om</strong>mend that<br />

the entire circuit be powered fr<strong>om</strong> a<br />

voltage of 7.5 to 9 V, but definitely no<br />

higher than this.<br />

Online<br />

There’s actually not much more to say<br />

about the hardware. Configuring the<br />

board is fully described in the text box.<br />

Once you’ve gotten the server ‘up’, you<br />

can start testing.<br />

This is where things start to get interesting.<br />

To start off, simply connect the<br />

board to the network. LED D2 will be<br />

continuously on if an Ethernet signal is<br />

detected. This is a pr<strong>om</strong>ising start, but<br />

the real test c<strong>om</strong>es next. It consists of<br />

trying to ‘ping’ the server using the<br />

Windows C<strong>om</strong>mand Pr<strong>om</strong>pt window<br />

(DOS c<strong>om</strong>mand window). On a PC connected<br />

to the network, type the following<br />

c<strong>om</strong>mand in the c<strong>om</strong>mand line:<br />

ping 192.168.1.156<br />

(of course, the IP address here must be<br />

the address previously assigned to the<br />

Webserver). LED D1 should start blinking<br />

as an indication that data is being<br />

transferred via the Ethernet, and a<br />

reply fr<strong>om</strong> the server should appear in<br />

the c<strong>om</strong>mand win-<br />

dow.<br />

Ping is a simple protocol<br />

that allows a<br />

few bytes to be<br />

transmitted and<br />

waits for an ‘echo’.<br />

It’s a really handy<br />

way to quickly check<br />

a network connection.<br />

If the ping test is OK,<br />

you can then access<br />

the webserver using<br />

a web browser. In the<br />

browser window,<br />

enter the following<br />

address:<br />

http://192.168.1.156<br />

(use the address that has previously<br />

been assigned to the webserver). And<br />

that’s it: what you see next c<strong>om</strong>es fr<strong>om</strong><br />

that little board (see Figure 5).<br />

In the terminal download window, you<br />

can also see which page was<br />

requested.<br />

How it works<br />

What actually happened when you<br />

requested the web page? First, you<br />

made a connection to an IP address.<br />

Actually, it’s a bit more c<strong>om</strong>plicated<br />

than that: you made a connection to a<br />

‘socket’ at a particular address. A<br />

socket is a sort of ‘connector’, in this<br />

case one that only fits web links. Each<br />

socket is also assigned a specific port<br />

Monitoring and controlling machinery:<br />

– rpm<br />

– voltage and current<br />

– temperature<br />

– liquid level<br />

– flow rate / discharge rate<br />

– pressure<br />

– valve control<br />

– relay control or PWM (servo) control<br />

Terminal for a central database (in c<strong>om</strong>bination<br />

with an LC display and barcode reader)<br />

Internet references<br />

[1] www.wickenhaeuser.c<strong>om</strong><br />

μC/51 c<strong>om</strong>piler with source code<br />

[2] www.mikrocontroller.info/kabelsalat/<br />

Wiring diagram for a null-modem cable<br />

[3] www.ti.c<strong>om</strong>/msc MSC121x h<strong>om</strong>e page<br />

[4] groups.yahoo.c<strong>om</strong>/group/TI-MSC<br />

MSC121x users group. Definitely worth the effort.<br />

Free, but registration is required.<br />

[5] groups.yahoo.c<strong>om</strong>/group/TI-MSC/files<br />

You can find tools for the MSC121x here, such as<br />

the original TI downloader.<br />

[6] www.cirrus.c<strong>om</strong>/en/pubs/proDatasheet/<br />

cs8900a-4.pdf<br />

Data sheet for the CS8900A network driver<br />

number. Port 80 is frequently used for<br />

webservers. You can see this in the<br />

program line SOCKET_SETUP(i,<br />

SOCKET_TCP,80,FLAG_PASSIVE_OPEN).<br />

The final parameter<br />

here indicates that<br />

the socket is passive,<br />

which means it waits<br />

for requests fr<strong>om</strong><br />

clients. The sockets<br />

are created in a FOR<br />

loop. The number of<br />

sockets created<br />

determines how<br />

many clients can be<br />

connected to the<br />

server at the same<br />

time. As each socket<br />

costs memory, the<br />

total number is limited.<br />

The CS8900A IC<br />

used here also has a<br />

buffer (approximately<br />

4 kB) for inc<strong>om</strong>ing Ethernet packets.<br />

That’s not especially large if several<br />

users want to connect to the server at<br />

the same time, or if large items such as<br />

images are requested. Actually, this<br />

doesn’t matter all that much, since<br />

TCP allows the occasional packet to<br />

remain unanswered. If necessary, the<br />

client resends unanswered packets on<br />

its own initiative.<br />

After the sockets have been created,<br />

ELM_FLEX.C initiates the A/D converter<br />

of the microcontroller a few lines<br />

later in the code. For more information<br />

about the A/D converter, see the c<strong>om</strong>panion<br />

Micro Webserver article ‘Measurement<br />

and Control via the Internet’<br />

in this issue.<br />

After this, the program enters a endless<br />

FOR loop. In this loop, poll_web-<br />

Micro Webserver • 63<br />

7-8/2004 - elektor electronics 15


Elektor blockbusters<br />

16<br />

COMPONENTS<br />

LIST<br />

Resistors (SMD):<br />

R1 = 100�, shape 0603<br />

R2,R3 = 24�9, shape 0603<br />

R4 = 4k�99, 1 %, shape 0603<br />

R5,R10 = 4k�7, shape 0603<br />

R6-R9 = 1k�, shape 0603<br />

Capacitors (SMD):<br />

C1,C2,C4-C10 = 100nF, shape 0603,<br />

ceramic<br />

C3 = 68pF, shape 0603, ceramic, NP0<br />

Semiconductors (SMD):<br />

IC1 = CS8900A-CQ (5 V), shape<br />

TQFP100<br />

D1-D4 = chip-LED, shape 0805<br />

Rec<strong>om</strong>mended colours: D1 green; D2<br />

yellow; D3,D4 red<br />

Miscellaneous:<br />

T1 = Ethernet transformer type TG43<br />

(Halo) or ST7010T (Valor), see also ref.<br />

[6]<br />

X1 = 20MHz quartz crystal, HC49_SMD<br />

case<br />

K1 = 34-way DIL pinheader<br />

K2 = 8-way pinheader<br />

K3 = RJ45 connector (screened)<br />

S1 = mini pushbutton<br />

For software, bare PCBs and fully<br />

assembled boards,<br />

see the ‘What you need’ box.<br />

Figure 3. The network card for the<br />

MSC1210 board.<br />

Figure 4. The web page sent by<br />

the micro webserver.<br />

Micro Webserver • 64<br />

elektor electronics - 7-8/2004


Elektor blockbusters<br />

Configuring the board<br />

The Micro Webserver only works in a TCP/IP network. Just like all other c<strong>om</strong>puters in a<br />

TCP/IP network, the microcontroller is assigned a unique address, which is its IP<br />

address. Before you start programming the microcontroller, you must manually specify<br />

this address, since the Micro Webserver does not work with aut<strong>om</strong>atic address assignment.<br />

The default IP address is set to 192.168.1.156. It belongs to a range of addresses<br />

that are specifically reserved for networks that are not directly connected to the<br />

Internet. Subscribers to ADSL or cable Internet use addresses in this range for their local<br />

networks. Addresses having the form 10.0.0.x also belong to this category. It may also<br />

be possible to request a ‘real’ Internet address for your Micro Webserver, but that<br />

depends on your provider. In any case, you must personally check which address range<br />

is used in your network and which addresses are available to be assigned to the server.<br />

After choosing an address, you can turn your attention to the necessary programming<br />

software and C files. Part of the required source code (the part that implements the<br />

actual webserver) is included with the uC/51-c<strong>om</strong>piler (fr<strong>om</strong> version 1.20 onwards). A<br />

fully functional demo version of this c<strong>om</strong>piler can be downloaded free of charge fr<strong>om</strong><br />

the author’s h<strong>om</strong>e page (see reference [1]). The only difference between the demo version<br />

and the registered version is that code size for the Micro Webserver is limited to<br />

16 kB, but that’s more than enough for this application. Sample source code for initialising<br />

the webserver and implementing web pages (including several sample pages) is<br />

included in the package.<br />

After installing the uC c<strong>om</strong>piler, you must first use MakeWiz to create a workspace. In<br />

MakeWiz, open the file ...\SRC\MSC1210\ELM_FLEX\ELM_FLEX.MAK. Then change<br />

s<strong>om</strong>ething in the text (for example, add your own version number) so that the Save<br />

button will be enabled. Tick the ‘Write JFE-Workspace File’ check box and save the file<br />

(Figure 5).<br />

Now you can start the JFE editor (with thanks to Jens Altmann). In JFE, use ‘Open<br />

Workspace’ to open the file ...\SRC\MSC1210\ELM_FLEX\ELM_FLEX.WSP. All of the files<br />

belonging to the project will appear in the editor window. Now you have to specify the<br />

previously determined IP address in the ELM_FLEX.C file. You can do so in the line<br />

COMPOSE_IP(my_ip, 192.168.1.156).<br />

A workspace that has been created using MakeWiz causes three special buttons to<br />

appear in JFE: ‘MAKE’, ‘RE-MAKE’ and ‘DL.BAT’. The MAKE button causes the project to<br />

be c<strong>om</strong>piled, but it limits processing to the files that have actually been modified. The is<br />

the usual (and fastest) way to generate<br />

the hex file you need for programming<br />

the microcontroller. RE-MAKE must be<br />

used if s<strong>om</strong>ething not present in the<br />

workspace has been modified, such as a<br />

header file (.h). This c<strong>om</strong>mand causes<br />

everything to be rec<strong>om</strong>piled. Finally,<br />

DL.BAT causes the result to be sent to the<br />

MSC board. This actually amounts to simply<br />

executing a batch file, to which JFE<br />

passes a parameter. This parameter is<br />

always the name of the target file, which<br />

in this case is ELM_FLEX (with no extension).<br />

The specific c<strong>om</strong>mand line that initiates<br />

downloading to the MSC board is stated<br />

in the batch file (which is also located in<br />

the project folder). In this case, the c<strong>om</strong>mand<br />

line is download<br />

/F%1.hex /X11 /P1 /T<br />

/B9600.<br />

Parameter P1 indicates that COM1 of the<br />

PC must be used for programming. This<br />

can be changed if necessary.<br />

So far, so good: you’ve modified the IP<br />

address in ELM_FLEX.C, you’ve c<strong>om</strong>piled<br />

the project, and your finger is just itching<br />

to press DL.BAT — but hang on a<br />

Figure 6. With JFE, all files are easily accessible.<br />

m<strong>om</strong>ent! Before you can download anything to the board, you have to acquire a copy<br />

of the original Texas Instruments downloader (Downloader.exe). You can obtain this<br />

fr<strong>om</strong> the MSC group site at Yahoo (reference [4]), among other places, and it can be<br />

placed in the project folder. If you wish, you can also place it in a more general location,<br />

but in that case you naturally have to specify its new location in DL.BAT.<br />

Be sure to fit jumpers J1 and J2 on the MSC1210 board (J3 must remain open). If J1<br />

and J2 are not fitted, the board is protected against resetting and modifying the<br />

firmware via the PC. Finally, you need a null modem cable to connect the board to the<br />

PC, but that should be obvious. After you’ve found a place for the downloader, modified<br />

DL.BAT if necessary (to specify a different COM port or change the path to the<br />

downloader), connected the board to the proper PC port, and powered up the board,<br />

you’re finally ready to click on DL.BAT in JFE.<br />

If everything goes as it should, the MSC1210 board will return a short greeting message,<br />

and if ‘’ is not included in this message, the Ethernet board has<br />

been successfully recognised. In addition, one of the red LEDs on the MSC board should<br />

blink slowly.<br />

After downloading the code, don’t forget to remove jumpers J1 and J2.<br />

Figure 5. Use MakeWiz to store the project.<br />

Micro Webserver • 65<br />

7-8/2004 - elektor electronics 17


What you need<br />

The Micro Webserver consists of:<br />

– the MSC1210 ‘Precision Measurement Central’ board (see<br />

the July/August 2003 issue of Elektor Electronics)<br />

– the 10-Mbit Ethernet network card (RJ45, twisted pair)<br />

– the μC c<strong>om</strong>piler with the necessary software (Readers<br />

Services order code 044026-11)<br />

– the TI downloader program (Downloader.exe)<br />

The MSC1210 microcontroller card and the associated network<br />

extension are available fr<strong>om</strong> Elektor Electronics.<br />

The μC c<strong>om</strong>piler, including all the necessary source code,<br />

can be downloaded at no charge fr<strong>om</strong> www.wickenhaeuser.c<strong>om</strong><br />

or fr<strong>om</strong> the Elektor Electronics website.<br />

The programming software for the MSC board<br />

(Downloader.exe) is available fr<strong>om</strong> reference [4]. Updates<br />

will be available fr<strong>om</strong> the author’s website.<br />

server() is called periodically. As long<br />

as the result returned by this call is ‘0’,<br />

other (user-written) routines can also<br />

be executed in this loop. However, it’s<br />

important to ensure that user-written<br />

extensions do not take up too much<br />

processor time, since the webserver<br />

will otherwise bec<strong>om</strong>e inaccessible.<br />

The FlexGate TCP/IP stack works with<br />

events. The Micro Webserver only<br />

responds to EVENT_HTTP_REQUEST<br />

(page request) and<br />

EVENT_SOCKET_IDLETIMER (which<br />

has a period of approximately 0.5 s). If<br />

a client wants to access a page, the<br />

name is first requested using webpage_name().<br />

Following this, webpage_bind()<br />

is used to prepare the cor-<br />

Elektor blockbusters<br />

18<br />

Prices:<br />

responding page for the reply. Pages<br />

that are to be externally available must<br />

be declared in advance as array extern<br />

code uchar (see ELM_FLEX.C).<br />

This c<strong>om</strong>pletes the process if the<br />

requested page does not contain any<br />

dynamic data. However, dynamic data<br />

is exactly where the power of this<br />

handy little device lies. An example of<br />

dynamic data is measurement data<br />

c<strong>om</strong>ing fr<strong>om</strong> the microcontroller board.<br />

Such data can easily be incorporated<br />

into a web page. And in the other<br />

direction, you can remotely control the<br />

microcontroller outputs via a web page.<br />

To find out more about this, see the<br />

c<strong>om</strong>panion article ‘Measurement and<br />

Control via the Internet’ in this issue.<br />

– ready-made MSC1210 board: £69.00 (US$112.50)<br />

(assembled and tested; Readers Services order code<br />

030060-91)<br />

– ready-made network extension for the MSC1210 board:<br />

£41.95 (US$73.95) (assembled and tested; Readers<br />

Services order code 044026-91)<br />

– c<strong>om</strong>bined package: assembled MSC1210 board, network<br />

extension and all related Elektor Electronics articles on<br />

diskette: only £103.50 (US$184.95) (Readers Services<br />

order code 044026-92)<br />

For die-hard DIYers, bare PCBs are also available for the<br />

MSC1210 board (Readers Services order code. 030060-<br />

11) and the network extension (Readers Services order code<br />

044026-11). Note that most of the c<strong>om</strong>ponents are SMD<br />

types, and s<strong>om</strong>e of them are very difficult to obtain as oneoffs<br />

as well as solder by hand.<br />

Naturally, there’s a lot more we could<br />

say about the Internet portion of the<br />

software (the TCI/IP stack), but that<br />

goes beyond what we had in mind for<br />

this article. If you want explore this<br />

question in more detail, have a look at<br />

the manual for the stack. You’ll find it<br />

in the folder ...SRC\FLEXGATE\ that<br />

c<strong>om</strong>es with the microcontroller c<strong>om</strong>piler.<br />

In addition, Texas Instruments is<br />

presently preparing an application<br />

note for this project. The details will<br />

appear in due time on the TI website.<br />

(044026-1)<br />

About the introductory illustration:<br />

This jumble of lines may appear chaotic, but it<br />

actually represents a reasonably well-organised<br />

entity: the Internet. This ‘map’ was aut<strong>om</strong>atically<br />

generated by a program that literally c<strong>om</strong>bs the<br />

Internet. In its travels, the program also came close<br />

to the server where the Elektor Electronics website is<br />

hosted. See www.opte.org.<br />

Indicators:<br />

Cyan: Asia Pacific<br />

Pink: Europe, Middle East, Central Asia, Afrika<br />

Yellow: North America<br />

Blue: Latin America and Caribbean<br />

Red: RFC1918 IP Addresses<br />

Black: Unknown<br />

Micro Webserver • 66<br />

elektor electronics - 7-8/2004


Elektor blockbusters<br />

non reflected<br />

reflected<br />

Micro Webserver • 67


PROJECTS SDR<br />

Software Defi ned<br />

With USB Interface<br />

Burkhard Kainka<br />

SD (software-defi ned) radio receivers use a bare minimum of hardware, relying instead on their<br />

software capabilities. This SDR project demonstrates what’s achievable, in this case a multi-purpose<br />

receiver covering all bands fr<strong>om</strong> 150 kHz to 30 MHz. It’s been optimised for receiving DRM and AM<br />

broadcasts but is also suitable for listening in to the world of amateur transmissions.<br />

The designer’s aim for this project was<br />

to create a receiver displaying high linearity<br />

and phase accuracy. Development<br />

was focussed on the characteristics<br />

that were most important for a<br />

top-notch DRM receiver and the end<br />

result is a receiver with remarkable interference<br />

rejection characteristics. Reception<br />

of DRM stations using DREAM<br />

software produced signal-to-noise ratio<br />

(S/NR) values of well over 30 dB. The<br />

design principle of the receiver guarantees<br />

an extremely fl at fi lter-curve<br />

response. This works out rather well<br />

not only for DRM but also for the audio<br />

quality of AM broadcasts, which sound<br />

almost as good as VHF FM. It’s worth<br />

noting too that s<strong>om</strong>e transmitters that<br />

do not conform to the normal bandwidths<br />

laid down for medium wave (9<br />

kHz) and shortwave (10 kHz) as rigidly<br />

as perhaps they should. Whilst these<br />

stations produce no observable sound<br />

improvement for listeners using normal<br />

receivers (since their IF fi lters limit the<br />

bandwidth and in the process the frequency<br />

response too), this is not the<br />

case with SDR, where it’s no problem<br />

to select a wider bandwidth at will. It<br />

gets even better: in software receivers<br />

the fi ne-tuning capabilities of PC decoder<br />

programs give you the capability<br />

of determining the desired bandwidth<br />

Elektor blockbusters<br />

with notch fi lters to the aut<strong>om</strong>atic level<br />

control (ALC) settings along with<br />

selecting all the usual receive modes<br />

fr<strong>om</strong> AM by way of DRM and SSB to<br />

CW.<br />

Further refi nements can be added for<br />

SWL (shortwave listening) applications.<br />

If for instance you wish to increase<br />

the sensitivity on the upper amateur<br />

bands this is easily arranged by<br />

using two switchable antenna inputs<br />

and providing an optimised preselector<br />

circuit or preamplifi er in one of them.<br />

The receiver’s printed circuit board<br />

itself provides a pretty basic RF front<br />

end, which is nevertheless perfectly<br />

adequate for broadcast reception. A<br />

long wire antenna of adequate length<br />

will lift the strength of signals above<br />

atmospheric noise level to ensure you<br />

miss virtually nothing.<br />

Hardware requirements<br />

Most SDR programs [1] require the Windows<br />

XP platform to operate satisfactorily.<br />

The most important hardware necessary<br />

then is an SDR-capable sound<br />

card. We have developed a small circuit<br />

for testing sound cards, described<br />

elsewhere in this issue under the heading<br />

‘Developer Tips’. Without performing<br />

this test fi rst it’s utterly pointless<br />

starting to make the SDR receiver!<br />

All about USB<br />

The receiver is controlled over a USB<br />

connection and powered with +5 V<br />

in the same way (no additional mains<br />

power supply needed). For the USB interface<br />

in the receiver circuit (Figure 1)<br />

we selected the FT232R fr<strong>om</strong> our Scottish<br />

friends at FTDI. This modern USBto-serial<br />

converter works without the<br />

need for a quartz crystal, as it is equipped<br />

with an internal R-C oscillator of<br />

adequate stability. The module (IC4) is<br />

used here in its ‘bit-bang’ mode along<br />

the lines of a fast parallel port. Eight<br />

data lines are available for use and these<br />

can be driven in whichever way we<br />

choose. Two of the lines are used as an<br />

I²C Bus and control the frequency of the<br />

receiver. Three wires connect the input<br />

multiplexer to one of up to eight antenna<br />

inputs with and without fi ltering.<br />

Two additional inputs serve to control<br />

the IF amplifi cation of the receiver. In<br />

this way the receiver operates entirely<br />

under remote control. Kiss good-bye to<br />

all those knobs and controls of bygone<br />

radio days…<br />

Please pay particular attention to decoupling<br />

the power supply. One reason<br />

for this is because the USB chip<br />

��������������������������<br />

14 elektor electronics - 5/2007


Radio<br />

K1<br />

5<br />

6<br />

3V3<br />

K3<br />

C8<br />

10n<br />

GND<br />

GND<br />

1<br />

2<br />

3<br />

4<br />

L2<br />

USB-B connector<br />

ANT<br />

GND<br />

L6<br />

L3<br />

R12<br />

470<br />

2200uH<br />

GND<br />

TEST_CLK<br />

GND<br />

PC1<br />

C16<br />

100n<br />

L5<br />

R24<br />

1k<br />

47uH<br />

C29<br />

220p<br />

C31<br />

100p<br />

5/2007 - elektor electronics<br />

VCC 20<br />

CBUS0 23<br />

RI 6<br />

CBUS1 22<br />

RTS 3<br />

TXD 1<br />

DTR 2<br />

CTS 11<br />

4<br />

VCCIO<br />

RXD<br />

17<br />

3V3OUT<br />

5<br />

DSR 9<br />

DCD 10<br />

CBUS2 13<br />

CBUS3 14<br />

CBUS4 12<br />

R2<br />

330<br />

16<br />

R3<br />

USBDM<br />

330<br />

15<br />

USBDP<br />

19<br />

RESET<br />

27 IC4<br />

OSCI<br />

28<br />

OSCO<br />

FT232R<br />

26<br />

TEST<br />

C23<br />

100n<br />

C25<br />

100n<br />

GND<br />

C32<br />

470<br />

100n<br />

R15<br />

GND<br />

C36<br />

4.7<br />

GND<br />

100n<br />

C38<br />

100n<br />

R25<br />

AGND<br />

GND<br />

GND<br />

GND<br />

25<br />

7<br />

18<br />

21<br />

GND<br />

L1<br />

VCC<br />

10uH<br />

C1 C4<br />

C2 C3<br />

100n 4u7<br />

16V<br />

100n 4u7<br />

16V<br />

GND GND GND GND<br />

13<br />

A0<br />

14<br />

A1<br />

15<br />

A2<br />

12<br />

A3<br />

1<br />

A4<br />

5<br />

A5<br />

2<br />

A6<br />

4<br />

A7<br />

INH 6<br />

COM 3<br />

A 11<br />

B 10<br />

C 9<br />

IC6<br />

74HC4051<br />

7<br />

VCC_HF<br />

VEE<br />

VCC 16<br />

8<br />

GND<br />

GND<br />

C21<br />

100n<br />

GND<br />

C30<br />

100n<br />

R16<br />

1M<br />

C7<br />

100n<br />

GND<br />

C26<br />

100n<br />

GND<br />

100k<br />

R17<br />

VCC_HF<br />

GND<br />

470<br />

VDD 2<br />

VDD 19<br />

VDD 14<br />

VSSL 7<br />

VDDL<br />

10<br />

PDM/OE<br />

6<br />

AVSS<br />

11<br />

4<br />

AVDD<br />

13<br />

SCL<br />

17<br />

VCXO/WP<br />

SDA<br />

CLOCK1<br />

5<br />

8<br />

CLOCK2 9<br />

CLOCK3 12<br />

CLOCK4 15<br />

CLOCK5 18<br />

CLOCK6 3<br />

IC3<br />

CY27EE16ZE<br />

TEST_CLK<br />

L4<br />

10uH<br />

T1<br />

BF245<br />

R18<br />

1<br />

XIN<br />

X1<br />

3V3<br />

20<br />

XOUT<br />

16<br />

C12<br />

C13<br />

10p 10MHz 10p<br />

Figure 1. Diagram of the receiver circuit, which in fact c<strong>om</strong>prises just a tuning oscillator and a mixer.<br />

Elektor blockbusters<br />

R7<br />

100<br />

R19<br />

100<br />

VSS<br />

GND<br />

I2<br />

5<br />

13<br />

Q2<br />

6<br />

12<br />

4<br />

3<br />

1 2<br />

8<br />

9<br />

11 10<br />

Q3<br />

IC2C<br />

IC2D<br />

Q1<br />

VCC<br />

S 10<br />

12<br />

D<br />

9<br />

11 C 8<br />

13<br />

R<br />

VCC<br />

VCC<br />

2<br />

D<br />

IC1A<br />

5<br />

3 C 6<br />

C33<br />

100n<br />

C35<br />

2n2<br />

GND<br />

S 4<br />

1<br />

R<br />

VCC<br />

IC1B<br />

Q_SW_N<br />

Q_SW<br />

I_SW_N<br />

I_SW<br />

I3<br />

C19 R6<br />

10k<br />

R5<br />

100k<br />

IC2B 100n<br />

C22<br />

2n2<br />

6<br />

GND<br />

5<br />

IC5B<br />

IC2A<br />

I1<br />

C24<br />

2n2<br />

100n<br />

R9<br />

R14<br />

10k<br />

4k7 C27<br />

4k7 C39<br />

13<br />

R13<br />

100k<br />

IC5D<br />

12<br />

100n<br />

C37 R21<br />

2n2<br />

070039 - 11<br />

7<br />

14<br />

IC1 = 74AC74<br />

IC2 = 74HC4066<br />

IC5 = TL084CN<br />

IC7 = 74HC4066<br />

10k<br />

R10<br />

10<br />

9<br />

C28<br />

100n<br />

GND<br />

10k<br />

R22<br />

3<br />

2<br />

C40<br />

100n<br />

GND<br />

VCC<br />

IC5C<br />

R11<br />

27k<br />

IC5A<br />

R23<br />

27k<br />

C5<br />

100n<br />

R8<br />

100k<br />

R20<br />

100k<br />

C9<br />

4u7<br />

16V<br />

R4<br />

100<br />

8<br />

1<br />

VCC<br />

14<br />

IC1C<br />

7<br />

GND<br />

1 2<br />

IC7B<br />

4 3<br />

5<br />

13 IC7A<br />

8 9<br />

6 IC7C<br />

IC7D<br />

11 10<br />

12<br />

C6<br />

100n<br />

VCC<br />

100<br />

GND<br />

C20<br />

100n<br />

C34<br />

100n<br />

R1<br />

14<br />

IC2E<br />

7<br />

C10<br />

4<br />

IC5E<br />

14<br />

IC7E<br />

C11<br />

100n<br />

11 7<br />

100n<br />

C14<br />

470u<br />

16V<br />

C15<br />

4u7<br />

16V<br />

C17<br />

100n<br />

VCC_HF<br />

GND<br />

C18<br />

10n<br />

GND<br />

��������������������������<br />

K2<br />

15


PROJECTS SDR<br />

FT232R operates internally at the same<br />

frequency range that we are receiving<br />

through the antenna downlead and we<br />

don’t want any of this RF to leak across<br />

fr<strong>om</strong> one stage to another. That said,<br />

the decoupling within the chip itself<br />

is remarkably good and the residual<br />

RF on the control port lines is barely<br />

detectible. Consequently we can control<br />

the HC4051 RF input multiplexer direct<br />

fr<strong>om</strong> the control port lines, without<br />

traces of the processor clock appearing<br />

in the wanted signal region.<br />

Using its built-in 3.3 V voltage regulator,<br />

the FT232R provides the operating<br />

supply for the programmable clock<br />

generator CY27EE16ZE, avoiding<br />

the need for an additional voltage regulator.<br />

The rest of the circuit (Figure<br />

1) operates exclusively on 5 V. Several<br />

different smoothed and fi ltered voltages<br />

are produced, to guarantee good<br />

RF decoupling on one hand and to ensure<br />

suppression of audio frequency<br />

interference on the other. This is particularly<br />

crucial at the RF input stage of<br />

the receiver, fr<strong>om</strong> which the signal is<br />

fed via the mixer to the IF circuitry. For<br />

this reason a large electrolytic is provided<br />

at this point (VCC_HF) to ensure<br />

proper ‘peace and quiet’.<br />

Programmable VFO<br />

The SDR calls for an oscillator frequency<br />

running four times higher than that<br />

of the signal received, in order that the<br />

necessary phase fi ltering can be divided<br />

by four. If we are aiming to receive<br />

signals up to 30 MHz, then the oscillator<br />

needs to run right up to 120 MHz.<br />

DDS oscillators are very popular in HF<br />

projects today but at 120 MHz a DDS<br />

is dearer, more power-thirsty and far<br />

less controllable. Accordingly we shall<br />

look away fr<strong>om</strong> DDS oscillators and use<br />

a programmable clock oscillator with<br />

internal PLL here. Many Elektor Electronics<br />

readers will remember the CY-<br />

27EE16ZE back fr<strong>om</strong> the February 2005<br />

issue. This clock oscillator, developed<br />

specially for digital applications, performs<br />

equally well in RF circuitry. The<br />

frequency resolution does not quite<br />

match that of a DDS but the phase accuracy<br />

of the output signal achieves<br />

c<strong>om</strong>parable results. Restricting power<br />

consumption to a relatively modest<br />

amount is important with this project,<br />

since we must not draw too much current<br />

fr<strong>om</strong> the USB port.<br />

The chip is programmed over the I²C-<br />

Bus using lines SCL and SDA. The internal<br />

VCO operates in the frequency<br />

range 100 to 400 MHz, stabilised by<br />

Elektor blockbusters<br />

means of the 10-MHz crystal and a<br />

PLL. Its output signal then goes via counters<br />

to the desired outputs. Here we<br />

select the clock output Clock5, where<br />

a VFO signal between 600 kHz and 120<br />

MHz is available for further processing<br />

in the 74AC74 counter.<br />

The principle of the I-Q mixer has been<br />

described already in Elektor Electronics<br />

12/2006. A two-stage mixer is created<br />

here fr<strong>om</strong> a total of four analogue<br />

switches inside an HC4066 IC. This is<br />

controlled by two phase-shifted oscillator<br />

signals, which themselves are<br />

produced with a 74HC74 counter. Supposing<br />

the programmable clock oscillator<br />

produces 24 MHz, then the mixer<br />

would need a drive of 6 MHz. The receiver<br />

would in this case operate in a<br />

region of around ±24 kHz either side of<br />

the centre frequency of 6 MHz.<br />

Vital here is a phase shift of exactly 90<br />

degrees between the two oscillator signals.<br />

Any deviation will lead to reduced<br />

suppression of the image frequencies.<br />

A 74HC4053 or 74HC4052 integrated<br />

changeover switch device would<br />

not make a good choice for the analogue<br />

switch because the signal transit<br />

delays in the internal decoders would<br />

then cause different phase errors to<br />

appear in every frequency range. Our<br />

chosen solution using the rather more<br />

basic switches of an HC4066 retains all<br />

four phases in sync. Since the 74AC74<br />

counter is confi gured as a synchronous<br />

counter we would not expect to fi nd<br />

any phase errors here either. In fact the<br />

receiver displays image frequency suppression<br />

of around 40 dB up to 15 MHz<br />

or so, although this value decreases<br />

beyond about 20 MHz (which we can<br />

tolerate given that these frequencies<br />

are not so heavily occupied).<br />

Signal processing<br />

The receiver is provided with several<br />

inputs, selected by the 74HC4051 input<br />

multiplexer (IC6). The antenna input<br />

ANT is fed by way of fi lters to the fi rst<br />

three inputs. The fi rst switch setting<br />

(wideband) uses only one input choke<br />

(L6), which shunts any audio frequency<br />

signals at the input to ground. In the<br />

second position (Medium Wave) there<br />

is a low-pass fi lter with a boundary frequency<br />

of 1.6 MHz, using resistor R12<br />

to attenuate excessive resonance. This<br />

fi lter suppresses interference to medium<br />

wave reception fr<strong>om</strong> overtone mixing<br />

with stations in the short wave<br />

range. The third position makes use of<br />

a simple R-C high-pass fi lter to attenuate<br />

strong medium wave signals.<br />

An additional input (PC1) can be selected<br />

if you wish to connect external<br />

tuned input circuits or preamplifi ers. Finally<br />

three more inputs are provided for<br />

future developments. The input fi lters<br />

on the printed circuit board are good<br />

to be getting on with and are certainly<br />

adequate for most applications. You<br />

can of course introduce steep low-pass<br />

fi ltering ahead of the fi lters provided<br />

if you want to be certain of blocking<br />

out overtone mixing in every possible<br />

situation. Or you might choose to fi t<br />

different resonant circuits, selected by<br />

input switching.<br />

The particular input that is active at<br />

any given time is connected to the<br />

c<strong>om</strong>mon output COM (pin 3). Coupling<br />

capacitors are provided either side of<br />

the switch. A bias voltage of about 2.5<br />

V is provided to the switch fr<strong>om</strong> the<br />

source connection of the BF245 via a<br />

1-megohm resistor. This eliminates any<br />

distortion fr<strong>om</strong> large input signals that<br />

might arise when signals are limited<br />

by the protection diodes on the analogue<br />

inputs to the ICs.<br />

Input A7 delivers a calibration signal<br />

fr<strong>om</strong> Output 3 (Test-Clk) of the programmable<br />

crystal oscillator. The oscillator<br />

produces a square-wave signal of<br />

3.3 V peak-to-peak at 5 MHz. A signal<br />

voltage of around 5 mV at 5 MHz is<br />

produced at the voltage divider, corresponding<br />

to a signal strength of S9 +<br />

40 dB. This enables the fi eld strength<br />

meter created in software to be calibrated<br />

without any further expenditure.<br />

JFET BF245 on the output of the input<br />

multiplexer serves as an impedance<br />

transformer. This provides a relatively<br />

high impedance termination of 100<br />

k� for the RF signal, enabling for instance<br />

a high-Q resonant circuit to be<br />

connected even to input In2. At the<br />

low-impedance output of the source<br />

follower we arrange to have a voltage<br />

of circa 2.5 V, fed via the mixer and the<br />

following op-amp all the way to the<br />

output. It is important that no audio<br />

frequency signal remnants appear at<br />

the source connection and for this reason<br />

the ‘critical’ supply Vcc_HF is also<br />

fi ltered very thoroughly. The FET itself<br />

provides additional decoupling of the<br />

supply voltage, but we don’t want any<br />

signal escaping fr<strong>om</strong> the Gate either<br />

that might fall in the IF region below<br />

24 kHz. This is why an RF choke is connected<br />

directly to the antenna input,<br />

to shunt for instance any 50 Hz mains<br />

hum signal.<br />

Leading off fr<strong>om</strong> the Source connection<br />

are two 100-� resistors that go to the<br />

two mixers for the I and the Q signals.<br />

��������������������������<br />

16 elektor electronics - 5/2007


COMPONENTS<br />

LIST<br />

Resistors<br />

R1,R7,R19 = 100�<br />

R2,R3 = 330�<br />

R4 = 100�<br />

R5,R8,R13,R17,R20 = 100k�<br />

R6,R10,R14,R22 = 10k�<br />

R9,R21 = 4k�7<br />

R11,R23 = 27k�<br />

R12,R15,R18 = 470�<br />

R16 = 1M�<br />

R24 = 1k�<br />

R25 = 4�7<br />

Capacitors<br />

C1,C2,C5,C6,C7,C10,C11,C16,C17,C1<br />

9,C20,C21,C25-C28,C30,C32,C33,C<br />

34,C36,C38,C39,C40 = 100nF<br />

C3,C4,C9,C15 = 4μF7 16V radial<br />

C8,C18 = 10nF<br />

C12,C13 = 10pF<br />

C14 = 470μF 16V radial<br />

C22,C24,C35,C37 = 2nF2<br />

C29 = 220pF<br />

C31 = 100pF<br />

Semiconductors<br />

IC1 = 74AC74<br />

IC2,IC7 = 74HC4066<br />

IC3 = CY27EE16 (Cypress)<br />

IC4 = FT232R (FTDI)<br />

IC5 = TL084CN with socket (see text)<br />

IC6 = 74HC4051<br />

T1 = BF245<br />

Inductors<br />

L1-L4 = 10μH<br />

L5 = 47μH<br />

L6 = 2.2mH<br />

Miscellaneous<br />

K1 = USB-B socket, PCB mount<br />

K2 = stereo jack socket, 3.5mm, PCB<br />

mount<br />

K3 = 2-way PCB terminal block, lead<br />

pitch 5mm<br />

PC1 = solder pin<br />

X1 = 10MHz quartz crystal<br />

Ready-populated and tested PCB, order<br />

code 070039-91<br />

Project software, free download<br />

070039-11<br />

Supplementary document, free download<br />

PCB, bare, ref. 070039-1 fr<strong>om</strong> www.thepcbshop.c<strong>om</strong><br />

They improve the symmetry of the mixers,<br />

the ‘on’ resistances of which let<br />

through a certain amount of leakage.<br />

The mixers themselves are HC4066<br />

analogue switch ICs ganged as changeover<br />

switches. The voltage of these<br />

too is set around 2.5 V, allowing them<br />

to be controlled without overdriving up<br />

to about 5 V peak-to-peak.<br />

The IF amplifi er consists of two exact-<br />

Elektor blockbusters<br />

5/2007 - elektor electronics<br />

Figure 2. The SDR receiver board.<br />

��������������������������<br />

17


PROJECTS SDR<br />

ly equal branches that together produce<br />

an attenuation of up to 40 dB at<br />

all times. When you are using 5 V supplies,<br />

the gain bandwidth (GBW) of<br />

the selected op-amp is important, in<br />

order to achieve tenfold amplifi cation<br />

without phase errors for signals around<br />

20 kHz. In the author’s test samples a<br />

TL084 turned out to be adequate. If<br />

you provide a socket for IC5 you will<br />

be able to try other, faster op-amps.<br />

The input stage works as a differential<br />

amplifi er. In dimensioning the resistors<br />

what we are looking for is not the best<br />

c<strong>om</strong>mon-mode suppression but rather<br />

an input resistance that’s as equal as<br />

possible across the inverting and noninverting<br />

inputs. Tests show that good<br />

phase accuracy (and consequently high<br />

image-frequency suppression) depend<br />

on equal impedance existing on all four<br />

phases of the mixer. The input impedance<br />

amounts to around 5 k� at all<br />

of the inputs. Note the load resistance<br />

of 4.7 k� on the non-inverting input as<br />

opposed to 10 k� on the inverting one.<br />

This is correct, since signal transit on<br />

this input gets dispersed in exact antiphase<br />

by inverse feedback, halving<br />

the input resistance to 5 k�. In this<br />

way both inputs offer the same input<br />

resistance as close as matters.<br />

The 2.2 nF capacitors together with<br />

the mixer’s internal resistance and the<br />

Elektor blockbusters<br />

Figure 3. This lab sample board is not quite equivalent to the production version supplied through the Elektor SHOP.<br />

100 � series resistors form simple lowpass<br />

fi lters with a limiting frequency of<br />

over 100 kHz, so as to keep remnants of<br />

RF well away fr<strong>om</strong> the audio frequency<br />

stages. The limiting frequency lies<br />

far above the transfer frequency range,<br />

meaning that capacitor tolerances do<br />

not produce any discernible phase errors.<br />

You can use even ceramic disc capacitors<br />

here. Tolerances between 10<br />

and 20 % are not a problem with any of<br />

the capacitors in the signal path acting<br />

as high-pass elements with a limiting<br />

frequency of around 300 Hz.<br />

The fi nal stage has a tenfold gain (20<br />

dB), which can, however, be reduced to<br />

unity gain by the analogue switches.<br />

A total of three attenuation steps are<br />

provided: 0 dB, –10 dB und –20 dB.<br />

To avoid it being driven too hard, the<br />

gain can be reduced in software. As<br />

the receiver’s input displays high resistance<br />

to being overdriven the attenuator<br />

is placed in the fi nal stage, so<br />

as to prevent overdriving of the output.<br />

This corresponds to gain control in an<br />

IF amplifi er.<br />

Construction<br />

The printed circuit board shown in Figure<br />

2 uses standard wire-ended c<strong>om</strong>ponents<br />

as far as possible, with the exception<br />

of the LSI (large scale integra-<br />

tion) chips FT232RL and CY27EE16,<br />

which unfortunately are available only<br />

in SSOP case format with a pin spacing<br />

of 0.65 mm. Figure 3 shows the<br />

laboratory prototype PCB with c<strong>om</strong>ponents<br />

fi tted.<br />

The best way to begin is by soldering<br />

the two surface-mount device (SMD)<br />

chips in place. It pays to start fi rst at<br />

the four corners, before soldering all<br />

the other pins generously. Superfl uous<br />

solder can be removed with desolder<br />

braid, followed by thorough checking<br />

with a magnifying glass to avoid unwelc<strong>om</strong>e<br />

surprises later on.<br />

The c<strong>om</strong>ponents with wire leads will<br />

present no diffi culty. The circuit does<br />

not call for any special RF c<strong>om</strong>ponents<br />

or test points. Capacitors C12 and<br />

C13 should not be fi tted initially. The<br />

CY27EE16 has presettable internal<br />

capacitors that should enable you to<br />

achieve a frequency of exactly 10 MHz<br />

without diffi culty. C12 and C13 will be<br />

needed only if the crystal used requires<br />

greater loading capacity.<br />

Once all construction is c<strong>om</strong>plete you<br />

need to make a quick round-up with a<br />

multimeter checking for any short circuits<br />

around the USB connections, as<br />

you certainly don’t want to damage<br />

the PC.<br />

��������������������������<br />

18 elektor electronics - 5/2007


Hook-up and alignment<br />

Before connecting the receiver to the<br />

c<strong>om</strong>puter’s USB port for the fi rst time<br />

you will need to install the driver software<br />

for the FT232R. You can fi nd this<br />

on the manufacturer’s website (www.<br />

ftdichip.c<strong>om</strong>/FTDrivers.htm) or alternatively<br />

in the software download for<br />

this article. Installation using CDM_<br />

Setup.exe aut<strong>om</strong>atically removes any<br />

traces of older FTDI drivers on your<br />

c<strong>om</strong>puter. After this has been done<br />

Windows will fi nd the correct driver<br />

aut<strong>om</strong>atically as soon as the receiver<br />

is connected. The same process provides<br />

the PC aut<strong>om</strong>atically with an<br />

additional virtual COM-port interface.<br />

For this you do not even need to know<br />

which COM number is allocated to the<br />

device, as it effectively sets up its own<br />

direct connection to the FT232R. FT-<br />

D2XX.dll controls the eight data lines<br />

of the chip as for a parallel port, eliminating<br />

at the same time all timing<br />

problems. To save time the multiple level<br />

changes involved in controlling the<br />

I2C bus are loaded conveniently into<br />

a buffer and then fed out to the data<br />

lines in short order. The program ElektorSDR.exe<br />

enables you to control all<br />

functions of the receiver (Figure 4) and<br />

can be found in the download archive<br />

as an executable fi le together with the<br />

Delphi source code. Also available for<br />

download is a supplementary .pdf document<br />

that describes initialisation<br />

and c<strong>om</strong>missioning.<br />

Decoder software<br />

Nearly all signifi cant characteristics of<br />

the receiver are determined by settings<br />

in the decoder software on your PC. As<br />

the survey in [1] indicates, there are a<br />

number of different programs to choose<br />

fr<strong>om</strong>. You could perform your fi rst test<br />

with SDRadio [2] for example. After this<br />

you will discover additional possibilities<br />

in DREAM [3] or G8JCFSDR [4].<br />

Whichever program you select, it’s vital<br />

to set up the sound card correctly (this<br />

is described in the supplementary document).<br />

Information on the programs<br />

can be found on the relevant Web<br />

pages and in the Elektor Electronics<br />

articles listed below. Further advice<br />

may be found on the author’s h<strong>om</strong>epage<br />

(www.b-kainka.de) and will appear<br />

also in due course on the project<br />

page at www.elektor-electronics.co.uk<br />

and, if necessary, in the Forum on the<br />

same website.<br />

Elektor blockbusters<br />

5/2007 - elektor electronics<br />

(070039-1)<br />

Figure 4. Elektor Electronics SDR Tuning control program.<br />

Figure 5. Four AM stations in tuning range spectrum, as displayed by the SDRadio program.<br />

Web links:<br />

[1] www.nti-online.de/diraboxsdr.htm<br />

[2] www.sdradio.org/<br />

[3] http://sourceforge.net/projects/drm<br />

[4] www.g8jcf.dyndns.org/<br />

Literature:<br />

Burkhard Kainka: DREAM Team –Software for DRM reception, Elektor Electronics 4/2004, pp.<br />

20 ff.<br />

Wolfgang Hartmann and Burkhard Kainka: ‘Radio listening with Matlab—Diorama software<br />

DRM receiver’, Elektor Electronics 4/2006, pp. 76 ff.<br />

Burkhard Kainka: I-Q: a highly intelligent approach to quality radio, Elektor Electronics<br />

12/2006, pp. 38 ff.<br />

��������������������������<br />

19


TECHNOLOGY WIRELESS<br />

Dr. Erik Lins and Christian Meinhardt<br />

Wireless<br />

iDwaRF: a network<br />

iDwaRF brings together a Cypress WirelessUSB transceiver and an Atmel AVR microcontroller to create a<br />

networkable 2.4 GHz radio module featuring a free protocol stack and development environment.<br />

Besides standard applications such<br />

as mobile radio, WLAN and Bluetooth,<br />

highly-integrated low power radio devices<br />

open up many new possibilities,<br />

Figure 1. The iDwaRF radio module with 2.4 GHz WirelessUSB<br />

transceiver and ATmega168 AVR microcontroller.<br />

Elektor blockbusters<br />

including wireless sensor networks<br />

and even radio-controlled robotic football<br />

teams able to orchestrate an offside<br />

trap in the blink of an eye! And,<br />

with iDwaRF, we can do all this without<br />

c<strong>om</strong>plex protocols or licensing<br />

problems.<br />

An alternative to ZigBee<br />

For wireless sensor network applications<br />

ZigBee [1] is often the protocol of<br />

choice. The protocol is relatively c<strong>om</strong>plicated,<br />

and only members of the Zig-<br />

Bee Alliance are permitted to use it in<br />

c<strong>om</strong>mercial products. Cypress [2] offers<br />

a simpler alternative in its WirelessUSB<br />

technology [3]. The devices are cheap<br />

and the radio protocol makes only moderate<br />

demands in terms of hardware<br />

and memory in the microcontroller.<br />

WirelessUSB supports wireless manyto-one<br />

links and is thus ideal for use in<br />

wireless sensor networks. The protocol<br />

details are freely available and can be<br />

used without restriction in c<strong>om</strong>bination<br />

with Cypress radio chips.<br />

iDwaRF<br />

The iDwaRF-Net software that acc<strong>om</strong>panies<br />

the iDwaRF-168 module (Figure<br />

1) is a port of the Cypress WirelessUSB<br />

protocol to the ATmega168<br />

AVR-family microcontroller [4]. The<br />

iDwaRF-168 module can be freely reprogrammed<br />

and can equally well play<br />

the role of hub or sensor in a manyto-one<br />

wireless sensor network. It is<br />

easy to add extra application-specifi c<br />

functions.<br />

WirelessUSB operates in the 2.4 GHz<br />

ISM band. Each WirelessUSB radio network<br />

uses a selection fr<strong>om</strong> a total of 79<br />

channels: even when multiple WirelessUSB<br />

devices are operating simultaneously<br />

the protocol will be able to fi nd a<br />

free channel to use.<br />

Transmission uses a robust DSSS (direct<br />

sequence spread spectrum) modulation<br />

scheme [5]. Even at a 10 % error<br />

rate the data can still be received correctly,<br />

and if there should be long-term<br />

interference the protocol provides for<br />

Wireless USB in miniature • 74<br />

44 elektor electronics - 3/2007


USB in miniature<br />

able WirelessUSB radio module<br />

an aut<strong>om</strong>atic change of channel. Like<br />

Bluetooth, WirelessUSB c<strong>om</strong>es in shortrange<br />

(up to 10 m) and long-range (up<br />

to 50 m) versions. The latter is used in<br />

the iDwaRF-168 module.<br />

Hub and sensors<br />

An iDwaRF module programmed to<br />

act as a hub forms the centre point<br />

of a star-topology many-to-one radio<br />

network, which can consist of many<br />

sensors (Figure 2). Normally the hub<br />

operates continuously and can be connected<br />

to a PC or another microcontroller,<br />

acting as a host, using a serial<br />

link. For simple applications the<br />

iDwaRF module itself can be programmed<br />

to carry out the required<br />

dedicated host functions.<br />

ANT2<br />

1<br />

3/2007 - elektor electronics<br />

1<br />

ANT_WIGGLE_L<br />

ANT1<br />

ANT_WIGGLE_R<br />

L1<br />

3nH9<br />

Elektor blockbusters<br />

C1<br />

1p8<br />

C4<br />

10p<br />

C2<br />

NOLOAD<br />

VCC<br />

C11<br />

100n<br />

NC 48<br />

NC 47<br />

RFIN 46<br />

VCC 45<br />

VCC 44<br />

NC 43<br />

X13IN<br />

5<br />

RFOUT<br />

35<br />

X13OUT 26<br />

/PD 33<br />

PACTL 34<br />

SCK 25<br />

6<br />

VCC<br />

9<br />

VCC<br />

VCC 28<br />

VCC 29<br />

VCC 32<br />

1<br />

NC<br />

2<br />

NC<br />

3<br />

NC<br />

4<br />

NC<br />

7<br />

NC<br />

8<br />

NC<br />

10<br />

NC<br />

NC<br />

11<br />

NC<br />

12<br />

NC<br />

27<br />

NC 30<br />

NC 31<br />

NC 36<br />

U1<br />

CYWUSB6935-48LFX<br />

VCC 42<br />

VCC 41<br />

38<br />

X13<br />

NC 37<br />

NC 39<br />

NC 40<br />

14<br />

/RESET<br />

20<br />

DIO<br />

DIOVAL<br />

13<br />

GND<br />

15<br />

NC<br />

16<br />

VCC<br />

17<br />

NC<br />

18<br />

NC<br />

19<br />

21<br />

IRQ<br />

22<br />

/SS<br />

23<br />

MOSI<br />

24<br />

MISO<br />

VCC<br />

C5<br />

10u<br />

C6<br />

100n<br />

C10<br />

100n<br />

VCC<br />

C8 C7<br />

100n 100n<br />

E<br />

/INT0<br />

MISO<br />

MOSI<br />

/ SS<br />

X1<br />

13MHz<br />

VCC<br />

X13OUT<br />

SCK<br />

C9<br />

100n<br />

/WUSBRESET<br />

Figure 2. The star-topology radio network consists of a hub and several sensors.<br />

/PD<br />

/WUSBRESET<br />

/INT0<br />

14<br />

13<br />

12<br />

11<br />

10<br />

9<br />

8<br />

7<br />

6<br />

5<br />

4<br />

3<br />

2<br />

1<br />

CON1<br />

/RESET<br />

VCC<br />

PORT6<br />

PORT6<br />

VCC<br />

GND<br />

/RESET<br />

MOSI<br />

SCK<br />

VCC<br />

MISO<br />

PORT7<br />

PORT6<br />

PORT5<br />

PORT4<br />

PORT3<br />

PORT2<br />

PORT1<br />

PORT0<br />

Figure 3. Circuit diagram of the iDwaRF module.<br />

X2<br />

C12<br />

xxMHz<br />

C13 C14<br />

100n 22p 22p<br />

MISO<br />

MOSI<br />

/ SS<br />

SCK<br />

PORT4<br />

PORT5<br />

PD1 TXD 31<br />

32<br />

PD2 INT0<br />

PORT0<br />

PORT1<br />

PORT0<br />

PORT7<br />

PORT7<br />

PORT2<br />

PORT3<br />

PORT0<br />

PORT1<br />

1<br />

INT1 OC2B PD3<br />

2<br />

XCK T0 PD4<br />

3<br />

GND<br />

4<br />

VCC<br />

5<br />

GND<br />

6<br />

VCC<br />

7<br />

XTAL1 TOSC1 PB6<br />

8<br />

XTAL2 TOSC2 PB7<br />

PB5 SCK 17<br />

AVCC 18<br />

ADC6 19<br />

AREF 20<br />

GND 21<br />

ADC7 22<br />

PC0 ADC0 23<br />

PC1 ADC1 24<br />

U2<br />

ATmega168-20MI<br />

OC0B T1 PD5<br />

OC0A AIN0 PD6<br />

AIN1 PD7<br />

CLKO ICP PB0<br />

OC1A PB1<br />

/SS OC1B PB2<br />

MOSI OC2 PB3<br />

MISO PB4<br />

9<br />

10<br />

11<br />

PD0 RXD 30<br />

PC4 ADC4 SDA<br />

26<br />

PC3 ADC3<br />

25<br />

PC2 ADC2<br />

27<br />

PC5 ADC5 SCL 28<br />

PC6 /RESET 29<br />

12<br />

13<br />

14<br />

15<br />

16<br />

050402 - 11<br />

VCC<br />

C15<br />

100n<br />

Wireless USB in miniature • 75<br />

45


TECHNOLOGY WIRELESS<br />

Figure 4. The iDwaRF printed circuit board<br />

includes a printed antenna.<br />

Figure 6. The iDwaRF module is mounted<br />

on the hub printed circuit board.<br />

A sensor unit consists of a suitablyprogrammed<br />

iDwaRF module with<br />

sensors attached. To save power we<br />

use the AVR’s internal RC oscillator.<br />

Also, the module is only activated at<br />

intervals (as determined by the ‘beacon<br />

time’). C<strong>om</strong>munications are initiated<br />

by the sensor and terminated by<br />

the hub; a reverse channel (transmitting<br />

information fr<strong>om</strong> hub to sensor) is<br />

also available.<br />

Module printed circuit board<br />

Figure 3 shows the circuit diagram<br />

of the iDwaRF-168 module. The Cypress<br />

CYWUSB6935-LR transceiver is<br />

connected to an ATmega168 microcontroller<br />

over SPI, using the MISO,<br />

MOSI, SCK and /SS (chip select) signals.<br />

An interrupt signal (/INT0) fr<strong>om</strong><br />

the radio device indicates the reception<br />

of data. The ATmega168 can put<br />

the radio chip into power-down mode<br />

using an I/O pin connected to the /<br />

PD signal, and can reset it using the<br />

/WUSBRESET signal. The radio chip<br />

needs just an external 13 MHz crystal<br />

(X1) and decoupling capacitors (C6 to<br />

C11) for operation. The transmit and<br />

receive antennas are separate fr<strong>om</strong><br />

one another and integrated directly<br />

into the circuit board layout as meander<br />

lines (Figure 4). Having separate<br />

antennas gives greater range and sim-<br />

Elektor blockbusters<br />

CON1<br />

CON3<br />

CON1<br />

CON3<br />

1 PORT0<br />

2 PORT1<br />

3 PORT2<br />

4 PORT3<br />

5 PORT4<br />

6 PORT5<br />

7 PORT6<br />

8 PORT7<br />

9 MISO<br />

10 VCC<br />

11 SCK<br />

12 MOSI<br />

13 RST<br />

14 GND<br />

1 MISO<br />

2 VCC<br />

3 SCK<br />

4 MOSI<br />

5 RST<br />

6 GND<br />

1 PORT0<br />

2 PORT1<br />

3 PORT2<br />

4 PORT3<br />

5 PORT4<br />

6 PORT5<br />

7 PORT6<br />

8 PORT7<br />

9 MISO<br />

10 VCC<br />

11 SCK<br />

12 MOSI<br />

13 RST<br />

14 GND<br />

CON2<br />

1 PORT0<br />

2 PORT1<br />

3 PORT2<br />

4 PORT3<br />

5 PORT4<br />

6 PORT5<br />

7 PORT6<br />

8 PORT7<br />

9 MISO<br />

10 VCC<br />

11 SCK<br />

12 MOSI<br />

13 RST<br />

14 GND<br />

1<br />

2<br />

3<br />

4<br />

5<br />

6<br />

MISO<br />

VCC<br />

SCK<br />

MOSI<br />

RST<br />

GND<br />

12 SUSPEND<br />

9<br />

RST<br />

SUSPEND<br />

46 elektor electronics - 3/2007<br />

*<br />

1k5<br />

R1<br />

see text<br />

VCC<br />

VCC<br />

LED1<br />

green<br />

MOSI<br />

SCK<br />

RST<br />

SW1<br />

24<br />

RTS<br />

CTS<br />

23<br />

27<br />

28<br />

DTR<br />

DSR<br />

25<br />

26<br />

TXD<br />

RXD<br />

1<br />

11 RI<br />

2 DCD<br />

NC 16<br />

NC 17<br />

NC 18<br />

NC 19<br />

NC 20<br />

NC 21<br />

NC 22<br />

10<br />

NC<br />

NC<br />

13<br />

C1<br />

10u<br />

CP2102<br />

USB to UART<br />

Bridge<br />

29<br />

GND<br />

GND<br />

30 U2<br />

U1<br />

4<br />

IN<br />

2<br />

NC<br />

1<br />

BYPSS<br />

C2<br />

10n<br />

*<br />

14<br />

NC<br />

NC<br />

15<br />

3<br />

SHD 8<br />

GND<br />

Figure 5. Circuit of the hub board.<br />

BATT<br />

Battery Clip 3xAAA 2479<br />

PORT7<br />

1k5<br />

PORT3<br />

PORT2<br />

PORT6<br />

R1<br />

green<br />

PORT4<br />

PORT5<br />

VCC<br />

LED1<br />

J1<br />

SW1<br />

1k5<br />

R2<br />

1k5<br />

1<br />

2<br />

U3<br />

1<br />

SI<br />

2<br />

SCK<br />

3<br />

RST<br />

4<br />

CS<br />

R3<br />

*<br />

1k5<br />

Vbatt<br />

VCC<br />

R4<br />

7<br />

VCC 6<br />

GND<br />

VBUS 8<br />

REGIN 7<br />

D- 5<br />

D+ 4<br />

VDD 6<br />

GND 3<br />

Vbus<br />

OUT 5<br />

SNS 6<br />

ERR 7<br />

D-<br />

D+<br />

C5<br />

100n<br />

Vbus<br />

VCC<br />

LP2989IM-3.3<br />

C3<br />

10u<br />

SO 8<br />

WP 5<br />

AT45DB081D-SSU<br />

U2<br />

1<br />

SDA<br />

2<br />

SCL<br />

3<br />

O.S.<br />

C1<br />

10u<br />

4<br />

C5<br />

100n<br />

VCC<br />

VCC 8<br />

GND<br />

4<br />

2<br />

1<br />

C2<br />

10n<br />

A0 7<br />

A2 5<br />

A1 6<br />

LM75<br />

U1<br />

IN<br />

NC<br />

MISO<br />

BYPSS<br />

3<br />

SHD 8<br />

GND<br />

PORT0<br />

PORT1<br />

1<br />

2<br />

3<br />

4<br />

5<br />

C4<br />

1u<br />

OUT 5<br />

SNS 6<br />

ERR 7<br />

9<br />

8<br />

6<br />

7<br />

050402 - 12<br />

CON2<br />

USBMINIB<br />

LP2989IM-3.3<br />

C3<br />

10u<br />

PORT7<br />

Figure 7. Circuit diagram of the node board with temperature and light sensors.<br />

*<br />

C4<br />

100n<br />

J2<br />

4k7<br />

*<br />

LDR<br />

R7<br />

see text<br />

VCC<br />

VCC<br />

Vbatt<br />

1M<br />

1M<br />

050402 - 13<br />

R5<br />

R6<br />

Wireless USB in miniature • 76


Table 1. CON1 connection groups<br />

iDwaRF-168 CON1<br />

(port pin)<br />

plifi es matching (L1, C1 and C4). The<br />

antennas are laid out in the manner<br />

rec<strong>om</strong>mended by Cypress.<br />

The microcontroller is equipped with<br />

a crystal in an HC49 package, and so<br />

it is straightforward to change it for a<br />

different frequency. As supplied the<br />

ATmega168 is confi gured to use its internal<br />

RC oscillator.<br />

A 14-way header (CON1) brings out<br />

the ISP (in-system programming)<br />

signals of the ATmega168 (MOSI,<br />

MISO, SCK and /RST), power, and<br />

eight spare I/O port pins. S<strong>om</strong>e of the<br />

header pins are connected to more<br />

than one signal on the microcontroller<br />

to allow as many as possible of<br />

the peripheral functions of the device<br />

to be used. This means that you must<br />

ensure that any two microcontroller<br />

pins that are connected to the same<br />

header pin are never simultaneously<br />

confi gured as outputs, or damage to<br />

the microcontroller may result. Table<br />

1 shows the CON1 pinout and<br />

signals in detail.<br />

Application boards<br />

In the simplest wireless network scenario<br />

one iDwaRF-168 module is programmed<br />

as a hub and one or more<br />

modules are programmed as sensors.<br />

It is of course necessary to build the<br />

necessary interfaces to the sensors<br />

themselves and connect them to the<br />

modules. To simplify building such<br />

systems we have developed three application<br />

boards, to each of which can<br />

be attached an iDwaRF-168 module: a<br />

hub board, a node board and a prototyping<br />

board.<br />

3/2007 - elektor electronics<br />

First connection<br />

(ATmega168 pin number)<br />

Second connection<br />

(ATmega168 pin number)<br />

The hub board supports the iDwaRF<br />

module with a USB interface (the<br />

CP2102), a 3.3 V LDO voltage regulator,<br />

button and LED (Figure 5).<br />

The node board is used to make a sensor<br />

unit using an iDwaRF module. The<br />

circuit (Figure 6) includes an LDR as<br />

a light sensor, an LM75 temperature<br />

sensor, an (optional) AT45DB801D serial<br />

fl ash memory, a button and an LED.<br />

Power is provided by three AAA cells<br />

and a 3.3 V LDO voltage regulator.<br />

The two printed circuit boards (Figure<br />

7 and Figure 8) are chiefl y populated<br />

using SMD c<strong>om</strong>ponents. Figure 9<br />

shows the boards with iDwaRF-168<br />

modules fi tted.<br />

Third connection<br />

(ATmega168 pin number)<br />

PORT0 OC0B / T1 / PD5 (9) AIN1 / PD7 (11) ADC3 / PC3 (26)<br />

PORT1 OC0A / AIN0 / PD6 (10) ADC2 / PC2 (25) -<br />

PORT2 SCL / ADC5 / PC5 (28) - -<br />

PORT3 SDA / ADC4 / PC4 (27) - -<br />

PORT4 TXD / PD1 (31) - -<br />

PORT5 RXD / PD0 (30) - -<br />

PORT6 INT1 / OC2B / PD3 (1) XCK / T0 / PD4 (2) -<br />

PORT7 CLKO / ICP / PB0 (12) OC1A / PB1 (13) -<br />

Elektor blockbusters<br />

Figure 9. Node board (rear) and hub board (front)<br />

with iDwaRF radio modules fi tted.<br />

Figure 8. The node board converts the iDwaRF module<br />

into a c<strong>om</strong>plete sensor unit.<br />

Wireless USB in miniature • 77<br />

47


TECHNOLOGY WIRELESS<br />

Table 2. Example programs<br />

empty Empty program: framework for new applications.<br />

chat Creates a wireless serial connection between two host PCs, allowing ‘chatting’ between two terminal programs.<br />

tutorial<br />

terminal<br />

Example program that switches the LEDs on the hub and sensor modules on and off remotely when a button is pressed. The implementation<br />

of this example is explained step-by-step in a separate ‘how to’ document (see text box).<br />

This basic sensor network application supports the c<strong>om</strong>ponents on the node board or iDwaRFSensorBox. Data packets (including<br />

battery voltage, potenti<strong>om</strong>eter setting, button state and temperature) fr<strong>om</strong> several sensors are displayed in plain ASCII text. The terminal<br />

program can also send data to individual sensors.<br />

quad_adc This program reads four ADC channels and transmits the readings to the hub at regular intervals.<br />

K2<br />

1 PORT0<br />

2 PORT1<br />

3 PORT2<br />

4 PORT3<br />

5 PORT4<br />

6 PORT5<br />

7 PORT6<br />

8 PORT7<br />

9 MISO<br />

10 VCC<br />

11 SCK<br />

12 MOSI<br />

13 RST<br />

14 GND<br />

iDwaRF<br />

K4<br />

1 MISO<br />

2 VCC<br />

3 SCK<br />

4 MOSI<br />

5 RST<br />

6 GND<br />

AVRISP<br />

VCC<br />

K3<br />

1<br />

2<br />

3<br />

4<br />

5<br />

6<br />

7<br />

8<br />

9<br />

10<br />

11<br />

12<br />

13<br />

14<br />

EXT<br />

K1<br />

3<br />

1<br />

2<br />

BATT<br />

D1<br />

1N4001<br />

VCC<br />

Battery Clip 3xAAA 2479<br />

SOT-23/6<br />

SOIC-24<br />

1<br />

2<br />

SOT-23/6<br />

1u<br />

25V<br />

1 3<br />

The prototyping board has a generous<br />

area for building your own circuits<br />

and is suitable for creating more<br />

specialised applications using the<br />

iDwaRF-168 module. There are SMD<br />

pads on the reverse of the board. The<br />

only active c<strong>om</strong>ponent in the circuit<br />

(Figure 10) is the LDO voltage regulator,<br />

in a TO-92 or TO-220 package according<br />

to the expected current draw.<br />

As well as the regulator and socket to<br />

accept the iDwaRF-168 module there<br />

is an AVR programming connector, a<br />

battery holder and, as an alternative,<br />

a socket for a mains adaptor with a<br />

reverse polarity protection diode. The<br />

printed circuit board (Figure 11) is<br />

half-Eurocard sized and can be used<br />

in the place of a node board. For reasons<br />

of space we have made the parts<br />

lists for the circuit boards and layouts<br />

available for download fr<strong>om</strong> the Elektor<br />

Electronics website.<br />

Software<br />

The iDwaRF-Net software package [6]<br />

includes a library of fi rmware for use<br />

in hub and sensor modules with corresponding<br />

header fi les (in the ‘iDwaRF’<br />

directory), along with a few ancillary<br />

functions, for example to support serial<br />

c<strong>om</strong>munications (‘USART’ directory).<br />

There are also four example programs<br />

which can either be used as they stand<br />

or form the basis for dedicated applications.<br />

Table 2 gives more details of<br />

these example programs.<br />

Each example program consists of hub<br />

source code (userMain_hub.c) and<br />

sensor source code (userMain_sensor.<br />

c). The fi rmware provides the facility<br />

to register so-called ‘callback’ functions,<br />

which the fi rmware calls regularly<br />

in the course of normal operation.<br />

These functions can be used for application-specifi<br />

c code. The most important<br />

callback functions are explained<br />

in the text box.<br />

Ready, steady…<br />

Assembling the hardware is relatively<br />

straightforward. The SMD printed circuit<br />

boards (the iDwaRF module, the<br />

node board and the hub board) are<br />

available as ready-made units (see<br />

the ‘Elektor Shop’ pages at the back of<br />

this issue). A kit of parts is available<br />

for the prototyping board. Separately-ordered<br />

iDwaRF-168 modules are<br />

supplied unprogrammed and without<br />

header or crystal fi tted in order to give<br />

the user maximum fl exibility.<br />

The fi rmware for programming a hub<br />

or sensor module is freely available<br />

[6]. Modules ordered bundled with a<br />

48 elektor electronics - 3/2007<br />

C1<br />

IC1<br />

LP2950<br />

LF33CV<br />

Figure 10. Circuit diagram of the prototyping board for dedicated iDwaRF module applications.<br />

Figure 11. The prototyping board has an experimentation area<br />

with SMD footprints on the reverse.<br />

Elektor blockbusters<br />

2<br />

C2<br />

VCC<br />

1u<br />

25V<br />

050402 - 14<br />

Wireless USB in miniature • 78


node or hub board c<strong>om</strong>e ready-programmed.<br />

A crystal is always required<br />

for baud rate generation on the hub<br />

board (a 7.3728 MHz crystal is supplied<br />

as standard), and the microcontroller<br />

must be suitably programmed<br />

for crystal operation. The correct values<br />

for the ATmega168 with a crystal<br />

oscillator are: extended byte, 0xF9;<br />

high byte, 0xDF; and low byte, 0xFC.<br />

It is rec<strong>om</strong>mended to use the same<br />

values and same crystal frequency for<br />

the sensor, and the fi rmware is currently<br />

set up to work on this assumption.<br />

If the frequency is to be changed<br />

(using a different crystal or the internal<br />

RC oscillator) the relevant #defi ne<br />

in the fi rmware must be changed and<br />

the code c<strong>om</strong>piled afresh.<br />

The AVR ISP connectors have to be<br />

soldered on to the node board and<br />

hub board, and the node board also<br />

needs to be connected to the battery<br />

holder. Finally the iDwaRF module can<br />

be fi tted and (in the case of the node<br />

board) the batteries inserted. The<br />

USB connection on the hub board requires<br />

the corresponding CP2102 virtual<br />

COM port driver to be downloaded<br />

and installed [6]. Drivers are available<br />

for both Windows and Mac OS X. A<br />

CP210x module is provided as stand-<br />

3/2007 - elektor electronics<br />

ard in current Linux kernels, allowing<br />

the iDwaRF module to be used with<br />

non-Windows PCs.<br />

The pre-c<strong>om</strong>piled hex fi les [6] for hub<br />

and sensor are downloaded using the<br />

six-pin AVR ISP connector. Note that<br />

the supply voltage for the iDwaRF<br />

module on the node and hub boards is<br />

only 3.3 V, and so care must be taken<br />

Table 3. C<strong>om</strong>mands available in ‘terminal’ program<br />

C<strong>om</strong>mand Description<br />

to ensure that the programming adaptor<br />

also works at this voltage. Simple<br />

STK200-c<strong>om</strong>patible programming<br />

adaptors that connect to the PC’s<br />

printer port, which draw power fr<strong>om</strong><br />

the target device, do not always work<br />

reliably at 3.3 V. Modern USB programming<br />

adaptors (c<strong>om</strong>patible with the<br />

STK500-V2) such as the CrispAVR-USB<br />

work without problems.<br />

rst Restarts the hub fi rmware. All sensors are unregistered and lose their ID codes, and must register again with the hub.<br />

gps Returns an internal Cypress fi rmware state variable.<br />

bon<br />

Activates aut<strong>om</strong>atic bind mode on the hub. New sensors are probed for using PN code 0 and channel 0. In normal use aut<strong>om</strong>atic<br />

bind mode is activated.<br />

bof Deactivates aut<strong>om</strong>atic bind mode. New sensors can no longer register with the hub.<br />

enu<br />

cln<br />

cnf<br />

snd<br />

del<br />

Displays a list of the currently registered sensors on the hub. The list includes the sensor ID assigned during registration and the<br />

unique manufacturing ID stored in the radio chip.<br />

Cleans up the hub’s list of registered sensors. Sensors which have registered more than once with the hub and which have therefore<br />

been assigned different ID codes are removed fr<strong>om</strong> the list and only their current ID code remains valid.<br />

Confi gures network parameters. There are 8 different PN codes and channel subsets, and this c<strong>om</strong>mand allows the hub to be switched<br />

to a new PN code and channel. The facility to change channel number is for test purposes only, as the channel is changed<br />

aut<strong>om</strong>atically in normal operation. The PN code, however, remains fi xed. The format is<br />

cnf <br />

where 0 < pncode < 9 and 0 < channel < 80. The cnf c<strong>om</strong>mand aut<strong>om</strong>atically deletes all registered sensors fr<strong>om</strong> the list.<br />

Sends beacon time and other data to a sensor. The data packet is buffered in the hub and when the sensor in question next makes<br />

a transmission the packet is sent back in the back channel to the sensor. All parameters are given in decimal. The format is<br />

snd ...<br />

A beacon time of -1 indicates that the beacon time is not to be changed.<br />

Removes a sensor fr<strong>om</strong> the list of registered sensors in the hub. The format is<br />

del <br />

hex Causes sensor data to be displayed in hex rather than as plain text.<br />

Elektor blockbusters<br />

Figure 12. Prototyping board with iDwaRF radio module plugged on.<br />

Wireless USB in miniature • 79<br />

49


TECHNOLOGY WIRELESS<br />

The principal callback functions<br />

In the hub:<br />

cbSensorPacketReceived(): called when a packet is received fr<strong>om</strong> a sensor. Direct access to the current sensor data is possible, although if<br />

lengthy processing is to be carried out the data should be copied into a global buffer and the work done in the main program.<br />

cbSerialDataReceived(): called when a byte is received over the serial interface. Usually the byte is simply stored in a global buffer and its reception<br />

signalled using a fl ag, so that more time-consuming processing can be carried out in the main program.<br />

cbProcessRxData(): further processes the bytes received by cbSerialDataReceived(), for example to implement a c<strong>om</strong>plex c<strong>om</strong>munications protocol<br />

with the host PC. In the ‘terminal’ example the c<strong>om</strong>mands entered on the host PC are parsed and processed in this function.<br />

In the sensor:<br />

cbConfi gForSleep(): called shortly before the sensor switches into power-down mode. This allows for particular sensor devices to be switched<br />

off to reduce power consumption.<br />

cbExitFr<strong>om</strong>Sleep(): called when the sensor leaves power-down mode. At this point particular sensor devices can be powered up again.<br />

cbTxProcess(): assembles the data packet to be sent to the hub. At this point sensors can be read and the readings stored in the global transmit<br />

buffer. The current data packet is then aut<strong>om</strong>atically sent to the hub.<br />

cbBackchannelProcess(): called with data received fr<strong>om</strong> the hub in the reverse channel. This can be used to create an output signal on the<br />

sensor, or to generate an analogue voltage using PWM. The ‘terminal’ example switches on the LED when a data packet is received.<br />

... go!<br />

The ‘terminal’ example program is<br />

the best one to use to demonstrate<br />

all the important functions of a wireless<br />

sensor network. iDwaRF modules<br />

programmed as sensors aut<strong>om</strong>atically<br />

connect to the module programmed<br />

as the hub and transfer<br />

data. With one node board and a hub<br />

board connected to a PC it is possible<br />

to see immediately on the PC’s<br />

Data format<br />

screen when light falls on or is shaded<br />

fr<strong>om</strong> the light sensor, when the<br />

button is pressed, or when the temperature<br />

sensor is warmed or cooled.<br />

Setup proceeds as follows.<br />

Hub board<br />

The virtual COM port driver creates a<br />

virtual COM port when the USB cable<br />

is plugged in. The number of the port<br />

can be obtained fr<strong>om</strong> the Device Manager<br />

(reached fr<strong>om</strong> the Control Panel).<br />

Now we can run a terminal program,<br />

set to the relevant port, and talk to the<br />

hub in plain ASCII. If there are no sensors<br />

there will initially be no reports<br />

fr<strong>om</strong> the hub. The hub is reset by typing<br />

the c<strong>om</strong>mand ‘rst’ and pressing<br />

‘enter’: the hub will then emit its startup<br />

message. It is best to confi gure the<br />

terminal program to expect CR+LF at<br />

the end of each line and to enable local<br />

echo, as the hub does not echo the<br />

characters it receives.<br />

S5: ID 0 ldr 212 temp 22.5°C batt 2.9V button OFF (5 6 7 8 9 10) : 11<br />

a) b) c) d) e) f) g) h)<br />

Legend:<br />

a) Packet type: S0 (BIND_REQUEST); S1 (BIND_RESPONSE); S2 (PING, hub only); S3 (ACK); S4 (DATA, hub only); S5 (DATA, sensor only)<br />

b) Sensor ID<br />

c) ADC value fr<strong>om</strong> the light intensity sensor<br />

d) Temperature<br />

e) Battery voltage<br />

f) Button state (ON or OFF)<br />

g) Six unused bytes displayed as decimal indices<br />

h) Data byte count<br />

The values fr<strong>om</strong> c) to g) above form the packet data payload. The standard packet size is set to 17 bytes, of which six are protocol overhead,<br />

leaving 11 bytes of payload.<br />

Elektor blockbusters<br />

Wireless USB in miniature • 80<br />

50 elektor electronics - 3/2007


Sensor<br />

If a sensor is switched on the data<br />

packets received will be displayed<br />

line-by-line in the terminal window.<br />

The first packet is called a ‘bind request’<br />

where the sensor registers with<br />

the hub and, in return, receives an ID<br />

code assignment and a value called the<br />

‘beacon time’. This period, which has<br />

a default value of fi ve seconds, is the<br />

interval between the transmission of<br />

successive data packets. The format of<br />

the data packets is described in detail<br />

in the text box ‘Data format’. A brief<br />

fl ash of the LED on the sensor board<br />

shows when it is active; the LED is extinguished<br />

when the sensor returns to<br />

power-down mode.<br />

If the node board is moved to a warmer<br />

location, or if the ambient light intensity<br />

changes, the data packets displayed<br />

will refl ect the new sensor values.<br />

If the button on the node board is<br />

pressed a data packet is transmitted<br />

immediately: this shows that it is possible<br />

to react immediately to external<br />

events, without waiting for the preset<br />

beacon time to elapse.<br />

C<strong>om</strong>mand line<br />

C<strong>om</strong>mands can be typed into the terminal<br />

window at any time. Typing ‘enu’<br />

(‘enumerate’) lists the sensors that are<br />

registered with the hub, showing their<br />

ID code and unique serial number.<br />

Our fi rst sensor will appear in this list<br />

with ID ‘0’. To send data to this sensor<br />

we use the ‘snd’ c<strong>om</strong>mand. In its<br />

simplest form this has two parameters:<br />

‘snd 0 40’ sends the value 40 to<br />

the sensor with ID code ‘0’. The fi rst<br />

data byte is always interpreted by<br />

the sensor as a new beacon time, in<br />

units of 125 ms. In this example, the<br />

value of 40 corresponds to the default<br />

beacon time of fi ve seconds. So, if we<br />

type ‘snd 0 8’ we will set the beacon<br />

time for sensor 0 to one second, and<br />

data packets fr<strong>om</strong> this sensor will be<br />

displayed in the terminal window at<br />

this rate. The c<strong>om</strong>mand ‘snd 0 40 1’<br />

sets the beacon time back to fi ve seconds<br />

and also sends an extra data<br />

byte with value ‘1’, which will cause<br />

the LED on the node board to light. In<br />

the terminal example the code in the<br />

sensor simply checks whether there is<br />

an extra data byte beyond the beacon<br />

time or not, and sets the LED on or off<br />

accordingly. The actual value of the<br />

extra byte is not taken into account.<br />

The c<strong>om</strong>plete set of c<strong>om</strong>mands provided<br />

by the hub in the ‘terminal’ ex-<br />

Elektor blockbusters<br />

3/2007 - elektor electronics<br />

ample is listed in Table 3.<br />

If now a further sensor is activated<br />

another ‘bind request’ packet will appear<br />

among the data packets being received<br />

fr<strong>om</strong> the fi rst sensor, followed<br />

by a series of data packets. The ‘enu’<br />

c<strong>om</strong>mand can be used to list the registered<br />

sensors, and should now display<br />

two entries with ID codes ‘0’ and ‘1’.<br />

We can test the new sensor by adjusting<br />

its beacon time: ‘snd 1 8’ will set<br />

it to one second, and we should now<br />

receive packets fr<strong>om</strong> sensor 1 at fi ve<br />

times the frequency of those fr<strong>om</strong> sensor<br />

0. If an ‘x’ is used in place of the ID<br />

code in the send c<strong>om</strong>mand, the beacon<br />

times for all sensors are set simultaneously.<br />

Using ‘snd x 40’ we can therefore<br />

reset the beacon times for both sensors<br />

to fi ve seconds.<br />

If the data packets are to be processed<br />

on the host PC, the ‘hex’ c<strong>om</strong>mand<br />

can be used to switch the display<br />

fr<strong>om</strong> readable form to pure hex<br />

values. These can easily be read by<br />

another application, for example using<br />

the scanf() function.<br />

Ro<strong>om</strong> for expansion<br />

The supplied programs can form the<br />

basis of dedicated applications using<br />

iDwaRF modules: the possibilities are<br />

endless. Often a couple of extra c<strong>om</strong>ponents<br />

are all that is needed, for example<br />

to make measurements using an<br />

ADC, generate PWM waveforms, scan<br />

keys or drive an LCD.<br />

The iDwaRF-Net software can in theory<br />

work with up to 255 sensors, although<br />

at present the limit is 32. For larger<br />

sensor networks the xHub is planned,<br />

using an ATmega128 with more fl ash<br />

memory and an external SRAM. An external<br />

antenna will increase the range<br />

of the hub.<br />

Users of the iDwaRF radio module [7]<br />

and the iDwaRF-Net fi rmware can use<br />

a forum [8] organised by the author.<br />

This is in addition to the forum on the<br />

Elektor Electronics website. Further example<br />

programs will of course appear<br />

for download at [6] as soon as they bec<strong>om</strong>e<br />

available.<br />

(050402-I)<br />

References<br />

and links:<br />

[1] www.zigbee.org<br />

[2] www.cypress.c<strong>om</strong><br />

[3] Th<strong>om</strong>as Biel: ‘Wireless USB’,<br />

Elektor Electronics, September 2004, p. 8<br />

[4] www.atmel.c<strong>om</strong>/avr<br />

[5] Stefan Tauschek: ‘Wireless Connectivity’,<br />

Elektor Electronics, February 2005, p. 14<br />

[6] www.elektor-electronics.co.uk or<br />

www.chip45.c<strong>om</strong>/iDwaRF-168_Downloads<br />

[7] www.chip45.c<strong>om</strong>/iDwaRF-168<br />

[8] www.chip45.c<strong>om</strong>/iDwaRF-Net<br />

Wireless USB in miniature • 81<br />

51


HANDS-ON MICROCONTROLLERS<br />

A 16-bit T<strong>om</strong> Th<br />

Gunther Ewald and Burkhard Kainka<br />

Thanks to the efforts of Elektor Electronics and Glyn, for the first time now a European<br />

electronics magazine supplies a c<strong>om</strong>plete microcontroller starter board and acc<strong>om</strong>panying<br />

software CD-ROM at a very attractive price. We already introduced the Renesas R8C in the last<br />

issue. Now it’s time to start using it.<br />

Now it’s for real – fr<strong>om</strong> this issue you<br />

can order a circuit board with an<br />

R8C/13 microcontroller and the necessary<br />

software, at price consisting of<br />

P&P and handling only. The service is<br />

strictly limited to stocks and provided<br />

exclusively for Elektor Electronics<br />

readers in co-operation with Glyn.<br />

So if you want to grab an R8C starter<br />

kit, order it straight away — the online<br />

Elektor blockbusters<br />

38<br />

method using our website is by far the<br />

fastest.<br />

There are three good reasons for using<br />

the Renesas R8C/Tiny family: first, it<br />

provides 16-bit c<strong>om</strong>puting power at a<br />

low price; second, it c<strong>om</strong>es with a free<br />

but nevertheless very capable C c<strong>om</strong>piler;<br />

and third, no programming hardware<br />

is necessary, because code can<br />

be easily downloaded to flash mem-<br />

ory via the RS232 port. We already<br />

introduced the board and the software<br />

in the January 2006 issue. If you<br />

missed that article, you can download<br />

it free of charge fr<strong>om</strong> the Elektor Electronics<br />

website at www.elektor-electronics.co.uk<br />

(select the Magazine<br />

tab, then January 2006). Our objective<br />

in this article is to help you start<br />

using the board.<br />

A 16-bit T<strong>om</strong> Thumb • 82<br />

elektor electronics - 2/2006


umb<br />

Elektor blockbusters<br />

When installing the necessary<br />

software, follow<br />

the instructions exactly as<br />

given in order to ensure<br />

that what you later see<br />

on your PC matches<br />

what we describe here.<br />

Install the KD30 monitor/debugger<br />

first, followed<br />

by the NC30 C<br />

c<strong>om</strong>piler with the HEW<br />

development environment<br />

and an update.<br />

Installation in this order<br />

is important so the HEW<br />

will find the debugger<br />

already installed and link it in properly. Next, install the<br />

debugger package in order to integrate the debugger into<br />

the development environment. Later on, you only need to start<br />

the HEW in order to have everything together on your<br />

screen. Finally, you have to install the Renesas Flash<br />

Development Toolkit (FDT), which enables you to download<br />

finished programs to the microcontroller.<br />

After you insert the CD, a product summary in PDF format<br />

will be displayed first. You should see the main directory of<br />

the CD after you close the product summary. Alternatively,<br />

you can right-click on the drive icon and select ‘Open’ in<br />

order to skip the PDF intro. The most important directories on<br />

the CD are \Software and \Sample_NC30. They contain all<br />

the necessary programs (which should now be installed) and<br />

the initial sample projects.<br />

1. KD30<br />

The executable installer file KD30V410R1_E_20041203.exe.<br />

is located in the \Software\kd30400r1\ directory on the<br />

CD. Start the installation and confirm the default path<br />

C:\MTOOL\.<br />

2. NC30<br />

Run the setup file nc30wav530r02_2_ev.exe in the<br />

\Software\ nc30v530r0_hew\ directory on the CD. First you<br />

have to select whether you want to install the Japanese version<br />

or the English version. Most of our readers will probably<br />

prefer the English version. The program suggests C:\Program<br />

Files\Renesas as the default installation path. You should confirm<br />

this path.<br />

A second default path is shown for the tool chain:<br />

C:\Renesas\NC30WA\V530R02. You should also accept the<br />

default path name, as well as all subsequent default path names.<br />

At the end of the installation, an individual site code is displayed.<br />

You can ignore it, because it is only necessary for<br />

registering the software. If you purchase the full version of the<br />

c<strong>om</strong>piler, you will aut<strong>om</strong>atically receive a CD with your own<br />

Our R8C starter kit is available<br />

– now you can get going!<br />

The software<br />

code for enabling the<br />

software.<br />

After you have installed<br />

the HEW, you have to<br />

run the installer for the<br />

AutoUpdate program. As<br />

shown in the figure, confirm<br />

that you wish to<br />

receive weekly updates<br />

fr<strong>om</strong> the Renesas Tools<br />

website. That enables<br />

you to keep your software<br />

‘fresh’ all the time.<br />

If the PC on which your<br />

software is installed does<br />

not have access to the Internet, you can cancel installation of<br />

AutoUpdate without causing any problems. The most recent<br />

update file is on the CD, and it must be installed next.<br />

After being installed, the updater immediately checks to see<br />

whether there is anything new and aut<strong>om</strong>atically downloads<br />

the latest changes. The first update will then be installed aut<strong>om</strong>atically.<br />

The PC must then be restarted before you continue.<br />

3. Update HEW<br />

This step is only necessary if you have not already downloaded<br />

the latest update fr<strong>om</strong> the Internet and installed it. Run<br />

the first HEW update fr<strong>om</strong> the CD by starting<br />

hewv40003u.exe in the<br />

\Software\HEW_V.4.00.03.001_Update directory on the<br />

CD. That will update your c<strong>om</strong>piler to the latest version<br />

(Database Version 7.0). That is important, because the sample<br />

projects have been generated for this version. Although<br />

you can use the new version to load older projects, which<br />

will then be updated aut<strong>om</strong>atically, regressing to an older<br />

version of the c<strong>om</strong>piler is not that easy.<br />

4. Debugger package<br />

Run the installer file m16cdebuggerv100r01.exe in the<br />

\Software\Debugger Package\ directory on the CD. Follow<br />

the instructions of the installer program and confirm your<br />

agreement to the licence conditions. Everything else is aut<strong>om</strong>atic.<br />

You must restart the c<strong>om</strong>puter after this installation.<br />

5. Flash Development Toolkit<br />

Install the FDT by running the installer file fdtv304r00.exe in<br />

the \Software\Flasher_FDT directory on the CD. Confirm all<br />

default settings. Everything else is aut<strong>om</strong>atic.<br />

When everything has been installed, you will find the<br />

Renesas program group under Start / All Programs. The two<br />

relevant programs in the group are High-performance<br />

Embedded Workshop and Flash Development Toolkit.<br />

A 16-bit T<strong>om</strong> Thumb • 83<br />

2/2006 - elektor electronics 39


HANDS-ON MICROCONTROLLERS<br />

40<br />

Figure 1. The hardware you can order fr<strong>om</strong> us at low cost forms a c<strong>om</strong>plete microcontroller system.<br />

SUB-D9<br />

+9V<br />

1<br />

2 RXD<br />

3 TXD<br />

Elektor blockbusters<br />

6<br />

7<br />

8<br />

4<br />

9<br />

5<br />

27k<br />

1N4004<br />

Figure 2. The fully assembled board with the pin headers fitted.<br />

10k<br />

4k7<br />

BC<br />

548C<br />

78L05<br />

100n 100n<br />

R8C/13<br />

1<br />

RXD1 TXD1<br />

32<br />

2<br />

AN6<br />

31<br />

3<br />

RESET AN5<br />

30<br />

4<br />

AN4<br />

29<br />

5<br />

VSS MODE<br />

28<br />

6<br />

AN3<br />

27<br />

7<br />

VCC<br />

AN2<br />

26<br />

8<br />

P17<br />

AN1<br />

25<br />

9<br />

P16<br />

AN0<br />

24<br />

10<br />

P15<br />

23<br />

11<br />

P14<br />

P30<br />

22<br />

12<br />

P13<br />

21<br />

13<br />

P12<br />

P31<br />

20<br />

14<br />

P11<br />

19<br />

15<br />

P10<br />

P32<br />

18<br />

16<br />

P45 P33<br />

17<br />

Figure 3. The circuit diagram of a minimal system for initial tests.<br />

100k<br />

10k<br />

BC<br />

558C<br />

050179 - 2 - 11<br />

The hardware<br />

The low-profile PCB with pre-assembled<br />

SMD c<strong>om</strong>ponents is supplied with<br />

two pin headers that you must fit and<br />

solder yourself (Figure 1). That yields<br />

a c<strong>om</strong>plete processor module in the<br />

format of a 32-pin DIL IC (Figure 2).<br />

There is also space reserved on the<br />

board for a 14-way pin header, but it<br />

does not have to fitted right away<br />

because it is only needed for the E8<br />

debugger.<br />

The actual microcontroller (the R8C/13)<br />

is contained in the 32-pin LQPF SMD<br />

package, which measures 7 by 7 mm<br />

and has a lead spacing of 0.8 mm. The<br />

marking ‘R5F21134FP#U0’ reveals that<br />

it is an R8C/13 with 16 KB of flash<br />

ROM. We selected the R8C/13 because<br />

it has the same characteristics as its<br />

‘siblings’ (R8C/10, R8C/11 and<br />

R8C/12). The board also c<strong>om</strong>es fitted<br />

with a 20-MHz crystal and the necessary<br />

capacitors, as well as several<br />

other capacitors and resistors. Altogether,<br />

this amounts to a c<strong>om</strong>plete<br />

microcontroller system. Once a program<br />

has been loaded, all you have to<br />

do is connect a 3.3-V or 5-V supply voltage<br />

and you’ve got a working system.<br />

Program code can be loaded using a<br />

serial interface; no special programming<br />

hardware is necessary. That’s<br />

because the microcontroller has a<br />

debug interface and a corresponding<br />

boot program that can be used to copy<br />

the software into the flash ROM.<br />

First contact<br />

In the next issue of Elektor Electronics,<br />

we will describe a c<strong>om</strong>plete development<br />

system with RS232 and USB<br />

interfaces. But you naturally don’t<br />

want to wait that long to try out the<br />

board. For that reason, we describe a<br />

solution here that only requires a few<br />

c<strong>om</strong>ponents fr<strong>om</strong> your parts bin:<br />

• a source of 5-V power, preferably stabilised<br />

by a voltage regulator<br />

• an inverting level converter for connection<br />

to the RS232 port<br />

• a pushbutton reset switch<br />

• a mode switch to select the programming<br />

mode<br />

The microcontroller board feeds out all<br />

the microcontroller leads one to one.<br />

As we already mentioned, a crystal, a<br />

few capacitors and s<strong>om</strong>e resistors are<br />

fitted on the board. The schematic diagram<br />

in Figure 3 shows only the con-<br />

A 16-bit T<strong>om</strong> Thumb • 84<br />

elektor electronics - 2/2006


Elektor blockbusters<br />

nections that are essential for a ‘quick<br />

start’, so you can get your bearings as<br />

fast as possible. The connections not<br />

shown in the figure must always<br />

remain open. Figure 4 shows an experimental<br />

setup on a prototyping board.<br />

The serial port of the PC is connected<br />

here via transistor inverters. Although<br />

a MAX232 could be used just as well<br />

for this purpose, the transistors will<br />

probably be easier to find in your parts<br />

bin. A BC548C NPN transistor inverts<br />

the TXD signal fr<strong>om</strong> the PC and feeds<br />

it to the RXD1 input of the microcontroller.<br />

This input does not have an<br />

internal pull-up, so the collector resistor<br />

is essential. In the opposite direction,<br />

TXD1 drives a BC558C PNP transistor.<br />

The RXD input of the PC has its own<br />

pull-down, so the collector resistor can<br />

be <strong>om</strong>itted here.<br />

The MODE input of the microcontroller<br />

determines whether the internal<br />

boot program or a downloaded<br />

user program is run after a reset. The<br />

MODE input is pulled high by a 10-k�<br />

resistor when the switch is open,<br />

which causes the user program to be<br />

started. If you want to load a program<br />

into the flash memory, you first have<br />

to close the switch in order to pull<br />

MODE low. Then you must briefly<br />

press the Reset switch. That causes<br />

the microcontroller to start up in the<br />

debug mode, which allows new software<br />

to be loaded into the flash ROM.<br />

After the software has been transferred,<br />

open the Mode switch and<br />

press the Reset switch again. That<br />

causes the downloaded program to be<br />

started. However, duty c<strong>om</strong>es before<br />

pleasure, and in this case the duty is<br />

installing the software on the PC.<br />

That’s described step-by-step in the<br />

inset. Follow the instructions exactly<br />

as given in order to ensure that what<br />

you later see on your PC matches<br />

what we describe here.<br />

Ready, set, flash!<br />

The first thing you should do is to try<br />

out the Flash Development Toolkit<br />

(FDT) by downloading a finished program<br />

to the microcontroller. For the<br />

time being, we’ll skip the process of<br />

developing you own programs, so you<br />

can enjoy s<strong>om</strong>e tangible results as<br />

soon as possible.<br />

After installing the Renesas software<br />

package, you will find the FDT program<br />

in the Windows ‘Start’ menu. The<br />

program is shown there in two versions:<br />

a full version and a c<strong>om</strong>pact<br />

Figure 4. A prototype of the test system built on a lab prototyping board.<br />

‘Basic’ version. Start ‘Flash Development<br />

Toolkit Basic’ (Figure 5).<br />

You must configure several settings<br />

the first time you start the program.<br />

If necessary, you can access them<br />

later on via the Options / New Settings<br />

menu. Select ‘R5F21134’ as the<br />

microcontroller type, and select the<br />

upper of the two core protocol options<br />

(Figure 6).<br />

In the next window, select the serial<br />

interface port fr<strong>om</strong> the range<br />

COM1–COM4. The third window asks<br />

you to specify a baud rate for the link<br />

to the microcontroller. Enter ‘9600<br />

baud’ here (Figure 7).<br />

Finally, you have to specify whether<br />

you want to enable readout protection<br />

for the microcontroller. As the risk of<br />

criminal industrial espionage is rather<br />

small with the initial familiarisation<br />

programs, you can dispense with any<br />

form of protection. Save the settings as<br />

shown in Figure 8. That c<strong>om</strong>pletes the<br />

preparations.<br />

Hurrah, it blinks!<br />

Now connect the board to the specified<br />

COM port on your PC. Close the Mode<br />

switch and briefly press the Reset<br />

switch. The microcontroller will enter<br />

boot mode and wait for you to send it<br />

data.<br />

The next step is to download a fully<br />

c<strong>om</strong>piled program to the microcontroller.<br />

On the CD, you will find the<br />

‘Sample NC30’ folder with several sample<br />

projects. That includes the project<br />

folder ‘Sample_NC30\ port_toggle’,<br />

which contains the folder ‘port_toggle\<br />

Release’. The file port_toggle.mot is<br />

located in the latter folder. It is a program<br />

in Motorola hex format that can<br />

be downloaded directly to the microcontroller.<br />

Specify the path to this file, and then<br />

start the download process by selecting<br />

‘Program Flash’. The download<br />

takes around two seconds. The flash<br />

memory is first erased, and the new<br />

program is then copied over. If everything<br />

goes properly, the message<br />

‘Image successfully written to device’<br />

will be displayed. Open the Mode<br />

switch and briefly press the Reset<br />

switch. That will start the program<br />

that you just downloaded.<br />

The program toggles the first four<br />

lines of Port 1 (P1_0 to P1_4) at a slow<br />

rate, so you can observe their states<br />

using a LED with a series resistor. The<br />

ports of the R8C and the other M16<br />

microcontrollers have a low impedance<br />

in the output direction, regardless<br />

of whether they are in the high or<br />

low state. That means you must<br />

always use a series resistor (1 k�, for<br />

A 16-bit T<strong>om</strong> Thumb • 85<br />

2/2006 - elektor electronics 41


HANDS-ON MICROCONTROLLERS<br />

example) when connecting a LED to<br />

them (Figure 9).<br />

All of the sample programs described<br />

below can be copied to the microcontroller<br />

in the manner just described. If<br />

the R8C cannot be flashed due to a<br />

c<strong>om</strong>munication error, it must be left<br />

without power for one minute to erase<br />

the internal RAM loader. This error can<br />

occur if you have been working with<br />

the debugger before attempting to<br />

download a program.<br />

The R8C as a musician<br />

Like to try another hardware test?<br />

Elektor blockbusters<br />

42<br />

Figure 5. The Flash Development Toolkit, Basic version.<br />

Then download the ‘Jingle_Bells’<br />

Motorola file fr<strong>om</strong> the R8C project to<br />

the microcontroller. Connect a small 8-<br />

� loudspeaker or a headphone with a<br />

1-k� series resistor to the board (Figure<br />

10), and then start the microcontroller.<br />

You will hear a simple melody.<br />

Incidentally, this program uses the<br />

internal high-speed ring oscillator<br />

(8 MHz) and does not require the crystal<br />

oscillator. If you touch an oscilloscope<br />

probe to the crystal lead Xin<br />

(pin 6) or Xout (pin 4), you will see that<br />

no clock signal is present (in contrast<br />

to the situation with the port_toggle<br />

project). As you can hear fr<strong>om</strong> the<br />

Figure 6. Selecting the microcontroller type and transmission protocol.<br />

absence of any sour notes c<strong>om</strong>ing fr<strong>om</strong><br />

the speaker, the internal RC oscillator<br />

is fully adequate for this task. That<br />

means you could flash the program<br />

into an R8C/13, connect it to a piezoelectric<br />

speaker and a 3-V button cell,<br />

and hang it fr<strong>om</strong> your Christmas tree<br />

or insert it in a Christmas card.<br />

Now that you know the hardware is<br />

OK, your fingers are probably itching<br />

to start programming s<strong>om</strong>ething,<br />

aren’t they? OK, it’s time to start up<br />

the integrated hardware development<br />

environment (HEW). In order to keep<br />

things fairly simple at first, let’s start<br />

by making a few changes to an existing<br />

project. We’ll also work without the<br />

debugger to start with.<br />

High C<br />

You can use HEW to generate assembly-language<br />

projects. However, programming<br />

the R8C in assembly language<br />

is significantly more difficult<br />

than programming it in C, because<br />

there are so many different data formats<br />

and addressing modes. The C<br />

c<strong>om</strong>piler looks after all that for you. You<br />

don’t even have to know whether the<br />

microcontroller is processing a word, a<br />

byte or a bit. In this case, C is easier<br />

than assembly language even for people<br />

who are only used to working in<br />

assembly language. The unfamiliar<br />

notation will quickly bec<strong>om</strong>e second<br />

nature after you work through a few<br />

examples, so there’s no need to be<br />

afraid of C!<br />

First copy the entire ‘port_toggle’ project<br />

fr<strong>om</strong> the CD to your PC. When you<br />

start a new project, use a directory<br />

such as C:\WorkSpace, which is also<br />

the default directory suggested by<br />

HEW. In the Renesas program group,<br />

start the ‘High-Performance Embedded<br />

Workshop’ program. A selection<br />

window is displayed when the program<br />

starts, and you can specify<br />

whether you want to generate a new<br />

project or open an existing project.<br />

Use File/ Open Workspace to open the<br />

port_toggle file. All the files belonging<br />

to the project will then be shown at the<br />

left. Click on port_toggle.c to open the<br />

source code file. Everything should<br />

then appear as shown in Figure 11.<br />

Next, you should try to c<strong>om</strong>pile the<br />

project, just for the exercise. First you<br />

have to decide whether you want to<br />

generate a debug version or a release<br />

version. You should work without the<br />

debugger for now, which means you<br />

should select the ‘Release’ option<br />

A 16-bit T<strong>om</strong> Thumb • 86<br />

elektor electronics - 2/2006


Elektor blockbusters<br />

under Build / Build Configurations.<br />

Then start the c<strong>om</strong>pilation by selecting<br />

Build / Build All. The C source code<br />

will be c<strong>om</strong>piled, linked, and written to<br />

the output directory \Release in the<br />

form of a Motorola hex file. The entire<br />

process is listed at the bott<strong>om</strong> of the<br />

Build window. At the end, you’ll see<br />

the longed-for message that signals<br />

success:<br />

Build Finished<br />

0 Errors, 1 Warning<br />

No errors – that’s very good! Warnings<br />

occur relatively often and aren’t all that<br />

dramatic. In this case, the warning<br />

reads: ‘Warning (ln30): License has<br />

expired, code limited to 64K (10000H)<br />

byte(s)’. You don’t have to worry about<br />

that, because you’re using the free version<br />

of the c<strong>om</strong>piler, and 64 kB is anyhow<br />

more than R8C/13 can hold. If you<br />

wish, you can download the output file<br />

to the microcontroller again and run<br />

the program. It will work just as well<br />

as the Motorola hex file on the CD.<br />

Now let’s have a look at the source<br />

code:<br />

while (1) /* Loop */<br />

{<br />

p1_0 = 0;<br />

p1_1 = 0;<br />

p1_2 = 0;<br />

p1_3 = 0;<br />

for (t=0; t


HANDS-ON MICROCONTROLLERS<br />

cm05 = 0; /* Xin on */<br />

cm16 = 0; /* Main clock = No<br />

division mode */<br />

cm17 = 0;<br />

cm06 = 0; /* CM16 and CM17<br />

enable */<br />

asm(“nop”); /* Waiting for<br />

stable oscillation */<br />

asm(“nop”);<br />

asm(“nop”);<br />

asm(“nop”);<br />

ocd2 = 0; /* Main clock<br />

change */<br />

prc0 = 0; /* Protect on */<br />

The above listing shows the relevant<br />

instruction lines at the beginning of<br />

the source code. It’s necessary to<br />

change a few control bits in System<br />

Clock Control Registers 0 and 1, but<br />

they are initially in protected mode.<br />

This protection is disabled in the first<br />

line so the relevant control bits can be<br />

altered. After the bits have been<br />

44<br />

P1- 0<br />

Elektor blockbusters<br />

1k<br />

050179 - 2 - 20<br />

LED<br />

Figure 9. Connecting a LED to P1_0.<br />

P1- 0<br />

switched, we have to wait a little<br />

while for the oscillator to stabilise after<br />

being started up. After this, the clock<br />

source is changed and write protection<br />

is re-enabled. Fr<strong>om</strong> now on, all programs<br />

will run at 20 MHz.<br />

If you now remove this entire block of<br />

code fr<strong>om</strong> the listing, including prc0 =<br />

1 and prc0 = 0, the oscillator will not<br />

be changed and the microcontroller<br />

will continue operating at 125 kHz. To<br />

make it possible to observe the result<br />

within a finite length of time, you must<br />

also shorten the wait loops by a factor<br />

of 100:<br />

void main(void)<br />

{<br />

pd1 = 0x0F; /* Set Port 1.0 -<br />

1.3 be used for output*/<br />

1k<br />

050179 - 2 - 21<br />

Figure 10. Connecting a loudspeaker to the<br />

microcontroller.<br />

while (1) /* Loop */<br />

{<br />

p1_0 = 0;<br />

Figure 11. The port_toggle project in the development environment.<br />

}<br />

p1_1 = 0;<br />

p1_2 = 0;<br />

p1_3 = 0;<br />

for (t=0; t


PROJECTS MICROCONTROLLERS<br />

USB Flash Board<br />

An 8051-based system for rapid software<br />

Alexander Kniel<br />

Flash microcontrollers are easy to program, which makes them suitable for rapid software development<br />

environments and educational uses. In the past, program code was usually downloaded via a serial<br />

interface, but nowadays many PCs (especially laptops) only have USB ports. Our versatile Flash Board<br />

provides a solution to this problem. It is built around an AT89C5131A, which is an extended 8051-family<br />

microcontroller with an 80C52 core and a Full Speed USB port. As a sort of bonus, the IC has a c<strong>om</strong>plete<br />

update interface for downloading new firmware. Atmel also provides suitable software in the form of its<br />

FLIP program, which is available free of charge.<br />

The Flash Microcontroller Board originally<br />

published in December 2001<br />

is well known to Elektor readers,<br />

and it has helped many readers get<br />

started in the world of microcontrollers.<br />

That’s hardly surprising, since<br />

microcontrollers with flash memory,<br />

such as the AT89C8252 used in the<br />

original Flash Board, are easy to program.<br />

As with many other similar<br />

boards used for educational purposes,<br />

the code is downloaded fr<strong>om</strong> a<br />

development PC to the microcontroller<br />

via a serial interface. Unfortunately,<br />

the good old RS232 interface is<br />

bec<strong>om</strong>ing increasingly rare. Laptops<br />

in particular often have only USB<br />

ports and no longer c<strong>om</strong>e with printer<br />

ports or serial ports. If a teacher<br />

wants to give his students training<br />

boards that they can also program at<br />

h<strong>om</strong>e using a laptop, a different approach<br />

is necessary.<br />

The author, an electronics instructor<br />

at a vocational/technical school in<br />

Heilbronn (Germany), thus developed<br />

a version of the Flash Board based on<br />

a modern microcontroller with a USB<br />

interface. For this purpose he selected<br />

the Atmel AT89C5131AM, which has<br />

an 80C52 core and thus belongs to the<br />

8051 family, just like the AT89C8252.<br />

The IC incorporates an Full Speed USB<br />

Elektor blockbusters<br />

port, and it is specifically designed for<br />

use in USB devices such as printers,<br />

cameras, and so on. As a sort of bonus,<br />

the microcontroller has a c<strong>om</strong>plete<br />

update interface for downloading new<br />

firmware. This in particular enabled<br />

the author, who has a weakness for<br />

hardware and all sorts of programming<br />

languages, to build an extremely simple<br />

USB Flash Board because Atmel also<br />

provides suitable software in the form<br />

of its FLIP program, which is available<br />

free of charge. All you have to do is provide<br />

the program code in a hex file and<br />

you’re ready to go.<br />

Generation-2 Flash Board<br />

Many copies of the first version of the<br />

new board developed by Alexander<br />

Kniel have already been built by students<br />

and used with laptop c<strong>om</strong>puters.<br />

The board design was modified<br />

slightly in the Elektor lab, and among<br />

other things Elektor designer Chris<br />

Vossen added an LCD interface. The<br />

board thus follows in the footsteps of<br />

the 2001 version of the Elektor Flash<br />

Microcontroller Board and is suitable<br />

for not only learning how to program<br />

microcontrollers, but also for mature<br />

applications in device controllers, robots,<br />

and many other areas.<br />

Everything revolves around the abo-<br />

ve-mentioned AT89C5131AM, which<br />

is an extended member of the 8051 family.<br />

Its core is an 80C52X2 with six<br />

clocks per instruction cycle. Besides<br />

32 KB of flash memory, the IC has<br />

1024 bytes of extended RAM, additional<br />

EEPROM, and many other useful<br />

peripherals. Another helpful feature is<br />

that the M version of the microcontroller<br />

can also operate at 5 V, and a version<br />

in the user-friendly PLCC52 package<br />

is available. However, probably the<br />

most important feature is the USB 1.1<br />

/ USB 2.0 Full Speed module (for the<br />

experts: with endpoint 0 for control<br />

transfers and six additional endpoints<br />

with up to 512 bytes of FIFO memory).<br />

If you want to develop USB software,<br />

this gives you everything you<br />

could wish for, although you do need<br />

a bit of technical expertise. Everyone<br />

else can regard the microcontroller as<br />

a normal 8051 device that can be programmed<br />

via USB.<br />

The schematic diagram (Figure 1)<br />

shows a dual power supply that can<br />

draw power either fr<strong>om</strong> the USB bus<br />

or (with jumper JP4 fitted) via voltage<br />

regulator IC2 fr<strong>om</strong> an AC adapter connector<br />

K9. The D+ and D– pins of the<br />

Figure 1. Schematic diagram of the USB Flash Board.<br />

USB Flash Board • 89<br />

22 elektor - 11/2007


development<br />

Elektor blockbusters<br />

11/2007 - elektor<br />

100R<br />

K2<br />

5<br />

6<br />

R5<br />

C4<br />

10n<br />

K9<br />

S1<br />

1<br />

2<br />

3<br />

4<br />

+5V<br />

C3<br />

2n2<br />

+5V<br />

+5V<br />

4k7<br />

R6<br />

4k7<br />

R11<br />

R4<br />

1k5<br />

R2<br />

27R<br />

R3<br />

27R<br />

K4<br />

1 2<br />

3 4<br />

5 6<br />

1 2 P1.0<br />

P1.1 3 4 P1.2<br />

P1.3 5 6 P1.4<br />

P1.5 7 8 P1.6<br />

P1.7 9 10<br />

C8<br />

10u<br />

16V<br />

K6<br />

JP2<br />

2<br />

JP3<br />

4k7<br />

R10<br />

1k<br />

24<br />

VREF<br />

23<br />

D+<br />

D-<br />

22<br />

21<br />

C1<br />

100n<br />

PLLF<br />

26<br />

EA<br />

34<br />

NC<br />

NC<br />

46<br />

7<br />

P4.0<br />

P4.1<br />

8<br />

27<br />

ALE<br />

47<br />

P1.0<br />

48<br />

P1.1<br />

49<br />

P1.2<br />

50<br />

P1.3<br />

51<br />

P1.4<br />

4<br />

P1.5<br />

5<br />

P1.6<br />

6<br />

P1.7<br />

43<br />

RESET<br />

28<br />

PSEN<br />

18<br />

UCAP<br />

C9<br />

1u<br />

16V<br />

D9<br />

3<br />

1<br />

D10<br />

IC2<br />

7805<br />

1 3<br />

BAT46<br />

JP4<br />

2<br />

1N4001<br />

C12<br />

C13 C14<br />

1000u<br />

16V<br />

100u<br />

16V<br />

100n<br />

R7<br />

P1.0<br />

P1.1<br />

P1.2<br />

P1.3<br />

P1.4<br />

P1.5<br />

P1.6<br />

P1.7<br />

25<br />

UCAP<br />

19<br />

AVSS<br />

AVDD 17<br />

12<br />

X1<br />

VDD 16<br />

IC1<br />

AT89C5131<br />

C10<br />

D11<br />

6V2<br />

22p<br />

+5V<br />

+5V<br />

X1<br />

24MHz<br />

13<br />

X2<br />

C11<br />

22p<br />

D12<br />

C15 C16<br />

100n 100n<br />

C2<br />

100n<br />

41<br />

52 P0.0<br />

P0.0<br />

45 P0.1<br />

P0.1<br />

44 P0.2<br />

P0.2<br />

42 P0.3<br />

P0.3<br />

40 P0.4<br />

P0.4<br />

38 P0.5<br />

P0.5<br />

37 P0.6<br />

P0.6<br />

36 P0.7<br />

P0.7<br />

1 P2.0<br />

P2.0<br />

2 P2.1<br />

P2.1<br />

3 P2.2<br />

P2.2<br />

9 P2.3<br />

P2.3<br />

10 P2.4<br />

P2.4<br />

11 P2.5<br />

P2.5<br />

14 P2.6<br />

P2.6<br />

15 P2.7<br />

P2.7<br />

20 P3.0<br />

P3.0<br />

29 P3.1<br />

P3.1<br />

30 P3.2<br />

P3.2<br />

31 P3.3<br />

P3.3<br />

32 P3.4<br />

P3.4<br />

33 P3.5<br />

P3.5<br />

35 P3.6<br />

P3.6<br />

39 P3.7<br />

P3.7<br />

VSS<br />

1k5<br />

R12<br />

+5V<br />

P0.6<br />

P0.4<br />

P0.2<br />

P0.0<br />

P2.3 14<br />

P2.1 12<br />

10<br />

8<br />

P2.4 6<br />

P2.7 4<br />

2<br />

K3<br />

1 2<br />

3 4<br />

5 6<br />

7 8<br />

9 10<br />

K7<br />

K8<br />

+5V<br />

P0.7<br />

P0.5<br />

P0.3<br />

P0.1<br />

13 P2.2<br />

11 P2.0<br />

9<br />

7<br />

5<br />

3<br />

1<br />

1 2 P3.0<br />

P3.1 3 4 P3.2<br />

P3.3 5 6 P3.4<br />

P3.5 7 8 P3.6<br />

P3.7 9 10<br />

P3.2<br />

P3.3<br />

P3.0<br />

P3.1<br />

P0.0<br />

D1<br />

P0.1<br />

C6 C7<br />

100n 100n<br />

1<br />

2<br />

3<br />

4<br />

5<br />

6<br />

7<br />

8<br />

9<br />

D2<br />

P0.2<br />

C5<br />

100n<br />

+5V<br />

D3<br />

P0.3<br />

+5V<br />

P1<br />

10k<br />

9<br />

8<br />

D4<br />

S3 S4 S5 S6<br />

+5V<br />

P0.4<br />

JP1<br />

7<br />

6<br />

D5<br />

1<br />

P0.5<br />

5<br />

4<br />

D6<br />

R1<br />

1k5<br />

P0.6<br />

3<br />

2<br />

1 2 3<br />

D7<br />

4<br />

P0.7<br />

D8<br />

R9<br />

10k<br />

P3.4<br />

P3.5<br />

P3.6<br />

P3.7<br />

S2 8 7 6 5<br />

070125 - 11<br />

USB Flash Board • 90<br />

23


PROJECTS MICROCONTROLLERS<br />

K9<br />

14<br />

13<br />

K7<br />

K4<br />

2<br />

1<br />

R6<br />

R7<br />

070125-1<br />

(C) Elektor<br />

IC2<br />

C11<br />

C10<br />

X1<br />

C2<br />

C9<br />

C4<br />

1 2 3<br />

C14<br />

C3<br />

C12<br />

D10<br />

microcontroller are for the USB data<br />

lines. To activate the internal USB<br />

boot loader, a low signal level must<br />

be applied to PSEN via JP2 (jumper<br />

toward the edge of the board).<br />

When reset switch S1 is pressed, the<br />

boot loader starts up and receives<br />

data via the USB port. Jumper posi-<br />

6<br />

5<br />

+<br />

C1<br />

R5<br />

C5<br />

JP3<br />

+<br />

+<br />

C13<br />

R12<br />

D9<br />

IC1<br />

D11<br />

R10<br />

R2<br />

D12<br />

JP4<br />

Figure 2. Assembling the circuit board should not present any problems.<br />

C<strong>om</strong>ponents<br />

list<br />

Resistors<br />

R1 = 1k�5 8-way SIL array<br />

R2,R3 = 27�<br />

R4,R12 = 1k�5<br />

R5 = 100�<br />

R6,R7,R11 = 4k�7<br />

R9 = 8-way 10k� array<br />

R10 = 1k�<br />

P1 = 10k� potenti<strong>om</strong>eter<br />

P1<br />

Capacitors<br />

C10,C11=22pF<br />

C3 = 2nF2<br />

C4 = 10nF<br />

C1,C2,C5,C6,C7,C14,C15,C16 = 100nF<br />

C8 = 10μF 16V<br />

C9 = 1μF 16V<br />

C12 = 1000μF 16V<br />

C13 = 100μF 25V<br />

Elektor blockbusters<br />

2<br />

1<br />

10<br />

9<br />

JP1<br />

JP2<br />

1<br />

2<br />

10<br />

9<br />

K6 D1 D2<br />

K3<br />

D3 D4 D5 D6 D7 D8<br />

R11<br />

R9<br />

S3 S1<br />

C15<br />

R4<br />

R3<br />

S5 S4<br />

S6<br />

ON<br />

1 234<br />

K2<br />

tion JP3 must be closed (jumper toward<br />

IC2) to activate the USB port.<br />

This connects pullup resistor R4 to<br />

the D+ line, which indicates a Full<br />

Speed USB device to the PC. If you<br />

would like to have a more convenient<br />

way to switch between run mode<br />

and download mode, you can connect<br />

a changeover switch to JP2 and JP3.<br />

It can be fitted directly on the PCB or<br />

mounted on a front panel.<br />

Four full-fledged 8-bit ports<br />

The microcontroller has four fullfledged<br />

8-bit ports, each of which is<br />

accessible via a connector and/or assigned<br />

a specific peripheral function.<br />

Port P0 is available on K3, and it also<br />

drives eight LEDs that can be connected<br />

to VDD (+5 V) via series resistors.<br />

Port P1 is freely usable and<br />

accessible via K6. Port P2 is wired to<br />

LCD connector K7. An LCD module<br />

can be operated in 4-bit mode via this<br />

connector, and a contrast adjustment<br />

trimpot is provided on the board. Finally,<br />

port P3 is specifically intended<br />

to be used for inputs, and it can be<br />

accessed externally via K8. For testing<br />

user-developed programs, the board<br />

is fitted with pullup resistors, four<br />

pushbutton switches (P3.0…P3.3),<br />

and four DIP switches (P3.4…P3.7) on<br />

port 3. Switches normally require debouncing,<br />

which can usually be implemented<br />

in software. The P3.2 and P3.3<br />

lines have supplementary hardware<br />

debouncing in the form of capacitors<br />

C6 and C7, since these lines are connected<br />

to the interrupt inputs of the<br />

microcontroller. We also mustn’t forget<br />

port P4 with the P4.0 and P4.1 lines,<br />

which form the I2C bus interface and<br />

are accessible via K4.<br />

The bare PCB for the USB Flash Board<br />

(Figure 2) is available fr<strong>om</strong> the Elektor<br />

Shop under order number 070125-<br />

1. Alternatively, you can purchase a<br />

c<strong>om</strong>plete kit with all the c<strong>om</strong>ponents<br />

under order number 070125-71. Assembling<br />

the board is not difficult.<br />

Be sure to avoid creating any shorts<br />

between D+, D– or the 5 V supply<br />

line and ground in the area around<br />

the USB socket. As there is no special<br />

protection for the D+, D- and 5-V<br />

supply lines, it’s a good idea to check<br />

this with an ohmmeter – but be sure<br />

to remove the microcontroller fr<strong>om</strong> its<br />

socket first. There is ro<strong>om</strong> for an extra<br />

100-nF ceramic capacitor beneath<br />

the IC socket, which should be fitted<br />

first. It provides optimal supply voltage<br />

decoupling.<br />

Initial operation<br />

You should use an AC adapter (8–<br />

12 V DC) for initial testing. Fit jumper<br />

JP4 to select this power source. LED<br />

D1 should light up now. If you have<br />

already connected an LCD module, it<br />

24 elektor - 11/2007<br />

1<br />

2<br />

R1<br />

+<br />

S2<br />

C7 C6<br />

C8<br />

2<br />

1<br />

K8<br />

10<br />

9<br />

Semiconductors<br />

D1-D8,D12 = LED, red, low-current<br />

D9 = BAT46<br />

D10 = 1N4001<br />

D11 = zener diode 6V2<br />

IC1 = AT89C5131AM<br />

IC2 = 7805<br />

X1 = 12MHz quartz crystal<br />

Miscellaneous<br />

JP1,JP4 = 2-way SIL pinheader<br />

JP2,JP3 = 3-way SIL pinheader<br />

K2 = USB-A socket<br />

K3,K6,K8 = 10-way boxheader<br />

K4 = 6-way (2x3) pinheader<br />

K7 = 14-way boxheader<br />

K9 = mains appliance socket, PCB mount<br />

S1,S3-S6 = miniature pushbutton<br />

PLCC socket<br />

PCB, # 070125-1 fr<strong>om</strong> Elektor SHOP<br />

Kit of parts, # 070125-71 fr<strong>om</strong> Elektor<br />

SHOP<br />

USB Flash Board • 91


should display dark pixels in the top<br />

line. If necessary, adjust the contrast<br />

trimpot until both lines are clearly distinguishable.<br />

The upper line will remain<br />

dark until the board has been initialised<br />

with a program. If you have an<br />

oscilloscope, you can also check the 12-<br />

MHz clock signal on the crystal. This<br />

clearly shows that the microcontroller<br />

is running.<br />

You have to download a program for<br />

the first real software test. For this<br />

purpose, you can use the Flexible In-<br />

System Programmer (FLIP) software,<br />

which you can download free of charge<br />

fr<strong>om</strong> Atmel’s h<strong>om</strong>e page (www.atmel.<br />

c<strong>om</strong>). Enter ‘Flip’ as the search term<br />

to find FLIP 2.4.6 for Windows (4 MB,<br />

Version 2.4.6, updated May 2006). First<br />

extract the contents of archive file flip-<br />

2_4_6.zip to a separate folder and then<br />

run the Setup.exe file in that folder. Follow<br />

the installation instructions and<br />

accept the licence conditions and suggested<br />

installation location. You will<br />

then see a short list of instructions for<br />

what you have to do next (Figure 3).<br />

The program is installed by default in<br />

C:\Program Files\Atmel\FLIP 2.4.6\.<br />

Now connect a cable to the USB connector<br />

and fit jumper JP2 in the ‘USB’<br />

position (toward the edge of the<br />

board). To be on the safe side, press<br />

reset switch S1 and close JP3. This<br />

starts the USB download firmware,<br />

which waits for contact with the PC to<br />

be established. The program reports<br />

vendor ID 03EB and product ID 2FFD,<br />

which enable Windows to assign a suitable<br />

driver. Windows will recognise<br />

a new device and ask you to select a<br />

suitable driver. Select the driver located<br />

in folder C:\Program Files\Atmel\<br />

FLIP 2.4.6\usb (see Figure 4). After it<br />

is installed, you will see the new device<br />

in the Device Manager window. It<br />

can be recognised by its name ‘Jungo<br />

AT89C5130/AT89C5131’.<br />

If s<strong>om</strong>ething goes wrong during this<br />

process, you have to track down the<br />

problem. Possible problem sources include<br />

incorrectly fitted jumpers. For<br />

instance, if you activate the USB port<br />

with JP3 (pullup connected to D+) but<br />

do not start the internal firmware (JP2<br />

still in the ‘Run’ position or no reset<br />

executed after switching over), Windows<br />

will report a new device – but not<br />

the right one. By contrast, you might<br />

start the update firmware correctly but<br />

fit JP3 incorrectly. In this case, Windows<br />

will not recognise that a device<br />

Elektor blockbusters<br />

11/2007 - elektor<br />

Figure 3. The free FLIP programming software displays a list of what you have to do to start using the board.<br />

Figure 4. The microcontroller is recognised by Windows as a new device.<br />

Figure 5. After you click Run, FLIP downloads the program to the flash memory of the microcontroller.<br />

USB Flash Board • 92<br />

25


PROJECTS MICROCONTROLLERS<br />

Figure 6. Main menu of the BASCOM c<strong>om</strong>piler.<br />

is connected, and thus no c<strong>om</strong>munication<br />

will be established. After a bit of<br />

practice, you won’t have any problems<br />

making the right settings, and you can<br />

establish a c<strong>om</strong>munication session<br />

with the PC whenever you need it.<br />

Program download<br />

Now launch FLIP. First you have to<br />

use F2, Device à Select, or the IC icon<br />

to select the correct IC (AT89C5131).<br />

Then use F3, Settings à C<strong>om</strong>munication<br />

à USB, or the cable icon to select<br />

and open the USB interface. Finally,<br />

you have to use F4 or File à Load Hex<br />

Hardware test in Basc<strong>om</strong>-51<br />

‘Simple test for inputs,<br />

‘outputs and LCD<br />

‘**********************<br />

Dim X As Byte<br />

P1 = 0<br />

Cls<br />

Lcd “ 8051-Test “<br />

Wait 1<br />

Lowerline<br />

Lcd “ Elektor “<br />

Wait 3<br />

For X = 1 To 13<br />

Shiftlcd Right<br />

Waitms 200<br />

Next<br />

Cls<br />

Lcd “ Test Port 0 “<br />

Lowerline<br />

Lcd “ Bit 2 exp 0 “<br />

Elektor blockbusters<br />

File to load a suitable hex file. Select<br />

program file: 5131_TEST_ELEKTOR.<br />

HEX, which you can obtain along<br />

with the BASCOM AVR source code<br />

fr<strong>om</strong> the Elektor h<strong>om</strong>e page. Click the<br />

Run button (see Figure 5) to download<br />

the program code to the flash memory.<br />

After this, you must change over<br />

JP2 and press the Reset button to run<br />

the program. Caution: the BLJB option<br />

is enabled aut<strong>om</strong>atically with a new<br />

microcontroller. You must deselect<br />

(uncheck) it the first dime you download<br />

a program, since otherwise it will<br />

not be possible to run the program after<br />

it has been downloaded.<br />

P0 = &B11111110<br />

Wait 1<br />

Lowerline<br />

Lcd “ Bit 2 exp 1 “<br />

P0 = &B11111101<br />

Wait 1<br />

Lowerline<br />

Lcd “ Bit 2 exp 2 “<br />

P0 = &B11111011<br />

Wait 1<br />

Lowerline<br />

Lcd “ Bit 2 exp 3 “<br />

P0 = &B11110111<br />

Wait 1<br />

Lowerline<br />

Lcd “ Bit 2 exp 4 “<br />

P0 = &B11101111<br />

Wait 1<br />

Lowerline<br />

Lcd “ Bit 2 exp 5 “<br />

P0 = &B11011111<br />

Wait 1<br />

Lowerline<br />

Lcd “ Bit 2 exp 6 “<br />

P0 = &B10111111<br />

Wait 1<br />

Lowerline<br />

If you want to download a new hex<br />

file after this test, you must first disconnect<br />

the USB cable and then reconnect<br />

it – and of course, with the right<br />

jumper settings and a Reset first. After<br />

this, you must establish the connection<br />

again in FLIP.<br />

Alternatively, you can leave the USB<br />

cable connected and simply open<br />

JP3, which will also isolate the device<br />

fr<strong>om</strong> the USB without interrupting the<br />

supply voltage. In order to download<br />

a new program, you must first change<br />

the setting of JP2 again. The press<br />

Reset, wait two seconds, and fit JP3<br />

again. This initialises the USB device.<br />

You will have to open the interface in<br />

FLIP again, after which you can start<br />

the download.<br />

Programming with BASCOM<br />

The BASCOM-51 Basic c<strong>om</strong>piler is an<br />

ideal tool when you are just getting<br />

started with developing programs<br />

for the system, although you can also<br />

write programs for the microcontroller<br />

in C or assembly language. You can<br />

download a free demo version of BAS-<br />

COM-51 fr<strong>om</strong> the site of its producer,<br />

MCS Electronics (www.mcselec.c<strong>om</strong>).<br />

The free version can generate up to<br />

4 KB of code, which is sufficient for<br />

many applications.<br />

Figure 6 shows the main menu of the<br />

c<strong>om</strong>piler. In order to ensure correct<br />

operation of the board, you must as-<br />

Lcd “ Bit 2 exp 7 “<br />

P0 = &B01111111<br />

Wait 1<br />

Lowerline<br />

Lcd “ All Bits “<br />

P0 = &B00000000<br />

Wait 1<br />

Cls<br />

Lcd “ Test Port 3 “<br />

Lowerline<br />

Lcd “ Test Port 0 (LED) “<br />

Wait 3<br />

Status:<br />

P0 = P3<br />

X = P0<br />

Cls<br />

Lcd “ Inputs “<br />

Lowerline<br />

Lcd “Port 3 = “ ; X ; “ “<br />

Waitms 60<br />

Goto Status<br />

26 elektor - 11/2007<br />

End<br />

USB Flash Board • 93


sign the LCD pins to port P2 under<br />

Options (Figure 7).<br />

BASCOM supports configuration of<br />

different register files for individual<br />

8051 derivatives. Although there are<br />

no specific settings for the AT89C5131,<br />

this microcontroller is largely c<strong>om</strong>patible<br />

with the 8052, so you should use<br />

register file 8052.dat.<br />

The listing shows the source code of<br />

the test program. It is easy to read and<br />

largely self-explanatory. After an introductory<br />

message is displayed on the<br />

LCD, a running-light routine is executed<br />

to check all the LEDs on Port P0.<br />

Following this, the inputs on port P3<br />

are read in an endless loop and their<br />

states are copied to output port P0<br />

Elektor blockbusters<br />

11/2007 - elektor<br />

Figure 7. The assignment of the LCD pins to port P2 must be configured under Options.<br />

and<br />

shown on<br />

the LCD.<br />

You can actuate<br />

the<br />

DIP switches<br />

(S2) and<br />

pushbuttons<br />

S3–S6 to check<br />

that they are properly<br />

assigned to the<br />

port pins. The associated<br />

output<br />

LED will light<br />

up for each<br />

switch.<br />

The test<br />

program<br />

thus<br />

exercises<br />

practically all<br />

of the hardware.<br />

A couple of ideas<br />

Finally, a couple of ideas for further<br />

projects. The microcontroller has an<br />

internal EEPROM, similar to what is<br />

found in the 89S8252 and the 89S8253.<br />

However, in this case it is governed by<br />

different control registers (SFRs). This<br />

means that you cannot escape a careful<br />

study of the data sheet if you want<br />

to use the supplementary hardware.<br />

Like the 8052, the AT89C5131 has another<br />

serial interface that can be used<br />

with BASCOM by instructions such<br />

as Print and Input. However, this requires<br />

connecting an additional line<br />

driver (such as a MAX232), since the<br />

USB Flash Board does not have a serial<br />

interface port. This opens the door to<br />

typical interface applications, which<br />

means that you can use the microcontroller<br />

as a PC-based measuring instrument,<br />

counter or motor controller.<br />

Of course, the AT89C5131 can also do<br />

a lot more, including implementing a<br />

c<strong>om</strong>plete USB device. This is described<br />

in several application notes and<br />

acc<strong>om</strong>panying source code on the Atmel<br />

website. The archive file c5131usb-kbd-stand-alone-1_0_2.zipdemonstrates<br />

how to construct a USB<br />

keyboard.<br />

With this USB microcontroller and the<br />

extensive software archive, you have<br />

essentially everything you need to develop<br />

your own USB applications.<br />

(070999-1)<br />

USB Flash Board • 94<br />

27


5<br />

Elektor blockbusters Artikeltitel • 95

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!