STIMA  3
i2c-power-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_POWER_CONFIG_H
22 #define _I2C_POWER_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 (1)
46 
51 #define MODULE_TYPE (STIMA_MODULE_TYPE_POWER)
52 
53 /*********************************************************************
54 * CONFIGURATION
55 *********************************************************************/
56 
61 #define CONFIGURATION_DEFAULT_ONESHOT (false)
62 
67 #define CONFIGURATION_DEFAULT_I2C_ADDRESS (I2C_POWER_DEFAULT_ADDRESS)
68 
73 #define CONFIGURATION_RESET_PIN (8)
74 
75 
80 #define POWER_ADC_CHANNEL_INPUT_PANEL (0)
81 
86 #define POWER_ADC_CHANNEL_INPUT_BATTERY (2)
87 
88 /*
89  ADS1115 Address Selection
90 
91 The ADS111x have one address pin, ADDR, that configures the I2C
92 address of the device. This pin can be connected to GND, VDD, SDA, or
93 SCL, allowing for four different addresses to be selected with one
94 pin, as shown in Table 4. The state of address pin ADDR is sampled
95 continuously. Use the GND, VDD and SCL addresses first. If SDA is used
96 as the device address, hold the SDA line low for at least 100 ns after
97 the SCL line goes low to make sure the device decodes the address
98 correctly during I2C communication.
99 */
100 #define ADC_GND_I2C_ADDRESS (0x48) // GND
101 #define ADC_VDD_I2C_ADDRESS (0x49) // VDD
102 #define ADC_SCL_I2C_ADDRESS (0x4B) // SCL
103 #define ADC_SDA_I2C_ADDRESS (0x4A) // SDA
104 
105 #define ADC_I2C_ADDRESS ADC_VDD_I2C_ADDRESS
106 
107 // max value in mV to be applied before partitor to get max ADC input (2.048 V)
108 #define CONFIGURATION_DEFAULT_ADC_VOLTAGE_MAX_PANEL (29521)
109 #define CONFIGURATION_DEFAULT_ADC_VOLTAGE_MAX_BATTERY (29521)
110 
112 //\def POWER_ANALOG_PIN1
113 //\brief Input pin 1 for reading panel value.
114 //*/
115 //#define POWER_ANALOG_PIN1 (A0)
116 //
118 //\def POWER_ANALOG_PIN2
119 //\brief Input pin 2 for reading battery value.
120 //*/
121 //#define POWER_ANALOG_PIN2 (A1)
122 #define SDCARD_CHIP_SELECT_PIN 7
127 
132 #define SPI_SPEED SD_SCK_MHZ(4)
133 
134 /*********************************************************************
135 * POWER DOWN
136 *********************************************************************/
141 #define USE_POWER_DOWN (true)
142 
147 #define DEBOUNCING_POWER_DOWN_TIME_MS (10)
148 
153 #define USE_TIMER_1 (true)
154 
155 /*********************************************************************
156 * WATCHDOG
157 *********************************************************************/
166 #define WDT_TIMER (WDTO_8S)
167 
168 /*********************************************************************
169 * POWER SENSORS
170 *********************************************************************/
171 // observations with processing every 1-10 seconds (minutes for processing sampling)
172 // report every 5-60 minutes (> OBSERVATIONS_MINUTES)
173 
178 #define SENSORS_SAMPLE_TIME_MS (10000)
179 
180 
185 #define RMAP_REPORT_SAMPLE_ERROR_MAX_PERC (10.)
186 
187 
188 
193 #define RMAP_REPORT_SAMPLE_MIN_TIME (60)
194 
195 
196 /*********************************************************************
197 * SENSORS
198 *********************************************************************/
203 #define USE_SENSORS_COUNT (USE_SENSOR_PWR)
204 
205 #if (USE_SENSORS_COUNT == 0)
206 #error No sensor used. Are you sure? If not, enable it in RmapConfig/sensors_config.h
207 #endif
208 
209 /*********************************************************************
210 * TIMER1
211 *********************************************************************/
216 #define TIMER1_INTERRUPT_TIME_MS (SENSORS_SAMPLE_TIME_MS)
217 
222 #if (F_CPU == 8000000L)
223 #define TIMER1_OVERFLOW_TIME_MS (8388)
224 #elif (F_CPU == 16000000L)
225 #define TIMER1_OVERFLOW_TIME_MS (4194)
226 #endif
227 
232 #define TIMER1_TCNT1_VALUE ((uint16_t)(0xFFFF - (float)(1.0 * 0xFFFF * TIMER1_INTERRUPT_TIME_MS / TIMER1_OVERFLOW_TIME_MS)))
233 
238 #define TIMER_COUNTER_VALUE_MAX_MS (SENSORS_SAMPLE_TIME_MS)
239 #define TIMER_COUNTER_VALUE_MAX_S (60)
240 
241 /*********************************************************************
242 * TASKS
243 *********************************************************************/
244 
249 #define TRANSACTION_TIMEOUT_MS (5000)
250 
251 #endif
#define SDCARD_CHIP_SELECT_PIN
Chip select for SDcard SPI.
Definition: i2c-leaf-config.h:103