After some soldering I manage to put the components on a small development boards and start coding.
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 !
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 :
And plot them with a quick and dirty Java program:
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
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.