Microcontrollers

I want to discuss my approach to the microcontrollers I have used in these projects and the tools I have used. Straight, concise information is hard to find.

Background

At UC Davis, we mostly dealt with Altera PGAs and various Motorola 68000HC12 based boards. The Altera PGAs were simple to use and easy to program (though we had to use DOS programs to do it!). The Motorola chips needed a bit more circuitry to run. We coded for them in C using Imagecraft’s ICC HC12.

Learning languages is easy. If you’ve already learned one, you can pick up a book and figure new ones out in a few days. The hard bit is learning the gotchas of all the tools and libraries.

How do you program interrupt handlers in C? Eh? It varies between compilers. The ICC software was a homely feeling IDE with some strange quirks. It took an evening of puttering around to get programs to compile and load onto our HC12s. Once we had a ‘golden’ project we just copied the project file over and over, editing it for each new project.

When I wanted to build my own microcontroller systems I took a look at the chips favored by hobbyists: the 68000 series, PIC, and the AVR. The 68000 series is rather ancient. Newer uCs include bags of features that make them easier to use. The PIC seemed hokey to me– programmed in basic or assembly, and, if I recall correctly, no guarantees that instructions would take one clock cycle. The AVR AT90 series were modern RISC processors with plenty of free tools available, and you could use gcc to compile C programs for them.

There are plenty of other microcontrollers out there, but at the time the learning curve seemed steeper, for example, ARM and some TI chips.

When choosing a chip, think of:

  • Does the chip come in a useable package? DIP is the easiest by far, though bulky
  • Are there tools available for the chip? if you can’t find a compiler or a programmer without shelling out a ton of money, it’s probably not worth it
  • Can I easily source the chip? I wanted chips I could buy locally, in case I fry one, I can drive to a distributor and get another one
  • How much stuff do I need to get the chip running in my project? The AVR just needs an oscillator and two capacitors

Software

I downloaded and used ImageCraft’s ICC AVR software at version 6.26 for a while. It was very much like the HC12 software, so I was up and compiling right away. I tried out AVR Studio but it seemed geared towards using the STK500 evaluation board which I didn’t have. The ICC software was familiar and it spit out a binary file just like I expected.

The ICC AVR software is NOT freeware. But it works for 45 days and that was enough time to finish the drum project :) Available here.

I now use AVR Studio and highly recommend it. It has a large user base and excellent integration with debugging and Atmel’s programmers. The debugging alone is the single most useful feature for me.

You can download AVR Studio here.

Programmer Hardware

Programming the chip was a nightmare. I didn’t have the cash to get the STK500 kit. After some searching I settled on using a program called PonyProg, available here, and built the serial ISP circuit on the site. I used the circuit showing the 8515. Actually two of the pins are switched compared to the 8535 chip I had. It was a while before I got that and the other bugs worked out, during which I fried a number of LM7805 regulators, but it did work in the end.

Three years later I pulled the protoboard with the circuit out and it doesn’t work anymore. I blew up another regulator.

There are tons of options available for the AVR now. All sorts of serial and parallel programmers, available as schematics or kits. Even a few USB programmers.

I tried a BAFO USB to Parallel adapter bought off Amazon, since I don’t own a PC with a parallel port, but it uses a “virtual” parallel port and does not work with PonyProg. If you do have a parallel port, here’s how to use it (then I’ll answer how I got my setup working).

Parallel port programmer circuit for PonyProg here: http://www.flightsim.com/howto/mind/avrisp.gif

The parts for the circuit:

  • 25 pin male solder cup
  • 25 pin hood
  • 3x 330ohm resistors
  • Two feet of four conductor wire (telephone chord) and two feet of one conductor wire
  • 4 pin header + mm whatever the word is for the thing the header plugs into :)
  • 1 crimp pin

On the ATMega16 I am now using and the 8535s I have left, the four pins needed for programming the chip are all adjacent. So I placed the 4 pin header at the end of the four conductor wire and placed the header pins onto my protoboard. The remaining fifth wire is for ground. It would have been nice to use shielded wire, I guess, but I only had telephone chord on hand.

The protoboard also contains two capacitors and an oscillator. It is powered by a five volt wall wart. I also have a resistor and a led on the board to show when the power is on.

After building the circuit, open PonyProg and get to the settings page. Choose parallel and then the port (LPT1 in my case). I left the method of access as the default.

For more info, go to AVRFreaks.net or AVRBeginners.net.

I currently use the Atmel AVRISP MkII and also highly recommend it. It’s USB, you can hit one button in AVR Studio and program your chip, and you can take it apart and make your own cables for it. It comes with a 2×3 connector that I couldn’t use for my protoboard, so I just attached another cable inside the AVRISP MkII.

Oh yah, the AVRISP MkII costs $35. Even a home built parallel port programmer will cost around $10. And then you have to bother building it and debugging it.

I promise I will insert the schematic of how to wire the AVRISP up to a chip here, and what settings to use in AVR Studio. The documentation is really vague, and I needed the help of the good people on the AVR forums to figure it out.

Conclusion

So, Atmel AVR ATMEGAs is a good choice for hobbyists. Go with the ATMEGA16 if you want a nice cheap chip with a couple of PWM channels. ATMEGA88-20PU for 3 PWM channels. Use AVR Studio to code, debug, and program. Buy a AVR ISP MkII to program.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>