update ARDUINO_MPPT_FIRMWARE_V2.1/2_Read_Sensors.ino.

修正powerInput,powerOutput的算法bug,之前忽略了分压电阻比例
pull/1/head
慕炎 2022-08-05 13:54:04 +00:00 committed by Gitee
parent 25e5a0a58e
commit 7c2310acc7
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
1 changed files with 46 additions and 7 deletions

View File

@ -94,6 +94,31 @@ void resetVariables() {
daysRunning = 0;
timeOn = 0;
}
/*
* @description: NTC GND----|NTC |----|10k|VCC
* @param {*}
* @return
*/
/*
double GetNTCTemp(void) {
static uint32_t CoolTimer = 0;
if (millis() - CoolTimer > 1000){
if (sampleStoreTS <= avgCountTS) { //TEMPERATURE SENSOR - Lite Averaging
TS = TS + analogRead(TempSensor);
sampleStoreTS++;
} else {
double Ert = analogReadMilliVolts(TempSensor) / 1000.0;
double Rt = (Ert * ntcResistance) / (3.3 - Ert);
NTC_Temp = 1 / ((log(Rt / ntcResistance)) / (3950)+1 / (25 + 273.15)) - 273.15;
//重置冷却计时器
CoolTimer = millis();
}
}
return NTC_Temp;
}
*/
void Read_Sensors() {
/////////// TEMPERATURE SENSOR /////////////
@ -107,7 +132,21 @@ void Read_Sensors() {
sampleStoreTS = 0;
TS = 0;
}
/*
3.3= ADC/(Rb/(Ra+Rb))
ADC=(Rb/(Ra+Rb))*3.3
Rb/(Ra+Rb)=ADC/3.3
ADC*(Ra+Rb)/3.3=Rb
ADC*(Ra+Rb)=Rb*3.3
ADC*Ra+ADC*Rb=Rb*3.3
Ra=(Rb*3.3-ADC*Rb)/ADC
Ra=Rb*(3.3-ADC)/ADC
Rb*3.3-ADC*Rb=ADC*Ra
Rb*(3.3-ADC)=ADC*Ra
Rb=ADC*Ra/(3.3-ADC)
*/
/////////// VOLTAGE & CURRENT SENSORS /////////////
VSI = 0.0000; //Clear Previous Input Voltage
VSO = 0.0000; //Clear Previous Output Voltage
@ -135,13 +174,12 @@ void Read_Sensors() {
/*
for (int i = 0; i < avgCountCS; i++) {
CSI = CSI + ads.computeVolts(ads.readADC_SingleEnded(2));
CSI = CSI + ina1.readShuntCurrent();
CSO = CSO + ina2.readShuntCurrent();
}
CSI_converted = (CSI/avgCountCS)*1.3300;
currentInput = ((CSI_converted-currentMidPoint)*-1)/currentSensV;
CSI_converted = (CSI/avgCountCS);
CSO_converted = (CSO/avgCountCS);
*/
/*
= /(R*R3/R4)
*/
CSI_converted = ina1.readShuntCurrent();
CSO_converted = ina2.readShuntCurrent();
@ -177,10 +215,11 @@ void Read_Sensors() {
//POWER COMPUTATION - Through computation
//powerInput = voltageInput*currentInput;
powerInput = ina1.readBusPower();
powerInput = ina1.readBusPower() * inVoltageDivRatio;
//powerOutput = voltageInput*currentInput*efficiencyRate;
powerOutput = ina2.readBusPower();
powerOutput = ina2.readBusPower() * outVoltageDivRatio;
outputDeviation = (voltageOutput / voltageBatteryMax) * 100.000;
buckEfficiency = powerOutput/powerInput * 100.000;
//STATE OF CHARGE - Battery Percentage
batteryPercent = ((voltageOutput - voltageBatteryMin) / (voltageBatteryMax - voltageBatteryMin)) * 101;