builds, but has bugs and crashes in ISR
This commit is contained in:
parent
24c079663d
commit
b56272cfc6
|
@ -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;
|
||||
|
||||
|
@ -95,31 +93,24 @@ void setup() {
|
|||
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();
|
||||
}
|
||||
}
|
||||
|
@ -237,8 +239,8 @@ void TickSecond() {
|
|||
char buf[255];
|
||||
sprintf(buf, "*** TICK(%d): WWVB going low after %d ms high (EDGE)\n",
|
||||
frameCounter, lastBitHighMS);
|
||||
SendPPS();
|
||||
Serial.print(buf);
|
||||
SendPPS();
|
||||
}
|
||||
|
||||
void readBit() {
|
||||
|
@ -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…
Reference in New Issue