-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
72 lines (59 loc) · 2.31 KB
/
main.cpp
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
#include "mbed.h"
#include "MPPT.h"
#include "ChargeController.h"
/*
Tracks the maximum power point for multiple solar arrays (solar cell groups),
And controls the power flow in the system, to maximize solar power usage, without overcharging the batteries.
*/
/* Control signal to be read from ChargeController.
0 = track MPPT
1 = pause MPPT
2 = track Pload
3 = overcurrent protection (track lower PP)
4 = reset MPPT
*/
int Control;
float Target; // Target variable to be sent to MPPTs in case they need to track a lower power point
// Pins for tracking group 1
#define I1 PA_0 // Current sensor
#define V1 PA_1 // Voltage sensor
#define PWM1 PA_3 // Pulse width modulation output
/* Pins for tracking group 2 */
//Pins for charge Controller
#define Vbat PA_5 // Battery voltage sensor
#define Iload PA_6 // Load current sensor
#define BatSw PA_8 // Switch which can enable battery charging
MPPT MPPT1(I1,V1,PWM1); // Create Maximum Power Point Tracker 1
/* Create Maximum Power Point Tracker 2 */
ChargeController CC(Vbat,Iload,BatSw); // Create Charge Controller object
// define the Serial object, for debugging
Serial pc(USBTX, USBRX);
int main() {
while(1) {
CC.Ppv = MPPT1.readP(); // Send measured solar power to the charge controller
CC.run(); // execute charge controller algorithm
Control = CC.readControl(); // read control variable
if (Control == 0) { // Track MPPT
MPPT1.PerturbObserve(); // Execute the P&O algorithm for tracking group 1
/* Execute the P&O algorithm for tracking group 2 */
}
else if (Control == 1) { // Pause the MPPT algorithm
MPPT1.pause();
/* pause MPPT2 */
}
else if (Control == 2) { // Track Target power
Target = CC.readPload(); // read Pload as target power.
MPPT1.PerturbObserve(Target);
/* Track target MPPT2 */
}
else if (Control == 3){ // Prevent overcurrent in battery
Target = CC.readPload() + CC.readPbatMax(); // Track load power + maximum allowed battery charging power
MPPT1.PerturbObserve(Target);
}
else if (Control == 4){
MPPT1.reset();
}
// MPPT doesn't need to happen very fast
wait_ms(1); // Track the power point every 10 ms
}
}