DCF77 + IF482 debugging

This commit is contained in:
Klaus K Wilting 2019-02-08 23:08:14 +01:00
parent bfc8f13cc7
commit ed5c7f46f3
4 changed files with 38 additions and 23 deletions

View File

@ -61,8 +61,8 @@ void doHousekeeping() {
uxTaskGetStackHighWaterMark(BmeTask), eTaskGetState(BmeTask)); uxTaskGetStackHighWaterMark(BmeTask), eTaskGetState(BmeTask));
#endif #endif
#ifdef HAS_DCF77 #ifdef HAS_DCF77
ESP_LOGD(TAG, "DCF77loop %d bytes left | Taskstate = %d", ESP_LOGD(TAG, "Clockloop %d bytes left | Taskstate = %d",
uxTaskGetStackHighWaterMark(DCF77Task), eTaskGetState(DCF77Task)); uxTaskGetStackHighWaterMark(ClockTask), eTaskGetState(ClockTask));
#endif #endif
#if (HAS_LED != NOT_A_PIN) || defined(HAS_RGB_LED) #if (HAS_LED != NOT_A_PIN) || defined(HAS_RGB_LED)

View File

@ -9,7 +9,7 @@ https://www-user.tu-chemnitz.de/~heha/viewzip.cgi/hs/Funkuhr.zip/
#ifdef HAS_DCF77 #ifdef HAS_DCF77
#ifdef IF_482 #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 #endif
#include "dcf77.h" #include "dcf77.h"
@ -19,8 +19,9 @@ static const char TAG[] = "main";
#define DCF77_FRAME_SIZE (60) #define DCF77_FRAME_SIZE (60)
#define DCF77_PULSE_DURATION (100) #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 #else
#define PPS DCF77_PULSE_DURATION #define PPS DCF77_PULSE_DURATION
#endif #endif
@ -63,10 +64,14 @@ void DCF_Out(uint8_t startOffset) {
#endif #endif
if (!BitsPending) { if (!BitsPending) {
// do we have confident time/date?
if ((timeStatus() == timeSet) || (timeStatus() == timeNeedsSync)) {
// prepare frame to send for next minute // prepare frame to send for next minute
generateTimeframe(now() + DCF77_FRAME_SIZE + 1); generateTimeframe(now() + DCF77_FRAME_SIZE + 1);
// start blinking symbol on display and kick off timer // start blinking symbol on display and kick off timer
BitsPending = true; BitsPending = true;
} else
return;
} }
// ticker out current DCF frame // 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 #if (PPS == DCF77_PULSE_DURATION) // we don't need clock rescaling
DCF_Out(0); DCF_Out(0);
#else // we need clock rescaling by software timer #elif (PPS > DCF77_PULSE_DURATION) // we need upclocking
for (uint8_t i = 1; i <= PPS; i++) { for (uint8_t i = 1; i <= PPS / DCF77_PULSE_DURATION; i++) {
DCF_Out(0); DCF_Out(0);
vTaskDelayUntil(&wakeTime, pdMS_TO_TICKS(DCF77_PULSE_DURATION)); 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 #endif
} // for } // for
} // dcf77_loop() } // dcf77_loop()

View File

@ -80,7 +80,7 @@ not evaluated by model BU-190
#ifdef HAS_IF482 #ifdef HAS_IF482
#ifdef HAS_DCF77 #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 #endif
#include "if482.h" #include "if482.h"
@ -90,8 +90,9 @@ static const char TAG[] = "main";
#define IF482_FRAME_SIZE (17) #define IF482_FRAME_SIZE (17)
#define IF482_PULSE_DURATION (1000) #define IF482_PULSE_DURATION (1000)
#ifdef RTC_CLK #ifdef RTC_CLK
#define PPS (RTC_CLK / IF482_PULSE_DURATION) #define PPS RTC_CLK
#else #else
#define PPS IF482_PULSE_DURATION #define PPS IF482_PULSE_DURATION
#endif #endif
@ -174,14 +175,20 @@ void if482_loop(void *pvParameters) {
&wakeTime, // receives moment of call from isr &wakeTime, // receives moment of call from isr
portMAX_DELAY); // wait forever (missing error handling here...) 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 // wait until it's time to start transmit telegram for next second
vTaskDelayUntil(&wakeTime, shotTime); // sets waketime to moment of shot vTaskDelayUntil(&wakeTime, shotTime); // sets waketime to moment of shot
IF482.print(IF482_Out(now() + 1)); IF482.print(IF482_Out(now() + 1));
#else // we need clock rescaling by software timer #elif (PPS > IF482_PULSE_DURATION) // we need upclocking
/* for (uint8_t i = 1; i <= PPS / IF482_PULSE_DURATION; i++) {
not yet implemented for IF482 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 #endif
} }
} // if482_loop() } // if482_loop()

View File

@ -102,9 +102,9 @@ float get_rtctemp(void) {
#endif // HAS_RTC #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 // 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 // setup external interupt for active low RTC INT pin
pinMode(RTC_INT, INPUT_PULLUP); pinMode(RTC_INT, INPUT_PULLUP);
@ -123,11 +123,11 @@ int pps_init(uint32_t clk_freq_Hz) {
#else #else
// use clock with adjustable frequency // use clock with adjustable frequency
if (clk_freq_Hz) { if (clk_freq_ms) {
ESP_LOGI(TAG, "Time base ESP32 clock"); 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); timerAttachInterrupt(clockCycle, &CLOCKIRQ, true);
timerAlarmWrite(clockCycle, 100 * clk_freq_Hz, true); timerAlarmWrite(clockCycle, 10 * clk_freq_ms, true); //ms
} else { } else {
ESP_LOGE(TAG, "Invalid pulse clock frequency"); ESP_LOGE(TAG, "Invalid pulse clock frequency");
return 0; // failure return 0; // failure