-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
60 lines (55 loc) · 1.25 KB
/
main.c
File metadata and controls
60 lines (55 loc) · 1.25 KB
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
#include <stdio.h>
#include <math.h>
float Pprevious, Vprevious, Dprevious; // These are previous values (threshold)
float Ppv, Vpv, Ipv; // These are new values that are scanned
float deltaD = 110e-6; // One unit increasing of duty cycle
float DutyCycle = 2000.0; // Duty Cycle for updating
float scanVoltage(){
printf("Scanning for Voltage...\n");
scanf("%f",&Vpv);
return Vpv;
}
float calculatePower()
{
printf("Scanning for Current...\n");
scanf("%f",&Ipv);
Ppv = Ipv*Vpv;
return Ppv;
}
void pAndqAlgorithm()
{
if((Ppv-Pprevious) != 0){
if((Ppv-Pprevious) > 0){
if((Vpv-Vprevious) > 0){
DutyCycle = Dprevious - deltaD;
printf("Duty Cycle decreased.\n");
}
else{
DutyCycle = Dprevious + deltaD;
printf("Duty Cycle increased.\n");
}
}
else{
if((Vpv-Vprevious) > 0){
DutyCycle = Dprevious + deltaD;
printf("Duty Cycle increased.\n");
}
else{
DutyCycle = Dprevious - deltaD;
printf("Duty Cycle decreased.\n");
}
}
}
}
int main()
{
Vprevious = scanVoltage();
Pprevious = calculatePower();
while(1){
Vpv = scanVoltage();
Ppv = calculatePower();
pAndqAlgorithm();
Vprevious = Vpv;
Pprevious = Ppv;
}
}