Figure 1: Typical AT32UC3L Setup
The Celtic Engineer is a weekly newsletter produced by Celtic Engineering Solutions. We hope you enjoy it. If you have any suggestions for topics, would like to give feedback or want your email added to the distribution list please send an email to [email protected]
Starting every project from scratch?
No engineer that I have ever known will start a project from scratch every time. Whether you have example designs stored on your hard drive or in your head, we all create blocks of circuits that we understand and can plug in to solve a particular problem. One of the most common areas where this is practiced is with microcontrollers. Most engineers will have one, or perhaps a few, favorite microcontrollers they use on projects.
Why not pick a new MCU with each project? The answer is obvious, there are costs, in both time and money, to starting a design from scratch. If you can start with something you know, you can save hours or months of time. I can’t remember the last time I was given a project that didn’t need to be done yesterday.
I have spent a lot of time working on battery powered projects that needed to last for months without a battery change. One of my goto MCU’s is the AVR UC3L.
I have been using the L-Series MCU for almost 10 years. In that time the program size has grown from 16KB to 256KB. And the price has shrunk from $12 each to, currently, $4.35.
This is a very powerful 32-bit MCU. I began using it not only because of its powerful ability to crunch numbers, but its low power capabilities. It is part of Atmels picoPower group and utilizes a technology they call SleepWalking which provides advanced power saving control for embedded projects.
SleepWalking is the ability of the MCU to continue operating without the CPU being online. One of the biggest draws of power comes from the CPU, so the ability to work without it is a great advantage. It does this by using intelligent peripherals. These peripherals are able to complete a specific task without the use of the CPU. So, while a peripheral is working hard, the CPU can be asleep.
The MCU operates off of 3.3Volts. It has an internal 1.8V regulator that can be used to power the core. I have been very successful using 0.1uF caps for the VDDIN and the VDDIO pins. I place a 2.2uF and a 0.1uF on the 1.8V reg out (called VDDCORE) and a 0.1uF on the VDDANA and ADVREFP pins.
There is a 120Mhz oscillator on board which will let you get up and going pretty easily. You will probably want to slow it down as running that fast is a power pig. If all you are doing is controlling, the internal oscillator is great. If you want to communicate, you will want some more accuracy. You can use the DFLL (Digital Frequency Locked Loop) and a 32Khz crystal to set the main clock speed. I usually run at 30Mhz in this mode.
Communication is King
I once worked for someone with a PhD in Computer Science. He said the hard part is to get the MCU to communicate over the serial port. Once you do that, everything else is easy. The first thing I do is to set up the USART. With the internal oscillator you can usually communicate, but there is drift from device to device and over temperature that makes it necessary to tune the frequency of the USART. That is a pain, so I always use a crystal. Then you don’t have to worry about tuning. With the serial port set up, you can send yourself messages about anything you would like. That is why everything else is easy.
How about Ports?
There are just two ports PA and PB. These control the pins and allow access to the GPIO or peripheral functions. The USART is a peripheral as are the ADC (8-12bit) and the16 bit counter. You would be amazed at how much you can get accomplished with just those few peripherals. Additionally, there is a capacitive touch module, an analog comparator, a frequency meter, 8-bit PWM modules, SPI, and TWIS (better known as I2C).
One of the first things I set up is a heartbeat. I set up the 16-bit counter and the interrupts to give a 100uS or 1mS interrupt depending on what I will need to do. Then you toggle an LED every 500mS and you know if your system is up and running. You set up your main loop with a user interface from one of the 4 USARTS and you are ready to write code.
C Code and IDE
Atmel provides a free IDE called Atmel Studio, currently at revision 7.0. This makes it very easy to organize your code, compile, debug and program your device. You will need a programmer. I use the Atmel ICE, sells for about $100.
This newsletter is sponsored by Celtic Engineering Solutions LLC, a design engineering firm based out of West Jordan, Utah, which can be found on the web at: www.celticengineeringsolutions.com. You can find the newsletter on the company blog, LinkedIn or in your inbox by subscribing. Send your emails to The Celtic Engineer at: [email protected], with the subject line SUBSCRIBE.