Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 17:46 02 Aug 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : PicoMite DCF77 Decoder

Author Message
PilotPirx

Regular Member

Joined: 03/11/2020
Location: Germany
Posts: 99
Posted: 07:18pm 01 Mar 2023
Copy link to clipboard 
Print this post

I wrote a little DCF77 decoder to get the exact time without having to type it in every time. DCF77 is a time signal transmitter near Frankfurt Main/Germany. For our Australian and American friends a bit far away, but for the Europeans great to use.
I use the Milageto DCF77 Receiving modul DCF-3850M-800 from Amazon which works fine with 3.3V and the Pico at GP1. The program writes the data to the RTC. If someone is interested, i made an 3D STL housing for the receiver.
Have fun and always the right time!

'*******************
'* DCF77 Decoder   *
'* 01.03.2023 V1.0 *
'* P.Doerwald      *
'*******************

Option EXPLICIT
Option DEFAULT INTEGER

Dim DCF(60)
Dim INTEGER year,month,day,dow,hour,min,sec
Dim INTEGER summer,DCFOK,DCFSTART,DCFSTEP,DCFNOERROR

Const TRUE=1
Const FALSE=0
Const HIGH=1
Const LOW=0

SetPin GP1,INTB,DCFSUB  'Clock signal at GP1

DCFSTEP=0
DCFSTART=FALSE
DCFNOERROR=FALSE
Timer =0
Print "DCF77 Decoder for MMBasic V1.0 by P.Doerwald"
Print "Waiting for sync"
Do
Do
Loop Until DCFOK=TRUE
DCFCALC
Loop Until DCFNOERROR=TRUE
SetPin GP1,OFF
Do
Loop Until Timer>=2000

RTC SETTIME year,month,day,hour,min,0
RTC GETTIME

Print "DCF77 successful"
Print "Date: ",Date$
Print "Time: ",Time$
Print "Day of week:";dow
Print "Summertime:",
If summer=2 Then Print "yes" Else Print "no"
End

Sub DCFSUB  'Interrupts every edge change
If Pin(GP1)=HIGH Then
  If Timer>1700 Then 'new minute
    DCFSTART=TRUE
    DCFSTEP=0
    Print "Start"
  EndIf
  Timer =0
Else
  If DCFSTART=TRUE Then
    If Timer>150 Then
      DCF(DCFSTEP)=1
    Else
      If Timer>75 Then
        DCF(DCFSTEP)=0
      Else   'Error, pulse too short
        DCFSTART=FALSE
        Print "Pulse ERROR"
        DCFSTEP=0
      EndIf
    EndIf
    Inc DCFSTEP
    If DCFSTEP=59 Then DCFOK=TRUE
  EndIf
EndIf
End Sub

Sub DCFCALC   'calculating bits to time and date
Dim x,PM,PH,PD
' No Errors - parity OK?
For x=21 To 27
   PM=PM+DCF(x)
Next x
For x=29 To 34
   PH=PH+DCF(x)
Next x
For x=36 To 57
   PD=PD+DCF(x)
Next x
If ((PM And 1)=DCF(28))And((PH And 1)=DCF(35))And((PD And 1)=DCF(58)) Then
  If DCF(20)=1 Then
     DCFNOERROR=TRUE
  'ALL OK, begin calculations
  min=(DCF(25)+(DCF(26)*2)+(DCF(27)*4))*10
  min=min +DCF(21)+(DCF(22)*2)+(DCF(23)*4)+(DCF(24)*8)
  hour=(DCF(33)+(DCF(34)*2))*10
  hour=hour +DCF(29)+(DCF(30)*2)+(DCF(31)*4)+(DCF(32)*8)
  day=(DCF(40)+(DCF(41)*2))*10
  day=day +DCF(36)+(DCF(37)*2)+(DCF(38)*4)+(DCF(39)*8)
  dow=DCF(42)+(DCF(43)*2)+(DCF(44)*4)
  month=DCF(49)*10
  month=month +DCF(45)+(DCF(46)*2)+(DCF(47)*4)+(DCF(48)*8)
  year=(DCF(54)+(DCF(55)*2)+(DCF(56)*4)+(DCF(57)*8))*10
  year=year +DCF(50)+(DCF(51)*2)+(DCF(52)*4)+(DCF(53)*8)
  summer=DCF(18)+(DCF(17)*2)
  EndIf
EndIf
End Sub
 
homa

Guru

Joined: 05/11/2021
Location: Germany
Posts: 471
Posted: 07:41pm 01 Mar 2023
Copy link to clipboard 
Print this post

  PilotPirx said  If someone is interested, i made an 3D STL housing for the receiver.

Yes, I am :-)
Order for the Milageto DCF77 Receiving modul DCF-3850M-800 from Amazon is already out.
 
PilotPirx

Regular Member

Joined: 03/11/2020
Location: Germany
Posts: 99
Posted: 08:27pm 01 Mar 2023
Copy link to clipboard 
Print this post

  Quote  Yes, I am :-)
Order for the Milageto DCF77 Receiving modul DCF-3850M-800 from Amazon is already out.

Great! I uploaded the files to Thingiverse. You need only VDD (3,3V), GND and Out for connecting.

Thingiverse Link
 
Plasmamac

Guru

Joined: 31/01/2019
Location: Germany
Posts: 580
Posted: 04:00pm 02 Mar 2023
Copy link to clipboard 
Print this post

Like 👍
Plasma
 
atmega8

Guru

Joined: 19/11/2013
Location: Germany
Posts: 724
Posted: 08:47pm 02 Mar 2023
Copy link to clipboard 
Print this post

Also ordered one
 
DrifterNL

Regular Member

Joined: 27/09/2018
Location: Netherlands
Posts: 58
Posted: 10:19pm 02 Mar 2023
Copy link to clipboard 
Print this post

Hello PilotPirx,

I tried your software but got the following error:

[75] Dim x,PM,PH,PD
ERROR: x already declared

After relocating the Dim x,PM,PH,PD in Sub DCFCALC to the top of your software under the other dims the software seems to work great!

The first time it synced the time was off by 10 min but running it again it got the correct time.

I am using a 5V DCF77 module through a sparkfun level converter.
Floating Point Keeps Sinking Me!
Back To Integer So I Don't Get Injured.
 
phil99

Guru

Joined: 11/02/2018
Location: Australia
Posts: 2642
Posted: 12:10am 03 Mar 2023
Copy link to clipboard 
Print this post

"After relocating the Dim x,PM,PH,PD in Sub DCFCALC to the top "

Another option might instead be to change Dim to Local.
 
PilotPirx

Regular Member

Joined: 03/11/2020
Location: Germany
Posts: 99
Posted: 08:33am 03 Mar 2023
Copy link to clipboard 
Print this post

  Quote  The first time it synced the time was off by 10 min but running it again it got the correct time.

It is difficult to verify the time read in.
I only check the parity bits for minute, hour and date here. If an odd number of bits is wrong, it is detected, if x*2 bits flip, the error is not detected. Unfortunately, there is no checksum. The worse the signal, the more likely errors can creep in. I have also noticed that the pulse length is different for many receivers. By definition, 100ms is a 0 and 200ms is a 1.
Maybe you have an idea how to better check the plausibility of the result.

  Quote  After relocating the Dim x,PM,PH,PD in Sub DCFCALC to the top

Strange, i got no error. I´ll write them as Local.
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025