Embedded Programming


Concept

Starting from a circuit with an ATTiny44 and FTDI connection, add an LED and a switch. Program it using the FabISP built week 1.

Design with Eagle

Key eagle commands in Schematic mode:
move, net, name, label, add, value, show, erc (electronic rules check), run BOM

Key eagle commands in Board mode:
route, rats, ripup (rip up), drc (design rules check)

Couple other key points:
When exporting the png for kokompe, remember: monochrome and 1000dpi.


I added 3 LEDs and a switch, to use up the free pins.

Milling and Stuffing Process

Milling was straight forward.

Stuffing Round 1 : moving a bit too fast. Got the processor inverted. Back to Milling.
Stuffing Round 2 : not bad. Went pretty quickly (but not too quickly).

Programming

Tricky stuff. Take this amazing example:

unsigned short pauseTime = 1000;
while (1)
{
    PORTA = (1<<PA3);
    PORTB = 0;
    _delay_ms(pauseTime);

    //pauseTime--;
}

Compile with the "make -f hello.ftdi.44.echo.c.make" and get

AVR Memory Usage
----------------
Device: attiny44
Program: 136 bytes (3.3% Full)
(.text + .data + .bootloader)
Data: 0 bytes (0.0% Full)
(.data + .bss + .noinit)

Now uncomment the decrement line, and what happens after compile?

AVR Memory Usage
----------------
Device: attiny44
Program: 3878 bytes (94.7% Full)
(.text + .data + .bootloader)
Data: 264 bytes (103.1% Full)
(.data + .bss + .noinit)

Yowch! Brian Mayton explained to me what is happening. Once the compiler realized that the argument to _ms_delay was not constant, it compiled in a floating point library. Take away:

(1) Embedded programming is subtle
(2) I need a good cookbook

To get a variable time loop I can do this (again, from Brian):
for (unsigned short i = 0; i < 1000; ++i)
_ms_delay(1);

So now I can do arithmetic decrement, e.g., pauseTime = pauseTime-10;
But I wanted to do geometric decrement, roughly down 10% each loop. But pauseTime = .9*pauseTime links in the floating point library again. But I found a trick. The bit shift operator will divide by 2. So if I want to decrement by say an eighth, this should work: pauseTime = pauseTime - (3< < pauseTime);

Result. A circuit that cycles through the 3 LEDs getting faster and faster. Push the button to restart.
The video:

http://youtu.be/jac7xnuf88U