Close

Tiny is as tiny does

A project log for AC Safety timer

Turns your soldering iron off after a half hour

nick-sayerNick Sayer 06/09/2020 at 06:300 Comments

Well, the ATTiny9 variant works. I'm programming with the ATMelICE under Windows for now, but I have found a solution for using the usbtiny with an external adapter with avrdude.

The really tough part is that the chip has 32 bytes of RAM. That was not a mistake. 32 bytes. That has to accommodate the call stack, all of the static variables... everything. The code didn't work at first, and I think the stack was just smashing the BSS.

The fix was to rearchitect it to separately track seconds and milliseconds. That allows time values to be 16 bit values instead of 32 and still be able to both debounce the button (with milliseconds) and track long time intervals (in seconds).

Additionally, all of the functions except for the timer ISR and main() have to be forced inline to reserve the stack for the ISR. This trades flash for RAM, effectively, but for this architecture, that's necessary.

It's also a little irritating that the 150Ω impedance on the opto-isolator breaks programming, so you have to disconnect it for every code change. It's unclear whether this is the fault of the programmer or the chip. The fix is to add a MOSFET as an impedance "buffer" of a sort. But if that's really necessary then it drives up the part count by one. I really hope it's just changing to a different programmer that makes the difference.

EDIT: Yes, it turns out that you can't directly drive an LED on TPID without disconnecting it for programming. So there needs to be a MOSFET driver as an impedance buffer unless you want to remove the series resistor every time.

Discussions