Accurate Time Keeping Without RTC

by tapish101 in Circuits > Electronics

443 Views, 1 Favorites, 0 Comments

Accurate Time Keeping Without RTC

Screenshot_20210727-191051-02.jpeg
IMG_20210727_190306__01-01.jpeg

This would be a simpler, without any library neither any expensive hardware way for timekeeping on any microcontroller with just using one interrupt pin. I would say this will serve about 95% of your time keeping projects unless you want an ultra precise timekeeping or the reliability of keeping time without power. While working on this project I found RTC are kind of overrated.

The cons of our diy way over RTC are when microcontroller reset or loose power the time lost, otherwise a RTC does not offer much value.

Supplies

  • Old wall quartz clock
  • LM358 op-amp
  • Resistores( two 100 ohm one 320 ohm) , 100 ohm ones would be actually 90-95 ohm.
  • Male header pins
  • Pref board

Extracting Components

IMG_20210727_105321_313.jpg
IMG_20210727_105323_141.jpg
IMG_20210727_101556__01__01.jpg
IMG_20210727_101454__01.jpg

An old quartz wall clock is the heart of our project. Take the clock and disassemble it to take out the PCB. The PCB would have a coil connected to it. Remove the coil from solder joints, and also trace back battery bay metal connectors to find which solder pad is positive and negative.

The working of such clocks is simpler on electronics level, in a nutshell the coil is magnetised with alternative polarity every second. So each coil terminal goes high after every two second.

And other components is any opamp, or a comparator. The opamp I am using as a comparator is LM358P.

The Circuit

circuit-01.jpg
IMG_20210727_103513.jpg
ezgif.com-gif-maker.gif
IMG_20210727_190400__01.jpg
IMG_20210727_190250__01-01.jpeg

The need for the circuit it to only provide power to clock PCB, as it operates at much lower voltage and opamp to make the output of the PCM high enough so that microcontroller reads it as a high signal.

The circuit is self explanatory there are three resistors as a voltage divider, to power the clock PCB with 1.8v and the opamp non-inverting input, for reference with 0.9v, to both the non-inverting pin.

Firstly I prototype on bread board and the solder the final schematic on pref board.

Result

Screenshot from 2021-07-28 17-55-42__01-01-01.jpeg
Screenshot from 2021-07-28 09-41-39__01.png

The sample code I used for testing..

//connect any one of out pin from two to interrupt 0 pin of arduino (pin 2 for uno).

//since each pin pulses alternatively each second so for each pulse on same pin two second has passed

int sec=0;
void setup() {

Serial.begin(9600);

attachInterrupt(0,Time,RISING);

Serial.println("starting time measurement");

}

void loop() {

if(sec>=300){

Serial.println("5 min passed");

sec=0;

}

}

void Time(){

sec=sec+2;

}

//ends here

You can see in the attached pic, the accuracy is pretty good, about 200ms drifts in 30 min (on multiple tests I was getting on average about 300ms slower for each hour).

Theoretically about 7 sec drift each day and around 42 min and 30 sec slower in a year, which can easily corrected with code as time difference is linear.

Hopefully you liked:)