Society of Robots
Search and Index Search Here

 Parts List
 Robot Forum
 Member Pages
 Axon MCU
 Robot Books

 How To Build
  A Robot




 Robot Journals
 Robot Theory

    UPGRADE ATmega8 TO ATmega168 (SWAP OUT)

    This quick tutorial will teach you why and how to upgrade your microcontroller for The $50 Robot to work faster and store larger programs.

    Specific Differences Between ATmega8 and ATmega168
    In terms of the user, there are few differences between the ATmega8 and ATmega168.

    The first difference is that the ATmega8 can run at a maximum 16Mhz while the ATmega168 can run up to 20Mhz maximum. To run at this maximum value will require an external crystal oscillator.

    "The device is shipped with internal RC oscillator at 8.0MHz and with the fuse CKDIV8 programmed, resulting in 1.0MHz system clock."

    The $50 Robot by default uses the slow internal oscillator. This is plenty fast already for most applications. If you ever require complex math capabilities (floating point math, for example), or you are doing serious computation as with mapping or computer vision, then you might need the faster processor.

    The next major difference (the most important one) is flash memory size. The ATmega8 comes with 8k while the ATmega168 comes with 16k. As you start to create more advanced robots you will quickly realize that 8k is barely enough memory to do what you want.

    The last major difference is price. lists ATmega168 part # 556-ATMEGA168V10PU for $4.11 while list ATmega8 part # 556-ATMEGA8L-8PU for $3.66. Ok so not that big of a difference, but now you know part numbers and where to buy them at . . .

    Update: The ATmega328P is the latest and greatest. It sports twice the memory as the 168, but is a bit more expensive. Its a drop in replacement, meaning its pin-for-pin.


    How Do I Know That My Robot Needs More Memory?
    Simple. When you compile your code, you will get an error something like this:

    c:\program files\winavr\bin\..\lib\gcc\avr\4.1.1\..\..\..\..\avr\bin\ld.exe: region text is full

    How do I Upgrade?
    There are three steps. Since the pin-out is the same on both chips, simply take out the ATmega8 microcontroller and replace it with the ATmega168. Make sure the small notch on the chip still points in the correct direction.

    If you were using the PonyProg method of programming, you will need to download the newest version of PonyProg2000: v2.07c BETA. I have not tested this version on the ATmega8, but it should still work. Previous PonyProg versions will not work with the ATmega168. If you always used AVR Studio to upload your code, just ignore this step.

    The last step is to make a few quick changes in your source code. In your file called 'makefile' (check your source code folder), look for a line that says this:

    # MCU name
    MCU = atmega8

    and change it to:

    # MCU name
    MCU = atmega168

    Next, also in the makefile, look for a line called timer.c and change it to timerx8.c. If you are not using this file, don't worry about it.

    Then in the file SoR_utils.h, look for a line that says #include "timer.h" and change it to #include "timerx8.h".

    If you do not have these new timer files, the $50 Robot source code has been updated with them.

    The global.h file should also be modified since it contains a F_CPU define, depending on if you use the makefile to overwrite that value or not.

    The compiler will know what to do and handle the rest automatically for you.

    What if I Want to Use a different ATmega?
    The pin-outs of the other ATmega's are different, so you cannot directly swap them out. But if you pay attention to the wiring, you can physically rewire your board to accommodate any ATmega you desire.

    I will not go into detail explain this, but look at the section called CONFIGURE PORTS in the SoR_Utils.h file. With a little thought, it shouldn't be too hard to reverse engineer it.

    In that same file you will see lines such as PORT_OFF(PORTD, 4); that should also be changed to do what you want.

Get Your Ad Here

Has this site helped you with your robot? Give us credit - link back, and help others in the forums!
Society of Robots copyright 2005-2014
forum SMF post simple machines