Wednesday, 28 May 2014

ATMega vs XMega

Following an earlier post, where I suggested I'd spent a good few hours redesigning my generic board game sections to use a single, 64-pin QFN packaged chip, with 0.8mm pin pitch (an AVR XMega no less) I recently received a reply via the modern marvel that is G+, in which someone asked why I hadn't considered an ATMega.

Well, because it only has about 28 pins, of course!
But it seems that my relatively small amount of experience with Arduino (and AVR chips in general) has "legged me up" - just like Microchip's PIC microcontroller range, AVR also offer a wide range of their 8-bit micros - some of which come in a 64-pin QFN package, and offer more than the 48 i/o lines available on the XMega I'd identified as a potential replacement.

In fact, the ATMega165 seems like an ideal chip that matches all our previous requirements - with a few extra bonuses to boot. For example, it's already fully supported in the Arduino IDE. No need to learn a new programming environment (AVR Studio) when I can just use tools I'm already familiar with. And it also supports ICSP programming - so I can use my dedicated Arduino/AVR USBTiny ICSP programmer, instead of learning a whole new (two-wire PDI) protocol.

Add in the fact that ATMega165 (and it's relative cousin the ATMega128) are available in volume from AliExpress for about $1.40 each (just over a quid a time) and they're starting to look like real viable alternatives to learning how to use a whole new chipset. (Normally I'd be quite up for this, but right now, I need quick results, not another massive learning curve to tackle!)

The pinout for the ATMega is slightly different to the XMega




It also has fewer "unavailable" pins, fewer power/ground connectors and, even allowing for a dedicated crystal, has up to 54 i/o lines (rather than just 48 available on the XMega). True, it doesn't have as many peripheral devices as the XMega, but for this project, we're just interested in very basic input detection and sending serial data.

In fact, it was only after counting the available i/o on the ATMega that I realised the XMega I'd chosen wasn't actually suitable for what I wanted. Each board game section has 48 input sensors, needs power and ground, preferably pins for a crystal (though these may be omitted if the internal oscillator can auto-calibrate to take any drift out due to temperature etc) but it also needs at least one extra pin for (software, bit-banged) serial data. So I actually need at least 49 i/o pins.

Luckily, the ATMega still has digital i/o pins left over, even after mapping all my hall sensors and the serial data to pads on a PCB. All that remained was to design (yet another) layout for the ATMega128/165


I don't know if I need a crystal, or whether I can get away without one, but it makes sense to at least provide provision for one, should the need arise. The tracks get a bit "cosy" around the bottom left corner of the chip where I've routed a couple of traces out to an external crystal:


But all in all, the whole layout wasn't massively different to the XMega layout, and was designed using just two 0R jumpers to route the serial/power lines over existing traces. Already a massive improvement on the shift-register based design (which had those 6 extra ICs and about ten 0R jumpers).

Reading the datasheet of the AVR has also further simplified the design for this board. Namely, that every digital i/o pin on the ATMega128/165 has a controllable pull-up resistor on it. Which means that there's no need for a pull-up resistor on each of the hall effect sensors on the board. That's made an impressive 48 SMT resistors redundant! Which means we don't have to bother soldering them onto the board - all those potential points of failure eliminated!

Of course, I'll keep the resistor pads in the first/prototype design of the board (after all, how many times have you seen, even in a production circuit board, empty, silkscreen printed component outlines, which indicate something has changed/improved in the design, even after the PCBs have gone out for manufacture?) Even modern LCD TV controllers have un-populated component pads on them, so there's no harm in leaving the resistor pads in place, even if they're not used.

Slowly, slowly, after multiple revisions (only about a third of the designs actually started get finished to the point where I can add them to this blog) it feels like I'm finally closing in on the "proper" design for the generic board game sections. One which is not only cheaper, but also easier, to produce/assemble/manufacture. This design process has felt a bit like carving from a block of stone - we had a working prototype quite a while ago now, but it's through constantly chipping away, shaping and polishing the design that we've gone from a roughed-out shape, to a fully formed object.

Hopefully when I get back to Brighton tomorrow, I can see what the other nerds think and actually make up one or two of these boards and give them a try.