Close

Code contraints and Prototyping

A project log for Another Candle

An attempt to mimic a real candle. Another digression based on the work of many people, plus a PIC10F320

muthMuth 01/04/2018 at 18:130 Comments

After some soldering I manage to put the components on a small development boards and start coding.

IMG_5267

IMG_5268

I used the Microchip IDE and their XC8 C compiler. The challenge here is that the compiler is in ‘free’ mode, so the compiled code is rather large. I didn’t want to use assembly mainly because I’m not quite confident to prototype with it. But I admit it is the preferable way to do something with only 256 bytes of program available. It’s perfectly legit to argue that an ATtiny10 would at least do the job better. I should invest time to the AVR side one day !candle_XC8

After many iteration to reduce the program size, I end up with only 4 free bytes. Wow. Some C operations give more compact program for the same function (for example initialisation to 0 or an arbitrary value).

The code uses the famous Linear feedback shift register as random generator. The flame position, the speed to go from one to the other position, the oscillations occurrence and their period number are random. The two LEDs are dimmed with the build in PWM, and the speed of change with the Timer0.

It is still open to more complex code as I can use the PIC10F322 with 512 bytes of program space (or even ATtiny10 which seems to be almost pin compatible).

I acquired the two LEDs PWM signal with my recently acquired DSLogic :

candlePWM

And plot them with a quick and dirty Java program:

candlePWMchart2

You can notice the oscillation mode on the chart after 4th second, and the flame swing mode surrounding it. For the oscillations, the total brightness is changing while otherwise it stays constant at 50% (the sum of the two led brightness).

The PIC code is on this github repositoy : https://github.com/pierre-muth/another-candle/blob/master/candle01.X/main.c

Discussions