Pfad: Home => AVR overview => applications => Egg-timer

A small homemade project - just for fun - but very practical

The ATtiny2313V-egg-timer

  1. Description
  2. Hardware
  3. Functioning

1. Description

Who didn't already run into that: the n-th birthday celebration of friend X.Y. is coming up, and you do not have any idee what your friend's household is missing. Now, you can just go to a shop, that sells any kind of presents, and buy something sense- and useless, wrap it in nice paper, and just hope that no one else will have the same (non-)idea. Otherwise the main question will come up: exchange this piece to another piece, that no one needs?

If you are experienced in soldering some electronic parts together and of programming an AVR, you have a clear avantage over all your other friends: producing a very individual gift, that no one can copy by chance, and put it on the birthday gift table. During the next twelve monthes, all our friends, relatives and neighbours receive an up-to-date, individually designed and personally flavoured egg-timer. Of course, equipped with the latest, greatest micro-professor, as available on the electronic device scene today. Not just one of the old-fashioned and traditional flasks, filled with acid-cleaned silica sand. Quietly rippling sand was yesterday, today it is beeping and blinking.

The principle is very easy: a row of LEDs, e.g. placed like a bar, is lit green and red (first variation: yellow and red), whenever a minute is over, one more green light changes from green to red. To save battery capacity and use the timer for more than one egg to cook, only one LED is lit at a time in the display cycle. The band is running fast, so that there is some action in the kitchen and you can catch the timer's state in just a short glimpse, looking up from your morning newspaper.

If you are too fascinated by all the news in your newspaper, you do NOT even need to keep an eye on your timer: it just beeps the number of elapsed minutes. That makes your egg-timer also compatible with the needs of handicapped people, that arent able to see the disco lights, which makes a major difference to the sand-filled equipment. If ten minutes are over, a yellow light and a continous beep tells you, that the egg yolk has turned to green now, and that the egg can be thrown into the trashcan.

I only describe the electronic and software design here, so you must add your own creativity in the package design. For placing the LEDs, consider the following opportunities:
  1. A straight line of LEDs signals geometric strength, and is more adapted to straight-thinking people like e.g. mathmaticians or housekeepers, model "straight forward",
  2. A circle is possible, and more adapted to people with a similiar belly, model "beercan",
  3. For the more playful people, the form of an egg is more appropriate. This model is also good for the short-memoried, because it reminds what the equipment is made for, model "short-term memory",
  4. For the more chaotic, untidiness- and complexity-loving neighbor, you can place the LEDs in a random manner on the unregular-shaped casing, model "Hundertwasser" (see an intro to Hundertwasser),
  5. The design for the gamer: place the LEDs randomly, and exchange the LEDs every minute randomly by software. He will love to guess where the next LED will get red, model "vote and surprise".
From my own experience it has been proven top, to add an individually designed instruction manual to that gift. Humorous formulations, like english words combined with taiwanese grammar, bring good vibes to the birthday celebration. Also, you can write the instruction in english, translate this to japanese language, retranslate it with Babelfish to english, and then exchange single words by their dutch translation.

To the top of page

2. Hardware

Schematic Egg-timer The hardware scheme is pretty easy: the two batteries (2*AA, 2*AAA is suitable, too) supply the hardware with 3 wonderful Volts. More voltage destroys the LEDs very fast, so don't supply with 5 Volts. The row of dual-LEDs is cascated with resistors, limiting the currents. Each LED can be driven in both ways by the portpins. When soldering the LEDs, only ensure their uniform direction, their colour can be easily changed by software.

All portpins that are not needed to drive a certain single LED, are set to tristate (input) and therefore do not interfere. The ATtiny2313V (without V is also fine) always drives only one LED, the voltage drop, when sourcing from the pin under load, has been calculated in the design of the resistor. The yellow egg-throw LED has its own portpin. A small piezo-speaker is directly pinned to the OC0A output. If you don't have a piezo, you can use a small 32-Ohm-speaker, decoupled with a C of 100 µF.

pcb layout Here a possible layout for a PCB for the eggtimer. The format is 100 by 80 mm (3.15 by 3.94 inches).

pcb parts Parts placement displayed here.

Eggtimer in a casing Building the eggtimer into a black case looks like this.

Eggtimer in plastic Somewhat more sophisticated, in plastic glas, with two layers: the battery and the speaker are mounted on the lower layer.

To the top of page

3. Functions

3.1 Processor programming

The processor hardware cannot be programmed in in-system-mode (ISP), because the operating voltage should not exceed 3 V. The processor has to be prgrammed on an extra programming board and then moved to the egg-timer hardware.

First, the processor is changed to operate with the internal 4-Mcs/s-RC-oscillator, to reduce power consumption. The DIV8 fuse stays activated, so that the processor runs with a 500 kcs/s clock. Slow enough for the V-version.

Assembler source code for the basic version is for download in asm format here and can be viewed in HTML format here. A newer version of the code provides a gamut and a melody at the start-up, asm format here and html format here.

In the source code, first the portpins are assigned. That means that all LEDs can be mounted in any sequence and assigned here. The drive row must be assigned by the correct output port, portpin and direction port. The extensive program code to drive the correct LED, at the end of the source code, is attributed to that flexibility in placing the LEDs.

Time measurement and LED-switching is assigned task of the 16-bit-timer 1, that runs in CTC mode. When reaching the value in the compare register A, every 0.2 sec, an interrupt is triggered and the T flag in the status register is set. The interrupt wakes up the processor from idle sleep. The T flag is cleared, and the lowest bit of the LED counter is checked. If this is one, the beep tone is switched off. If it is zero, it is checked whether a beep tone has to be generated. If yes, the speaker output is turned on (Timer 0 is activated) and the number of remaining beep tones is decremented.

After that, the last LED that was on, is switched off. The LED counter in incremented by one and is checked, if it is already higher than 10. If yes, the two-second-counter is incremented and checked, if this has reached 30. If yes, a minute is over and the minute register is incremented. If that has exceeded 10, the yellow LED is activated and a continous beep is initiated.

At the end, the next LED to be lit is calculated and, according to the minute counter, is switched to red or green. For calculation of the correct routine, the start address of a jump instruction table (red or green) is written to the register pair ZH:ZL and the LED number is added. By executing IJMP a jump to the correct routine is performed. After switching the correct LED, the routines all jump back to the sleep instruction of the main program loop.

3.2 Variations

There is a broad palette of possible variations:
  1. LED band speed:
  2. Incorrect LED order? No problem: exchange the lines
    ldi ZH,HIGH(TabRot) ; try with red, and
    ldi ZL,LOW(TabRot)
    against the lines
    ldi ZH,HIGH(TabGruen) ; no, it is green, and
    ldi ZL,LOW(TabGruen)
    and the line runs with opposite colors.
  3. Higher tone? No problem, in the line
    ldi rmp,63 ; CTC-value
    just exchange 63 by a smaller value for timer 0.
  4. Egg-timer for a musician? Possible. Just add a table with the CTC values of the gamut to the flash, and, after each minute, change the CTC value with the next value in the table.
  5. If your customer prefers hard-boiled eggs of the type "golfball": add four dual-LEDs to the four available portpins and add them to the software.
  6. ...
The number of possible variations makes it impossible to offer the software for all these variations. The number of variations should be big enough to design an individual gift for each and everyone in your circle of friends, so that no one gets a timer with exactly the same design. But: keep good records on all the distributed variations. Otherwise you might run into new trouble.

And now: good luck with your handicrafts.



To the top of page

©2009 by http://www.avr-asm-tutorial.net