main/task_ina219.c

changeset 24
74609f70411e
parent 14
2a9f67ecbc72
child 28
5872b972e553
equal deleted inserted replaced
23:2cc30d828d6e 24:74609f70411e
103 * We run the ESP32-C3 in Power Save mode, Dynamic Frequency Scaling. 103 * We run the ESP32-C3 in Power Save mode, Dynamic Frequency Scaling.
104 * This means a wrong current measurement (too high) unless we let the CPU 104 * This means a wrong current measurement (too high) unless we let the CPU
105 * rest for a while. The INA219 runs in continuous mode so we get the 105 * rest for a while. The INA219 runs in continuous mode so we get the
106 * results during the vTaskDelay(). 106 * results during the vTaskDelay().
107 */ 107 */
108 // vTaskDelay(20 / portTICK_PERIOD_MS); 108 vTaskDelay(20 / portTICK_PERIOD_MS);
109 ESP_ERROR_CHECK(ina219_get_bus_voltage(&ina219_b_dev, &bus_voltage)); 109 ESP_ERROR_CHECK(ina219_get_bus_voltage(&ina219_b_dev, &bus_voltage));
110 vTaskDelay(10 / portTICK_PERIOD_MS);
110 ESP_ERROR_CHECK(ina219_get_shunt_voltage(&ina219_b_dev, &shunt_voltage)); 111 ESP_ERROR_CHECK(ina219_get_shunt_voltage(&ina219_b_dev, &shunt_voltage));
111 vTaskDelay(20 / portTICK_PERIOD_MS); 112 vTaskDelay(10 / portTICK_PERIOD_MS);
112 ESP_ERROR_CHECK(ina219_get_current(&ina219_b_dev, &current)); 113 ESP_ERROR_CHECK(ina219_get_current(&ina219_b_dev, &current));
113 ESP_LOGI(TAG, "Battery VBUS: %.04f V, VSHUNT: %.04f mV, IBUS: %.04f mA", bus_voltage, shunt_voltage * 1000, current * 1000); 114 ESP_LOGI(TAG, "Battery VBUS: %.04f V, VSHUNT: %.04f mV, IBUS: %.04f mA", bus_voltage, shunt_voltage * 1000, current * 1000);
114 } 115 }
115 if (xSemaphoreTake(xSemaphoreINA219, 25) == pdTRUE) { 116 if (xSemaphoreTake(xSemaphoreINA219, 25) == pdTRUE) {
116 if (ina219_state->Battery.fake) { 117 if (ina219_state->Battery.fake) {
132 } 133 }
133 134
134 if (! ina219_state->Solar.fake) { 135 if (! ina219_state->Solar.fake) {
135 vTaskDelay(20 / portTICK_PERIOD_MS); 136 vTaskDelay(20 / portTICK_PERIOD_MS);
136 ESP_ERROR_CHECK(ina219_get_bus_voltage(&ina219_s_dev, &bus_voltage)); 137 ESP_ERROR_CHECK(ina219_get_bus_voltage(&ina219_s_dev, &bus_voltage));
138 vTaskDelay(10 / portTICK_PERIOD_MS);
137 ESP_ERROR_CHECK(ina219_get_shunt_voltage(&ina219_s_dev, &shunt_voltage)); 139 ESP_ERROR_CHECK(ina219_get_shunt_voltage(&ina219_s_dev, &shunt_voltage));
138 vTaskDelay(20 / portTICK_PERIOD_MS); 140 vTaskDelay(10 / portTICK_PERIOD_MS);
139 ESP_ERROR_CHECK(ina219_get_current(&ina219_s_dev, &current)); 141 ESP_ERROR_CHECK(ina219_get_current(&ina219_s_dev, &current));
140 ESP_LOGI(TAG, " Solar VBUS: %.04f V, VSHUNT: %.04f mV, IBUS: %.04f mA", bus_voltage, shunt_voltage * 1000, current * 1000); 142 ESP_LOGI(TAG, " Solar VBUS: %.04f V, VSHUNT: %.04f mV, IBUS: %.04f mA", bus_voltage, shunt_voltage * 1000, current * 1000);
141 } 143 }
142 if (xSemaphoreTake(xSemaphoreINA219, 25) == pdTRUE) { 144 if (xSemaphoreTake(xSemaphoreINA219, 25) == pdTRUE) {
143 if (! ina219_state->Solar.fake && ! ina219_state->Battery.fake) { 145 if (! ina219_state->Solar.fake && ! ina219_state->Battery.fake) {

mercurial