17 int impulseCount = 0; ///< 100 mSec transmit slices. |
17 int impulseCount = 0; ///< 100 mSec transmit slices. |
18 int8_t impulseArray[61]; ///< Pulses, 0 = no pulse, 1=100ms, 2=200ms |
18 int8_t impulseArray[61]; ///< Pulses, 0 = no pulse, 1=100ms, 2=200ms |
19 int actualSecond = 0; ///< Current second to transmit. |
19 int actualSecond = 0; ///< Current second to transmit. |
20 time_t dcf_now; ///< Current time to send. |
20 time_t dcf_now; ///< Current time to send. |
21 struct tm dcf_tm; ///< Local broken down time. |
21 struct tm dcf_tm; ///< Local broken down time. |
22 /// |
22 |
|
23 |
|
24 ledc_timer_config_t ledc_timer = { |
|
25 .speed_mode = LEDC_LOW_SPEED_MODE, ///< Use high speed timer |
|
26 .timer_num = LEDC_TIMER_0, ///< Timer 0 |
|
27 .duty_resolution = LEDC_TIMER_10_BIT, ///< 10 bits resolution |
|
28 .freq_hz = 77500, ///< 77.5 KHz |
|
29 .clk_cfg = LEDC_AUTO_CLK ///< Auto select PWM clock |
|
30 }; |
|
31 |
|
32 ledc_channel_config_t dcf77_100tx = { ///< 100% Antenna power |
|
33 .channel = LEDC_CHANNEL_0, |
|
34 .duty = 0, ///< Default 0% |
|
35 .gpio_num = CONFIG_ANTENNA_100_PIN, ///< Antenna pin 100% |
|
36 .speed_mode = LEDC_LOW_SPEED_MODE, |
|
37 .hpoint = 0, |
|
38 .intr_type = LEDC_INTR_DISABLE, |
|
39 .timer_sel = LEDC_TIMER_0 ///< Timer 0 |
|
40 }; |
|
41 ledc_channel_config_t dcf77_15tx = { ///< 15% Antenna power |
|
42 .channel = LEDC_CHANNEL_1, |
|
43 .duty = 0, |
|
44 .gpio_num = CONFIG_ANTENNA_15_PIN, ///< Antenna pin 15% |
|
45 .speed_mode = LEDC_LOW_SPEED_MODE, |
|
46 .hpoint = 0, |
|
47 .intr_type = LEDC_INTR_DISABLE, |
|
48 .timer_sel = LEDC_TIMER_0 ///< Timer 0 |
|
49 }; |
|
50 |
|
51 |
23 extern bool System_TimeOk; |
52 extern bool System_TimeOk; |
24 |
53 |
25 |
54 |
26 #define LED1 CONFIG_LED1_PIN |
55 #define LED1 CONFIG_LED1_PIN |
27 #define LED2 CONFIG_LED2_PIN |
56 #define LED2 CONFIG_LED2_PIN |
72 switch (impulseCount++) { |
101 switch (impulseCount++) { |
73 case 0: if (actualSecond == 0) { |
102 case 0: if (actualSecond == 0) { |
74 time(&dcf_now); |
103 time(&dcf_now); |
75 dcf_now += 60; |
104 dcf_now += 60; |
76 } |
105 } |
|
106 /* Carrier to 15% */ |
|
107 ledc_set_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_0, 0); |
|
108 ledc_update_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_0); |
|
109 ledc_set_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_1, 512); |
|
110 ledc_update_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_1); |
77 if (impulseArray[actualSecond] == 1) { |
111 if (impulseArray[actualSecond] == 1) { |
78 gpio_set_level(CONFIG_LED1_PIN, 1); |
112 gpio_set_level(CONFIG_LED1_PIN, 1); |
79 } else if (impulseArray[actualSecond] == 2) { |
113 } else if (impulseArray[actualSecond] == 2) { |
80 gpio_set_level(CONFIG_LED2_PIN, 1); |
114 gpio_set_level(CONFIG_LED2_PIN, 1); |
81 } |
115 } |
82 break; |
116 break; |
83 case 1: if (impulseArray[actualSecond] == 1) { |
117 case 1: if (impulseArray[actualSecond] == 1) { |
|
118 /* Carrier back to 100% */ |
|
119 ledc_set_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_0, 512); |
|
120 ledc_update_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_0); |
|
121 ledc_set_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_1, 0); |
|
122 ledc_update_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_1); |
84 gpio_set_level(CONFIG_LED1_PIN, 0); |
123 gpio_set_level(CONFIG_LED1_PIN, 0); |
85 } |
124 } |
86 break; |
125 break; |
87 case 2: gpio_set_level(CONFIG_LED1_PIN, 0); |
126 case 2: /* Carrier back to 100% */ |
|
127 ledc_set_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_0, 512); |
|
128 ledc_update_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_0); |
|
129 ledc_set_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_1, 0); |
|
130 ledc_update_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_1); |
|
131 gpio_set_level(CONFIG_LED1_PIN, 0); |
88 gpio_set_level(CONFIG_LED2_PIN, 0); |
132 gpio_set_level(CONFIG_LED2_PIN, 0); |
89 break; |
133 break; |
90 case 9: impulseCount = 0; |
134 case 9: impulseCount = 0; |
91 /* |
135 /* |
92 * To spread the CPU load, we set all bits during the first seconds |
136 * To spread the CPU load, we set all bits during the first seconds |
93 * because we don't use these bits. |
137 * because we don't use these bits. |
94 */ |
138 */ |
95 switch (actualSecond) { |
139 switch (actualSecond) { |
96 case 0: /* the first 20 bits of each minute at a logical zero value */ |
140 case 0: /* |
97 for (i = 0; i < 20; i++) |
141 * Bit 0 is always 0. |
|
142 * Bits 1..14 are used to transmit weather information. |
|
143 * Just some fixed values here. |
|
144 * Bit 15, Antenna bit. 0 = normal operation, 1 = fault |
|
145 */ |
|
146 for (i = 0; i < 16; i++) |
98 impulseArray[i] = 1; |
147 impulseArray[i] = 1; |
99 for (i = 1; i < 9; i++) |
|
100 impulseArray[i] = 2; /* Civil warning bits 1..14 */ |
|
101 /* Bit 15, Antenna bit. 0 = normal operation, 1 = fault */ |
|
102 break; |
148 break; |
103 case 1: localtime_r(&dcf_now, &dcf_tm); |
149 case 1: localtime_r(&dcf_now, &dcf_tm); |
104 char strftime_buf[64]; |
150 char strftime_buf[64]; |
105 strftime(strftime_buf, sizeof(strftime_buf), "%c", &dcf_tm); |
151 strftime(strftime_buf, sizeof(strftime_buf), "%c", &dcf_tm); |
106 ESP_LOGI(TAG, "The current date/time to send is: %s", strftime_buf); |
152 ESP_LOGI(TAG, "The current date/time to send is: %s", strftime_buf); |
240 |
286 |
241 esp_timer_create_args_t timerDCF = { |
287 esp_timer_create_args_t timerDCF = { |
242 .callback = &DCFout, |
288 .callback = &DCFout, |
243 .name = "DCF timer" |
289 .name = "DCF timer" |
244 }; |
290 }; |
245 esp_timer_create(&timerDCF, &timerHandle); |
291 ESP_ERROR_CHECK(esp_timer_create(&timerDCF, &timerHandle)); |
|
292 |
|
293 /* |
|
294 * Prepare the LEDC PWM channels |
|
295 */ |
|
296 ESP_ERROR_CHECK(ledc_timer_config(&ledc_timer)); |
|
297 ESP_ERROR_CHECK(ledc_channel_config(&dcf77_100tx)); |
|
298 ESP_ERROR_CHECK(ledc_channel_config(&dcf77_15tx)); |
|
299 ESP_LOGI(TAG, "DCF77 antennas at pins %d and %d", CONFIG_ANTENNA_100_PIN, CONFIG_ANTENNA_15_PIN); |
|
300 ledc_set_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_0, 0); |
|
301 ledc_update_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_0); |
|
302 ledc_set_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_1, 0); |
|
303 ledc_update_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_1); |
246 |
304 |
247 for (int i = 0; i < 59; i++) |
305 for (int i = 0; i < 59; i++) |
248 impulseArray[i] = 1; |
306 impulseArray[i] = 1; |
249 impulseArray[59] = impulseArray[60] = 0; |
307 impulseArray[59] = impulseArray[60] = 0; |
250 |
308 |