From d52dc0263c19c6dc51706f132e927dcd48a3cad9 Mon Sep 17 00:00:00 2001 From: sneak Date: Tue, 11 Jan 2022 03:16:39 -0800 Subject: [PATCH] no longer crashes the mc --- wwvb/wwvb.ino | 46 ++++++++++++++-------------------------------- 1 file changed, 14 insertions(+), 32 deletions(-) diff --git a/wwvb/wwvb.ino b/wwvb/wwvb.ino index 37a77c5..eb6b059 100644 --- a/wwvb/wwvb.ino +++ b/wwvb/wwvb.ino @@ -197,19 +197,13 @@ void loop() { TickSecond(); } - yield(); - if(bitReadyForRead) { bitReadyForRead = 0; readBit(); } - yield(); - PPSLowIfRequired(); - yield(); - if (displayUpdateRequired) { updateDisplay(); displayUpdateRequired = 0; @@ -244,46 +238,34 @@ void TickSecond() { } void readBit() { - char buf[255]; - unsigned int ms = lastBitHighMS; - sprintf(buf, "*** carrier was high for %sms befor \n", ms); - Serial.print(buf); + //char buf[255]; + //sprintf(buf, "*** carrier was high for %sms befor \n", lastBitHighMS); + //Serial.print(buf); displayUpdateRequired++; - registerBit(convertBit(ms)); + registerBit(convertBit(lastBitHighMS)); } int convertBit(unsigned int ms) { char buf[255]; - /* - - 20% - marker - 50% - one bit - 80% - zero bit - our cutoff points will be 50% and 80% - */ char bitbuf[20]; - int output = 0; output = ZEROBIT; sprintf(bitbuf, "ZERO"); - return output; - /* - if (rawVal < 800) { + if (ms < 800) { output = ONEBIT; sprintf(bitbuf, "ONE"); - } + } - if (rawVal < 680) { + if (ms < 400) { output = MARKBIT; sprintf(bitbuf, "MARK"); - } + } - sprintf(buf, "frame rawVal=%d, bit=%s\n", rawVal, bitbuf); - Serial.print(buf); - return output; - */ + sprintf(buf, "frame prevHighMs=%s, bit=%s\n", ms, bitbuf); + Serial.print(buf); + return output; } void registerBit(int doot) { @@ -291,6 +273,7 @@ void registerBit(int doot) { frameCounter++; } + if (doot == MARKBIT) { if (lastBitReceived == MARKBIT) { // two mark bits in a row means we are in the first second of the minute @@ -363,11 +346,10 @@ void updateDisplay() { if (lossOfSignal) { sprintf(statusString, "LOS"); - } - - if (millisSinceBoot - frameStartTime < 10000) { + } else { sprintf(statusString, "RX(syncing)"); } + if (minuteSync) { sprintf(statusString, "RX(bit %d)", frameCounter); }