Pages

Wednesday, April 27, 2011

Chapter 5: Programming the AVR


As we progress with our mission to deal with Microcontrollers, its time that we really start programming it. I have shown you how to construct an ISP Cable. Its time to test it. We will implement and test our system in a breadboard.

We will need a power supply for the digital circuits. We know a digital circuit runs from either 3.33V or 5V of supply. We will be commonly using 5V logic. So we need a 5V power supply capable of feeding all the devices we might run.
I will describe how to build one in the section below. However, if you already have one, just skip this section and proceed to the next one.


The Power Supply
We need a 5V regulated power supply. Regulated power supplies provide a smooth, constant DC voltage independent of the load current. The supply will be free of any noise, providing pure dc which is essential for digital circuits.
Regulation can be obtained using the 78XX series Linear Regulators. A regulator in combination with some capacitors will make an excellent DC supply. I have given a design below.
Fig: 5V Linear Regulated Power Supply

For generating 5V, I used LM7805. These designs are flexible; you can choose any capacitor value. The capacitor values given here should be optimum. This supply will work even with the 7805 alone. The other things are given here to make it better. Just give some dc voltage at the input of 7805 and you will get a regulated 5V at the output.  The LED is a power on/off indicator (Optional). You can implement this circuit on a breadboard. This supply can provide up to 1A.

However, this is not the complete picture, the DC-In jack J1 is used to feed unregulated dc voltage of any magnitude from 7 - 20V. I myself used an AC/DC adapter which was rated to supply 500mA at 7.5V.
Fig: An AC to DC Adapter
The following clip will give you the whole idea of building it.



The necessary items are listed below,

Fig: List of necessary items


Connecting the AVR Microcontroller
It’s time to put the MCU on breadboard for our first program. Look at the following diagram,
Fig: The AVR connections
Remember to connect the VCC and the GND lines to the 5V power supply output. Connect the parallel extension cable to the PC I/O panel and connect the ISP Cable with it. Turn on the power supply. The following video will accompany you with the connections.





Setting up the software
I have discussed earlier about the software required to program the AVR. We will install the following three packages. Install them in this sequence one after one,
  • Compiler: WinAVR
  • IDE: AVR Studio
  • Programmer:
      • Parallel Port: Pony Prog
      • USBASP: AVRDUDE*
*See Chapter 7.
Now the question comes, which version to use? Its always better to use the latest version.
The older versions are smaller and easier to download. I have used AVR Studio 5 which is just great. However, in the beginning you can use the following versions.


WinAVR 20060421
Click the link to download WinAVR-20060421. After downloading, run the installer and install it.

AVR Studio 4.12 sp4 build 498
After installing WinAVR, install AVR Studio. We will install version 4.12 and update it with Service Pack 4 build 498. Download both of them from the following links,
First install AVR Studio and then install the service pack for updating it.


PonyProg 2000

Download and install PonyProg 2000 version 2.07c from this link.



Notes:
  • I have discussed about the purpose of these programs earlier. If you want to read about those, go to Chapter 2.
  • A full version of AVR Studio 5 is now available. It is much improved than the previous ones. It has built in c compiler, so you don't need WinAVR. I have not given any tutorial on AVR Studio 5 yet. There are some changes in the interface of AVR Studio 5 from the old version 4.
  • Whether you use AVR Studio 5 and/ or USBASP for programming or not, you should see the following demo to learn how to write the codes and how to compile them.
  • Download AVR Studio 5 from this page. You will have to go register for this. You wont need WinAVR. Only AVR Studio 5 alone is enough to produce hex files from your code.
  • If you want to use an USB programmer, go to Chapter 6 and 7 of this blog.

Programming the AVR
After Installing them, you can program the AVR. The following video will guide you completely in writing c codes, compiling and transferring it to the Microcontroller. Connect the microcontroller to the PC and the Power Supply as shown in the earlier sections. Then do the tasks according to the following video to program it.
This video describes,
  1. How to use AVR Studio to write your codes.
  2. How to use Pony Prog for programming.


This is our first program and this will not do anything. But you can verify and understand that your ISP cable, Microcontroller Connections and the Installed Softwares are correct and working properly.

Note: All the videos in this page are given up to 720p quality. To watch them in better quality, watch them at YouTube by clicking the YouTube logo at the lower right corner.

7 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete
  3. Thank you for your questions,

    Parallel ports can supply very low amount of power which causes the AVR to run, you should connect a 5V external source during programming. If you see the connections in chapter 4, you will see that the +5V line is not connected directly to the parallel port, it is connected to the 14th pin (Vcc) of the 74HC125 buffer. So, it should not damage your port.

    For win 7, check this out, I don't know if it works.
    http://ponyprog.sourceforge.net/phorum/read.php?2,2249

    ReplyDelete
    Replies
    1. This comment has been removed by the author.

      Delete
    2. Sorry for such a late reply, I didn't notice your comment.

      It will not matter which one you connect first & there is no problem if the micro-controller starts running first. The running microcontroller does not affect the programming process.

      The power which seems to come out of the parallel port is very low. The voltage generated from parallel port should be much lower than 5 V. So, certainly your external source (which is 5V) will dominate. Micro-controller will never draw power from the parallel port if external source is connected.

      Delete
    3. This comment has been removed by the author.

      Delete
  4. This comment has been removed by the author.

    ReplyDelete