About Me

Pilani, Rajasthan, India
I am an engineering student currently pursuing an undergraduate degree in Electronics & Instrumentation from BITS Pilani, Pilani campus. My hobbies are reading novels- fiction and non-fiction alike, playing and watching football, dabbling with new software and going through blogs. I love reading Electronics For You. It has helped me a lot in my college life. And sometimes, people around me.

Hope you find this blog useful. Thank you.

Tuesday, July 5, 2011

IDE for AVR - Introduction to AVR Studio


To work on any microcontroller, you need an IDE (Integrated Development Environment) to choose the various settings and compose codes for your task-at-hand. AVR Studio is by far the most widely used IDE for working on Atmel products. It supports the development of a large number of controllers. Other popular IDEs are CodeVision AVR and IAR Embedded Workbench. The latter is compatible with environments created in AVR Studio and hence is very popular.

About AVR Studio

AVR Studio 5 is the latest version available and it is by far the greatest leap that AVR Studio has made since its inception. For the first time, AVR Studio comes with an integrated C compiler. The earlier versions supported C codes but needed an external C compiler toolchain, the most popularly used being ‘WinAVR’ developed solely for AVR products. Also, it uses Visual Studio 2010 for an improved user-friendly multi-tabbed interface and a predictive coding facility that makes coding for microcontrollers very comfortable. So once you select the desired device for your project, you don’t need to remember the entire name of the register – a drop-down menu ensures you focus more on the algorithm and less on the details you will otherwise get in the datasheets. Apart from all this, it also provides the luxury of simulating and debugging your code using the in-house debugger and simulator environments.
AVR Studio 5 is here to stay!! J
For more details and download, visit this page. Please note:
1) To download, you will have to register first. The link is on the site itself. It is necessary.
2) The screenshots won't be visible clearly, you will have to zoom the page or open the screenshots in a new tab.

Welcome to AVR Studio 5

Once done with the download, launch AVR Studio 5 (henceforth referred to as ‘studio’). The screen looks something like the following screenshot. 

The logo is wonderful right?!
You will be greeted by a welcome screen. It has a lot of tutorial links and guides and many more options. In this post, I will show you how to create a new project, compose a demo code, debug and simulate this code and generate the hex file needed to program your controller. The terms related to AVR Studio have been italicised for clarity.

Creating and configuring a new project

Once you have been greeted by the welcome page, go to the File menu and choose hover your mouse pointer over the ‘New’ option and in the side-menu, choose Project. Use the following screenshot as reference.

Now, a New Project window will appear. In that window, select C Executable Project and provide a name and path for your project. Make sure that the Create directory for solution checkbox is checked. Use the following screenshot as reference.

Next, you will be prompted to select a device for your project in the Device Selection window. This is where you tell Studio which device you are developing the code for. In the Device Family drop-down menu, choose megaAVR, 8-bit. In the list of controllers available, select ATmega32 and click OK. Use the following screenshot as reference.

Now, you will find a default code opened for you. Edit that code by adding your piece of code to it. Be sure to save the code, once you are done. During the process of writing your code, you will appreciate the predictive coding facility of Studio. The following screenshot shows a very basic code written in the space provided.


Compile and Build

Now compile your code. If there are some errors, you will get a message at the bottom of your screen that says Build failed. If successful, it will display a message informing the same. Next step is to build your code using the Build Solution option from the Build menu. What the build option does is that it generates the .hex files and other allied files for your code. The .hex file is simply a file that is written in a language that your controller will understand. Programming your controller is nothing but downloading the contents of this .hex file into your controller. You can open this file in Notepad. This file is located in the directory whose path you provided while creating the project. Use the following screenshot as reference.


Debugging and Simulating

Debugging your code is the process of checking if your code is behaving as you want it to. If not, make appropriate changes to it. You will come to know about the various changes you should make with the help of breakpoints. During debugging, Studio executes your code very slowly so that you can see the effect of each and every statement on the registers of your controller. It uses the feature called AVR Simulator. Breakpoints are points in your code at which the Simulator will stop execution. Hence, very critical statements in the code, where multiple registers undergo bit-changes, are used as breakpoints so that code execution can be halted and the effect of the statement studied. Breakpoints are created by simply left-clicking on the gray area besides the code-area or right-clicking and selecting Create Breakpoint option. A red balloon will appear indicating the location of a breakpoint. Use the following screenshot as reference.
For debugging a very simple code, you need only the following three options. Start debugging starts the debugging process, Continue proceeds to the next breakpoint and I/O View opens a floating menu that contains the bit status of each and every register present in your selected controller. Go ahead, try it yourself!
Refer to the following screenshots for reference.


Hope this was helpful. See ya!   

2 comments: