Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 5 of 5

Thread: DCF77 and module - Which library is working?

  1. #1

    DCF77 and module - Which library is working?

    Hi, has anyone managed to synchronise time on Teensy 3.6 with a module DCF77?

    I am using a module from pollin and I am able to get some signal from the module with this very basic test program:

    Code:
    //Funktioniert mit Teensy 3.6 und Pollin-Empfänger
    #define DCF77PIN 2
    #define DCF77_POWER 28
    
    unsigned char signal = 0;
    unsigned char buffer;
    
    void setup(void) {
     Serial.begin(9600);
     pinMode(DCF77PIN, INPUT_PULLUP);
     pinMode(DCF77_POWER, OUTPUT); 
     digitalWrite(DCF77_POWER, LOW);
    }
    
    void loop(void) {
     signal = digitalRead(DCF77PIN);
     if (buffer != signal) {
     Serial.println(signal);
     buffer = signal;
     }
    }
    But I am not able to use the longer test program on https://arduino-hannover.de/2012/06/...ino-betreiben/ due to a compiler error at the interrupt routine.

    "DCF Binary Stream" on http://www.hjberndt.de/soft/rtctftdcf.html does not work too.

    Is there a library which is working together with teensy?

    Thank you very much for some help!

  2. #2
    OK, now I found
    http://muck-solutions.com/?page_id=1637

    I can compile the following code and I get a blinking LED with 1 Hz (as far as I can see):
    Code:
    #include <DCF77.h>
    //#include <Time.h> // Funktioniert nicht mit DCF77
    #include <TimeLib.h> // neue lib einbinden
    
    
    #define DCF_PIN 2                // Connection pin to DCF 77 device
    #define LEDPin 13                // LED Output 
    #define DCF77_POWER 28           // PIN to switch on the module
    #define DCF_INTERRUPT 0          // Interrupt number associated with pin
    #define timeinterval 2000        // in ms
    time_t time;
    // Non-inverted input on pin DCF_PIN
    DCF77 DCF = DCF77(DCF_PIN,DCF_INTERRUPT, true); 
    //DCF77 DCF = DCF77(DCF_PIN,DCF_INTERRUPT, false); 
    
    int timediv;
    int oldtime; 
    
    void setup() {
      Serial.begin(115200); 
      pinMode(LEDPin, OUTPUT);
      DCF.Start();
      Serial.println("Waiting for DCF77 time ... ");
      Serial.println("It will take at least 2 minutes before a first time update.");
      oldtime = millis();
      pinMode(DCF77_POWER, OUTPUT); 
      digitalWrite(DCF77_POWER, LOW);   
    }
    
    void loop() {
      timediv = millis()- oldtime;
      digitalWrite(LEDPin, digitalRead (DCF_PIN));
      time_t DCFtime = DCF.getTime(); // Check if new DCF77 time is available
      if (DCFtime!=0)
      {
        Serial.println("Time is updated");
        setTime(DCFtime);
      }    
      if (timediv >= timeinterval){
        oldtime = millis();
        digitalClockDisplay();  
      }
    }
    
    void digitalClockDisplay(){
      // digital clock display of the time
      Serial.print(hour());
      printDigits(minute());
      printDigits(second());
      Serial.print(" ");
      Serial.print(day());
      Serial.print(" ");
      Serial.print(month());
      Serial.print(" ");
      Serial.print(year()); 
      Serial.println(); 
    }
    
    void printDigits(int digits){
      // utility function for digital clock display: prints preceding colon and leading 0
      Serial.print(":");
      if(digits < 10)
        Serial.print('0');
      Serial.print(digits);
    }
    But time does not synchronise.

    I am not sure, if the interupt routine is not working or if the signal is not clear enough. How can I check this?

  3. #3
    OK, this is working and can decode the hours and minutes:
    Code:
    // Funktioniert mit Teensy 3.6
    int DCF77_pin = 2;
    #define DCF77_POWER 28           // PIN to switch on the module
    int DCFSplitTime = 170;         // war 140
    unsigned long duration;
    int bit_counter = 0;
    
    char bits[60];
    
    void setup()
    { Serial.begin(9600); 
      pinMode(DCF77_pin, INPUT);
      Serial.println("DCF-77 Tester, jede Sekunde ein Signal...");
      delay(1000);
      pinMode(DCF77_POWER, OUTPUT); 
      digitalWrite(DCF77_POWER, LOW);    
    }
     
    void loop()
    { 
      duration = pulseIn(DCF77_pin, HIGH,1300000); // gibt ein 0 zurück wenn t ~ 1,8s; Startbit
      bit_counter ++;
      Serial.print("Time is updated: ");
      if (duration == 0)
      {      bit_counter = -1;         
             Serial.println("\t Start, neue Minute beginnt."); 
             int Stunde= bits[29]+ 2*bits[30] + 4*bits[31] + 8*bits[32];
             Stunde+= 10*bits[33]+ 20* bits[34];         
             int Minute= bits[21]+ 2*bits[22] + 4*bits[23] + 8*bits[24];
             Minute+= 10*bits[25]+ 20* bits[26] + 40*bits[27];
             Serial.print(Stunde);
             Serial.print(":"); 
             Serial.println(Minute);        
      }        
      else { Serial.print(duration/1000);
             Serial.print("ms");         
             Serial.print("\t Bit:");
             Serial.print(bit_counter);
             Serial.print("\t Bit_Status:");
             if (duration/1000 > DCFSplitTime)
             {
              Serial.println("1");
              bits[bit_counter]=1;
               }
             else 
             {
              Serial.println("0");
              bits[bit_counter]=0;                   
              }
           }
      
     }

    So, the module works and there is not too much noise in the reception.

    I think there could be problems with interupts or timers with the libraries?

  4. #4
    Hi,
    I managed to solve the question:
    At
    http://thijs.elenbaas.net/2012/04/ar...eiver-library/
    is a description of his library, which is also on:
    http://playground.arduino.cc/Code/DCF77

    This can be used but has to be modified just a little bit.

    In DCF77.cpp the modification is:
    Code:
    void DCF77::Start(void) 
    {
    	// attachInterrupt(dCFinterrupt, int0handler, CHANGE); // *** original Arduino Version
        attachInterrupt(digitalPinToInterrupt(dCF77Pin), int0handler, CHANGE); //(recommended)
    }

    Then the following sketch works:
    Code:
    /*
     * DCFBinaryStream.ino
     * example code illustrating time synced from a DCF77 receiver
     * Thijs Elenbaas, 2012
     * This example code is in the public domain.
     
      This example shows the binary stream generated by the 
      pulse train coming from the DCF decoder and the resulting
      time
      In order for this example to give output from the DCF library,
      make sure that logging is turned on in the DCF library. You can 
      do this by adding the   #define VERBOSE_DEBUG 1   in Utils.cpp. 
     */
    
    // Funktioniert nicht wegen Time.h ???
    
    
    #include <DCF77.h>       //https://github.com/thijse/Arduino-Libraries/downloads
    #include <TimeLib.h>        //http://www.arduino.cc/playground/Code/Time
    
    #define DCF_PIN 2	         // Connection pin to DCF 77 device
    #define DCF77_POWER 28
    #define LED_Pin 13
    #define DCF_INTERRUPT 0		 // Interrupt number associated with pin *** is not used!
    
    
    time_t time;
    DCF77 DCF = DCF77(DCF_PIN,DCF_INTERRUPT);
    
    void setup() {
     Serial.begin(9600);
     pinMode(LED_Pin, OUTPUT);
     digitalWrite(LED_Pin, HIGH); 
     delay(2000);  
     Serial.println("1   - binary 1 corresponding to long pulse");
     Serial.println("0   - binary 0 corresponding to short pulse");
     Serial.println("BF  - Buffer is full at end of time-sequence. This is good");
     Serial.println("EoB - Buffer is full before at end of time-sequence");
     Serial.println("EoM - Buffer is not yet full at end of time-sequence");
     pinMode(DCF77_POWER, OUTPUT); 
     digitalWrite(DCF77_POWER, LOW); 
     DCF.Start();
    }
    
    void loop() {
    	delay(1000);
    	time_t DCFtime = DCF.getTime();
    	if (DCFtime!=0) {
        setTime(DCFtime);
        Serial.print(" DCF: ");    
    		digitalClockDisplay(DCFtime);
    	}	
      else {
        Serial.print(" running: ");
        digitalClockDisplay(now());
      }
    }
    
    void digitalClockDisplay(time_t _time){
      tmElements_t tm;   
      breakTime(_time, tm);
    
      // Serial.println("");
      Serial.print("Time: ");
      Serial.print(tm.Hour);
      Serial.print(":");
      printDigits(tm.Minute);
      Serial.print(":");
      printDigits(tm.Second);
      Serial.print(" Date: ");
      Serial.print(tm.Day);
      Serial.print(".");
      Serial.print(tm.Month);
      Serial.print(".");
      Serial.println(tm.Year+1970);
    }
    
    void printDigits(int digits){
      // utility function for digital clock display: prints preceding colon and leading 0
      Serial.print(":");
      if(digits < 10)
        Serial.print('0');
      Serial.print(digits);
    }

  5. #5
    Senior Member DD4WH's Avatar
    Join Date
    Oct 2015
    Location
    Central Europe
    Posts
    618
    FYI:

    for DCF77 without a dedicated hardware modul you could also use this direct sampling approach:

    https://forum.pjrc.com/threads/40102...ighlight=dcf77

    All the best,

    Frank DD4WH

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •