-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path01_readSensors.ino
95 lines (80 loc) · 2.83 KB
/
01_readSensors.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
void readSensors()
{
//sensors measurement
float VinTemp = 0, VoutTemp = 0, IoutTemp = 0, IinTemp = 0;
float IinZero = 2850; //must be calibrated --> raw value with current = 0A
int i = 0;
for (i = 0; i < Smooth; i++) VinTemp += analogRead(VIN_PIN);
for (i = 0; i < Smooth; i++) VoutTemp += analogRead(VOUT_PIN);
// analogSetAttenuation(ADC_0db); //Sets the input attenuation for ALL ADC inputs, default is ADC_11db, range is ADC_0db=0, ADC_2_5db=1, ADC_6db=2, ADC_11db=3
for (i = 0; i < Smooth; i++) IinTemp += analogRead(I_IN_PIN);
// Serial.print("VinMPPT ");
// Serial.print(VinMPPT);
// TelnetStream.print("vMPPT ");
// TelnetStream.print(VinMPPT);
VinTemp = VinTemp / Smooth ;
Serial.print(", Vin ");
TelnetStream.print(", Vin ");
Serial.print(VinTemp);
TelnetStream.print(VinTemp);
Serial.print(" / ");
TelnetStream.print(" / ");
Vin = volts(VinTemp);
Serial.print(Vin);
TelnetStream.print(Vin);
//if (Vin > 15.)
{
VinAverage = (15. * VinAverage + Vin) / 16.;
IinAverage = (15. * IinAverage + Iin) / 16.;
}
// Serial.print(", VinAv ");
// Serial.print(VinAverage);
// TelnetStream.print(", VinAv ");
// TelnetStream.print(VinAverage);
Serial.print(", Iin ");
TelnetStream.print(", Iin ");
IinTemp = IinTemp / Smooth;
Serial.print(IinTemp);
TelnetStream.print(IinTemp);
Serial.print(" / ");
TelnetStream.print(" / ");
Iin = (IinZero - IinTemp) * 3.65 / 280.;
Serial.print(Iin);
TelnetStream.print(Iin);
Serial.print(", Vout ");
TelnetStream.print(", Vout ");
VoutTemp = VoutTemp / Smooth;
Serial.print(VoutTemp);
TelnetStream.print(VoutTemp);
Serial.print(" / ");
TelnetStream.print(" / ");
Vout = volts(VoutTemp);
Serial.print(Vout);
TelnetStream.print(Vout);
Win = Iin * Vin;
Wmin += Win;
nbSamples++;
Wout = Win * efficiency; //power is almost preserved but efficiency is not 100%
if (Vout < 2) Wout = 0.;
Iout = Wout / Vout; //compute Iout with assumption of power preservation and Buck converter efficiency
Serial.print(", Iout ");
TelnetStream.print(", Iout ");
Serial.print(Iout);
TelnetStream.print(Iout);
Serial.print(", Watt ");
Serial.print(Win);
TelnetStream.print(", Watt ");
TelnetStream.println(Win);
deltaWin = abs(Win - WinPrev) / Win * 100.;
// Serial.print(", delta ");
// Serial.print(deltaWin);
Serial.print(", MPPTduty ");
Serial.println(dutyCycle);
// TelnetStream.print(", duty ");
// TelnetStream.println(dutyCycle);
}
float volts(float raw)
{
if (raw < 735.1) return 0.0096 * raw + 2.2767; //see excel spreadsheet (multi linear regression) y = 0,0096x + 2,2767
else return 0.0117 * raw + 0.7156; //y = 0,0117x + 0,7156
}