Avr

From DaphneWiki

Revision as of 03:31, 3 March 2011 by Matt (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

AVR

AVR is a micro-controller suitable for (potentially) emulating actual laserdisc players so that original arcade hardware can run with an AVR instead of an old, obsolete laserdisc player.

STK600

The STK600 is a "starter kit" designed to help newbies ease into the world of digital electronics and AVR microcontrollers. Unfortunately, the documentation SUCKS. So I am going to list the steps I had to do to get my STK600 up and running.

  1. Download WinAVR and AVRStudio 4 (I guess 5 just came out but I'm still on 4). Read some tutorials on how to write a hello world program in a simulator to get your feet wet. This is beyond the scope of this article.
  2. AVRStudio came with a USB driver called Jungo. The one that comes with it won't work correctly on Windows 7 x64 but there is a beta version, v10.2, which you can get from here: http://www.atmel.no/beta_ware/ . Probably any version after v10.2 should fix the issue.
  3. From within AVRStudio, go to Help->AVR Tools Users Guide. You will find the sparse documentation for the STK600 listed in here. Follow its instructions on mounting the AVR2560 board that comes with the STK600. Also follow its instructions in the Quick Start Guide about how to install the 6-pin cable for ISP programming.
  4. Plug in your STK600 to the USB port of your PC, turn on the STK600, and launch AVRStudio.
  5. From within AVRStudio, go to Tools->Program AVR->Connect
  6. For platform, choose STK600, and for port, choose USB.
  7. Click 'Connect'
  8. It should prompt you to update your firmware and this should be safe to do (but you may want to hold off until you get other things working). I updated and it worked.
  9. On the 'Main' tab, in the Device and Signature Bytes section, choose the "ATmega2560" as your device. That's the one that comes with the STK600.
  10. Go to the HW Settings tab. The VTarget will be set to 0.0V which means no power will be flowing to the AVR2560. Move the slider over to 5.0V, then click the 'Write' button inside the Voltages section to apply the change. You should see a new green LED light up on the far side of the STK600.
  11. Go back to the Main tab, and set your programming mode to "ISP mode". Click Settings and change the ISP Frequency to 100 kHz for now. Click the 'Write' button to apply the changes.
  12. You should now be able to click 'Erase Device' and have it work. Don't worry, this does not do any harm because you can reprogram the device at any time.

The Clock

Now comes the part that is hard to find documentation on, and that is setting up the clock. The AVR2560 comes configured to use its crappy internal 1MHz clock which is inaccurate. If you want to see how inaccurate it is, follow this tutorial http://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&t=50106 . The tutorial will show you how to set up a 1 second timer, but when using the AVR2560's internal clock, the resulting timer will be off quite a bit. The STK600 does provide a more accurate external clock, but finding information about how to enable this is actually pretty difficult, at least for me. I had to search a bunch of forum posts and piece the information within them all together. So here we go:

  1. Go to the 'HW Settings' tab and set the Clock Generator to some sensible value, anywhere between 1 and 16 MHz. (the AVR2560 isn't designed to work on a clock faster than 16 MHz). Click 'Write' to apply the changes.
  2. Although you have set this clock, it won't actually have any effect yet. Going back to the STK600 documentation found within AVR Studio, you may want to read section 4.8 about Clock Settings. You will see that there there is a little switch on the STK600 that you need to change. For our purposes, we want to use the STK600's clock, so you need to change the switch to "EXT" instead of "XTAL" where it defaults.
  3. You'd think this would be all you'd have to do, but incredibly, there's more. From within the STK600 dialog in AVRStudio again, click on the 'Fuses' dialog. You'll see a bunch of schlop here that won't make any sense. Well as near as I can tell, this section represents internal configuration for the AVR2560 that can be changed/programmed within AVRStudio which is actually pretty cool. But it is lousy that I need to know something about the AVR2560 in order to use the STK600! But anyway.. go to the next step once you've clicked on the Fuses tab.
  4. CKDIV8 will most likely be checked. Uncheck this to get the clock to perform at a normal speed, instead of being divided by 8 internally.
  5. Now go to SUT_CKSEL where it will likely be set to use the Internal RC Oscillator. I changed this to "Ext. Clock; Start-up time: 6 CK + 65ms". I'm not sure what the deal with the delayed startup time is but I guess it matters in some cases. I choose the longest delay in startup time just to be conservative.
  6. Now double-check that you've made the correct changes before clicking the 'Program' button because if you mess up, you could temporarily "brick" your AVR2560 from what I understand. I say temporarily because there are apparently ways to fix this. Fortunately I did not have to go down this path.
  7. Once you've verified your settings, click 'Program' and your AVR2560 should now be using the clock source supplied by the STK600. Now you can go to the HW SEttings tab and adjust the clock in real-time which is what you obviously wanted to do in the first place when you bought the STK600 right? :)
Personal tools