From 7c2310acc702b4142858aac524d22ed16d629735 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=85=95=E7=82=8E?= <29385962@qq.com> Date: Fri, 5 Aug 2022 13:54:04 +0000 Subject: [PATCH] =?UTF-8?q?update=20ARDUINO=5FMPPT=5FFIRMWARE=5FV2.1/2=5FR?= =?UTF-8?q?ead=5FSensors.ino.=20=E4=BF=AE=E6=AD=A3powerInput,powerOutput?= =?UTF-8?q?=E7=9A=84=E7=AE=97=E6=B3=95bug=EF=BC=8C=E4=B9=8B=E5=89=8D?= =?UTF-8?q?=E5=BF=BD=E7=95=A5=E4=BA=86=E5=88=86=E5=8E=8B=E7=94=B5=E9=98=BB?= =?UTF-8?q?=E6=AF=94=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ARDUINO_MPPT_FIRMWARE_V2.1/2_Read_Sensors.ino | 53 ++++++++++++++++--- 1 file changed, 46 insertions(+), 7 deletions(-) diff --git a/ARDUINO_MPPT_FIRMWARE_V2.1/2_Read_Sensors.ino b/ARDUINO_MPPT_FIRMWARE_V2.1/2_Read_Sensors.ino index 3ccc6d8..609c18a 100644 --- a/ARDUINO_MPPT_FIRMWARE_V2.1/2_Read_Sensors.ino +++ b/ARDUINO_MPPT_FIRMWARE_V2.1/2_Read_Sensors.ino @@ -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;