close-circle
Close
0%
0%

AVR vs PIC: The case of the candle

A self-igniting candle implemented using AVR and PIC microcontrollers

Similar projects worth following
close
This project has two variations, one using an ATTiny25, the other using a PIC12LF1822.

In a series of minimalistic devices, this electronic candle periodically measures ambient light levels. Once it detects nightfall, it self-ignites and burns for three hours, flickering as a candle does. The flicker intensity changes about every minute, adding more variability.

The hardware is as simple as it gets: A battery, a microcontroller, and an LED connected to two pins of the microcontroller.

I used cheap equipment for programming the microcontrollers. An Arduino for the ATTiny and the PicKit3 for the PIC. This gave the AVR project one disadvantage. I do still not manage to talk to ATTinys running slower than at 500kHz, so that was the frequency I had to stick with. As to the PIC, it runs on the internal low power oscillator at 31 kHz.

It's probably no surprise to anyone that this project is simple to implement on both microcontrollers. As to differences between the two platforms, I am more used to AVRs, so programming the ATTiny25 simply felt more familiar. The PIC had a lot going for it, though, in terms of programmer (I wish there was a good, cheap debugger for AVRs too), watchdog timer power consumption and the low power oscillator.

Power consumption comparison

StatusATTiny25PIC12LF1822
Waiting for day or night4 uA< 1 uA
Candle burning (without LED)190 uA5 uA
Candle burning (with LED)2.5 mA

2.3mA

The ATTiny seems to be at a disadvantage in terms of power consumption. For this project however, the microcontroller consumption is not really relevant. A typical CR2032 will last 30 days with the ATTiny and 33 days with the PIC. You could also just dim the LED on the ATTiny a bit more and noone would notice.

I must say that the PIC's ability to do some computation at 5uA is extremely nice. The ATTiny at 128kHz still uses something like 110uA.

PIC-candle.c

Candle implementation for PIC(L)F1822/1840

C Source File - 6.97 kB - 07/01/2016 at 18:58

download-circle
Download

AVR-candle.c

Candle implementation for ATTiny25/45/85

C Source File - 5.23 kB - 07/01/2016 at 18:57

download-circle
Download

  • 1 × ATTiny25/45/85 or PIC12(L)F1822/1840
  • 1 × CR2032 with battery holder Batteries and Battery Accessories / Batteries
  • 1 × LTL2T3YR6JS - 5mm LED, yellow, 1150mcd, 60° viewing angle

  • Schematic added

    Thierry07/01/2016 at 19:10 0 comments

    Just a small update to the code. I have added a schematic to the code files to show how the connections are done. It is really simple to the extreme.

    BTW, it is very nice to see that this project has gained some followers. I am not sure why. Is it the simplicity? Or is it because everyone loves candles? In any case, I decided to create another type of candle as a first application of my "Visible Light Communication" project. The circuit will be just as simple!


View project log

Enjoy this project?

Share

Discussions

Dan wrote 06/23/2016 at 12:25 point

Perhaps it's just as simple as connecting an led and resistor to PB1...?

  Are you sure? yes | no

Thierry wrote 06/23/2016 at 20:30 point

Good point, I should add a small schematic one of these days. It is indeed simple enough. Connect an LED with anode on PB1 and cathode on PB2 (on the ATTiny that is). You won't need a resistor at 3 volts.

  Are you sure? yes | no

Dan wrote 06/23/2016 at 12:22 point

Nice project.  Any chance you can post the schematic?  

  Are you sure? yes | no

Nick Sayer wrote 06/19/2016 at 15:23 point

Programming AVRs that are clocked slow requires slowing down the programming SPI clock. You can do this with a command line arg to avrdude. The specific arg depends on which programmer you're using, and not all programmers support changing their SPI clocks without changing the programmer's firmware. The best choice for programming slow AVRs is the usbtiny. For that, use -B n, where n is a delay factor. I use 250 to make a 4 kHz clock for my 32 kHz clocked projects.

  Are you sure? yes | no

Stuart Longland wrote 06/19/2016 at 20:31 point

Another option for programming the ATTiny might be to use a Linux-based single-board computer which can run `avrdude` using the `linuxgpio` interface.  Then since it's essentially bit banging, it has full control.

https://hackaday.io/project/10529/log/40183-debugging-an-attiny24a-programmer-upgrade is an example of this using a Raspberry Pi.

That said, you can probably modify the code on the Arduino to achieve the same effect.

  Are you sure? yes | no

Nick Sayer wrote 06/19/2016 at 21:07 point

Absolutely. With linuxgpio, instead of using -B, you use -i and divide the number in half. FWIW, I sell a Raspberry Pi AVR ISP "cap" that does the hardware side of that (I also sell a USB Tiny clone too).

  Are you sure? yes | no

Thierry wrote 06/21/2016 at 18:47 point

Thank you both for the comments! I will certainly try to slow down my AVRs accordingly. I have an usbtiny programmer somewhere. Otherwise I'll just use a Raspberry Pi. Ah, I might even be able to reanimate the ATTinys I seemingly bricked the last time I tried to slow down.

(Sorry, BTW, for the slow answer. I have lost my Atmel Studio some days ago and had a long fight to get it back. As it turns out, it seems to be a bad idea to try developing Windows 10 UWP and AVRs on the same computer. The Visual Studio components do not mix well somehow).  

  Are you sure? yes | no

Stuart Longland wrote 06/21/2016 at 20:39 point

No problems on the reply delay.  As for Atmel Studio… the good news is that AVRs are basic enough that just about any development environment will do.  I personally use `make` and `gvim`.  Primitive, but gets the job done. :-)

  Are you sure? yes | no

Nick Sayer wrote 06/28/2016 at 14:44 point

I second what Stuart says. Most of my AVR projects nowadays are built with make and plain avr-gcc from either crosspack (for the Mac) or wherever apt-get gets them on R-Pi.

  Are you sure? yes | no

Similar Projects

Does this project spark your interest?

Become a member to follow this project and never miss any updates