Changed voltage range to 32 volt. Tried INA219 powersave mode, doesn't work.

Mon, 03 Apr 2023 20:11:29 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Mon, 03 Apr 2023 20:11:29 +0200
changeset 13
c3b29a1dcf1e
parent 12
bb72d448e282
child 14
2a9f67ecbc72

Changed voltage range to 32 volt. Tried INA219 powersave mode, doesn't work.

main/task_ina219.c file | annotate | diff | comparison | revisions
--- a/main/task_ina219.c	Mon Apr 03 16:07:34 2023 +0200
+++ b/main/task_ina219.c	Mon Apr 03 20:11:29 2023 +0200
@@ -54,7 +54,7 @@
     ina219_state->Battery.error = INA219_ERR_NONE;
     if (ina219_b_dev.i2c_dev.addr) {
 	ESP_LOGI(TAG, "Configuring INA219 Battery");
-	ESP_ERROR_CHECK(ina219_configure(&ina219_b_dev, INA219_BUS_RANGE_16V, INA219_GAIN_0_125,
+	ESP_ERROR_CHECK(ina219_configure(&ina219_b_dev, INA219_BUS_RANGE_32V, INA219_GAIN_0_125,
             INA219_RES_12BIT_1S, INA219_RES_12BIT_1S, INA219_MODE_CONT_SHUNT_BUS));
     	ESP_LOGI(TAG, "Calibrating INA219 Battery");
     	ESP_ERROR_CHECK(ina219_calibrate(&ina219_b_dev, (float)I_MAX_CURRENT, (float)I_SHUNT_RESISTOR_MILLI_OHM / 1000.0f));
@@ -66,7 +66,7 @@
     ina219_state->Solar.error = INA219_ERR_NONE;
     if (ina219_s_dev.i2c_dev.addr) {
         ESP_LOGI(TAG, "Configuring INA219 Solar");
-        ESP_ERROR_CHECK(ina219_configure(&ina219_s_dev, INA219_BUS_RANGE_16V, INA219_GAIN_0_125,
+        ESP_ERROR_CHECK(ina219_configure(&ina219_s_dev, INA219_BUS_RANGE_32V, INA219_GAIN_0_125,
             INA219_RES_12BIT_1S, INA219_RES_12BIT_1S, INA219_MODE_CONT_SHUNT_BUS));
         ESP_LOGI(TAG, "Calibrating INA219 Solar");
         ESP_ERROR_CHECK(ina219_calibrate(&ina219_s_dev, (float)I_MAX_CURRENT, (float)I_SHUNT_RESISTOR_MILLI_OHM / 1000.0f));
@@ -96,10 +96,18 @@
 	     * 4. Fake everything.
 	     */
 	    if (! ina219_state->Battery.fake) {
+		/*
+		 * Note, on Arduino power down and resume works, but not on esp-idf.
+		 * This could save only 0.5 mA per device.
+		 */
+//		ESP_ERROR_CHECK(ina219_configure(&ina219_b_dev, INA219_BUS_RANGE_32V, INA219_GAIN_0_125,
+//			INA219_RES_12BIT_1S, INA219_RES_12BIT_1S, INA219_MODE_CONT_SHUNT_BUS));
 		ESP_ERROR_CHECK(ina219_get_bus_voltage(&ina219_b_dev, &bus_voltage));
 		ESP_ERROR_CHECK(ina219_get_shunt_voltage(&ina219_b_dev, &shunt_voltage));
 		ESP_ERROR_CHECK(ina219_get_current(&ina219_b_dev, &current));
 		ESP_ERROR_CHECK(ina219_get_power(&ina219_b_dev, &power));
+//		ESP_ERROR_CHECK(ina219_configure(&ina219_b_dev, INA219_BUS_RANGE_32V, INA219_GAIN_0_125,
+//                        INA219_RES_12BIT_1S, INA219_RES_12BIT_1S, INA219_MODE_POWER_DOWN));
 		ESP_LOGI(TAG, "Battery VBUS: %.04f V, VSHUNT: %.04f mV, IBUS: %.04f mA, PBUS: %.04f mW",
                 		bus_voltage, shunt_voltage * 1000, current * 1000, power * 1000);
 	    }
@@ -123,10 +131,14 @@
 	    }
 
 	    if (! ina219_state->Solar.fake) {
+//		ESP_ERROR_CHECK(ina219_configure(&ina219_s_dev, INA219_BUS_RANGE_32V, INA219_GAIN_0_125,
+//                        INA219_RES_12BIT_1S, INA219_RES_12BIT_1S, INA219_MODE_CONT_SHUNT_BUS));
                 ESP_ERROR_CHECK(ina219_get_bus_voltage(&ina219_s_dev, &bus_voltage));
                 ESP_ERROR_CHECK(ina219_get_shunt_voltage(&ina219_s_dev, &shunt_voltage));
                 ESP_ERROR_CHECK(ina219_get_current(&ina219_s_dev, &current));
                 ESP_ERROR_CHECK(ina219_get_power(&ina219_s_dev, &power));
+//		ESP_ERROR_CHECK(ina219_configure(&ina219_s_dev, INA219_BUS_RANGE_32V, INA219_GAIN_0_125,
+//                        INA219_RES_12BIT_1S, INA219_RES_12BIT_1S, INA219_MODE_POWER_DOWN));
                 ESP_LOGI(TAG, "  Solar VBUS: %.04f V, VSHUNT: %.04f mV, IBUS: %.04f mA, PBUS: %.04f mW",
                                 bus_voltage, shunt_voltage * 1000, current * 1000, power * 1000);
 	    }

mercurial