STIMA  3
i2c-radiation-config.h
1 /*********************************************************************
2 Copyright (C) 2022 Marco Baldinetti <m.baldinetti@digiteco.it>
3 authors:
4 Paolo patruno <p.patruno@iperbole.bologna.it>
5 Marco Baldinetti <m.baldinetti@digiteco.it>
6 
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License as
9 published by the Free Software Foundation; either version 2 of
10 the License, or (at your option) any later version.
11 
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
19 **********************************************************************/
20 
21 #ifndef _I2C_SOLAR_RADIATION_CONFIG_H
22 #define _I2C_SOLAR_RADIATION_CONFIG_H
23 
24 #include <sensors_config.h>
25 
26 /*********************************************************************
27 * MODULE
28 *********************************************************************/
33 #define MODULE_MAIN_VERSION (3)
34 
39 #define MODULE_MINOR_VERSION (18)
40 
45 #define MODULE_CONFIGURATION_VERSION (2)
46 
51 #define MODULE_TYPE (STIMA_MODULE_TYPE_SOLAR_RADIATION)
52 
53 /*********************************************************************
54 * CONFIGURATION
55 *********************************************************************/
56 
61 #define CONFIGURATION_DEFAULT_ONESHOT (false)
62 
67 #define CONFIGURATION_DEFAULT_I2C_ADDRESS (I2C_SOLAR_RADIATION_DEFAULT_ADDRESS)
68 
73 #define CONFIGURATION_RESET_PIN (8)
74 
75 /*
76  ADS1115 Address Selection
77 
78 The ADS111x have one address pin, ADDR, that configures the I2C
79 address of the device. This pin can be connected to GND, VDD, SDA, or
80 SCL, allowing for four different addresses to be selected with one
81 pin, as shown in Table 4. The state of address pin ADDR is sampled
82 continuously. Use the GND, VDD and SCL addresses first. If SDA is used
83 as the device address, hold the SDA line low for at least 100 ns after
84 the SCL line goes low to make sure the device decodes the address
85 correctly during I2C communication.
86 */
87 #define ADC_GND_I2C_ADDRESS (0x48) // GND
88 #define ADC_VDD_I2C_ADDRESS (0x49) // VDD
89 #define ADC_SCL_I2C_ADDRESS (0x4B) // SCL
90 #define ADC_SDA_I2C_ADDRESS (0x4A) // SDA
91 
92 #define ADC_I2C_ADDRESS ADC_GND_I2C_ADDRESS
93 
94 #define CONFIGURATION_DEFAULT_ADC_VOLTAGE_OFFSET_1 (0.0)
95 #define CONFIGURATION_DEFAULT_ADC_VOLTAGE_OFFSET_2 (0.0)
96 #define CONFIGURATION_DEFAULT_ADC_VOLTAGE_GAIN_1 (1.0)
97 #define CONFIGURATION_DEFAULT_ADC_VOLTAGE_GAIN_2 (1.0)
98 #define CONFIGURATION_DEFAULT_ADC_VOLTAGE_MIN (SOLAR_RADIATION_SENSOR_VOLTAGE_MIN)
99 #define CONFIGURATION_DEFAULT_ADC_VOLTAGE_MAX (SOLAR_RADIATION_SENSOR_VOLTAGE_MAX)
100 
101 
102 #define CONFIGURATION_DEFAULT_ADC_VOLTAGE_OFFSET (0)
103 #define CONFIGURATION_DEFAULT_ADC_VOLTAGE_GAIN (1.0)
104 #define CONFIGURATION_DEFAULT_SENSOR_VOLTAGE_MAX (SOLAR_RADIATION_SENSOR_VOLTAGE_MAX)
105 #define CONFIGURATION_DEFAULT_SENSOR_RADIATION_MAX (SOLAR_RADIATION_SENSOR_RADIATION_MAX)
106 
107 
108 #define ACQUISITION_COUNT_FOR_POWER_RESET (100)
109 
110 #if (USE_SENSOR_DSR)
115 #define SOLAR_RADIATION_POWER_PIN (5)
116 
121 #define SOLAR_RADIATION_ANALOG_PIN (A0)
122 
123 #define ADC_VOLTAGE_MAX (5000.0)
124 #define ADC_VOLTAGE_MIN (0.0)
125 #define ADC_VOLTAGE_OFFSET (-20.0)
126 
127 #define ADC_MAX (1023.0)
128 #define ADC_MIN (0.0)
129 
130 #define SOLAR_RADIATION_VOLTAGE_MAX (5000.0)
131 #define SOLAR_RADIATION_VOLTAGE_MIN (1000.0)
132 
133 #define SOLAR_RADIATION_ERROR_VOLTAGE_MAX (SOLAR_RADIATION_VOLTAGE_MAX + 50.0)
134 #define SOLAR_RADIATION_ERROR_VOLTAGE_MIN (SOLAR_RADIATION_VOLTAGE_MIN - 50.0)
135 
136 #define SOLAR_RADIATION_MAX (1600.0)
137 #define SOLAR_RADIATION_MIN (0.0)
138 
139 #define SOLAR_RADIATION_ERROR_MAX (1600.0)
140 #define SOLAR_RADIATION_ERROR_MIN (8.0)
141 
142 #endif
143 
144 #if (USE_SENSOR_VSR)
149 #define SOLAR_RADIATION_POWER_PIN (5)
150 
151 #define ADC_VOLTAGE_OFFSET (0.0)
152 
153 /*
154 Single-ended signal measurements, where VAINN = 0 V and VAINP = 0 V to +FS, only use
155 the positive code range from 0000h to 7FFFh. However, because of device offset, the
156 ADS111x can still output negative codes in case VAINP is close to 0 V
157 */
158 #define ADC_MIN (-32768)
159 #define ADC_MAX (32767)
160 
161 #define SOLAR_RADIATION_SENSOR_VOLTAGE_MIN (0.0)
162 #define SOLAR_RADIATION_SENSOR_VOLTAGE_MAX (5000.0)
163 
164 #define SOLAR_RADIATION_SENSOR_RADIATION_MIN (0.0)
165 #define SOLAR_RADIATION_SENSOR_RADIATION_MAX (2000.0)
166 
167 #define SOLAR_RADIATION_ERROR_VOLTAGE_MIN ((SOLAR_RADIATION_SENSOR_VOLTAGE_MAX/100.))
168 #define SOLAR_RADIATION_ERROR_VOLTAGE_MAX ((SOLAR_RADIATION_SENSOR_VOLTAGE_MAX/100.))
169 
170 #define SOLAR_RADIATION_ADC_CHANNEL_INPUT (1)
171 
172 #endif
173 #define SDCARD_CHIP_SELECT_PIN 7
178 
183 #define SPI_SPEED SD_SCK_MHZ(4)
184 
185 /*********************************************************************
186 * POWER DOWN
187 *********************************************************************/
192 #define USE_POWER_DOWN (true)
193 
198 #define DEBOUNCING_POWER_DOWN_TIME_MS (10)
199 
204 #define USE_TIMER_1 (true)
205 
206 /*********************************************************************
207 * WATCHDOG
208 *********************************************************************/
217 #define WDT_TIMER (WDTO_8S)
218 
219 /*********************************************************************
220 * RADIATION SENSORS
221 *********************************************************************/
222 // observations with processing every 1-10 minutes (minutes for processing sampling)
223 // report every 5-60 minutes (> OBSERVATIONS_MINUTES)
224 
229 #define SENSORS_SAMPLE_TIME_MS (4000)
230 
231 
236 #define RMAP_REPORT_SAMPLE_ERROR_MAX_PERC (10.)
237 
238 
239 
244 #define RMAP_REPORT_SAMPLE_MIN_TIME (60)
245 
246 
247 /*********************************************************************
248 * SENSORS
249 *********************************************************************/
254 #define USE_SENSORS_COUNT (USE_SENSOR_DSR + USE_SENSOR_VSR)
255 
256 #if (USE_SENSORS_COUNT == 0)
257 #error No sensor used. Are you sure? If not, enable it in RmapConfig/sensors_config.h
258 #endif
259 
260 /*********************************************************************
261 * TIMER1
262 *********************************************************************/
267 #define TIMER1_INTERRUPT_TIME_MS (SENSORS_SAMPLE_TIME_MS)
268 
273 #if (F_CPU == 8000000L)
274 #define TIMER1_OVERFLOW_TIME_MS (8388)
275 #elif (F_CPU == 16000000L)
276 #define TIMER1_OVERFLOW_TIME_MS (4194)
277 #endif
278 
283 #define TIMER1_TCNT1_VALUE ((uint16_t)(0xFFFF - (float)(1.0 * 0xFFFF * TIMER1_INTERRUPT_TIME_MS / TIMER1_OVERFLOW_TIME_MS)))
284 
289 #define TIMER_COUNTER_VALUE_MAX_MS (SENSORS_SAMPLE_TIME_MS)
290 #define TIMER_COUNTER_VALUE_MAX_S (60)
291 
292 /*********************************************************************
293 * TASKS
294 *********************************************************************/
299 #define SOLAR_RADIATION_READ_DELAY_MS (500)
300 
305 #define SOLAR_RADIATION_VALUES_READ_DELAY_MS (10)
306 
311 #define SOLAR_RADIATION_READ_COUNT (20)
312 
317 #define TRANSACTION_TIMEOUT_MS (5000)
318 
319 #endif
#define SDCARD_CHIP_SELECT_PIN
Chip select for SDcard SPI.
Definition: i2c-leaf-config.h:103