Simple digital timer as NE555 killer in many application were accurate timing is required from seconds until hours.

Simple digital timer

Not exactly a drop-in replacement for the good old NE555, but usefull for many timing jobs where a delay of seconds until hours is needed.
Original designed for a coffee-machine containing 3 NE555 timers for 3 different keys: cup, half pot, full pot. But the timer never came into production. Now, a couple of years later, I think the idea may be usefull for other hobbyists.

The main reason to replace the NE555 timers were incovenient calibration and because of electrolytics in the circuit the long-time stability was not so good.

The calibration procedure of the NE555 timer was as follows:
  1. place the cup or pot in the machine
  2. press the required button
  3. wait until finished
  4. if the coffee-level is not OK: turn the potmeter a bit
  5. repaeat the procedure until you are satisfied
This was a very time-consuming job as the filling of a pot lasted a few minutes and the proces had to be repeated a couple of times.


I first started with a PIC16F84A, the type of microcontroller I used most often at that moment. For the coffee-machine 3 push-buttons were needed and a button to initialize the setup routine. Originally there were only 2 outputs: a flahing LED to signalize setup and the water-valve. Also the timers were locked against each other. To create a more universal timer now 3 outputs for the timers plus 1 for the LED are available and the timers became independent.
This prototype timer went into the source as version 3.

Later the real NE555 replacement was added: an 8-pin microcontroller with 1 timer. For stability a crystal can be used, but for a lot of application (as for the coffee machine) the internal oscillator is good enough. This became version 1.

But the 8-pin chip has 6 I/O-pins, therefore also 3 timers can be implemented in this small chip. This is version 2, which was originally designed as the target of my development.

Version 4 with max. 8 timers was created later when I looked at my simple PLC-board and thought a stand-alone board with 8 independent timers could be usefull, for instance for the modell-railroad. If you need more accuracy by using a crystal still 6 timers are available, but in that case you have to design your own board.

Summarizing: the 4 versions are:
1: PIC12F629/675:
  • the mini-version using an 8-pin chip
  • 1 timer, crystal-osc. (or internal RC-osc.)

2: PIC12F629/675:
  • meant for the coffee-machine
  • 3 timers, internal RC-osc.

3: PIC16F84:
  • the original prototype; in fact obsolete
  • 4 timers, crystal-osc.

4: PIC16F628A:
  • the max. version using my PLC-board (the most actual version)
  • 6 timers, crystal-osc. or
  • 8 timers, internal RC-osc.

The source code is for all versions. To get the right one you only have to change the value of the define 'VERSION'.


In the main loop the inputs are monitored. Every change triggers TSTART for the specific timer. If a new interval has to be started the timing interval is copied to the RAM-area of this timer and the appropriate output is set.
Every timer uses 3 bytes in the EEPROM for the timing. These bytes can be filled by the programmer or by the setup routine.
Using a 4 MHz clock the interrupt routine is running continuously at 256 Hz. This routine checks the 3 byte counter for each timer which is decremented until it reaches zero. Then the end of the timing interval is reached and the output is reset.
Because the timers are independent you can start any timer at any time.
If the timer is switched on with the setup-input active it enters the setup-routine, indicated by the flashing LED. Now the timing can be programmed, 1 timer at the same time (see Setup). Beware that in versions 2 and 4 the setup key is combined with a timer key; if this is undesirable then don't use that timer! In my original version 2 design for the coffee machine only 1 output was needed for the water valve, so 2 additional ports were free for the setup key and LED.
By changing the program you can use any port to enter the calibration procedure (defines: 'REDLED' and 'PRG_PB').
The program is written in assembler (sorry for the inconvenience) because it had to run on the small 8-pin chip. But it is not very complicated. The most important jobs are done by 3 macros and quite a lot of things can be changed by defines.
By bits in a fourth EEPROM-cel for each timer you can change the behaviour:
  • retriggerable or not
  • edge or level triggered
  • immediate output or delayed pulse
  • length of the delayed pulse (1/256 sec., 1/16 .. 15/16 sec. or 1 .. 15 sec.)
The behaviour of a timer depending on the configuration is shown graphically in the diagram.


Original description: place the cup or pot in the machine, select calibration-mode, press the required button and keep it pressed until the coffee-level is OK. Then release the button. Ready. Quite a lot more comfortable compared to the NE555
calibration procedure!
Moreover there are 2 ways to calibrate the timing:
  1. keep the button pressed until end of interval (convenient for short periods)
  2. press the button a short time to start and press again to end the interval
Repeatability can be improved by using a crystal-oscillator; for simplicity the internal RC-oscillator of the chip can be used in most situations. The exact oscillator-frequency is only important if the timing is programmed into the EEPROM by a programmer. If the unit is calibrated by the manual keys it simply repeats the delay. The program runs with a 256 Hz cycle and the timing is stored as multiples of 1/256 sec into 3 bytes. Therefore the maximum delaytime is more than 18 hours.


Byte 4 (timer configuration) of the setup can only be changed using a programmer; it would be nice if this can also be done by a build-in setup routine.

Entering the setup by a standard timer-key is not very safe and the flashing of a standard timer-output can disturb a proces. Therefore the entering and signalizing of the setup could be improved for instance by using some inputs as temporary outputs.
For the time being: if the double usage of an input for setup and timer is a problem then do not use that timer!

Rewrite the whole program in a high-level language and use a more modern controller. This would simplify the addition of new options for anyone who does not speak assembler .