Library to decode MSF time signal.

Committer:
dswood
Date:
Fri Jan 07 12:12:25 2022 +0000
Revision:
0:340305453f64
A simple library to decode MSF time signal. Probably useful for DSF

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dswood 0:340305453f64 1 /*This library will decode an MSF signal on a digital input pin and turn it
dswood 0:340305453f64 2 into a timestamp.
dswood 0:340305453f64 3 Copyright (C) 2017 Duncan Wood
dswood 0:340305453f64 4
dswood 0:340305453f64 5 This library is free software; you can redistribute it and/or
dswood 0:340305453f64 6 modify it under the terms of the GNU Lesser General Public
dswood 0:340305453f64 7 License as published by the Free Software Foundation; either
dswood 0:340305453f64 8 version 2.1 of the License, or (at your option) any later version.
dswood 0:340305453f64 9
dswood 0:340305453f64 10 This library is distributed in the hope that it will be useful,
dswood 0:340305453f64 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
dswood 0:340305453f64 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
dswood 0:340305453f64 13 Lesser General Public License for more details.
dswood 0:340305453f64 14
dswood 0:340305453f64 15 You should have received a copy of the GNU Lesser General Public
dswood 0:340305453f64 16 License along with this library; if not, write to the Free Software
dswood 0:340305453f64 17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
dswood 0:340305453f64 18 */
dswood 0:340305453f64 19
dswood 0:340305453f64 20
dswood 0:340305453f64 21
dswood 0:340305453f64 22 #include "mbed.h"
dswood 0:340305453f64 23 class MSF_Time
dswood 0:340305453f64 24 {
dswood 0:340305453f64 25 public:
dswood 0:340305453f64 26 /* Start MSF_Time with this function
dswood 0:340305453f64 27 InputPin is the data coming from your reciever
dswood 0:340305453f64 28 Polarity is 0 if your receiver output is high for no carrier
dswood 0:340305453f64 29 polarity is 1 to invert this logic. */
dswood 0:340305453f64 30
dswood 0:340305453f64 31
dswood 0:340305453f64 32 MSF_Time(PinName InputPin, int polarity,int OffsetTuning =48000);
dswood 0:340305453f64 33
dswood 0:340305453f64 34 bool Valid(); // Is the time valid
dswood 0:340305453f64 35 time_t Read();
dswood 0:340305453f64 36
dswood 0:340305453f64 37 protected:
dswood 0:340305453f64 38 struct MSF_Data {
dswood 0:340305453f64 39 int BCDYear;
dswood 0:340305453f64 40 int BCDMonth;
dswood 0:340305453f64 41 int DayOfWeek;
dswood 0:340305453f64 42 int BCDTime;
dswood 0:340305453f64 43 int SyncByte; //This is sent and allows you to detect leap seconds
dswood 0:340305453f64 44 int DUT;
dswood 0:340305453f64 45 int BST;
dswood 0:340305453f64 46 };
dswood 0:340305453f64 47
dswood 0:340305453f64 48 struct MSF_Data MyData;
dswood 0:340305453f64 49 struct tm Received_Time; // Normal data coming in
dswood 0:340305453f64 50 time_t Received_timestamp; //Data converted to timestamp
dswood 0:340305453f64 51 unsigned int Time_Data_Duration; //Pulse length - The minute marker is 500ms
dswood 0:340305453f64 52 bool Time_Data_Sync; // True when a 500ms pulse is detected denoting the start of a minute
dswood 0:340305453f64 53 Ticker Time_Data_Ticker; // A 50ms clock used to clock in data
dswood 0:340305453f64 54 unsigned int Time_Data_Count;// counts the 50ms for clocking in the data
dswood 0:340305453f64 55 void Time_Data_Strobe(); // When the ticker ticks do this
dswood 0:340305453f64 56 void Falling();
dswood 0:340305453f64 57 void Rising();
dswood 0:340305453f64 58 bool DataValid;
dswood 0:340305453f64 59 Timeout offset; // used to fine tune the seconds 50ms equals zero offset
dswood 0:340305453f64 60 InterruptIn Time_Data;
dswood 0:340305453f64 61 DigitalIn MyInput;
dswood 0:340305453f64 62 int Polarity;
dswood 0:340305453f64 63 int OffsetTuning;
dswood 0:340305453f64 64 Timer Time_Data_timer;
dswood 0:340305453f64 65 void LogicOne();
dswood 0:340305453f64 66 void LogicZero();
dswood 0:340305453f64 67 int ParityCheck(unsigned int CheckMe);
dswood 0:340305453f64 68 void ProcessData();
dswood 0:340305453f64 69 void IncrementSeconds();
dswood 0:340305453f64 70 void IncrementSecondsNow();
dswood 0:340305453f64 71 //int const OffsetTuning=48000; //in microseconds
dswood 0:340305453f64 72 bool debug; //turn on off debugging noise
dswood 0:340305453f64 73 bool DV;
dswood 0:340305453f64 74
dswood 0:340305453f64 75 };