Make me a simple timer

Svetlana Linuxenko
4 min readJan 30, 2022

- You are an Engineer, make me a simple timer please.

I was never asked to make anything "simple", especially when it comes from friends of mine. This time it was one of the most challenging projects. The project must be a hardware device with a relatively big screen, which could be easily read from a distance. Its configuration have to be simple for user, using buttons to set the timer for up to 60 minutes.

Never had any of those big LCD screens, so I found a broken clock with an appropriate size of screen. A surface of its controller IC had no numbers or any recognizable marks, so I’ve decided to get rid of it.

After this I was able to check if leds work and which connection type they have on the PCB (there is a common cathode and common anode connection types).

Making a programmable interface

Every LED was working, every segment was easily recongized by NPN transistors connected with segments. The only thing left is to find out which anode coresponds for a specific segment, lets say it was a magic, because some parts of the circuit was shorted. It looks like someone tried to make the clock work under water.

Love this small wires:

Then I noticed there is no room for a number of components I planned to use for the project. It is quite important if you prefer to use DIP components.

Programming the interface

The most important part is the timer’s precision. There was no room for any other external components so this part have to be solved by programming. I had one of those 16Mhz crystals which is quite precisely work on ranges from 3v to 5v with the controller (atmega8 was used btw). After some time of testing I’ve realized that it jumps over a second for a 12hour period, so it should be precise enough for my needs, lets make some calculations 1 / 12 = 0.0833333, yep, it’s quite precise for my needs. I set the timer for a millisecond overflow (when you intend to display seconds in a real time it is the only way).

```c

ocr1a = 160;

tccr1b |= (1 << wgm12);

timsk |= (1 << ocie1a);

tccr1b |= (1 << cs12) | (1 << cs10);

```

Configured the previously soldered interface in the code like this:

```c

DDRD |= 1 << PIND2; // SEGMENT A

DDRD |= 1 << PIND3; // SEGMENT B

DDRD |= 1 << PIND4; // SEGMENT C

DDRD |= 1 << PIND5; // SEGMENT D

DDRD |= 1 << PIND6; // SEGMENT E

DDRD |= 1 << PIND7; // SEGMENT F

DDRB |= 1 << PINB0; // SEGMENT G

/* Digit Pins */

DDRC |= 1 << PINC0; //D1

DDRC |= 1 << PINC1; //D2

DDRC |= 1 << PINC2; //D3

DDRC |= 1 << PINC3; //D4

```

Now it looks clear. The only thing left is to write the driver for the display, it is not a difficult task so I wan’t bother you with details. A second problem was debouncing the buttons, as I had no room for any capacitors, it had to be solved by programming too (there was some pulldown resistors connected with every button btw).

The decision was to use a timer interrupt to simple reset "lock" for a specific period of time and check if button was pressed. The code which checks is simple as:

```

if (!toggle_lock)

return;

toggle_lock = TOGGLE_LOCK_TIME;

if (PINB & (1 << PINB1) && !previous_toggle) {

previous_toggle = 1;

int smin = minutes % 10;

int fmin = (minutes- smin) / 10;

switch (mode) {

case MODE_SET1:

if (smin < 9)

minutes++;

break;

case MODE_SET2:

if (fmin < 5)

minutes += 10;

break;

}

return;

}

```

The first 5 lines work with “lock”, the rest is intended to increment timer’s time in setup mode.

Time to assemble the device

I had a small battery which I wanted to place inside of the enclosure but after some time lying on a shelf it didn’t want to charge. The replacement I found was too huge, therefore was placed outside. It reminds me the "css is awesome" meme :)

Anyways it isn’t a problem and can be replaced anytime.

Video of working device

Will share on twitter, because medium is a little bit too sux for writting. Sorry but it is true (at least for mobile version).

Conclusion

The UI/UX development for everyday’s tasks may require an Engineering set of mind, sometimes to be a good programmer could be not enough.

--

--