Forum Rule: Always post complete source code & details to reproduce any issue!
Page 1 of 2 1 2 LastLast
Results 1 to 25 of 36

Thread: Time signal LF Receiver Teensy DCF77 with minimal hardware effort

  1. #1
    Senior Member DD4WH's Avatar
    Join Date
    Oct 2015
    Location
    Central Europe
    Posts
    541

    Time signal LF Receiver Teensy DCF77 with minimal hardware effort

    Born from an idea by Frank Boesing and developed together with him: this is the Teensy time signal receiver „Teensy DCF77“.



    Yes, this is yet another script to decode the highly accurate time signal data from the longwave station DCF77. But this one works with the Teensy plus audio board and does not need any special receiver hardware! Only very few external components are needed:
    These are the hardware options, ranging from a few cents to a maximum of 10 EUROS:


    1. Just add a few metres of wire to your MIC INPUT (via a 100nF cap) and connect GND to a good ground connection, a heating or a rain pipe or similar --> DONE
    2. If the signal is not strong enough with option 1, use an inductor/choke of some milli-Henrys and a capacitor of a few nano-Farads as a parallel resonator with a resonance frequency of 77.5kHz (Look here how to calculate that: https://github.com/DD4WH/Teensy-DCF77/wiki). Connect to the MIC input (via a 100nF cap) and add ground and a few metres of wire as an antenna.
    3. If option 2 is not possible, use a ferrite rod, put 300 windings of thin copper wire on it (on a length of about 2cm), measure the inductance and add a capacitor as described in option 2
    4. If none of the options above work, you would have to take the „expensive“ option and buy a DCF77-receiver for 5-15 EUROS and connect ist output to the LINE input of the audio board


    Start the script and it will adjust your Teensy Real Time Clock automatically to the atomic clock in Braunschweig, Germany and display the time, date, some signal decoding data and the FFT of the decoded longwave signal on an ILI9341.

    The reception should work in a circle around the transmitter in Frankfurt/Main of about 2000 – 3000km.

    However, the script is also prepared to take your favourite time signal station´s frequency (60kHz MSF for the UK, 60kHz for WWVB in the USA, 68.5kHz in China etc.). You would have to alter the decoding accordingly.

    It is astonishing how easy it is to get reception and perfect decoding even inside buildings in noisy environments (noisy meaning polluted by electromagnetic noise: switching power supplies, plasma TVs, DSL modems, microprocessors like the Teensy etc. ;-)) with such a low budget-low tech receiving circuit.

    The code uses a direct sampling approach (like the high performance professional SDRs) and converts the audio to baseband:

    1. The input signal is sampled at 192ksps
    2. Bandpassfilter with high Q at 77.5kHz
    3. Mix with a local oscillator signal of 76.9kHz
    4. Audio with 600Hz
    5. FFT with 1024 points
    6. The relevant bins at 77.5kHz are treated with a sophisticated AGC algorithm written by Frank B and the length of the AM carrier pauses are measured and decoded. The corresponding bit pattern is decoded
    7. The built-in Teensy Real-Time-Clock is set to the decoded time and is now as accurate as the atomic clock of the PTB in Braunschweig ;-). To be honest: do not expect an accuracy of more than 0.1 seconds with this method!


    Find more information and full source code here:

    https://github.com/DD4WH/Teensy-DCF77/wiki

    Suggestions and additions for your specific time signal station in your part of the world highly acknowledged!

    Have fun with the Teensy and the Audio lib (in our case running with a little more speed than usual ;-))!

    Frank DD4WH & Frank B

    P.S.: Known issues are the Q of the bandpassfilter (do not use values higher than 10 -->distortion due to fixed point 16 bit precision errors) and the lowpassfilter (do not use stop frequencies lower than 1700) which could be subtituted by FIR filters for better performance (but we did not do that, because in the present state you just put in your desired frequency, eg. 60kHz and the reception will easily work, however you would have to alter the decoding algorithm by yourself ;-)).
    Last edited by DD4WH; 11-21-2016 at 08:23 AM.

  2. #2
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    10,914
    Nice project and write up. I'm a bit outside the reception range of DCF77. You might link the github back to this post? What MIC input - what have you got hiding behind that display?

    My local atomic clock is WWVB is a continuous 60 kHz carrier wave. I see it has the same number of bits of data - but different format.

    What changes in the first 3 options to get a wire to pick up this signal?

  3. #3
    Senior Member DD4WH's Avatar
    Join Date
    Oct 2015
    Location
    Central Europe
    Posts
    541
    Yes, I will include a link on github, so the thread can be found more easily.

    Use the MIC input of the audio board, the grey cable in the video that leads to the ferrite core coil. See also the wiki on github, there is a schematic showing ALL the parts. There is nothing "hiding" behind the display, it´s the standard ILI9341 and its cables.

    WWVB uses the same amplitude modulation principle, but bit coding uses a little different time spans. Should be easy for you to modify.

    You can use exactly the same hardware setup for option 1.

    For options 2 & 3 change the capacitor value, so that the resonance frequency of the parallel circuit of the choke/ferrite core coil and the capacitor is 60kHz (instead of 77.5kHz). You can use a pocket calculator or use this:

    http://www.deephaven.co.uk/lc.html

    For example, a standard 3.3mH inductor with a 2.2nF capacitor brings you very close to your desired frequency ;-).

    In fact, this morning, I was able to hear the UK time signal station MSF Anthorn on 60kHz in a distance of about 1200km with the same ferrite coil/cap combination that you see in the video, although it is tuned to 77.5kHz, so it is not that critical . . . But to have the best reception, try to be as close as possible to your desired resonance frequency. [And try to get a noise free test environment, switch off all plasma TVs, switching power supplies, laptops, etc.]

    Would be very nice to hear about your advances, don´t hesitate to ask me about the hardware setup; Frank B is probably the best one to answer questions on the decoding;-)

  4. #4
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    10,914
    Looking for a pic - I missed these words on github: "Hardware Setup You need a Teensy 3.x and the Teensy audio board." - and above now that I look.

    Will take note of it - and at least order the inductor next time I place an order - and another audio board.

  5. #5
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    6,504
    Today, i got parts from DD4WH.
    Wow, much better than my old Antenna. Perfect decoding ! Thank you
    The clock works good, even in my cellar, where commercial DCF77 clocks are not working.

    I guess, shouldn't use my old multimeter for LC-measurings. The old Antenna must have been several 10kHz off...

    At the moment, the paritybit-calculation does not work - i will fix this issue to prevent more false positives.
    Edit: Fixed.

    Then, at the moment, the seconds are 100..200 ms "late". I think, i can fix this too with a bit more work.
    Last edited by Frank B; 11-21-2016 at 09:27 PM.

  6. #6
    Senior Member
    Join Date
    Nov 2012
    Posts
    1,243
    I have a couple of WWVB receiver modules, similar to this one, which have never worked here. The ferrite rod+coil+cap is apparently resonant at 60kHz so I disconnected the board and tried the antenna plus some wire with your code after I made a few mods to switch it to 60kHz. Unfortunately, I can't hear anything resembling the correct signal when I listen to the audio. I am right on the northern edge of the published range for WWVB so perhaps I was hoping for too much. "Atomic" clocks do work here, although a friend of mine who has one said that it can take four hours for the clock to lock on to WWVB.

    Pete

  7. #7
    Senior Member DD4WH's Avatar
    Join Date
    Oct 2015
    Location
    Central Europe
    Posts
    541
    Hi Pete,

    from my experience, it is most often local noise (inside buildings) that prevents reception, not so much the distance to a particular transmitter/ aka signal power. Particularly in the low frequencies around 10-150kHz we often have very powerful noise sources in our homes (the worst source is probably the display and the power supply of your laptop that the Teensy is connected to via the USB cable! And of course the Teensy itself and your cell phone ;-)). You could try the following:

    - try to rotate the ferrite rod, it is often possible to notch out noise sources and maximize the signal by slowly rotating the ferrite rod, because reception with the ferrite rod is strongly directional

    - Take a shielded wire of at least 20cm length to connect the antenna/coil combination to the Teensy. If it is not that long, it could be that all you will be hearing is the longwave emission of the Teensy itself with its multiple oscillators and digital square wave signals that emitt a whole lot of LF noise

    - disconnect the USB cable from your Teensy and operate the Teensy on a battery preventing noise coming from the USB

    - solder a few metres of wire as an antenna to the one side of your resonant circuit (it does not matter too much, whether this antenna is high up or just lying on the ground), and attach a ground connection to the other side (heating or rainpipe)

    - if all that does not help, go outside (have you got a parking site somewhere in the wild, preferably with no aerial electric lines around? Hopefully no electrical cattle fences around there ;-)) and try to operate the Teensy on batteries (but switch off all electrical things in your car; cars can emitt a lot of LF/RF noise) --> if even that does not work, well then you are really too far away from WWVB . . .

    There seems to be a huge difference in man-made-noise when you are in regions with aerial electric lines (parts of the USA, Australia) compared to regions with underground electrical lines (parts of Europe). I have experienced heavy man-made-noise even in very sparsely populated areas when electrical lines are above the ground and not burried underground. Overground electrical lines seem to radiate the noise like antennas.

    The synchronisation of the time does not take more than two minutes (because one full minute of coding has all the time data you need), if you have reception! If it takes four hours, then there were nearly four hours of non-reception of the signal and two minutes of reception.

    Good luck!

    Don´t hesitate to ask again, if something is not working as you would expect it to work. Frank B has added some more features yesterday (display of daylight saving time, more plausibility checking etc.), the newest version is on github:
    https://github.com/DD4WH/Teensy-DCF77/wiki

    All the best,

    Frank DD4WH
    Last edited by DD4WH; 11-23-2016 at 06:56 AM.

  8. #8
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    10,914
    Pete is North and I'm far west. I have some commercial 'atomic' things that work - and a couple I have to put a night or more in an east facing window. Those windows are farthest from my house noise - this last DST change it worked in one night. All are a few years old. My house being so remote and so noisy doesn't make me want to rush and try it - but I would enjoy making it work - though probably in a disused room needing an ESP8266 to get the data online.

  9. #9
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    6,504
    I found, when you can hear at least a minimum signal, and strong noise, it helps to increase bandpass's Q to unusual , very high values.
    With my old antenna, decoding was not possible with a Q less than 20. 40 and more worked too, sometimes better.
    Since the bit-detection in the code does not use the signal itself, but the derivation (i.e. "digitally" the falling edge, more exact: the length of the falling edge - not the level), such a high Q was ok and helped to remove noise.

    The audio does not sound good, then. But you want decoding, not good audio :-)
    Commercial clocks for DCF-77 work with a bandwidth of only 10 Hz.

    Edit: You can try to increase the AGC max value from 58 to 63 (more than 63 is not possible), too
    Last edited by Frank B; 11-23-2016 at 06:45 PM.

  10. #10
    Senior Member
    Join Date
    Nov 2012
    Posts
    1,243
    I tried everything I could think of with the original board+ferrite loop, including driving outside the city away from power lines, switching the car off and running it off a battery. The LED which indicates the pulse just flickered insanely or stopped altogether but nothing remotely resembling the pulse sequence from WWVB.
    I didn't try attaching some extra wire as an antenna but will give that a shot.

    Thanks
    Pete

  11. #11
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    6,504
    Which led ? On pin 13 ?
    It should not flicker - as long as your antenna is receiving anything, even noise, it should light (almost) constantly.
    Hm. The I2S is overclocked - you can try to reduce the sampling-speed to 176400 Hz - does this stop the flickering ?
    If not: Can you post a photo of your setup ? please ?

    A question: Which version of the software do you use ? Maybe you have to adjust the 76.9kHz value manually - in the first versions it was fixed to this frequency. This is wrong for a 60kHz signal.
    You want 60000 - 600 = 59400.

    Edit: Do you hear anything with connected headphones ?

  12. #12
    Senior Member
    Join Date
    Nov 2012
    Posts
    1,243
    Sorry, Frank. I meant the indicator LED on the WWVB board that I was trying (the link in #6). In theory, the board detects the WWVB modulation and lights the LED in sync with the bits as they are received. If it is flickering madly, it is obviously not receiving WWVB.

    In your code, I changed the carrier and LO frequencies:
    Code:
    const float DCF77_FREQ = 60000.0; //WWVB 60 kHz
    // start detecting at this frequency, so that
    // you can hear a 600Hz tone [60000-59400 = 0.6kHz]
    unsigned int freq_real = 59400;
    I haven't changed bandpass_q or mic_gain.

  13. #13
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    6,504
    ah, ok. the numbers are correct.

  14. #14
    Member squeeek's Avatar
    Join Date
    Feb 2015
    Location
    France
    Posts
    48
    Hey this looks awsome ! I already have a 12€ board I have not tested yet. Do I need to get an audio board as well or can I use the Teensy 3.1 directly (if I get a strong enough and not too polluted signal, still to be tested...) ?

  15. #15
    Senior Member DD4WH's Avatar
    Join Date
    Oct 2015
    Location
    Central Europe
    Posts
    541
    Hi squeeek,

    yes, in order to use the unmodified code, you will need the audio board.

    DCF77 should be readable in France, if you do not live in some deep valley in the pyrenées.

    Good luck and have fun,

    Frank

  16. #16
    Member squeeek's Avatar
    Join Date
    Feb 2015
    Location
    France
    Posts
    48
    Quote Originally Posted by DD4WH View Post
    DCF77 should be readable in France, if you do not live in some deep valley in the pyrenées.
    Well, I live in Toulouse, which is quite close to the Pyrenées, but not in a deep valley, so I shall have faith that it should work !

    It might be a "good" reason to get an audio board anyway, I have not played with it yet hehe...

  17. #17
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    6,504
    Yup, the board is great.

  18. #18
    Senior Member
    Join Date
    Nov 2012
    Posts
    1,243
    @the two Franks: I've got the DCF77 code working with WWVB now and also decoding the signal (I'll post the code eventually).
    There's one thing I don't understand about the code. In the set_sample_rate function the sampling rate is set to 192k and then biquad2 (lopass) and biquad1 (bandpass) are initialized. However, the audio library assumes that the sampling rate is 44100 and sets the parameters of the filters accordingly. How do those filters work at 192k?

    Pete

  19. #19
    Senior Member DD4WH's Avatar
    Join Date
    Oct 2015
    Location
    Central Europe
    Posts
    541
    Hi Pete!

    Great, that you got the direct sampling software defined radio code working to decode WWV !

    The sample rate is set to 192ksps, but the audio lib still assumes 44100ksps.

    That is why we have to cheat a bit and the filter and local oscillator frequencies passed to the audio lib have to be multiplied with the ratio of the original sample rate and the real sample rate:

    Code:
     freq_LO = freq * (AUDIO_SAMPLE_RATE_EXACT / sample_rate_real);
    
    sine1.frequency(freq_LO);
    So, if we want the LO to produce a sine wave at 192ksps with a frequency of 59400Hz (in order to hear a heterodyne tone of 600Hz with WWV transmitting at 60000Hz, 60000 - 600 = 59400), we set the LO to

    freq_LO = 59400 * (44118 / 192000) = 13649Hz

    However, we have to be sure that the real freq never exceeds the Nyquist frequency, which is half of the sample rate, so 192k / 2 = 96000Hz. That means that the maximum frequency communicated to the audio lib never exceeds AUDIO_SAMPLE_RATE_EXACT / 2 = 22000Hz. That is also the reason that this direct sampling receiver only works up to about 96kHz receive frequency (which should nonetheless cover every longwave time signal receiver worldwide ;-)). [the audio board also works with higher sample rates, I use it regularly with 234kHz and others have used even higher sample rates]

    A second problem is the biquad filter performance at low cutoff frequencies: due to the use of fixed point math in the audio library, calculations of biquad filters with low cutoff frequencies quickly become erroneous, i.e. they do not have the precision needed and start to produce unstabilities/ringing/oscillations. We have empirically tested this ("empirical test": we tuned the lower cutoff frequency limit and listened to the output with our ears, until audible distortion or annoying noise was present ;-)) and so we implemented a minimum cutoff frequency for the biquads at 1700Hz, translating to 1700 * 44118 / 192000 = 390Hz, which is pretty exactly the 400Hz low frequency limit that Paul Stoffregen states in his description of the biquad filters in the audio library GUI.

    Would be very interesting to have your code posted to see the differences between DCF77 and WWV. Do you use the amplitude modulation or the phase modulation of WWVB for decoding the time information?

    All the best,

    Frank DD4WH
    Last edited by DD4WH; 08-23-2018 at 07:29 AM.

  20. #20
    Senior Member
    Join Date
    Nov 2012
    Posts
    1,243
    Hi Frank,
    Thanks for the explanation. I saw those adjustments for the rate but misread them as adjusting for the difference between 44.1kHz and AUDIO_SAMPLE_RATE_EXACT rather than between AUDIO_SAMPLE_RATE_EXACT and 192kHz. Now it makes sense.
    I'm using the amplitude modulated signal to decode WWVB.
    I'll post the code soon. I'm currently trying to track down the source of a very annoying buzz which starts up randomly, lasts for a minute and then stops. It definitely appears to be external to the Teensy and audio recorder I am using (Tascam DR-40) because if I move the antenna it changes the volume of the signal. My HF rig (IC735) only goes down to 100kHz but it doesn't hear the noise.

    Pete

  21. #21
    Senior Member
    Join Date
    Oct 2012
    Location
    Portland OR
    Posts
    678
    I'm curious whether it is possible to use the phase modulation of WWVB, which I have read is supposed to allow for additional processing gain, eg. better performance on weak signals.

    There is a standalone WWVB module available at a reasonable price https://www.amazon.com/CANADUINO-60k.../dp/B01KH3VEGS but the MAS6180C receiver chip it uses appears to be AM only. https://www.mas-oy.com/wp-content/up...05/DA6180C.pdf

  22. #22
    Senior Member DD4WH's Avatar
    Join Date
    Oct 2015
    Location
    Central Europe
    Posts
    541
    Hi John,

    yes, demodulation of phase modulation is a bit like demodulating FM, and can be done in software with the Teensy. I dont think that you would need further hardware for that purpose. [Teensy Convolution SDR demodulates FM at a sample rate of 234ksps, so the Teensy 3.6 seems to have enough processing power for that]

    BTW, TDF in France on 162kHz (the former longwave transmitter of France Inter) also broadcasts time signals in phase modulation, similar to WWVB.

    It has been on my wishlist for a long time to demodulate these time signals, however my time does not allow at the moment.

    There are several approaches to do this: comparisons of arctan calculations of the current and the former phase, a complex Costas loop or PLL . . .

    As far as I understand it, you add a carrier to the signal by multiplying the incoming LF signal with a 60kHz sine wave. The result will be 2 x 60kHz (which you discard with a lowpass filter) and the DC component of interest which will be positive for 0 and negative for a 1. At higher sample rates this can be done in software.

    (in fact, this multiplication is already being done in the script :-))
    Code:
    AudioEffectMultiply      mult1;
    see András Retzlers master thesis on BPSK demodulation:

    https://sdr.hu/static/msc-thesis.pdf

    or have a look at the UHSDR C code:

    https://github.com/df8oe/UHSDR/blob/...rs/audio/psk.c

    Not quite as simple as demodulating AM, but feasible with the Teensy, I would say.

    If you plan to work on that, I would be happy to help, but at the moment I cannot take the initiative due to time constraints.

    All the best,

    Frank DD4WH

  23. #23
    Junior Member
    Join Date
    Jan 2020
    Posts
    13
    Hi, I would like to implement this with the new Teensy 4.0.
    I have downloaded the source.
    My first attempts to compile are failing on I2S0_MCR and I2S_MCR_DUF being undefined.

    The clues seem to lead me to the audio library for these, but I have not yet found an actual definition of what they are.
    I appreciate any pointers you might offer.

    Chris

  24. #24
    Senior Member
    Join Date
    Nov 2012
    Posts
    1,243
    Those two are in the Teensy3.* version of the setI2SFreq function. There is a thread about a version of that function for the Teensy4.
    Frank's original message:
    https://forum.pjrc.com/threads/58494...l=1#post222231
    a modified version:
    https://forum.pjrc.com/threads/58494...l=1#post222384
    I haven't tried either yet.

    Pete

  25. #25
    Junior Member
    Join Date
    Jan 2020
    Posts
    13
    Thanks!
    I have gotten the code to compile and almost run on the Teensy 4.0. I had to comment out displayDate function.
    In runtime it is going to a line which does a sprintf calling function weekday() and hangs there.
    If I take out the call to weekday() it seems to run OK. I have some further debugging to do.

    Is there a known problem with weekday()?

Posting Permissions

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