I needed a way to automatically control the main heating of my parents house. The basic idea is to start the heating at a certain time in the morning, and to switch it off at night. The switching points are different on various weekdays.
Of course, I could have bought a time switch. However, those things alway tend to have too much or too little switching points, an inaccurate clock, or they are just too complicated to be programmed (ok, this is relative, but you’ll agree with me that time switches with an RS232 port for programming are not really common ;-).
One of the first things I planned to make once I learned working with microcontrollers was a DCF77 time decoder. I never found the time to actually start building one, so this was the perfect excuse. I decided to make a PIC-controlled time switch that gets its time updated through the DCF77 radio signal.
The switch consists of three main parts: there is the microcontroller, in this case a PIC16F876A, the radio signal receiver, and of course, the relais to switch the output.
- eight fully programmable outputs
- up to 256 switchpoints (can be extended if required)
- the switchpoints are stored in flash memory, so there’s no need for a backup battery
- the time is kept in sync with the DCF radio transmissions, you don’t have to bother changing settings when daylight saving time is applied.
- programmable through RS232 using a command line interface
- has an internal clock to bridge periods when no DCF signal is available
- restores the state of the outputs to the programmed state after a power outage as soon as the time signal has been received
The radio receiver is a module I bought from Conrad (ordernumber 641138 – 89). It generates a pulse signal that still needs to be decoded. A job for the PIC of course.
The DCF signal from the radio module is directly fed into the PIC (the radio module has an open-collector output).
In the download section, you can find the source files, and a compiled hex file for direct programming.
The program consists of several modules:
- the clock module keeps track of the current time (internal clock)
- the DCF routines contain a state machine that is used to decode the DCF signal
- the flash routines are used to store and access the switchpoints (that are stored in program memory FLASH).
The source code is documented, so it should be no problem to get you up and running in no-time.
The source code for this project has been developed in C and can be compiled with the excellent BoostC compiler: [download#2#nohits]
If you are using the free version of the compiler, you might want to modify the base address for the switchpoints in FLASH memory to a lower location (it’s just a define-statement in the code), because otherwise the compilation process will fail.
Alternatively, you can get the most recent code from the Google code SVN repository. It is located under trunk/hasynode/firmware.
The code has been tested on a PIC16F876, mounted on a small board I designed for another project. Together with a relais for steering a single output, it looks like:
Is my work useful for you? Show your appreciation!