The FreeBSD Diary

The FreeBSD Diary (TM)

Providing practical examples since 1998

If you buy from Amazon USA, please support us by using this link.
Creating an NTP server with a cheap clock --- by Harald Schmalzbauer 10 March 2001
Need more help on this topic? Click here
This article has 1 comment
Show me similar articles
Harald Schmalzbauer wrote this article back in December.  I've been both busy and slack so I haven't done anything with his article until today.  Harald mentioned that this information probably will not be useful to those outside of Europe.

Harald wrote:

There are lots of cheap DCF77 modules (~10$) which demodulates the DCF77 signal and passes it to NTP as PPS signal via the serial interface.  But all of them have a simple LC(inductivity-capacity)-circuit as antenna and most server-rooms are located in the cellar or (as mine) under a metal shield roof, so receiving the signal is not guaranteed. So I decided to by a assembled module with an external active antenna from

I think this uses exactly one of the ususal U4224 designs:

which can operate at different frequencies for different continents (I think I remember that USA and the Asia/Pacific room both have something similar to DCF77 at different frequencies).

I'll monitor the hardware issue during the change of year.  Then I hope I have time to do some tests and design my own clock with a active antenna and I'll make a simple but very well working layout for such a clock. (My idea is a small plug for the serial motherboard connector inside the box with a BNC-connector outside to the antenna)

I took ntp4.0.99i from the ports (net/ntp) and installed it.  Then I created /etc/ntp.conf file which looks like this:

#ntp config for fileserver
server prefer mode 5 #GUDE DCF77 clock
peer outer              # first ntp ST1 to outside
peer outer2             # second ntp ST1 to outside
# Miscellaneous stuff
driftfile /etc/ntp.drift        # path for drift file
statsdir /var/log/ntpstats/     # directory for statistics files
filegen peerstats file peerstats type day enable
filegen loopstats file loopstats type day enable
filegen clockstats file clockstats type day enable

The RAWDCF-driver is and mode 5 works for that clock. For more information see

After that I created a symlink:

ln -s /dev/ttyd0 /dev/refclock-0

since the driver expects that device. Then, after starting ntpd, it complained for (about) a missig signal.

Now the problem with the new clock on the serial interface was that it expects to be voltage-supplied by the interface. In normal mode when NTP reads the data with 50 boud the LED on the module is lit red.  When the clock has the correct power supply the LED should be green and when it receives a signal it should flash red every second.

The "every second" is the indicator for the signal strength.  If it isn't exactly regular the signal is too weak.

I found a little C code on the web which should do the necessary modifications. This didn't work for me, so I experimented a bit and this came out:

/* dcf77power v1.00 */
#include <errno.h>
#include <fcntl.h>
#include <termios.h> /*Originally it was termio.h*/
#include <sys/ioctl.h>

int main()
    int dcf_dev, i;
    if((dcf_dev = open("/dev/refclock-0", O_RDWR|O_NOCTTY)) < 0)
        perror("open /dev/refclock-x");
        return (-1);
    i = TIOCM_DTR;

    /* set DTR, originally it was clear*/
    ioctl(dcf_dev, TIOCMBIS, &i);
    i = TIOCM_RTS;

     /* clear RTS, originally it was set*/
    ioctl(dcf_dev, TIOCMBIC, &i);
    return (0);

I compiled it with cc dcfpower.c -o power on FreeBSD 4.2 and after running ./power the LED of the clock switched to green. Great:-)


  • Install and config NTP4
  • compile this little code
  • start "ntpd"
  • run "power".

Now I connected the external antenna and, here we are, I had a signal in that server room where every other radio clock hasn't had any signal.  The advantage of this solution is that you can place the antenna where you want, so it's probably possible that you find a position where the clock gets a strong enough signal.

If you want to build the clock by your own you can safe money, but for me it was the cheapest way to have a reliable time server where every other cheap DCF-clock failed.

Need more help on this topic? Click here
This article has 1 comment
Show me similar articles