Anda di halaman 1dari 6

--- C:\Documents and Settings\MySys\Desktop\solar\delta_file.

c --------------------------------1:
2:
#include <pic.h>
3:
#include <pic16f684.h>
4:
5:
//*********************************************************************************
6:
//
7:
// File:
MPPT.c
8:
// Date:
4 Mrach 2011
Original code
9:
// Version: 1.00
10:
//
11:
//*********************************************************************************
12:
13:
14:
// __CONFIG _CP_OFF & _CPD_OFF & _BOD_OFF & _MCLRE_ON & _WDT_OFF &
_INTRC_OSC_NOCLKOUT & _FCMEN_ON;
15:
16:
17:
void PID();
18:
19:
20:
#define PWM_INC 1
//the value the increment to the pwm value for the ppt
algorithm
21:
#define MIN_SOL_WATTS 100
//value of solar watts scaled by 100 so this is 1.00 watts

22:
#define MAX_BAT_VOLTS 1410
//value of battery voltage scaled by 100 so this is 14.10
volts
23:
#define LOW_SOL_WATTS 500
//value of solar watts scaled by 100 so this is 5.00
watts
24:
25:
26:
int bat_volts;
// battery volts scaled by 100
27:
int delta = PWM_INC;
// variable used to modify pwm duty cycle for the ppt
algorithm
28:
int old_sol_watts = 600;
// solar watts from previous time through ppt routine scaled
by 100
29:
int pwm = 100;
//pwm duty cycle 0-100%
30:
int sol_amps;
// solar amps scaled by 100
31:
int sol_volts;
// solar volts scaled by 100
32:
int bat_volts;
// battery volts scaled by 100
33:
int sol_watts = 500;
// solar watts scaled by 100
34:
char charger_state;
35:
36:
//***************************************************************************
37:
//Main() - Main Routine
38:
//***************************************************************************
39:
void main()
40:
{
41:
// Init();
//Initialize 12F629 Microcontroller
42:
// Set_Constants();
//Get PID coefficients ki,
kp and kd
43:
while(1)
//Loop Forever
7BC 2FBA GOTO 0x7ba

44:
{
45:
PID();
7BA 27DF CALL 0x7df
7BB 2FBA GOTO 0x7ba
46:
47:
}
48:
}
7BD 2800 GOTO 0
49:
50:
51:
52:
void PID()
53:
{
54:
55:
/*
if (sol_watts < MIN_SOL_WATTS) {
//if watts input from the solar panel is less
than
56:
charger_state = 1;
//the minimum solar watts then it is getting dark so
57:
}
58:
else if (bat_volts > MAX_BAT_VOLTS) {
//else if the battery voltage has gotten above
the float
59:
charger_state = 2;
//battery float voltage go to the charger battery float state
60:
}
61:
else if (sol_watts < LOW_SOL_WATTS) {
//else if the solar input watts is less than low
solar watts
62:
charger_state = 0;
//it means there is not much power being generated by
the solar panel
63:
64:
}
65:
else {
// this is where we do the Peak Power Tracking ro Maximum
Power Point algorithm
66:
67:
*/
68:
if (old_sol_watts >= sol_watts) {
// if previous watts are greater change the value of
7DF 0873 MOVF 0x73, W
7E0 3A80 XORLW 0x80
7E1 00FD MOVWF 0x7d
7E2 0877 MOVF 0x77, W
7E3 3A80 XORLW 0x80
7E4 027D SUBWF 0x7d, W
7E5 1D03 BTFSS 0x3, 0x2
7E6 2FE9 GOTO 0x7e9
7E7 0876 MOVF 0x76, W
7E8 0272 SUBWF 0x72, W
7E9 1C03 BTFSS 0x3, 0
7EA 2FEC GOTO 0x7ec
7EB 2FED GOTO 0x7ed
7EC 2FF3 GOTO 0x7f3
69:
delta = -delta;
// delta to make pwm increase or decrease to
maximize watts
7ED 09F0 COMF 0x70, F
7EE 09F1 COMF 0x71, F
7EF 0AF0 INCF 0x70, F
7F0 1903 BTFSC 0x3, 0x2
7F1 0AF1 INCF 0x71, F
7F2 2FF3 GOTO 0x7f3
70:
}

71:
7F3
7F4
7F5
7F6
7F7
7F8
72:
7F9
7FA
7FB
7FC
7FD
7FE
73:
74:
75:
7FF

pwm += delta;
MOVF 0x70, W
ADDWF 0x74, F
BTFSC 0x3, 0
INCF 0x75, F
MOVF 0x71, W
ADDWF 0x75, F
old_sol_watts = sol_watts;
0877 MOVF 0x77, W
01F3 CLRF 0x73
07F3 ADDWF 0x73, F
0876 MOVF 0x76, W
01F2 CLRF 0x72
07F2 ADDWF 0x72, F
//
}

// add delta to change PWM duty cycle for PPT algorythm

0870
07F4
1803
0AF5
0871
07F5

}
0008

// load old_watts with current watts value for next time

RETURN

Add this snippet in solar charge controller Asm


--- C:\Documents and Settings\MySys\Desktop\solar\delta_file.c
--------------------------------1:
2:
#include <pic.h>
3:
#include <pic16f684.h>
4:
5:
//*********************************************************************************
6:
//
7:
// File:
MPPT.c
8:
// Date:
4 March 2011
Original code
9:
// Version:
1.00
10:
//
11:
//*********************************************************************************
12:
13:
14:
//
__CONFIG _CP_OFF & _CPD_OFF & _BOD_OFF &
_MCLRE_ON & _WDT_OFF & _INTRC_OSC_NOCLKOUT & _FCMEN_ON;
15:
16:
17:
void PID();
18:
19:
20:
#define PWM_INC 1
//the value the increment to the pwm
value for the ppt algorithm
21:
#define MIN_SOL_WATTS 100
//value of solar watts scaled by 100
so this is 1.00 watts
22:
#define MAX_BAT_VOLTS 141
//value of battery voltage scaled by

100 so this is 14.10 volts


23:
#define LOW_SOL_WATTS 200
//value of solar watts scaled by
100 so this is 5.00 watts
24:
25:
26:
27:
char delta = PWM_INC;
// variable used to modify pwm duty
cycle for the ppt algorithm
28:
int old_sol_watts = 60;
// solar watts from previous time through
ppt routine scaled by 100
29:
int pwm = 100;
//pwm duty cycle 0-100%
30:
int sol_amps;
// solar amps scaled by 100
31:
int sol_volts;
// solar volts scaled by 100
32:
int bat_volts;
// battery volts scaled by 100
33:
int sol_watts = 500;
// solar watts scaled by 100
34:
char charger_state;
35:
36:
//***************************************************************************
37:
//Main() - Main Routine
38:
//***************************************************************************
39:
void main()
40:
{
41:
//
Init();
//Initialize 12F629 Microcontroller
42:
//
Set_Constants();
//Get PID
coefficients ki, kp and kd
43:
while(1)
//Loop Forever
7BF 2FBD GOTO 0x7bd
44:
{
45:
PID();
7BD 27DF CALL 0x7df
7BE 2FBD GOTO 0x7bd
46:
47:
}
48:
}
7C0 2800 GOTO 0
49:
50:
51:
52:
void PID()
53:
{
54:
55:
/*
if (sol_watts < MIN_SOL_WATTS) {
//if watts input from the
solar panel is less than
56:
charger_state = 1;
//the minimum solar watts then it is
getting dark so
57:
}

58:
else if (bat_volts > MAX_BAT_VOLTS) {
//else if the battery
voltage has gotten above the float
59:
charger_state = 2;
//battery float voltage go to the charger
battery float state
60:
}
61:
else if (sol_watts < LOW_SOL_WATTS) {
//else if the solar input
watts is less than low solar watts
62:
charger_state = 0;
//it means there is not much power
being generated by the solar panel
63:
64:
}
65:
else {
// this is where we do the Peak Power
Tracking ro Maximum Power Point algorithm
66:
67:
*/
68:
if (old_sol_watts >= sol_watts) {
// if previous watts are greater
change the value of
7DF 0871 MOVF 0x71, W
7E0 3A80 XORLW 0x80
7E1 00FC MOVWF 0x7c
7E2 0875 MOVF 0x75, W
7E3 3A80 XORLW 0x80
7E4 027C SUBWF 0x7c, W
7E5 1D03 BTFSS 0x3, 0x2
7E6 2FE9 GOTO 0x7e9
7E7 0874 MOVF 0x74, W
7E8 0270 SUBWF 0x70, W
7E9 1C03 BTFSS 0x3, 0
7EA 2FEC GOTO 0x7ec
7EB 2FED GOTO 0x7ed
7EC 2FF0 GOTO 0x7f0
69:
delta = -delta;
// delta to make pwm increase or
decrease to maximize watts
7ED 09F6 COMF 0x76, F
7EE 0AF6 INCF 0x76, F
7EF 2FF0 GOTO 0x7f0
70:
}
71:
pwm += delta;
// add delta to change PWM duty cycle
for PPT algorythm
7F0 0876 MOVF 0x76, W
7F1 00FC MOVWF 0x7c
7F2 01FD CLRF 0x7d
7F3 087C MOVF 0x7c, W
7F4 07F2 ADDWF 0x72, F
7F5 1803 BTFSC 0x3, 0
7F6 0AF3 INCF 0x73, F

7F7 087D MOVF 0x7d, W


7F8 07F3 ADDWF 0x73, F
72:
old_sol_watts = sol_watts;
value for next time
7F9 0875 MOVF 0x75, W
7FA 01F1 CLRF 0x71
7FB 07F1 ADDWF 0x71, F
7FC 0874 MOVF 0x74, W
7FD 01F0 CLRF 0x70
7FE 07F0 ADDWF 0x70, F
73:
//
}
74:
75:
}
7FF 0008 RETURN
16-bit Subtract (All Devices)
movf

B0,W

subwf

A0,W

movwf

R0

movf

A1,W

movwf

R1

movf

B1,W

btfss

STATUS,C

incfsz

B1,W

subwf

R1,F

// load old_watts with current watts

Anda mungkin juga menyukai