background image

Projects/Microcontrollers 

Elektor AVR 

programmer 

Simple universal AVR programmer 

with USB interface

Dipl.-Inf. (FH) Benedikt Sauter and 

Dr. Thomas Scherer 

This companion to 

the Elektor AVR 

project is a plug-and-

play AVRISP MkII-

compatible USB 

programmer for AVR 

microcontrollers. 

 
Elektor asked Benedikt Sauter to 
design a simple AVRISP MkII-
compatible programmer which can be 
used with a wide range of software. It 
is particularly suitable for use with the 
ATM18 test board used in our 
microcontroller programming course. 
The main requirement was that the 
programmer should be as simple in 
design and use as possible and as 
inexpensive as possible. The result 
was the simple dedicated USB 
programmer described here. 
In comparison to the earlier USBprog 
design the circuit has changed little 
(Figure 1), the main update being that 
an ATmega32 is used in place of the 
ATmega16. The printed circuit board 
(Figure 2) has been made smaller, 
thanks to the use of a miniature USB 
socket and a 6-way header rather than 
a 10-way header for the ISP interface. 
The May 2008 issue of Elektor will 
include a more detailed discussion of 
this. 

S

O F T W A R E

 

Being a clone of the AVRISP MkII 
programmer, the Elektor design is 
compatible with a wide range of 
software. Since we are using Atmel’s 
AVR Studio 4 [3] with the test board, 
we can use it to install the relevant 
driver (see Figure 3). After the driver 
has been installed we can connect the 

Figure 1: The circuit diagram of the Elektor USB programmer is broadly similar to its 
predecessor described in the October 2007 issue of Elektor. A USB bridge and a microcon-
troller are the main components. 

background image

module to the PC and Windows should 
then automatically recognise the new 
hardware and select the correct driver. 
In some Windows XP installations, 
however, an error message is 
produced, claiming that the file 
‘libusb0.sys’ is not found. Ignore this 
error message and click ‘Cancel’. The 
driver will nevertheless be found and 
installed and all will be well. 

 
It is now possible to use the 
programmer with a wide range of 
software, including CodeVision AVR 
[4]. Unfortunately, the programmer 
cannot be used directly with Bascom 
[5] as that software does not yet 
implement the AVRISP MkII 
protocols. 
For non-Windows users there is a 
greater choice: do an internet search 
for ‘Linux’, ‘AVRISP MkII’ and 
‘software’. For Linux and Mac OS X 
the open source ‘AVRDUDE’ 
software [6] is particularly 
recommended. Since this software is 
driven from the command line, we 
have also made available a file 

‘Elektor-AVRprog Mac.pdf’ which 
explains how to integrate AVRDUDE 
with a ‘proper’ user interface. 

P

O I N T S   T O   N O T E

 

The ‘bitrate’ to which the programmer 
is set should not be greater than one 
quarter of the clock frequency of the 
microcontroller being used. The 
programmer supports bit rates from 

249 Hz to 2 MHz. From version 4.13, 
AVR Studio refuses to run the 
programmer at frequencies of less than 
5 kHz.  Figure 4 shows how the ISP 
frequency is set in AVR Studio. 
If any problems arise it is worth 
checking [2] to see if a new version of 
the firmware is available. To 
reprogram the firmware it is necessary 
to bridge the two holes next to the 
quartz crystal on the programmer. 
Then the new firmware can be loaded 
over the six-pin ISP connector using a 
second programmer. 
It is worth remembering that the 
programmer uses 5 V logic levels. If 
the target device is supplied with 3.3 V 
(or even less) during programming, 

this can cause problems. The solution 
is to operate the target device from 5 V 
during programming. 

ATM18

  T E S T   B O A R D

 

Pin 1 of the 6-pin ISP connector K13 
is located nearest to the 
microcontroller module (Figure 5). 
During programming JP1 should be set 
to the ‘EXT’ position if the board is 
powered from a mains adaptor. 
Alternatively, set JP1 to ‘USB’ and the 
board will draw power from the USB 
port via K5. 

A

B O U T   T H E   A U T H O R

 

Benedikt Sauter is a passionate open 
source hardware and software 
developer and for this project is 
responsible for the building and 
maintenance of open source 
applications. 

Figure 2. The assembled module. Thanks to the use of a mini USB connector and a 6-
pin ISP connector the unit can be very compact. 

Figure 5. Pin 1 of the 6-pin ISP interface is 
the one nearest to the microcontroller mod-
ule. 

L

I N K S   A N D   R E F E R E N C E S

 

[1] ‘USBprog’, Elektor, October 2007 

[2] Project 

website: 

http://www.embedded-
projects.net/usbprog 

[3] 

AVR Studio 4: 

http://www.atmel.com/avrstudio 

[4] CodeVision 

AVR: 

http://www.codevision.be 

[5] Bascom: http://www.mcselec.com 

[6] AVRDUDE: 
http://www.nongnu.org/avrdude 

S

O U R C E S

 

The USB programmer is available 
from  Elektor as a ready-made SMD-
populated printed circuit board 
including USB and ISP cables for 32 
Euro. 

You can order via 
http://www.elektor.com or via the 
Elektor shop.

Figure 3. Screenshot from the installation of AVR Studio 4. As soon as the software and 
drivers are installed the programmer is ready for use. 

background image

 

Figure 4. In this dialogue, under ‘Settings’ in AVR Studio 4 (version 4.13), the ISP
frequency is set. 

background image

Projects/Microcontrollers 

Parallel 

programmer 

Ultra-simple STK200- and STK300-

compatible AVR programmer

Dr. Thomas Scherer 

For some, even the 

low-cost USB 

programmer for the 

ATM18 test board 

described in the 

accompanying series 

of articles might 

seem a little 

expensive. Here is 

an even cheaper 

solution, using just a 

couple of resistors! 

Elsewhere we describe a simple and 
inexpensive USB programmer for 
AVR microcontrollers, designed for 
use in conjunction with the 
microcontroller programming course 
and ATmega88 module and test board. 
However, if the full flexibility of that 
programmer is not required, it is 
possible to simplify the design and 
reduce its cost even further. 

T

H E   C H E A P E S T  

P O S S I B L E   P R O G R A M M E R

 

It may come as a surprise to learn that 
the ISP (in-system programming) 
interface of an AVR microcontroller 
can be driven directly from a parallel 
port, and indeed this is how Atmel’s 
early STK200 and STK300 
programmers worked. All that is 
needed to make a fully-functional 
programmer for AVR microcontrollers 
is a PC with a parallel printer port. 
Four resistors are needed to protect the 
port and the target device from one 
another. The de luxe model of the 
programmer sports an extra resistor 
and a low-current LED to show when 
data transfer takes place between 

programmer and target device. 

T

H E   C I R C U I T

 

Calling Figure 1 a ‘circuit’ is perhaps 
stretching the term. Besides the ground 
connection and the wiring of pins 2 
and 3 of the printer port back to the 
flow control signals, just four 270 Ω 
resistors, R1 to R4, are needed. Pin 7 
can be used to drive a low-current 
LED via a 1 kΩ resistor to give a 
visual confirmation of data transfer, 
but this is an optional extra. 

C

O N S T R U C T I O N

 

The minimalist circuit can easily be 
built on a small piece of perforated 
prototyping board. The output takes 
the form of 6-pin header K2, the ISP 
connector. On the input side you can 
either use a Centronics socket in 
conjunction with an ordinary printer 
cable, or a 25-way sub-D insulation 
displacement connector (IDC) to fit 
the port on the PC, a suitable length of 
ribbon cable, and a two-row 26-way 
IDC header, with a corresponding 
socket on the programmer board as 
shown in Figure 2. The result is a neat 
and practical parallel programmer. 

S

O F T W A R E

 

Since the programmer is compatible 
with the STK200 and STK300 
devices, it will work with a wide range 
of existing software. Indeed, when 
configuring programming software 
either ‘STK200’ or ‘STK300’ should 
be selected as the programmer type. 
The programmer works perfectly with 
both CodeVision [1] and Bascom [2] 
software and the ATM18 test board 
(Figure 3).  Sadly, Atmel’s own AVR 
Studio 4 no longer supports parallel 
programmers, but the alternatives 
make more than adequate substitutes. 

ATM18

  T E S T   B O A R D

 

Pin 1 of ISP connector K13 on the 
ATM18 test board is the one nearest to 
the microcontroller module, as shown 

in  Figure 4. If the connector is 
inserted the wrong way round no harm 
will be done, but the device will fail to 
program. 
 
Also note that JP1 on the test board 
should be set to ‘EXT’ during 
programming if the test board is 
powered from a mains adaptor capable 
of providing 7 V to 16 V at a current 
of a few milliamps. Alternatively, set 
JP1 to ‘USB’ and the test board will be 
powered from the USB interface via 
K5. 
 
 

N

O T A   B E N E

 

If the parallel programmer is used in 
other projects, it is worth remembering 
that the printer port works with 5 V 
logic levels. If the target device is 
powered from 3.3 V or less during 
programming, it may not function 
correctly. In such cases power the 
target microcontroller from 5 V, if 
necessary transplanting it to a 
prototype board for programming. 
Some laptops have a parallel port that 
operates using 3.3 V logic levels. This 
will sometimes result in failure to 
program a microcontroller running on 
a 5 V supply. 

L

I N K S   A N D   R E F E R E N C E S

 

[1] CodeVision 

AVR: 

http://www.codevision.be

[2] Bascom: 

http://www.mcselec.com

 

background image

 

 

Figure 1. The circuit of the programmer could 
hardly be simpler. 

Figure 2. The minimalist circuit can be 
constructed on a small piece of perforated 
prototype board. 

Figure 3. The parallel programmer 
connected to the ATM18 test board. 

Figure 4. Pin 1 of the 6-pin ISP connector is 
the one nearest to the microcontroller mod-
ule. 

background image

Reaction timer 

 

Bonus program example for the 
Elektor AVR project 

Fancy a game? Here is a little test of skill in the form of a reaction timer. The only hardware required is a pushbutton, 
which is already available on the ATM18 test board. The button is connected to port PB0 of the ATM18 module, which 
is an input with an internal pull-up resistor. In fact we do not need the pull-up resistor in this experiment as all the 
pushbuttons on the board are already equipped with pull-up resistors, but it does mean that the example will still work if 
the microcontroller board is used in stand-alone configuration. The game could be built into a tiny enclosure with a 3 V 
lithium cell as power source. 
 

B

A S C O M   L I S T I N G   F O R   T H E   R E A C T I O N   T I M E R  

(T

I M E

1.

B A S

 

'Time of reaction measured on PB0, output on 6 LEDs on PortC 

 

$regfile = "m88def.dat" 

$crystal = 16000000 

 

Config Portc = Output 

Config Portb = Input 

Portb = 255                                                 'Pullups 

Config Portd = Input 

Portd = 255                                                 'Pullups 

 

Dim Leds As Byte 

Dim Timeout As Word 

Leds = 1 

 

Do 

  Portc = 255 

  Timeout = Rnd(1000) 

  Timeout = Timeout + 500 

  Waitms Timeout 

  Portc = 0 

  Timeout = 0 

  Do 

    Timeout = Timeout + 1 

    Waitms 10 

  Loop Until Pinb.0 = 0 Or Timeout = 127 

  Leds = Timeout 

  Portc = Leds 

  Waitms 1000 

Loop 

background image

 

 
The outermost infinite do loop means that the program repeatedly carries out new reaction time measurements. First all 
the LEDs are turned on and then there is a random delay of between 0.5 s and 1.5 s. The randomness ensures that the 
player cannot get used to the rhythm of the game. Tension builds, and suddenly all the LEDs are extinguished! The 
player must now press the button as quickly as possible, and the reaction time is counted in units of 10 ms. The result is 
displayed in binary on the LEDs, which gives the player the bonus mental exercise of converting the result to decimal. 
For example, the display 0010011 means that the measured time was 19 times 10 ms, or 190 ms (which is a pretty 
impressive performance). With a bit of practice your grey cells will get used to doing this conversion in the one second 
the game allows before the next trial begins! 
 

C

  P R O J E C T

 

 

On the Elektor website you will find not only the two Bascom projects but also the C project ATM18_Demo1 by Udo 
Jürß, created using the IAR compiler. The project is also a reaction timer game, but this version also uses the serial 
interface. The functions and required connections are listed in the program source code. Port C is used to drive six 
LEDs, and PD2 is used to drive the seventh LED. PD0 and PD1 are used for the serial port, and two buttons are needed, 
connected to inputs PB0 and PD6. 
 
More advanced experimenters will find in this example many elements and techniques that they can adapt for more 
complex projects, including the use of timers, interrupts and advanced output operations using the serial port. The 
program also demonstrates how to respond to commands received over the serial port. For example, it would be 
possible to arrange to turn individual outputs on and off or carry out various types of processing in response to serial 
commands. 
 

O

T H E R  

C

  C O M P I L E R S

 

 
We have also modified the first C project for the Elektor AVR board by Benedikt Sauter so that the source code can be 
compiled using WinAVR GCC, and Antoine Authier has contributed a suitable Makefile. It is also planned to make a 
version of this project available that is suitable for use the the CodeVision AVR C compiler. Future C projects in this 
series will be made available for the CodeVision compiler as well as for WinAVR GCC. 
 

C

O N T E N T S   O F   T H E   F I R S T   S O F T W A R E   D O W N L O A D

 

 
Elektor AVR download part 1 (071148-11.zip): 
 
- [ATM18_Demo1.zip] with C source code for the IAR compiler by Udo Jürß 
 
- [Bascom.zip] source code in Bascom AVR Basic 
 
- [ATM18_Hello_GCC.zip] modified C source code by Benedikt Sauter for use with WinAVR GCC 
 
- [makefile_for_hello_on_ATM18.zip] Makefile for AVR GCC (using WinAVR or under Linux or other operating 
systems) by Antoine Authier 
 


Document Outline