NOTE: This is an archive of my old blog. Go to http://gonium.net for my current website.

Tweaking the code 12

Posted by md on April 18, 2007

tweaking.png

Thanks to Lasse Lambrecht, I can release a new version of the DCF77 code – now you can run it on the ATMega168-based Arduinos.

The ATMega8 differs slightly from the ATMega48/88/168-series: The latter chips have an extended Timer2-hardware and therefore need different initializations. Lasse send me a nice adjustment of the code, basically he uses preprocessor flags to figure out which initialization commands to use: #ifdef ATMEGA168 TCCR2B |= (1<
  • arduino-dcf77-clock-0.2.1.tar.bz
  • For the hardware setup, please refer to my initial post.
    Trackbacks

    Use this link to trackback from your own site.

    Comments

    Leave a response

    1. Kurt Thu, 06 Dec 2007 16:01:10 UTC

      hi,

      thanks for the code!
      works perfectly on my ATMega168

      kurt

    2. julian Sun, 27 Jan 2008 17:09:09 UTC

      Hi..

      sorry i am a beginner. How to change the path of your librarys ?

      /Applications/arduino-0010/hardware/libraries/DCF77/DCF77.o: In function `DCF77::serialDumpTime()’:

      /Applications/arduino-0005/lib/targets/libraries/DCF77/DCF77.cpp:76: undefined reference to `HardwareSerial::print(char*)’

      /Applications/arduino-0005/lib/targets/libraries/DCF77/DCF77.cpp:78: undefined reference to `HardwareSerial::print(char*)’

      /Applications/arduino-0005/lib/targets/libraries/DCF77/DCF77.cpp:80: undefined reference to `HardwareSerial::print(char*)’

      /Applications/arduino-0005/lib/targets/libraries/DCF77/DCF77.cpp:82: undefined reference to `HardwareSerial::print(char*)’

      /Applications/arduino-0005/lib/targets/libraries/DCF77/DCF77.cpp:84: undefined reference to `HardwareSerial::print(char*)’

      /Applications/arduino-0010/hardware/libraries/DCF77/DCF77.o:/Applications/arduino-0005/lib/targets/libraries/DCF77/DCF77.cpp:86: more undefined references to `HardwareSerial::print(char*)’ follow

      Couldn’t determine program size: hardware/tools/avr/bin/avr-size: ‘/tmp/build3840.tmp/Serial_DCF77_Signal.hex’: No such file

      Thanks
      jul

    3. md Mon, 28 Jan 2008 10:21:33 UTC

      Hi Jul,

      are you sure we’re talking about my code above (v0.2.1)? There is no DCF77.cpp in this archive, and the serialDumpTime function starts at line 225. Nevertheless, there is no HardwareSerial.print(..) in Arduino, but a Serial.print(…), AFAIK.

      Sorry, but try to use this sketch unmodified first. I don’t have an Arduino 10 environment here, but since the interfaces weren’t changed, the code *should* work.

      HTH,
      -Mathias

    4. julian Mon, 28 Jan 2008 10:57:24 UTC

      Hallo Mathias,

      sorry my fault. My error is:

      In function ‘void DCF77Init()’:
      error: ‘TCCR2′ was not declared in this scope

      I have an arduiono diecimile an the atmega168.

      Jul

    5. md Mon, 28 Jan 2008 11:57:28 UTC

      Hi Jul,

      aparently, you don’t have the ATMEGA168 flag defined, so the Compiler tries to compile the definitions for the ATMega8 (and the initialization registers have slightly different names…)

      Try adding the line
      #define ATMEGA168
      to your code.

      -Mathias

    6. Jan Tue, 27 Jan 2009 20:32:52 UTC

      Hi Mathias,

      thanks for your DCF-77 code! I’ve got a question: I’ve been running version 0.2.1 for about a day on a Diecimila board, and found that it loses about half an hour over a day. Every now and then, it seems to miss a few seconds, and then goes back to the start of the same minute. Here’s an example from the serial log with two such hiccups:

      Time: 19:54:57 Date: 27.1.2009
      Time: 19:54:58 Date: 27.1.2009
      Time: 19:54:0 Date: 27.1.2009
      Time: 19:54:1 Date: 27.1.2009
      Time: 19:54:2 Date: 27.1.2009
      Time: 19:54:3 Date: 27.1.2009
      Time: 19:54:0 Date: 27.1.2009
      Time: 19:54:1 Date: 27.1.2009
      Time: 19:54:2 Date: 27.1.2009
      Time: 19:54:3 Date: 27.1.2009

      I’ll try to find the bug myself, but any ideas what might cause this?

      Thanks!

      - jan

    7. md Wed, 28 Jan 2009 20:31:55 UTC

      Hi Jan,

      I am sorry to hear that the code has these hiccups. I don’t have an Arduino any more (I gave it to my brother) so I can’t reproduce it now. If I remember the code correctly it simply measures the time between two signals as received by the DCF77 module. Depending on the time between two signals it determines if a “0″ or a “1″ bit was received. Each second a bit is transmitted.

      The 59th second does not contain a bit and is used to synchronize the beginning of a new minute. I think here lies the problem: there is no signal for longer than a second, so the code resets the second count.

      I would guess that you have an electrical problem: either the DCF signal is to weak where you are or the connection between the Arduino and the receiver is not solid. Try a different location and different pullup resistors (e.g. 10k vs 4k7).

      HTH,
      -Mathias

      BTW: In another (unpublished) project I use the DCF77 receiver only to synchronize time periodically. I rely on a RTC to keep the time, in my case the DS1307. It also allows you to have a backup battery that keeps your time even if the power goes down. Reminds me that I could blog about this project ;-)

    8. ahon Mon, 25 May 2009 17:01:14 UTC

      hallo,
      I hope you still check this thread.
      I tried your code, it seems work fine.
      but it starts always from 0, such as;
      Time: 0:0:1 Date: 0.0.0
      Time: 0:0:2 Date: 0.0.0
      i waited for start up for 5minutes.
      but start it still from 0..
      any idea?
      thanks
      ahon

    9. koos Thu, 28 May 2009 16:35:08 UTC

      Hello Mathias,

      Firstly, thank you for publishing this nice piece of code !
      Due to a faulty DCF board, as I found out later, I needed to take a closer look at it. I discovered a small bug that causes the backup stand-alone clock to lag a few milliseconds/second behind. Furthermore I needed to optimise the code in order to include the clock in other program. Amongst others, the timer interrupt now occurs once per second using the TimerOne library.
      If you would like I can mail the modified sketch to you to publish a new version.

      groeten, koos

    10. passi Sat, 06 Jun 2009 17:15:45 UTC

      I have some issues with keeping the time as well but got a rtc clock flying around here, can you drop me a line with the code for this one so I can see how you solved the periodical syncs?

      Cheers

      Passi

    11. Richard Sun, 07 Jun 2009 19:57:44 UTC

      hi,

      Atmega328 this code

      I am findi

    12. Richard Sun, 07 Jun 2009 20:02:30 UTC

      hi,
      on ATMega328-based Arduinos, this code is not running.
      Any idea if the changes for ATMega168 is also valid for ATMega328 ?
      Thanks a lot for this nice work !

      Best regards.

    Comments