# HG changeset patch # User Michiel Broek # Date 1697898140 -7200 # Node ID 426defedd40264d91325f3a42facbf0d15781b79 # Parent 849ca14d4a2fed6fe11051c1bc6c414ace70abdf Added 77.5 KHz signal generation diff -r 849ca14d4a2f -r 426defedd402 main/Kconfig.projbuild --- a/main/Kconfig.projbuild Sat Oct 21 11:44:46 2023 +0200 +++ b/main/Kconfig.projbuild Sat Oct 21 16:22:20 2023 +0200 @@ -18,13 +18,21 @@ endmenu - config ANTENNA_PIN - int "Pin to drive the DCF77 antenna" + config ANTENNA_100_PIN + int "Pin to drive the DCF77 antenna at 100% power" range ENV_GPIO_RANGE_MIN ENV_GPIO_OUT_RANGE_MAX - default 10 if IDF_TARGET_ESP32C3 - default 22 + default 4 if IDF_TARGET_ESP32C3 + default 4 help - GPIO number (IOxx) to connect to the DCF77 antenna. + GPIO number (IOxx) to connect to the DCF77 antenna for 100% power. + + config ANTENNA_15_PIN + int "Pin to drive the DCF77 antenna at 15% power" + range ENV_GPIO_RANGE_MIN ENV_GPIO_OUT_RANGE_MAX + default 5 if IDF_TARGET_ESP32C3 + default 5 + help + GPIO number (IOxx) to connect to the DCF77 antenna for 15% power. config LED1_PIN int "LED 1 port pin" diff -r 849ca14d4a2f -r 426defedd402 main/dcf77tx.h --- a/main/dcf77tx.h Sat Oct 21 11:44:46 2023 +0200 +++ b/main/dcf77tx.h Sat Oct 21 16:22:20 2023 +0200 @@ -21,6 +21,7 @@ #include "freertos/event_groups.h" #include "freertos/queue.h" #include "driver/gpio.h" +#include "driver/ledc.h" //#include "driver/rtc_io.h" //#include "soc/rtc.h" #include "esp_log.h" diff -r 849ca14d4a2f -r 426defedd402 main/task_dcf.c --- a/main/task_dcf.c Sat Oct 21 11:44:46 2023 +0200 +++ b/main/task_dcf.c Sat Oct 21 16:22:20 2023 +0200 @@ -19,7 +19,36 @@ int actualSecond = 0; ///< Current second to transmit. time_t dcf_now; ///< Current time to send. struct tm dcf_tm; ///< Local broken down time. - /// + + +ledc_timer_config_t ledc_timer = { + .speed_mode = LEDC_LOW_SPEED_MODE, ///< Use high speed timer + .timer_num = LEDC_TIMER_0, ///< Timer 0 + .duty_resolution = LEDC_TIMER_10_BIT, ///< 10 bits resolution + .freq_hz = 77500, ///< 77.5 KHz + .clk_cfg = LEDC_AUTO_CLK ///< Auto select PWM clock +}; + +ledc_channel_config_t dcf77_100tx = { ///< 100% Antenna power + .channel = LEDC_CHANNEL_0, + .duty = 0, ///< Default 0% + .gpio_num = CONFIG_ANTENNA_100_PIN, ///< Antenna pin 100% + .speed_mode = LEDC_LOW_SPEED_MODE, + .hpoint = 0, + .intr_type = LEDC_INTR_DISABLE, + .timer_sel = LEDC_TIMER_0 ///< Timer 0 + }; +ledc_channel_config_t dcf77_15tx = { ///< 15% Antenna power + .channel = LEDC_CHANNEL_1, + .duty = 0, + .gpio_num = CONFIG_ANTENNA_15_PIN, ///< Antenna pin 15% + .speed_mode = LEDC_LOW_SPEED_MODE, + .hpoint = 0, + .intr_type = LEDC_INTR_DISABLE, + .timer_sel = LEDC_TIMER_0 ///< Timer 0 + }; + + extern bool System_TimeOk; @@ -74,6 +103,11 @@ time(&dcf_now); dcf_now += 60; } + /* Carrier to 15% */ + ledc_set_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_0, 0); + ledc_update_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_0); + ledc_set_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_1, 512); + ledc_update_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_1); if (impulseArray[actualSecond] == 1) { gpio_set_level(CONFIG_LED1_PIN, 1); } else if (impulseArray[actualSecond] == 2) { @@ -81,10 +115,20 @@ } break; case 1: if (impulseArray[actualSecond] == 1) { + /* Carrier back to 100% */ + ledc_set_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_0, 512); + ledc_update_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_0); + ledc_set_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_1, 0); + ledc_update_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_1); gpio_set_level(CONFIG_LED1_PIN, 0); } break; - case 2: gpio_set_level(CONFIG_LED1_PIN, 0); + case 2: /* Carrier back to 100% */ + ledc_set_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_0, 512); + ledc_update_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_0); + ledc_set_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_1, 0); + ledc_update_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_1); + gpio_set_level(CONFIG_LED1_PIN, 0); gpio_set_level(CONFIG_LED2_PIN, 0); break; case 9: impulseCount = 0; @@ -93,12 +137,14 @@ * because we don't use these bits. */ switch (actualSecond) { - case 0: /* the first 20 bits of each minute at a logical zero value */ - for (i = 0; i < 20; i++) + case 0: /* + * Bit 0 is always 0. + * Bits 1..14 are used to transmit weather information. + * Just some fixed values here. + * Bit 15, Antenna bit. 0 = normal operation, 1 = fault + */ + for (i = 0; i < 16; i++) impulseArray[i] = 1; - for (i = 1; i < 9; i++) - impulseArray[i] = 2; /* Civil warning bits 1..14 */ - /* Bit 15, Antenna bit. 0 = normal operation, 1 = fault */ break; case 1: localtime_r(&dcf_now, &dcf_tm); char strftime_buf[64]; @@ -242,7 +288,19 @@ .callback = &DCFout, .name = "DCF timer" }; - esp_timer_create(&timerDCF, &timerHandle); + ESP_ERROR_CHECK(esp_timer_create(&timerDCF, &timerHandle)); + + /* + * Prepare the LEDC PWM channels + */ + ESP_ERROR_CHECK(ledc_timer_config(&ledc_timer)); + ESP_ERROR_CHECK(ledc_channel_config(&dcf77_100tx)); + ESP_ERROR_CHECK(ledc_channel_config(&dcf77_15tx)); + ESP_LOGI(TAG, "DCF77 antennas at pins %d and %d", CONFIG_ANTENNA_100_PIN, CONFIG_ANTENNA_15_PIN); + ledc_set_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_0, 0); + ledc_update_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_0); + ledc_set_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_1, 0); + ledc_update_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_1); for (int i = 0; i < 59; i++) impulseArray[i] = 1; diff -r 849ca14d4a2f -r 426defedd402 sdkconfig --- a/sdkconfig Sat Oct 21 11:44:46 2023 +0200 +++ b/sdkconfig Sat Oct 21 16:22:20 2023 +0200 @@ -397,7 +397,8 @@ CONFIG_ESP_WIFI_PASSWORD="abcjkltuv" # end of WiFi settings -CONFIG_ANTENNA_PIN=10 +CONFIG_ANTENNA_100_PIN=4 +CONFIG_ANTENNA_15_PIN=5 CONFIG_LED1_PIN=1 CONFIG_LED2_PIN=0 # end of DCF77tx configuration