Today on the blog, I’d like to discuss an important change to my megaPhone project: I’m switching the processor from the ATxmega384C3 that I’ve been baselining thus far to an ATSAML21G18B. I’ve listed some key characteristics of the two MCUs in the table below.
ATxmega384C3 | ATSAML21G18B | |
Max speed (MHz) | 32 | 48 |
Architecture | 8-bit AVR | 32-bit ARM Cortex-M0+ |
Program memory (kB) | 384 | 256 |
SRAM (kB) | 32 | 32 |
Pin count and package | 64-pin QFP | 48-pin QFP |
Power consumption at max speed (mA) | 10-15 | Up to 4.56 |
Price (£) | 6.58 | 4.32 |
You can see that the SAML21 beats the xmega384 in almost every respect, including price. I find it really amazing that you can get an ARM Cortex-M0+ processor for only £4.32 (including VAT). When I discovered Microchip’s range of 32-bit microcontrollers, I was keen to see how they compared to the ATxmega384C3, which sits right at the top end of the AVR lineup. I found, using Microchip’s handy comparison table, that even a relatively low end 32-bit device like the SAML family can go up against the xmega.
The smaller package for the SAM will give me more space on my board for other components and the much lower power consumption will help to give the megaPhone a long battery life. The lower price than that of the xmega is also very welcome to bring down the phone’s overall cost.
Given how complex the code for the megaPhone is likely to become, and given my lack of experience at writing code that doesn’t take much program memory, I wanted to make sure I had plenty of memory in my processor. This is why, when I was choosing the xmega, I went for the 384C3 version with 384kB of Flash program memory. I suspected this to be a bit of an overkill though, so I’m not really worried about reducing this to 256kB in the SAM chip.
Overall then, the ATSAML21G18B is a very worthy replacement for the ATxmega384C3, with better performance and much lower power consumption, in a smaller package and for less than two thirds of the price.
I/O Requirements
The SAML21 family is available in three different package sizes: the L21E series has 32 pins, the G series 48 and the J series 64. So why did I choose the 48-pin G series for this project?
One key aspect of choosing a processor for the megaPhone is making sure it has enough input and output (I/O) pins. To do this, I made a list of all the peripherals it’ll be connecting to, along with how many pins each peripheral needs. These details are shown in the table below.
Function | Number of pins required |
USB | 2 |
GSM module | 9 |
Display | 4 |
Keypad | 7 |
Direction buttons | 5 |
Battery voltage sense | 1 |
Vibration motor | 1 |
Total | 29 |
The SAMD21G18 has 37 pins that can be used for I/O, as shown in the pinout below, so has enough to accommodate the 29 pins needed for the phone’s components.
Development Changes
This change is processor necessitates a change to my work done so far: I need to change the device in my schematic and board layout. This is a relatively small change, particular given that not much had been connected to the xmega, so should only take a day or two.
I’ll also need to familiarise myself with the registers in the new processor, although many of their names are the same as those found in the xmega. I’ll be reacquainting myself with the use of pointers to manipulate registers, with the new processor commonly using 32-bit registers compared to the 8-bit registers found in the old chip.
Breakout Board
So how will this affect my breakout board for the ATxmega384C3? From now on, the breakout board will no longer be on sale, as I will not be using it for development of the megaPhone. However, if you’re particularly interested in buying the parts for a board, send me an email using my contact form and I’ll get back to you regarding cost and getting the parts shipped to you.
I still need something to develop my software on though before I send my PCB to manufacture. The SAMD21 family, which I’ll go into more detail about below, is very similar to the SAML21, so I’ll make use of one of the many breakout boards already available for that range of microcontrollers (such as the mini one from SparkFun). This was another advantage of switching the processor – I can use a known-good board for development so I can be sure that any problems are in my software.
The ATSAML21G18B is very similar to the ATSAMD21G18 used in the SparkFun board and the Arduino Zero, meaning that lots of people will already have developed code for this platform that I can use for debugging if needed. However, I’ll be developing my code in C in Atmel Studio 7.0, avoiding the overhead and extra layer of abstraction produced by using Arduino code.
I did consider using the ATSAMD21G18 for the megaPhone, and this would have made software development very easy by being able to directly transfer it from a development board to the final hardware. However, the SAML21 family adds a power management module, allowing greatly reduced power consumption (for example, using 1.92mA to run a Fibonacci algorithm at 48MHz versus around 4.53mA at 32MHz for the SAMD21) for only a modest increase in price (£4.32 versus £3.12). With long battery life being a primary concern for a mobile device like the megaPhone, I think the extra cost is very justifiable, and I’ll be making good use of the SAML21’s power management capability. The SAML21 is also almost pin compatible with the SAMD21, making porting of code from a SAMD21 breakout board easier.
Naming
One final, but important potential change to the project is its name. The megaPhone is so called because of the xmega processor that was found at its core. Now this has changed to a SAM chip though, I should probably think of a new name. SAMphone’s ok, but I’d love to hear if you have any suggestions for a good name for the project – let me know in the comments below. If there any features you think the phone really needs I’d really love to hear about them in the comments too.
As always, you can find all my posts about the project here on my website and under #megaPhone on Twitter (for now at least and if I decide to stick with the current name). I’m currently working on a requirements document for the phone, which I’ll be releasing on this blog once complete. I have plenty more work to do too though, so see you in the next blog post!