Power profiler with INA219 and ESP32-S2 TFT Feather

Please tell us which board you are using.
For CircuitPython issues, ask in the Adafruit CircuitPython forum.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
User avatar
AyubowanPro
 
Posts: 12
Joined: Wed Jul 27, 2022 6:18 am

Re: Power profiler with INA219 and ESP32-S2 TFT Feather

Post by AyubowanPro »

Hello, I did all of that and the timing is the same. I don't know what to do

User avatar
mikeysklar
 
Posts: 14181
Joined: Mon Aug 01, 2016 8:10 pm

Re: Power profiler with INA219 and ESP32-S2 TFT Feather

Post by mikeysklar »

The last thing to confirm is that voltage and current reading are also taking 2.5ms you are seeing when calling:

Code: Select all

  power_mW = ina219.getPower_mW();
You may have come across an issue with the library adding mutli-milisecond delays. You seem to have a short repeatable test case that works for you. Submit it with the ADC SADCRES and BADCRES CONFIG values for 9-bit (0x0000) as that should offer very fast times.

https://github.com/adafruit/Adafruit_INA219/issues

User avatar
AyubowanPro
 
Posts: 12
Joined: Wed Jul 27, 2022 6:18 am

Re: Power profiler with INA219 and ESP32-S2 TFT Feather

Post by AyubowanPro »

Hello,

I tried with only shunt voltage and current with ADC SADCRES and BADCRES CONFIG values of 9 bit. I'm using Wire.setClock(2560000) and ina219.setCalibration_16V_400mA(). Both shunt and current are taking 1.5ms

I am using this code:

Code: Select all

#include <Wire.h>
#include <Adafruit_INA219.h>

Adafruit_INA219 ina219;

#define INA219_CONFIG_BADCRES_MASK (0x0000)
#define INA219_CONFIG_SADCRES_MASK (0x0000)

float current_mA = 0;

void setup(void) 
{ 
  Serial.begin(115200);
  Wire.setClock(2560000);

  uint32_t currentFrequency;
  
  if (! ina219.begin()) {
    Serial.println("Failed to find INA219 chip");
    while (1) { delay(10); }
  }
  ina219.setCalibration_16V_400mA();

  Serial.println("Measuring voltage and current with INA219 ...");
}

void loop(void) 
{
  Serial.println(micros());
  current_mA = ina219.getCurrent_mA();
  Serial.println(micros());
  Serial.println();
}

User avatar
mikeysklar
 
Posts: 14181
Joined: Mon Aug 01, 2016 8:10 pm

Re: Power profiler with INA219 and ESP32-S2 TFT Feather

Post by mikeysklar »

Thank you for confirming that the voltage and current are taking 1.5ms when they should be running closer to 84uS for samples. This is probably a usage issue around printing out the data through serial or something else causing the slow down. If that is the case then saving samples and printing them after the total sample duration will be helpful. Something you should consider trying.

In the meantime lets have you open an issue with github and see if there is any performance enhancement or known issue with response time on the INA219.

https://github.com/adafruit/Adafruit_INA219/issues

User avatar
AyubowanPro
 
Posts: 12
Joined: Wed Jul 27, 2022 6:18 am

Re: Power profiler with INA219 and ESP32-S2 TFT Feather

Post by AyubowanPro »

Thank you for your reply. I think you're right, the issue might come from printing through serial. I'm going to test it out without printing.

User avatar
AyubowanPro
 
Posts: 12
Joined: Wed Jul 27, 2022 6:18 am

Re: Power profiler with INA219 and ESP32-S2 TFT Feather

Post by AyubowanPro »

So, I tried with this code:

Code: Select all

#include <Wire.h>
#include <Adafruit_INA219.h>

Adafruit_INA219 ina219;

#define INA219_CONFIG_BADCRES_MASK (0x0000)
#define INA219_CONFIG_SADCRES_MASK (0x0000)

float current_mA = 0;

bool hasRun = 0;
float diff = 0;

typedef struct
  {
      float time_uS;
      float ADCValue;
  }  data_type;

data_type data[2]={};

void setup(void) 
{ 
  Serial.begin(115200);
  Wire.setClock(2560000);

  uint32_t currentFrequency;
  
  if (! ina219.begin()) {
    Serial.println("Failed to find INA219 chip");
    while (1) { delay(10); }
  }

  ina219.setCalibration_16V_400mA();

  Serial.println("Measuring voltage and current with INA219 ...");
}

void loop(void) 
{
  delay(3000);
  
  if(hasRun == 0){
    for(int i=0;i<=1;i++){
      data[i].time_uS = micros();
      data[i].ADCValue = ina219.getCurrent_mA();
    }
    diff = data[1].time_uS - data[0].time_uS;
    Serial.print("delay: "); Serial.println(diff);
    hasRun = 1;
  }
}
I also modified the header file with 0x0 values. There is always 2ms delay between two adc readings.

User avatar
mikeysklar
 
Posts: 14181
Joined: Mon Aug 01, 2016 8:10 pm

Re: Power profiler with INA219 and ESP32-S2 TFT Feather

Post by mikeysklar »

It looks like you are on the right track, but your code is still only picking up a single sample and printing the delay. I would think for this to be effective you would have to batch up many samples 10 - 100 and print out a summary.

Locked
Please be positive and constructive with your questions and comments.

Return to “Feather - Adafruit's lightweight platform”