17 08 2013
DCF77 Radio Clock
In 2009 I made a DCF77 radio clock for my final years project. I used Flowcode to program the radio clock back then.
Today, I’ve rewritten the code in C and I used the free version of the XC8 compiler to compile it.
I’m using the Winstar yellow 16×2 OLED display and my library to display the time and date.
DCF77 is a longwave time signal and standard-frequency radio station. Its primary and backup transmitter are located at 50°0′56″N 9°00′39″E in Mainflingen, about 25 km south-east of Frankfurt am Main, Germany.
Note: Because it’s located in Germany, the time is GMT+1.
The DCF77 is an amplitude modulated signal with a carrier frequency of 77.5kHz.
It transmits one bit every second. These bits are time coded.
A logic 1 is transmitted by sending a 200ms pulse and a logic 0 is transmitted by sending a 100ms pulse.
Here’s an image of the DCF77 bits representation:
Those ‘P’ bits are parity bits. I don’t use those in my program, check wikipedia for more info.
My program just reads and decodes the: hours, minutes, day, day of week (1-7, Mon-Sun), month and year. It’s more a test program than an actual radio clock.
This code just receives, decodes and displays the DCF77 bits.
A real radio clock has probably an real time clock and synchronizes maybe once or twice a day.
To decode the bits, it’s very easy. Each bit has a value. If the bit is set to 1, add that particular value to the variable, if not add nothing.
This is how I’ve done it (decoding minutes):
1 2 3
// DCF_buffer : array containing every received bit // DCF_buffer[x] : bit at second x minute = DCF_buffer + DCF_buffer * 2 + DCF_buffer * 4 + DCF_buffer * 8 + DCF_buffer * 10 + DCF_buffer * 20 + DCF_buffer * 40;
There are 4 steps to make this program:
– Synchronize the PIC to the DCF77
– Receive bits
– Decode bits
– Display data
(- Go back to synch)
By synchronizing I mean searching the end of a full data packet.
If you check the scope image below, you’ll see that there’s no bit transmitted on the 59th second.
To receive a bit, I connected the DCF77 output signal to an input.
Whenever I have to receive the bits, I constantly read the input pin and check if it goes low.
If the microcontroller receives a pulse, it’ll delay for 160ms and read that pin again.
If it reads 1 back, that means the pulse received is less than 160ms. Write 0 to the DCF77 buffer.
If it reads 0, that means the pulse received is greater than 160ms. Write 1 to the DCF77 buffer.
Important thing to do is to wait until the pulse is over before trying to read a new pulse, else you’re going to have some issues like decoding two pulses when there’s only one.
Here’s the complete MPLAB X project in a zip file: DCF77 clock.zip