Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Esp32 I2S-based current sense (adc) driver #400

Draft
wants to merge 14 commits into
base: dev
Choose a base branch
from
2 changes: 2 additions & 0 deletions src/current_sense/InlineCurrentSense.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ void InlineCurrentSense::calibrateOffsets(){
offset_ic = 0;
// read the adc voltage 1000 times ( arbitrary number )
for (int i = 0; i < calibration_rounds; i++) {
_startADC3PinConversionInline();
if(_isset(pinA)) offset_ia += _readADCVoltageInline(pinA, params);
if(_isset(pinB)) offset_ib += _readADCVoltageInline(pinB, params);
if(_isset(pinC)) offset_ic += _readADCVoltageInline(pinC, params);
Expand All @@ -75,6 +76,7 @@ void InlineCurrentSense::calibrateOffsets(){
// read all three phase currents (if possible 2 or 3)
PhaseCurrent_s InlineCurrentSense::getPhaseCurrents(){
PhaseCurrent_s current;
_startADC3PinConversionInline();
current.a = (!_isset(pinA)) ? 0 : (_readADCVoltageInline(pinA, params) - offset_ia)*gain_a;// amps
current.b = (!_isset(pinB)) ? 0 : (_readADCVoltageInline(pinB, params) - offset_ib)*gain_b;// amps
current.c = (!_isset(pinC)) ? 0 : (_readADCVoltageInline(pinC, params) - offset_ic)*gain_c; // amps
Expand Down
2 changes: 2 additions & 0 deletions src/current_sense/hardware_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ float _readADCVoltageInline(const int pinA, const void* cs_params);
*/
void* _configureADCInline(const void *driver_params, const int pinA,const int pinB,const int pinC = NOT_SET);

void _startADC3PinConversionInline();

/**
* function reading an ADC value and returning the read voltage
*
Expand Down
Loading
Loading