builds, but has bugs and crashes in ISR
This commit is contained in:
parent
24c079663d
commit
b56272cfc6
102
wwvb/wwvb.ino
102
wwvb/wwvb.ino
@ -49,12 +49,10 @@ volatile unsigned int ppsActivationTime = 0;
|
|||||||
volatile unsigned int millisSinceSignalStateChange = 0;
|
volatile unsigned int millisSinceSignalStateChange = 0;
|
||||||
volatile unsigned int minuteSync = 0;
|
volatile unsigned int minuteSync = 0;
|
||||||
|
|
||||||
void ICACHE_RAM_ATTR WWVFallingEdge();
|
void ICACHE_RAM_ATTR TimerHandler();
|
||||||
void ICACHE_RAM_ATTR OSCEdge();
|
|
||||||
void ICACHE_RAM_ATTR MilliEdge();
|
void ICACHE_RAM_ATTR MilliEdge();
|
||||||
void ICACHE_RAM_ATTR SecondEdge();
|
void ICACHE_RAM_ATTR SecondEdge();
|
||||||
|
|
||||||
|
|
||||||
#include "ESP8266TimerInterrupt.h"
|
#include "ESP8266TimerInterrupt.h"
|
||||||
ESP8266Timer ITimer;
|
ESP8266Timer ITimer;
|
||||||
|
|
||||||
@ -87,39 +85,32 @@ void setup() {
|
|||||||
Serial.println(millis());
|
Serial.println(millis());
|
||||||
} else {
|
} else {
|
||||||
Serial.println(
|
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.init();
|
||||||
lcd.backlight();
|
lcd.backlight();
|
||||||
lcd.setCursor(0, 0);
|
lcd.setCursor(0, 0);
|
||||||
lcd.print("booting");
|
lcd.print("booting");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TimerHandler() {
|
void TimerHandler() {
|
||||||
//Serial.print(F("in timer OK, millis() = ")); Serial.println(millis());
|
|
||||||
clockCounter++;
|
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) {
|
if(clockCounter > CLOCKS_PER_MS) {
|
||||||
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();
|
MilliEdge();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -130,12 +121,24 @@ void SecondEdge() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void MilliEdge() {
|
void MilliEdge() {
|
||||||
digitalWrite(DEBUG1_OUTPUT_PIN, 1);
|
|
||||||
wwvbInState = digitalRead(WWV_SIGNAL_PIN);
|
|
||||||
|
|
||||||
milliCounter++;
|
milliCounter++;
|
||||||
millisSinceBoot++;
|
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) {
|
if(milliCounter > 1000) {
|
||||||
milliCounter -= 1000;
|
milliCounter -= 1000;
|
||||||
SecondEdge();
|
SecondEdge();
|
||||||
@ -222,13 +225,12 @@ void SetPPSLow() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void SendPPS() {
|
void SendPPS() {
|
||||||
unsigned int tickInterval = millisSinceBoot - ppsActivationTime;
|
|
||||||
ppsActivationTime = millisSinceBoot;
|
ppsActivationTime = millisSinceBoot;
|
||||||
SetPPSHigh();
|
SetPPSHigh();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PPSLowIfRequired() {
|
void PPSLowIfRequired() {
|
||||||
if ((millisSinceBoot - ppsActivationTime) > 500) {
|
if ((millisSinceBoot - ppsActivationTime) > PPS_PULSEWIDTH_MS) {
|
||||||
SetPPSLow();
|
SetPPSLow();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -236,9 +238,9 @@ void PPSLowIfRequired() {
|
|||||||
void TickSecond() {
|
void TickSecond() {
|
||||||
char buf[255];
|
char buf[255];
|
||||||
sprintf(buf, "*** TICK(%d): WWVB going low after %d ms high (EDGE)\n",
|
sprintf(buf, "*** TICK(%d): WWVB going low after %d ms high (EDGE)\n",
|
||||||
frameCounter, lastBitHighMS);
|
frameCounter, lastBitHighMS);
|
||||||
SendPPS();
|
|
||||||
Serial.print(buf);
|
Serial.print(buf);
|
||||||
|
SendPPS();
|
||||||
}
|
}
|
||||||
|
|
||||||
void readBit() {
|
void readBit() {
|
||||||
@ -267,21 +269,21 @@ int convertBit(unsigned int ms) {
|
|||||||
sprintf(bitbuf, "ZERO");
|
sprintf(bitbuf, "ZERO");
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
/*
|
/*
|
||||||
if (rawVal < 800) {
|
if (rawVal < 800) {
|
||||||
output = ONEBIT;
|
output = ONEBIT;
|
||||||
sprintf(bitbuf, "ONE");
|
sprintf(bitbuf, "ONE");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rawVal < 680) {
|
if (rawVal < 680) {
|
||||||
output = MARKBIT;
|
output = MARKBIT;
|
||||||
sprintf(bitbuf, "MARK");
|
sprintf(bitbuf, "MARK");
|
||||||
}
|
}
|
||||||
|
|
||||||
sprintf(buf, "frame rawVal=%d, bit=%s\n", rawVal, bitbuf);
|
sprintf(buf, "frame rawVal=%d, bit=%s\n", rawVal, bitbuf);
|
||||||
Serial.print(buf);
|
Serial.print(buf);
|
||||||
return output;
|
return output;
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
void registerBit(int doot) {
|
void registerBit(int doot) {
|
||||||
@ -413,15 +415,7 @@ void serialDebug() {
|
|||||||
char buf[255];
|
char buf[255];
|
||||||
sprintf(buf,"lossOfSignal=%d\n",lossOfSignal);
|
sprintf(buf,"lossOfSignal=%d\n",lossOfSignal);
|
||||||
Serial.print(buf);
|
Serial.print(buf);
|
||||||
sprintf(buf,"frameReadyToStart=%d\n",frameReadyToStart);
|
sprintf(buf,"waitingForSecond=%d\n",waitingForSecond);
|
||||||
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);
|
|
||||||
Serial.print(buf);
|
Serial.print(buf);
|
||||||
sprintf(buf,"millisSinceBoot=%d\n",millisSinceBoot);
|
sprintf(buf,"millisSinceBoot=%d\n",millisSinceBoot);
|
||||||
Serial.print(buf);
|
Serial.print(buf);
|
||||||
@ -431,8 +425,8 @@ void serialDebug() {
|
|||||||
Serial.print(buf);
|
Serial.print(buf);
|
||||||
sprintf(buf,"timeToTick=%d\n",timeToTick);
|
sprintf(buf,"timeToTick=%d\n",timeToTick);
|
||||||
Serial.print(buf);
|
Serial.print(buf);
|
||||||
sprintf(buf,"frameHigh=%d\n",frameHigh);
|
sprintf(buf,"highFor=%d\n",highFor);
|
||||||
Serial.print(buf);
|
Serial.print(buf);
|
||||||
sprintf(buf,"frameLow=%d\n",frameLow);
|
sprintf(buf,"lowFor=%d\n",lowFor);
|
||||||
Serial.print(buf);
|
Serial.print(buf);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user