Old radio clock upgraded to NTP

I own the radio clock on the title picture. I’ve used it for some time but it annoyed me because it drifted a lot (several seconds a day). It’s synchronized to power network frequency but it doesn’t work well in my case and I hate to adjust the clock over and over again. So I decided to sync it automatically using esp8266.First I opened it up to see what’s inside.

The heart of the clock is SC8560 and it’s implemented very similarly as the reference circuit in the datasheet. My first idea was to disconnect a clock signal (derived from network) and increase minute and hour counter by cron on esp each minute. But when I disconnected the clock signal, the display went off because the input clock also drives display driver.

Then I wanted to create my own 50Hz clock source but it needs to be about 9V peak-to-peak which would require more external components so I decided not to.

My last idea was to keep the original clock source but to reset the device daily so the inaccuracy is only few seconds in worst case. When you unpower the device the time resets to 0:00 but starts blinking annoyingly and stops only after you set the time so I needed to hook up to 2 circuits: power and hour setting. I also needed to get some power for the esp8266 so I started with this.

The SC8560 is powered by half-wave rectified 9V AC (one diode and capacitor) so I connected my NodeMCU Amica board to the same rail (the board has onboard 3.3V LDO regulator so it can be powered by 9V) but it didn’t work. When I measured the power waveform half of the time it was zero due to high power consumption by esp so I decided to add my own full-wave rectifier and capacitor behind AC transformer. This worked very well so I moved to controlling the main chip. This solution also implies using optocouplers to controll the main circuit.

So I started to poke with the main chip power circuit to find out how to reset it. There are many wire connections on the upper side of the main board so I tried disconecting one which leads to Vss. Current through this connection was about 60mA which is quite high for using basic optocoupler so I also tried to measure the Vdd connection. This was much better with current only about 6mA so I cut it and soldered my optocoupler instead.

Next I also needed to set hours and this was done with other optocoupler soldered between pin 22 and Vss. On the input side of both optocouplers I soldered jump wires which were connected to Amicas output pins. esp8266 can source maximum of 12mA so I didn’t solder any limiting resistor between. The result looked like this:

It’s not prettiest but it does the job. I also needed to remove the speaker to make the module fit into the case but I don’t regret it – I wasn’t using it either. The rest was only to write the program main.lua:

gpio.mode(1, gpio.OUTPUT)
gpio.mode(2, gpio.OUTPUT)
gpio.write(1, gpio.HIGH)
gpio.write(2, gpio.LOW)

synced=0
timeset=0
inchours=0
timezone=1 -- range 1 - 25

huptmr = tmr.create()

-- need to start clock first
rtctime.set(0, 1)

sntp.sync(nil,
 function(sec, usec, server, info)
 synced=1
 print('sync', sec, usec, server)
 end,
 function()
 print('failed!')
 end,
 1
)

function hup()
 gpio.write(2, gpio.HIGH)
 tmr.delay(100000)
 gpio.write(2, gpio.LOW)
end

function hups(hours)
 inchours = hours
 huptmr:register(1000, tmr.ALARM_AUTO, function()
 if inchours < 1 then
 huptmr.unregister()
 return
 end
 inchours = inchours - 1
 hup()
 end )
 huptmr:start() 
end


function reset(hours)
 gpio.write(1, gpio.LOW)
 rstt = tmr.create()
 rstt:register(700, tmr.ALARM_SINGLE, function() 
 gpio.write(1, gpio.HIGH) 
 hups(hours) 
 end)
 rstt:start() 
end

cron.schedule("0 0 * * *", function(e)
 if timeset == 1 and synced == 1 then
 reset(timezone)
 end
end)

cron.schedule("0 * * * *", function(e)
 if timeset == 0 and synced == 1 then
 tm = rtctime.epoch2cal(rtctime.get())
 timeset=1
 reset(timezone+tm["hour"])
 end
end)

After powering the module it waits for full hour to reset the clock. You can see it in action here:

It also resets the clock daily at 1:00 am.

It’s showing to be a reliable solution to me. I don’t say you can get better or cheaper NTP clock elsewhere but this was a fun project to me.

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *