Thursday 23 June 2016

Running Arduino atmega328 at 3.3v from lipo battery

Here's something that kept us stumped for a full day - getting an atmega328 to run at 3.3v.
We're using an accelerometer and a sound module that both run at 3.3v, so it made sense that we run our Arduino/AVR at 3.3v too.

Using our spanky TQFP socket, we could easily drop code onto an atmega328 chip; in the IDE simply select Sketch - Upload with programmer


And everything worked just fine.
But what we really wanted to do was make a "bootable" chip, so - if necessary - we could fine-tune the firmware, once the actual chip had been soldered onto the (tiny, cramped) PCB.

Which meant burning a bootloader - so we selected the appropriate board (since we're running at 3.3v we ditched the 16Mhz crystal and went with an 8Mhz ) and hit "burn bootloader".




Again, everything worked, and we could upload sketches from the IDE to the (naked) chip over serial. So then we pulled the power and connected up our lipo battery. For testing, we simply put the lipo output voltage - about 3.8v - through a diode to drop it down to around 3.35v

And then things started getting a bit weird.
Because the chip would respond at 5v, and at 3.7v. But at 3.3v it appeared dead.

(shocking ferric-fingers just look like dirty fingernails - how embarrassing!)

Very peculiar. Whether using the usb-to-serial 3.3v option or the "output" from the diode on the lipo, at anything less than about 3.5v the microcontroller appeared dead.

The first clue about what was going on came from this post: http://arduino.stackexchange.com/questions/23245/confusion-with-atmega328p-and-3-3v-8mhz

Already we were beginning to suspect the brown fuse settings, but we were unable to correctly change them and get a fresh bootloader burned. The "extended" fuse settings are where the brown-out voltage resides:


And we definitely wanted to disable the brown-out detector. So a value of 0xFF seemed like the best option. In the boards.txt file, we found the 3.3v/8Mhz option and changed it. After burning a fresh bootloader to the chip, we got this:


No bootloader. No flashing LED. Nothing.
But if bits 7-3 are not used, and we wanted to set bits 2-0, an extended fuse value of 0xFF seemed like the best option. Except it wasn't. It was only after setting masking the extended fuse value, and ensuring that the first 5 (most significant bits) were cleared could we even get the bootloader to burn.




With the extended fuses set to 0x07 (bit pattern 00000111) the bootloader not only burned, but the mcu started to work with voltages of 3.3v (and lower). So today's lesson: in Microchip and AVR land, "not used" means two very different things!




No comments:

Post a Comment