You are on page 1of 9

How to Start with AVR Series Microcontrollers

You can find microcontrollers everywhere, from wrist watches to washing machines. They are small computers squeezed into a small chip and you can get them in any sizes and flavours depending on your need for memory and I/O-pins. Nowadays the most commonly used microcontrollers in do-it-yourself projects are Atmel's AVR- and Microchip's PICfamilies. In this article we will introduce you to Atmel's AVR and how to get started with them. More in depth information about microcontrollers can be found from the internet. Atmel currently provides AVR microcontrollers in many shapes and sizes, ranging from small 8-pin tinys to 100-pin xmegas. Flash memory sizes for program code range from 1 kilobyte to 256 kilobytes. You can find more information and a list of devices on the Atmel Website For this basic tutorial on how to get started with AVR-microcontrollers we are using a an ATmega16 (full datasheet can be foundon Atmel Website), which has 16 kilobytes of flash and lots of general input/output-pins. Every pin can be programmed individually as an input (digital or analog) or output (digital only) pin. We will go step by step on what hardware and software do you need and after that some example programs. The hardware part will include using any ATmeg16 Development board and the programming cable, which is needed to get the compiled program from the computer to the chip. The software part then guides you what you need in order to make your program code and to transfer the ready compiled binary code to your board. You will need some basic knowledge about electronics (how to connect leds etc) and it is good to read some basic Electronics tutorials if all of this is new to you. There are example programs written in C later in the article so some knowledge in programming isn't bad either.

What you need (hardware)


First of all, you'll need a testing board such as the Board that will be given to you during the Nexus workshop for the Atmega16 controller and a programming cable.

What you need (software)


In order to be able to get your AVR circuit to do something, you'll need a couple of programs to your computer. We will look at the installing of programs on windows and below are the links to all we need. If you are using Linux, you can check out our "AVR Programming in Linux Enviroment Tutorial". For Windows download the following programs and install them WinAVR - A software package that includes avr-gcc that makes it possible to write the programs in C language and compile them for the AVR. Atmel's AVR Studio - Integrated Development Environment (IDE) for AVR microcontrollers, helps you to manage your projects etc. Downloading requires FREE registration. PonyProg - Simple yet powerful programmer that we need to get the compiled program to

the AVR chip through the parallel/serial programming cable as there isn't straight support for it in the AVR Studio.

Installation
First one is WinAVR, the installasion is quite straight forward, just read what it says and click next. The best option is to leave everything to their defaults. Next install AVR Studio, again leave everything to their defaults and everything should go well. Nothing special with PonyProg either, just unzip the package and run setup.exe and follow the instructions. You now have all the necessary programs installed and you'll find them from your program menu. Continue to the next step.

Coding and Compiling


After you've installed all the programs successfully, start AVR Studio and you should see a welcome screen. There is a button "New Project", click it. New project can be started from the Project menu too.

AVR Studio welcome screen You should now see a window with a "Project type" area and there should be "AVR GCC" (if not then there is something wrong with your WinAVR installation), choose it. Fill in the project name and choose a location where you want your projects to be saved. Click on the "Create folder" too so your projects are well organized under their own folders. Click Finish now, not Next.

AVR Studio, project window After clicking Finish, you should see the following view:

AVR Studio ready to be used In the following pages on this article you'll find some example codes that you can use to test your circuit. Let's copy&paste the first example code into the middle window.

AVR Studio, code pasted Now navigate into the Project menu (up left) and from there goto "Configuration Options" and you'll see the following screen. Select the right device for the project, atmega16 in this case (or what you are using). Fill in the frequency in Hz, which is 1000000 Hz (1 MHz) for the atmega16 with factory settings. Click OK.

AVR Studio, project settings Remember to save your project now. Navigate to Build menu and click Build (or hit F7 on your keyboard) and if all goes well, no errors should be there and you'll see a text like this in the message window.

AVR Studio, project compiled As you can see, the led flashing program doesn't take much space from the chip. After this is done you are ready to continue to the programming of the chip.

Getting the code to the chip - Programming


As we are using the parallel port programming cable, we'll need to use an external programming software to get the code to the chip. Now start the PonyProg program.

PonyProg Select File -> Open device file (or click the yellow folder icon). Navigate to your project directory and there you'll find a directory named "default". From there choose the "project_name.hex", in this case "test_project.hex". This file contains the compiled program in a form the chip understands.

PonyProg, hex file loaded

You can see two drop down boxes, find "AVR micro" to the first one and "AVR Auto" or "ATmega16" to the second one. Now navigate to Setup -> Interface Setup... and choose "Parallel" and "Avr ISP I/O" from the dropdown menu below it. Click OK. Go to Setup -> Calibration and click Yes. After this connect your programming cable to your computer and the chip if you haven't already done this and give some power to the chip too.

PonyProg, hex file loaded Click on the yellow arrow on the second line of icons, this will start the programming cycle. Let the program do its work and if you've done everything right you should get the following message that the programming has succeeded and the led should be flashing happily on the board. If there are some errors, check and double check all your connections!

PonyProg, program succesful

You might also like