Explaining the XMega XPlained (Dev. Board)

About two months ago, Atmel announced a smart new set of AVR development boards, the XPlained series.  One of these boards (which I’ve just recently purchased for $30) boasts a shiny new AVR XMega microcontroller.  What?  An XMega you say?  Why yes, haven’t you heard?  Come now, they’ve been around for fully three years at this point.  Well, don’t worry if this is fresh news, you’re not alone.  For some reason, adoption of the powerful new XMega MCU has been slow amongst hobbyists.

The XMega Xplained (click for high-res goodness)

When Atmel introduced their new XMega series of AVR microcontrollers back in 2008, I was pretty sure they’d be a quick sell.  Even in spite of their unavailability in DIP packaging, and this cheesy marketing video.  But sadly, a quick search of Hack a Day currently yields only four articles containing the term “XMega” (versus more than three hundred articles for “ATMega”).  I guess change is hard.  And yet, it’s really not.

The XMegas utilize the same AVR core as the ATMegas, and are fully supported by the free AVR-GCC compiler and AVR Studio (obviously, I guess).  Plus, you can still use your trusty AVRISP mkII programmer to load code onto an XMega.  In other words, the tool-chain is unchanged.  So, with a few register name changes, code from an ATMega will run perfectly well on an XMega.  Sadly though, the XMegas and ATMegas are not pin compatible, so you won’t be able to solder a new XMega onto your Arduino.

Alright, so for those of you keeping track, I guess I’ve now listed three strikes against the XMega which may help to explain its present unpopularity: no DIP packaging, no pin compatibility with the ATMegas, and changes to register names (plus the addition of new registers for new features).  Oh, and odd marketing tactics.  By the way, as a side note, it could be argued that the XMega register scheme is better than that of the old ATMegas.  They’re making good use of structs, so that you now address a port’s direction using PORTX.DIR, rather than DDRX.  And you output to that port using PORTX.OUT.

But let’s now take a look at the data in favor of the XMegas, yes?  To do that, we’ll compare the ATMega1280 (utilized on the Arduino MEGA) against the ATXMega128A1 (utilized on Atmel’s new XPlained development board):

Feature ATXmega128A1 ATMega1280
FLASH Memory 128KB 128KB
Max CLK Speed 32Mhz (PLL) 16Mhz
RAM Size 8KB 8KB
Voltage Range 1.6 – 3.6V 2.7V – 5.5V
ADC 16, 12-bit, 2Msps 16, 10-bit, 76.9Ksps
DAC 4, 12-bit, 1Msps N/A
USARTs 8 (one supports IrDA) 4
Hardware Encryption 128-bit AES, DES N/A
Timers 8, 16-bit 2, 8-bit and 4, 16-bit
Current Draw, 1Mhz, 1.8V 365uA 500uA
Event System Yes No
Price $10.20 $16.13

Not bad, right?  I’d say the XMega wins this round.  It’s faster, provides substantially better analog to digital conversion, offers digital to analog conversion (in other words, analog outputs – a feature not available on any ATMega), hardware-based encryption (again, not found on any ATMega), lower power consumption, and, wonder of wonders, a lower price.  I’m quite impressed (for what that’s worth) and am particularly excited about putting these new analog features to the test.  In fact, as I mentioned, I’ve just received my XPlained development board and have already written a quick test program to do ADC → DAC pass-through.  But I’ll describe my experiences with the XPlained board a bit later (spoiler alert: they weren’t all pleasant).

So what precisely does the new XMega series offer that makes it, in my opinion, such a substantial improvement over the ATMega series?  Let’s talk speed for a moment.  The old ATMega topped out at 20Mhz, at least officially (though overclocking is possible, as seen in the Uzebox gaming system).  But furthermore, there is no way to adjust the system clock on the fly (although you can, of course, adjust peripheral clocks).  You’d have to make fuse adjustments with an external programmer.  With the new XMega series, you can adjust the system’s clock frequency at run-time.  Both a 2Mhz and a 32Mhz internal RC oscillator are provided, plus a PLL which allows for clock multiplication (1x, 2x, 3x, …, 31x).  According to application note AVR1005, you can even use the PLL to increase the clock speed of your peripherals to a maximum of 128Mhz.  This might be useful for generating high-resolution PWM signals, for computing precise time intervals (think range-finders), or for just blinking an LED really really fast (although perhaps not this fast).  Man, I could’ve used this on my MS thesis

Another neat feature of the XMega series is the brand new event system which allows for high-speed signaling between peripherals.  This is not a communications bus in the traditional sense.  It’s actually more like a set of, shall we say, “personalized” interrupts sent between features.  Event signals can be sent quite rapidly – in no more than two clock cycles – and don’t require the CPU to be active.

The XMega Event System

The XMega’s event system opens up a whole new world of possibilities.  With it, you could tie a set of 16-bit counters together to form one highly-accurate 32-bit counter.  Or, how about this application note example:

You could use one event to synchronize two modules. For instance, you could use a pin change event to do an ADC conversion and an input capture on the Timer/Counter to get exact time-stamps for each conversion.

For more details on the event system, see the “Getting Started with XMega” application note AVR1005 or the “Getting Started with the XMega Event System” note AVR1001.

First Impressions of the XMega XPlained Dev Board

Alright, well let’s get down to business here.  As I mentioned earlier, I’m now the proud owner of a brand new Atmel XMega XPlained development board.  I was putting in an order with Digi-Key the other night when I thought to search for XMega products (yes, shame on me, I haven’t tried them out until now).  I found just one, but it was precisely what I was looking for: low cost ($30.16), USB-powered, and covered in blinking lights (well, nine of them anyways).  So of course I bought it.  I mean, it’s not quite as much of a steal as the $4.30 TI Launchpad, but even at $30, I didn’t even bother to do research before adding it to my cart.   I just figured it would work.  :)  Bad idea, I know…

So what did I get for my money?  A pretty padded box and the board itself.  Nothing more.  No documentation whatsoever, only a printed messages on the outside of the box requesting I go online for any required drivers and data.

XMega Xplained Unboxing

Now the lack of paper is fine with me; if Atmel wants to save some trees, good for them.  I’d have gone online for datasheets and schematics anyway.  My only gripe here is that Atmel’s site isn’t all that easy to navigate.  In fact I don’t think I ever located a link to the ZIP file associated with AVR1927 (instead I just crossed my fingers, manually typed in the assumed link, and bingo).  But maybe I’m just bad at the internet.  Well for the sake of centralization, here are a few URLs I found helpful when getting started:

The XMega XPlained comes pre-programmed with a cute little application that blinks its nine LEDs and plays different sounds (drums, trumpets, etc. – just one- or two-second clips) when each of the eight different buttons are pressed. And I’ve got to say, the little speaker actually impressed me with its sound quality.  It’s not exactly a M-Audio studio monitor, but it’ll probably hold its own against a speakerphone.  And it’s certainly not being driven by square waves; they’re making good use of the XMega’s analog outputs (DACs).  So what else does the XPlained offer?  Well, here’s the official list:

  • External memory (8MB SDRAM, MT48LC16M4A2TG)
  • Atmel AT32UC3B1256
    • Communication gateway
    • Programmer for Atmel AVR XMEGA
  • Analog input (to ADC)
  • Analog output (from DAC)
    • Mono speaker via audio amplifier
  • Digital I/O
    • UART communication through USB gateway
    • 8 mechanical button switches
    • 8 LEDs (plus one bi-color LED)
    • 8 spare analog pins
    • 24 spare digital pins

Programming the XPlained using FLIP

So the pre-loaded software entertained me for about sixty seconds, after which my desire to reprogram the board overcame my fascination with lights and sound effects.  I didn’t have my AVRISP mkII handy (left it at work again), so I started by looking into reprogramming via the board’s USB connection.  The first thing I needed was a driver for the virtual COM port (Windows 7 did not recognize the XPlained), a single INF file:

USB CDC Driver (Virtual COM Port) – required for USART communications.

I was pleased to find that the instructions provided in the “Getting Started” guide (AVR1927) for using the Flexible In-System Programmer (FLIP) for RS232 programming were quite simple.  I downloaded and installed FLIP via this link.  I also had to import an XML configuration file (provided here), although it sounded like this file should have been included in the latest FLIP installer.  But before adding this file to <Install Directory>Flip 3.4.xbinPartDescriptionFiles, I received an error stating that “the device does not exist” when using BatchISP (the FLIP command line utility).  I also attempted to use the FLIP GUI directly, but for some reason the RS232 communication option was greyed out.  No problem though, I simply threw the programming commands given in the instructions into a simple batch file:

batchisp -device ATXMEGA128A1 -hardware RS232 -port COM25 -baudrate 115200 -operation onfail abort memory flash erase f blankcheck loadbuffer c:xmegatestdefaultxmegatest.hex program verify start reset 0


I’ve highlighted the elements you’ll want to change when using this file.  Including that pause command causes the command window to wait for you to press a key before closing, that way you can take a look at the results of your programming attempt:

FLIP (BatchISP) Command Line Programmer

So using BatchISP (FLIP) worked just fine for me.  The whole programming process took a bit longer than I would have expected (maybe 20 seconds), but it’s not terrible.  The one catch is that you have to unplug the XPlained board, and then plug it back in while holding down switch SW0, every time you want to reprogram.  This is required in order to activate the bootloader.  Doing this gets old fast, and it didn’t seem to please my computer (it would occasionally freeze for a few seconds when the device was quickly plugged back in).  But there is an easier way; keep reading…

Programming the XPlained using the AVRISP mkII

So based on the literature I’ve run across, it seems the preferred means of reprogramming (and debugging) an XMega is via JTAG using either the AVR Dragon ($50), the AVR JTAGICE mkII ($300), or the Cadillac of debugger/programmers, the AVR ONE! ($600 – perhaps this is the reason for the exclamation point).  The new XMega series uses the PDI (Program and Debug Interface) programming interface (as opposed to ISP).  However, it is possible to use the AVRISP mkII programmer (though you cannot use it for debugging), which costs just $35.  And if you’ve done anything with AVRs in the past, you’ve probably got one of these hanging around (I should note that the original AVRISP, the one with the DB9 port, will not work with the XMega series).

Now, to get your AVRISP working with the XMega Xplained, you’ll need to create a simple pin adapter.  You cannot connect directly to the board as the pins are arranged for a 10-pin JTAG connection (I guess Atmel really wants you to use JTAG).  However, you’ll only need to connect four of the six pins present on your AVRISP, as shown in this diagram (found on page 9 of the XMega “Getting Started” guide, AVR1005):

AVRISP Pinout Comparison

These pins can be found on the XPlained’s JTAG connector, as shown in the schematics:

XMega XPlained JTAG Connector

Once you’ve made these connections, you can use AVR Studio to reprogram your device as usual.  Well, almost.  First, you need to make sure it’s fairly up-to-date (I used version 4.18, build 700 with success, but you might go straight to AVR Studio 5, which I’ve also tried with success).  You’ll then need to manually specify the ATXMega128A1 before programming or adjusting fuses.  Plus, and this is key, you’ll want to disable the JTAG interface by using AVR Studio to clear the JTAGEN bit on the fuses tab.  If you don’t, your programming may or may not be successful.  I actually got into an interesting cycle where alternate programming/read events would fail.  I’d perform one operation successfully, but on the next I’d see “Entering programming mode…FAILED.”  But disabling the JTAG interface took care of this issue.  And doing so does not prevent you from re-enabling JTAG later, or from using BatchISP (though you may need to reload the bootloader if you’ve erased it, which may be found in this ZIP).

For more details on programming and debugging an XMega, see this article (and actually, check out all of these “Getting Started with XMega” articles, they’re quite good).

A First Test of the Analog I/O

Now I think I’ve stated this already, but again, I’m pretty excited about the new analog I/O offered on the XMega series.  In particular, the 12-bit digital to analog converters (DACs) open up a whole new world of options.  I mean, there are all sorts of applications out there that might benefit from an on-chip DAC: function generators, analog power supplies, audio processors, lighting controls, you name it!

So the first bit of code I wrote for my XMega is a simple ADC → DAC pass-through.  It’s a touch long to include in this post (because of all the comments), but please feel free to download it here.  The code takes an analog input on ADCA1 (PORTA1, pin 96) in the 0-2.1V range and outputs a proportional analog signal on DAC0 (PORTA2, pin 97) in the 0-3.0V range.  Here’s a screenshot of the results taken using my RPI IOBoard and LabVIEW interfaces.  The bottom graph (red line) shows the sine wave signal being generated by the IOBoard and connected to the XMega’s ADC input.  The top graph (white line) shows the scaled sine wave being measured at the XMega’s DAC output:

XMEGA ADC-DAC Pass-through Test

You may be wondering: why the difference in input and output voltage ranges?  Well, here’s one additional problem I see with the XMega: Vcc (max 3.6V) is not directly available for use as a reference for the A to D conversion, only Vcc/1.6V (which is 3.3/1.6 = 2.0625V, in this case).  Now you can select AVcc (typically tied together with Vcc, perhaps via a filter) as a reference for the DACs, although according to the hardware datasheet, both ADC and DAC reference sources are limited to AVcc-0.6V, or 2.7V on a 3.3V source (which is what you get on the XPlained development board).

Now in testing these specifications, I have found the ADC limit to be fixed as stated, although when I’ve selected AVcc as the reference for the DACs I’ve seen max outputs reach just over 3V.  Honestly, I don’t know what prevents the XMegas from using Vcc as a reference, as this is commonly done with ATMegas.  Oh well!  You just may need to throw in a voltage divider and/or op-amp to compensate.

One other issue I noticed was noise in the ADC signal when measuring values near 0V.  This could be an issue with how I’ve setup my code, or with some other aspect of my hardware.  But you can see this effect in the slightly garbled low points of the sine wave shown in white in the above screenshot.  I guess the bottom line is that I’ll need to play around with this a bit more.  (NOTE: I believe we have solved this issue; it is a problem with the XMega chip itself.  The solution is to use a lower (e.g. 1V) reference for the DAC.  See comments section below.)  Apparently there are also calibration registers for the ADC, and some pretty advanced tweaks you can make.  Take a look at this page on configuring and tuning the XMega ADCs – it’s been a great help to me already.


Overall, I’m cautiously optimistic about the XMega and the XPlained development board.  I’ve encountered a couple of minor issues, and the list of problems in the errata section of the datasheet is frighteningly long.  I should also point out that a previous version of the XPlained, the XPlain, apparently had quite a few more serious issues.  You’ll find references and pictures of the XPlain if you do a bit of Googling.  I’m not sure who’s still selling it, but I can tell you that despite the picture and the name, Digi-Key is shipping the newer XPlained, not the old XPlain (this is where I got mine).

So I still say that the XMega a great leap forward by comparison with the ATMega series.  The only question left is what to do next?

I’ve been thinking about going further with this ADC-DAC application and creating an audio compressor and volume control.  You see, I’ve got this cheap portable speaker that I use with my Blackberry for listening to MP3s.  The trouble is, there’s no remote, and each track seems to play at a slightly different volume.  So I’m thinking of using the XMega to receive IR signals from a remote and then adjust the volume accordingly (by scaling the ADC result before sending it to the DAC).  And at the same time, it could automatically adjust volume, based on the incoming audio signal, within a certain range.  This is called compression.  My setup would require a bit of analog work to get the signals into the correct voltage ranges before and after processing, but a couple of op-amps would likely do the trick without much work.

That said, I’m open to other ideas.  Has anybody out there got suggestions for projects?

This entry was posted in Hobbies, Test, Tutorials/Educational and tagged , , , , , , , , , . Bookmark the permalink.

23 Responses to Explaining the XMega XPlained (Dev. Board)

  1. Pingback: Electronics-Lab.com Blog » Blog Archive » Explaining the XMega XPlained (Dev. Board)

  2. Bogdan says:

    Mike, I’ve played a bit with the XMEGA for a project that I have started ( http://www.electrobob.com/digital-power-supply-part-1-concept/ ). The DAC and ADC combination make them very suitable for my needs.

    My guess is that they are very powerful devices that offer quite some feature set at a low price. But one reason why people might not jump into adopting them is that the MEGAs seem to provide sufficient resources for the majority of projects. Also, i don’t seem to find that much promotion from Atmel. Compare things to Microchip which has a great number of dev boards for their 24, 32 and dspic families.

  3. David says:

    You said regarding the XPLained board experience, “spoiler alert: they weren’t all pleasant”. So what specifically wasn’t pleasant about dealing with the XPlained board? The scattering of documentation, FLIP hassles, bad A/D conversion, analog reference limit, all the above?

    Personally I would use the Dragon to deal with this part, it is only $15 more than the AVRISPMkII yet so much more powerful now that ATMEL removed the fake memory limit imposed by their Marketing Goons. Rumors that the Dragon is fragile are nonsense. Some early versions were, but that was sorted out PDQ and any Dragon you buy today will be quite robust. Granted you will have to buy some sockets and jumpers for the Dragon to make it fully usable, and then wrestle with the horrible ATMEL Web site to find the instructions and configuration information, none of which I found to be downloadable. (Hint read all about the Dragon before you order so you know what additional parts to order, like a set of ten or so female-female jumpers, a 28 pin DIP socket and a wide 40 pin DIP socket for programming parts directly on the Dragon.) I think everyone agrees that ATMEL’s Web site is a pain to deal with.

    Thanks for the nice article – David

  4. Mike says:

    Thanks Bogdan, David,

    Yes, the standard MEGAs definitely meet most needs, that’s a good point. Even the TINY series does a pretty good job in a lot of cases. I guess I figured, for the slight price difference (or even potential price advantage), the XMegas would’ve seen more use.

    I’m glad to hear the Dragon has been improved. Yea, $50 really isn’t so bad, particularly if it gets you the ability to debug. Maybe that’ll be my next spontaneous Digi-Key add… Oh, and I’m glad to hear somebody else finds Atmel’s site difficult.

    Thanks for the comments!

  5. Walter says:

    Hey, great article! I did my senior design project around the atxmega128a1. It really has that “Arm” feel to it when coding. There’s definitely a learning curve for the new series which makes me wonder why I would want to go with an xmega instead of an arm. Its too bad they don’t have any pin compatible versions to upgrade those arduino kits. I think they really could have had a product that could take off.

  6. Mike says:

    Thanks Walter,

    I’ve not yet tried any of the ARMs myself… my experience is mostly 8-bit. But for me, coming from an ATMega background, moving up to the XMega was no big deal. I imagine the ARM would be a bigger jump. But the new register names were really the only difference in terms of coding. And yea, I agree, I wish they’d gone for pin compatibility here!

    By the way, nice blog! You’ve got some cool stuff there.

  7. Pingback: Regarding Atmel’s Xmega chips - Hack a Day

  8. mojo says:

    Looking at the range it seems like they only come in surface mount packages. A bit of a shame but it seems to be the norm for Atmel’s more powerful parts. All their USB enabled devices are surface mount only, for example.

    An Teensy style board with an XMEGA would be cool.

    You skipped over the details a bit but the SD-RAM and DMA both look very interesting. Being able to interface with SD-RAM and use DMA is a major plus over the MEGA range which struggle to add even a frame buffer for a low resolution LCD via SRAM. I am doing a project with a 320x240x16 LCD at the moment and a large buffer for holding graphics to be blitted etc. would be very helpful. For music playback in MOD format loaded from SD it could be used too.

  9. Mike says:

    Thanks for the comment mojo; good point about the external RAM interface. I’ve never done anything that sophisticated myself, but I can imagine it would be a huge plus if needed.

  10. Pingback: hackaholicballa - Regarding Atmel’s Xmega chips

  11. Alan says:

    I had a similar problem show up with noise on the DAC output on a project I was working on. It turns out to be a problem with the xmega itself. If you look under the errata on the datasheet it says:
    “DAC is nonlinear and inaccurate when reference is above 2.4V or VCC – 0.6V
    Using the DAC with a reference voltage above 2.4V or VCC – 0.6V will give inaccurate output
    when converting codes that give below 0.75V output:
    – ±10 LSB for continuous mode
    – ±200 LSB for Sample and Hold mode
    Problem fix/Workaround

    My solution was to use the internal 1V reference, I was lucky in that I was already using some op-amps in my design so I just had to change some resistors. The xmega has quite a few issues with its analog i/o, which is disappointing because it has so many new and useful features. Its still a very powerful chip though even if I have to use a few more op-amps than I used to.


    • Mike says:

      Cool, thanks Alan! I must have missed this section when browsing the many pages of errata, but this is exactly my problem. I’ve added a note above to indicate this. Thanks!

  12. Anojan S. says:

    You don’t really need to buy a separate programmer. The XPLAIN Bridge firmware does a great job acting as avrisp mkII clone:

    • Diecore says:

      XPLAIN Bridge firmware from Dean
      ( http://www.fourwalledcubicle.com/XPLAIN.php ) is for the old xplain with AT90USB1287 usb mcu.

      • Mike says:

        Thanks for clearing that up Diecore. Anojan is still correct in that you don’t need a separate programmer though – FLIP (BatchISP) does the job just fine, as described above.

      • westfw says:

        Oh. Now there are two different xplain boards? Sigh. How is non-windows programming support?

        Also working against the XMEGA was that long gap between the time the chips were announced, and the time you could actually start buying them…

        • Mike says:

          Yep, the XPlain (old) and the Xplained (new)… I can’t speak from experience, but their site claims drivers are not necessary for Linux. Now maybe that’s because the XPlained doesn’t work on Linux, but I’m guessing they meant no additional drivers are necessary.

          Good point on the gap, I guess I didn’t notice that myself because I didn’t try and buy any XMegas right away.

    • yoshi says:

      Nice. Can’t wait to get my hands on one!

  13. Pingback: AVR XPLAINED | A-Control

  14. cjameshuff says:

    I’ve done a breakout board for the XMegaA4 that allows it to be plugged into a standard breadboard. It’s sized small enough to fit in Seeed’s 5×5 cm Fusion PCB service, it’s easy to assemble with a hot air gun or hot plate, and it looks like this: http://www.flickr.com/photos/cjameshuff/4746915893/in/set-72157626747727809

    Not all that much to it. There’s the crystal and programming connector to save breadboard space, and decoupling capacitors and analog supply/reference filters. Gerber files and other information available here: http://www.arklyffe.com/main/2011/03/13/xmega-breakout/

  15. Pingback: Digital Power Supply – Part 1: Concept « Electro Bob

  16. Pingback: Modulo - http://wiki.arcol.hu

  17. Rahul Yadav says:

    Great post mate, enjoys reading. you really keep it simple. thanks for sharing.

Leave a Reply

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