builds, but has bugs and crashes in ISR

refactor/wwvb-simple-timer
Jeffrey Paul 2 years ago
parent 24c079663d
commit b56272cfc6
  1. 106
      wwvb/wwvb.ino

@ -49,12 +49,10 @@ volatile unsigned int ppsActivationTime = 0;
volatile unsigned int millisSinceSignalStateChange = 0;
volatile unsigned int minuteSync = 0;
void ICACHE_RAM_ATTR WWVFallingEdge();
void ICACHE_RAM_ATTR OSCEdge();
void ICACHE_RAM_ATTR TimerHandler();
void ICACHE_RAM_ATTR MilliEdge();
void ICACHE_RAM_ATTR SecondEdge();
#include "ESP8266TimerInterrupt.h"
ESP8266Timer ITimer;
@ -87,39 +85,32 @@ void setup() {
Serial.println(millis());
} else {
Serial.println(
F("Can't set ITimer. Select another freq. or timer")
);
F("Can't set ITimer. Select another freq. or timer")
);
}
lcd.init();
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("booting");
}
void TimerHandler() {
//Serial.print(F("in timer OK, millis() = ")); Serial.println(millis());
clockCounter++;
// *****************************************************************
// *****************************************************************
// LOW LATENCY HACK to respond in 100us to a falling start-of-second
// edge respond really fast to a falling edge if in the waitingForSecond
// state
//lowLatencyInState = digitalRead(WWV_SIGNAL_PIN);
wwvbInState = digitalRead(WWV_SIGNAL_PIN);
// *****************************************************************
// *****************************************************************
if(clockCounter > CLOCKS_PER_MS) {
clockCounter -= CLOCKS_PER_MS;
// *****************************************************************************
// LOW LATENCY HACK to respond in 100us to a falling
// start-of-second edge
// respond really fast to a falling edge if in the waitingForSecond
// state
lowLatencyInState = digitalRead(WWV_SIGNAL_PIN);
if(waitingForSecond && !lossOfSignal && !lowLatencyInState) {
// TICK!
// falling edge, beginning of a new frame and second
digitalWrite(PPS_OUTPUT_PIN, 1);
waitingForSecond = 0;
timeToTick = 1;
lastBitHighMS = highFor;
bitReadyForRead = 1;
}
// *****************************************************************************
MilliEdge();
}
}
@ -130,12 +121,24 @@ void SecondEdge() {
}
void MilliEdge() {
digitalWrite(DEBUG1_OUTPUT_PIN, 1);
wwvbInState = digitalRead(WWV_SIGNAL_PIN);
milliCounter++;
millisSinceBoot++;
wwvbInState = digitalRead(WWV_SIGNAL_PIN);
if(waitingForSecond && !wwvbInState) {
// TICK! falling edge, beginning of a new frame and second
// FIXME reenable pps
//digitalWrite(PPS_OUTPUT_PIN, 1);
waitingForSecond = 0;
timeToTick = 1;
lastBitHighMS = highFor;
bitReadyForRead = 1;
return;
}
if(milliCounter > 1000) {
milliCounter -= 1000;
SecondEdge();
@ -222,13 +225,12 @@ void SetPPSLow() {
}
void SendPPS() {
unsigned int tickInterval = millisSinceBoot - ppsActivationTime;
ppsActivationTime = millisSinceBoot;
SetPPSHigh();
}
void PPSLowIfRequired() {
if ((millisSinceBoot - ppsActivationTime) > 500) {
if ((millisSinceBoot - ppsActivationTime) > PPS_PULSEWIDTH_MS) {
SetPPSLow();
}
}
@ -236,9 +238,9 @@ void PPSLowIfRequired() {
void TickSecond() {
char buf[255];
sprintf(buf, "*** TICK(%d): WWVB going low after %d ms high (EDGE)\n",
frameCounter, lastBitHighMS);
SendPPS();
frameCounter, lastBitHighMS);
Serial.print(buf);
SendPPS();
}
void readBit() {
@ -267,21 +269,21 @@ int convertBit(unsigned int ms) {
sprintf(bitbuf, "ZERO");
return output;
/*
if (rawVal < 800) {
output = ONEBIT;
sprintf(bitbuf, "ONE");
}
if (rawVal < 680) {
output = MARKBIT;
sprintf(bitbuf, "MARK");
}
sprintf(buf, "frame rawVal=%d, bit=%s\n", rawVal, bitbuf);
Serial.print(buf);
return output;
*/
/*
if (rawVal < 800) {
output = ONEBIT;
sprintf(bitbuf, "ONE");
}
if (rawVal < 680) {
output = MARKBIT;
sprintf(bitbuf, "MARK");
}
sprintf(buf, "frame rawVal=%d, bit=%s\n", rawVal, bitbuf);
Serial.print(buf);
return output;
*/
}
void registerBit(int doot) {
@ -413,15 +415,7 @@ void serialDebug() {
char buf[255];
sprintf(buf,"lossOfSignal=%d\n",lossOfSignal);
Serial.print(buf);
sprintf(buf,"frameReadyToStart=%d\n",frameReadyToStart);
Serial.print(buf);
sprintf(buf,"beginFrameSearch=%d\n",beginFrameSearch);
Serial.print(buf);
sprintf(buf,"frameSearch=%d\n",frameSearch);
Serial.print(buf);
sprintf(buf,"frameStart=%d\n",frameStart);
Serial.print(buf);
sprintf(buf,"frameStartTime=%d\n",frameStartTime);
sprintf(buf,"waitingForSecond=%d\n",waitingForSecond);
Serial.print(buf);
sprintf(buf,"millisSinceBoot=%d\n",millisSinceBoot);
Serial.print(buf);
@ -431,8 +425,8 @@ void serialDebug() {
Serial.print(buf);
sprintf(buf,"timeToTick=%d\n",timeToTick);
Serial.print(buf);
sprintf(buf,"frameHigh=%d\n",frameHigh);
sprintf(buf,"highFor=%d\n",highFor);
Serial.print(buf);
sprintf(buf,"frameLow=%d\n",frameLow);
sprintf(buf,"lowFor=%d\n",lowFor);
Serial.print(buf);
}

Loading…
Cancel
Save