dcf77.cpp bugfixes and now finalized

This commit is contained in:
Klaus K Wilting 2019-02-04 23:42:17 +01:00
parent 8d01b651bb
commit 82489524d3
3 changed files with 53 additions and 37 deletions

View File

@ -6,7 +6,7 @@
; ---> SELECT TARGET PLATFORM HERE! <---
[platformio]
env_default = generic
;env_default = generic
;env_default = ebox
;env_default = eboxtube
;env_default = heltec
@ -15,7 +15,7 @@ env_default = generic
;env_default = ttgov2
;env_default = ttgov21old
;env_default = ttgov21new
;env_default = ttgobeam
env_default = ttgobeam
;env_default = ttgofox
;env_default = lopy
;env_default = lopy4
@ -33,7 +33,7 @@ description = Paxcounter is a proof-of-concept ESP32 device for metering passeng
release_version = 1.7.152
; DEBUG LEVEL: For production run set to 0, otherwise device will leak RAM while running!
; 0=None, 1=Error, 2=Warn, 3=Info, 4=Debug, 5=Verbose
debug_level = 0
debug_level = 4
; UPLOAD MODE: select esptool to flash via USB/UART, select custom to upload to cloud for OTA
upload_protocol = esptool
;upload_protocol = custom

View File

@ -25,6 +25,8 @@ uint8_t DCFtimeframe[DCF77_FRAME_SIZE];
// initialize and configure DCF77 output
int dcf77_init(void) {
BitsPending = false;
pinMode(HAS_DCF77, OUTPUT);
digitalWrite(HAS_DCF77, HIGH);
@ -42,9 +44,13 @@ int dcf77_init(void) {
ESP_LOGD(TAG, "Starting DCF pulse...");
dcfCycle = timerBegin(1, 8000, true); // set 80 MHz prescaler to 1/10000 sec
timerAttachInterrupt(dcfCycle, &DCF77IRQ, true);
timerAlarmWrite(dcfCycle, 2000, true); // 100ms cycle
timerAlarmWrite(dcfCycle, 1000, true); // 100ms cycle
// wait until beginning of next minute, then start DCF pulse
do {
delay(2);
} while (second());
timerAlarmEnable(dcfCycle);
xTaskNotify(DCF77Task, 0, eNoAction);
return 1; // success
@ -100,6 +106,7 @@ void generateTimeframe(time_t t) {
DCFtimeframe[59] = dcf_off;
// !! missing code here for leap second !!
/*
// for debug: print the DCF77 frame buffer
char out[DCF77_FRAME_SIZE + 1];
uint8_t i;
@ -108,54 +115,60 @@ void generateTimeframe(time_t t) {
}
out[DCF77_FRAME_SIZE] = '\0'; // string termination char
ESP_LOGD(TAG, "DCF Timeframe = %s", out);
*/
}
// called every 100msec by hardware time
// helper function to convert gps date/time into time_t
time_t nextMinute(time_t t) {
tmElements_t tm;
breakTime(t, tm);
tm.Minute++;
tm.Second = 0;
return makeTime(tm);
}
// called every 100msec by hardware timer to pulse out DCF signal
void DCF_Out() {
static uint8_t bit = 0;
static uint8_t pulse = 0;
if (!BitsPending) {
// prepare next frame to send
generateTimeframe(now());
// prepare frame for next minute to send
generateTimeframe(nextMinute(now()));
// start blinking symbol on display and kick off timer
BitsPending = true;
// wait until next minute, then kick off hardware timer and first DCF pulse
do {
delay(2);
} while (second());
}
// ticker out current frame
while (BitsPending) {
// ticker out current DCF frame
if (BitsPending) {
switch (pulse++) {
case 0: // start of second -> start of timeframe for logic signal
if (DCFtimeframe[bit] != dcf_off)
digitalWrite(HAS_DCF77, LOW);
return;
break;
case 1: // 100ms after start of second -> end of timeframe for logic 0
if (DCFtimeframe[bit] == dcf_zero)
digitalWrite(HAS_DCF77, HIGH);
return;
break;
case 2: // 200ms after start of second -> end of timeframe for logic 1
digitalWrite(HAS_DCF77, HIGH);
return;
break;
case 9: // last pulse before next second starts
pulse = 0;
if (bit++ != DCF77_FRAME_SIZE)
return;
else { // end of DCF77 frame (59th second)
if (bit++ == (DCF77_FRAME_SIZE - 1)) // end of DCF77 frame (59th second)
{
bit = 0;
BitsPending = false;
};
break;
}; // switch
}; // while
}; // if
} // DCF_Out()
@ -179,8 +192,8 @@ void dcf77_loop(void *pvParameters) {
DCF_Out();
}
BitsPending = false; // stop blink in display
vTaskDelete(DCF77Task); // shoud never be reached
BitsPending = false; // stop blink in display, should never be reached
vTaskDelete(DCF77Task);
} // dcf77_loop()
#endif // HAS_DCF77

View File

@ -24,16 +24,19 @@
// enable only if device has these sensors, otherwise comment these lines
// BME680 sensor on I2C bus
//#define HAS_BME SDA, SCL
//#define BME_ADDR BME680_I2C_ADDR_PRIMARY // !! connect SDIO of BME680 to GND !!
#define HAS_BME SDA, SCL
#define BME_ADDR BME680_I2C_ADDR_PRIMARY // !! connect SDIO of BME680 to GND !!
// display (if connected)
//#define HAS_DISPLAY U8X8_SSD1306_128X64_NONAME_HW_I2C
//#define MY_OLED_SDA SDA
//#define MY_OLED_SCL SCL
//#define MY_OLED_RST U8X8_PIN_NONE
#define HAS_DISPLAY U8X8_SSD1306_128X64_NONAME_HW_I2C
#define MY_OLED_SDA SDA
#define MY_OLED_SCL SCL
#define MY_OLED_RST U8X8_PIN_NONE
//#define DISPLAY_FLIP 1 // use if display is rotated
// Settings for DCF77 interface
#define HAS_DCF77 GPIO_NUM_13
// user defined sensors (if connected)
//#define HAS_SENSORS 1 // comment out if device has user defined sensors