diff --git a/src/cyclic.cpp b/src/cyclic.cpp index b4e6e9ff..4b921e5a 100644 --- a/src/cyclic.cpp +++ b/src/cyclic.cpp @@ -61,8 +61,8 @@ void doHousekeeping() { uxTaskGetStackHighWaterMark(BmeTask), eTaskGetState(BmeTask)); #endif #ifdef HAS_DCF77 - ESP_LOGD(TAG, "DCF77loop %d bytes left | Taskstate = %d", - uxTaskGetStackHighWaterMark(DCF77Task), eTaskGetState(DCF77Task)); + ESP_LOGD(TAG, "Clockloop %d bytes left | Taskstate = %d", + uxTaskGetStackHighWaterMark(ClockTask), eTaskGetState(ClockTask)); #endif #if (HAS_LED != NOT_A_PIN) || defined(HAS_RGB_LED) diff --git a/src/dcf77.cpp b/src/dcf77.cpp index 8cc2313c..0648d854 100644 --- a/src/dcf77.cpp +++ b/src/dcf77.cpp @@ -9,7 +9,7 @@ https://www-user.tu-chemnitz.de/~heha/viewzip.cgi/hs/Funkuhr.zip/ #ifdef HAS_DCF77 #ifdef IF_482 -#error "You must define at most one of IF482 or DCF_77" +#error "You must define at most one of IF482 or DCF77" #endif #include "dcf77.h" @@ -19,8 +19,9 @@ static const char TAG[] = "main"; #define DCF77_FRAME_SIZE (60) #define DCF77_PULSE_DURATION (100) -#ifdef RTC_CLK -#define PPS (RTC_CLK / DCF77_PULSE_DURATION) + +#if defined RTC_INT && defined RTC_CLK +#define PPS RTC_CLK #else #define PPS DCF77_PULSE_DURATION #endif @@ -63,10 +64,14 @@ void DCF_Out(uint8_t startOffset) { #endif if (!BitsPending) { - // prepare frame to send for next minute - generateTimeframe(now() + DCF77_FRAME_SIZE + 1); - // start blinking symbol on display and kick off timer - BitsPending = true; + // do we have confident time/date? + if ((timeStatus() == timeSet) || (timeStatus() == timeNeedsSync)) { + // prepare frame to send for next minute + generateTimeframe(now() + DCF77_FRAME_SIZE + 1); + // start blinking symbol on display and kick off timer + BitsPending = true; + } else + return; } // ticker out current DCF frame @@ -124,11 +129,14 @@ void dcf77_loop(void *pvParameters) { #if (PPS == DCF77_PULSE_DURATION) // we don't need clock rescaling DCF_Out(0); -#else // we need clock rescaling by software timer - for (uint8_t i = 1; i <= PPS; i++) { +#elif (PPS > DCF77_PULSE_DURATION) // we need upclocking + for (uint8_t i = 1; i <= PPS / DCF77_PULSE_DURATION; i++) { DCF_Out(0); vTaskDelayUntil(&wakeTime, pdMS_TO_TICKS(DCF77_PULSE_DURATION)); } +#elif (PPS < DCF77_PULSE_DURATION) // we need downclocking + vTaskDelayUntil(&wakeTime, pdMS_TO_TICKS(DCF77_PULSE_DURATION - PPS)); + DCF_Out(0); #endif } // for } // dcf77_loop() diff --git a/src/if482.cpp b/src/if482.cpp index 41ac2834..71df7a56 100644 --- a/src/if482.cpp +++ b/src/if482.cpp @@ -80,7 +80,7 @@ not evaluated by model BU-190 #ifdef HAS_IF482 #ifdef HAS_DCF77 -#error "You must define at most one of IF482 or DCF_77" +#error "You must define at most one of IF482 or DCF77" #endif #include "if482.h" @@ -90,8 +90,9 @@ static const char TAG[] = "main"; #define IF482_FRAME_SIZE (17) #define IF482_PULSE_DURATION (1000) + #ifdef RTC_CLK -#define PPS (RTC_CLK / IF482_PULSE_DURATION) +#define PPS RTC_CLK #else #define PPS IF482_PULSE_DURATION #endif @@ -174,14 +175,20 @@ void if482_loop(void *pvParameters) { &wakeTime, // receives moment of call from isr portMAX_DELAY); // wait forever (missing error handling here...) -#if (PPS == DCF77_PULSE_DURATION) // we don't need clock rescaling +#if (PPS == IF482_PULSE_DURATION) // we don't need clock rescaling // wait until it's time to start transmit telegram for next second vTaskDelayUntil(&wakeTime, shotTime); // sets waketime to moment of shot IF482.print(IF482_Out(now() + 1)); -#else // we need clock rescaling by software timer - /* - not yet implemented for IF482 - */ +#elif (PPS > IF482_PULSE_DURATION) // we need upclocking + for (uint8_t i = 1; i <= PPS / IF482_PULSE_DURATION; i++) { + vTaskDelayUntil(&wakeTime, shotTime); // sets waketime to moment of shot + IF482.print(IF482_Out(now() + 1)); + } +#elif (PPS < IF482_PULSE_DURATION) // we need downclocking + IF482.print(IF482_Out(now() + 1)); + vTaskDelayUntil(&wakeTime, + shotTime - PPS); // sets waketime to moment of shot + #endif } } // if482_loop() diff --git a/src/rtctime.cpp b/src/rtctime.cpp index 5c08af77..de909866 100644 --- a/src/rtctime.cpp +++ b/src/rtctime.cpp @@ -102,9 +102,9 @@ float get_rtctemp(void) { #endif // HAS_RTC -int pps_init(uint32_t clk_freq_Hz) { +int pps_init(uint32_t clk_freq_ms) { // use fixed pulse clock as time base -#if defined RTC_INT && (RTC_CLK == clk_freq_Hz) +#if defined RTC_INT && defined RTC_CLK // setup external interupt for active low RTC INT pin pinMode(RTC_INT, INPUT_PULLUP); @@ -123,11 +123,11 @@ int pps_init(uint32_t clk_freq_Hz) { #else // use clock with adjustable frequency - if (clk_freq_Hz) { + if (clk_freq_ms) { ESP_LOGI(TAG, "Time base ESP32 clock"); - clockCycle = timerBegin(1, 8000, true); // set 80 MHz prescaler + clockCycle = timerBegin(1, 8000, true); // set 80 MHz prescaler to 1/10000 sec timerAttachInterrupt(clockCycle, &CLOCKIRQ, true); - timerAlarmWrite(clockCycle, 100 * clk_freq_Hz, true); + timerAlarmWrite(clockCycle, 10 * clk_freq_ms, true); //ms } else { ESP_LOGE(TAG, "Invalid pulse clock frequency"); return 0; // failure