ESP32使用INA219的取樣時間比ESP8266還慢?

dykhu1256
Posts: 1
Joined: Fri Jul 23, 2021 12:11 pm

ESP32使用INA219的取樣時間比ESP8266還慢?

Postby dykhu1256 » Sun Jul 25, 2021 4:53 pm

最近在測試ESP32使用INA219電源監控模組,發現取樣時間比ESP8266使用INA219的取樣時間還慢
測試方法參考了這篇Hans Dorn提供的範例:https://www.esp32.com/viewtopic.php?t=1215
想請問ESP32取樣時間比較久的原因
附件為範例程式及測試結果

Code: Select all

#include <Arduino.h>
#include <Wire.h>
#include "DFRobot_INA219.h"

DFRobot_INA219_IIC     ina219(&Wire, 0x40);
float ina219Reading_mA = 1000;
float extMeterReading_mA = 1000;

/***********************取樣*****************************/
int i;
uint32_t t[] = {};
float val[] = {};
uint32_t micro_second[] = {};

void setup(void){
    Serial.begin(115200);
    while(!Serial);
    Serial.println();
    while(ina219.begin() != true) {
        Serial.println(F("INA219 begin faild"));
        delay(2000);
    }
    ina219.linearCalibrate(ina219Reading_mA, extMeterReading_mA);
    Serial.println();
    ina219.setBRNG(eIna219BusVolRange_16V);
    ina219.setPGA(eIna219PGABits_8);
    ina219.setBADC(eIna219AdcBits_9, eIna219AdcSample_1);
    ina219.setSADC(eIna219AdcBits_9, eIna219AdcSample_1);
    ina219.setMode(eIna219SAndBVolCon);
    Wire.setClock(2000000);
}

void loop(void){

  for(i=0; i<500; i++)
  {
    micro_second[i] = micros();
    val[i] =  ina219.getCurrent_mA();
  }

  for(i=1; i<500; i++)
  {
    Serial.print(micro_second[i]); 
    Serial.print("\t"); 
    Serial.println(val[i]);
  }
  delay(500);
}
Attachments
02.JPG
02.JPG (56.84 KiB) Viewed 3650 times
01.JPG
01.JPG (55.74 KiB) Viewed 3650 times
00.JPG
00.JPG (23.79 KiB) Viewed 3650 times

Who is online

Users browsing this forum: No registered users and 12 guests