Project - Arduino MPPT Solar Charge Controller - Hackaday
Project - Arduino MPPT Solar Charge Controller - Hackaday
ARDUINO MPPT SOLAR CHARGE CONTROLLER
ack to project overview
An Arduino ased Solar MPPT charge controller.
Deasish Dutta
Newest
Battery Temperature and Charging Voltage Compensation
09/16/2015 at 09:45 • 0 comments
All chemical reactions are affected temperature. atter charging is also an electrochemical reaction, so it too is affected
temperature. As the atter gets warmer, the gassing increases. As the atter gets colder,it ecomes more resistant to charging. So
atter charging voltages should e corrected ased on atter temperature. This adjustment is referred to as temperature
compensation, a charging feature that helps ensure that a atter is neither undercharged nor overcharged regardless of atter
temperature.
Using normal target voltages to charge a atter that is colder than approximatel 25ºC (77ºF) will result in an undercharged atter,
which will deliver lower performance, reduced life and a higher life ccle cost. Appling normal target voltages to a atter that is hotter
than 25ºC ma result in an overcharged atter. This condition could lead to the dring out of VRLA atter cells. With flooded cells,
the result will e excessive outgassing, increased atter maintenance in the form of more frequent watering and reduced atter life
due to thermal stress. In fact, some atter manufacturers and charger manufacturers recommend not charging a atter that is 50ºC
(122ºF) or hotter.
Temperature Sensor :
To monitor the atter temperature a DS1820 1-Wire digital temperature sensor from Maxim IC will e used. It can measures
temperatures from -55°C to +125°C. Fahrenheit equivalent is -67°F to +257°F with ±0.5°C accurac.
We choose a waterproofed version of the DS1820 Temperature sensor. It is quite hand to measure something far awa, or in wet
conditions.
xample :
1. Let the atter temperature is 0 degC and float voltage is 13.8V ( STC : at 25degC )
2. Let the atter temperature is 35 degC and float voltage is 13.8V ( STC : at 25degC )
Reference : http://solarprofessional.com
Software requirements for MPPT controller V3.1
08/30/2015 at 15:06 • 1 comment
Charging states
The charger operates in one of several charging states, depending on the sunlight level.
At nil or low sunlight levels, as indicated solar voltage elow atter voltage + 0.5 Volts, the charger state is OFF.
a) if atter voltage is greater than 11.5 volts and solar voltage rises aove atter voltage + 0.5 Volts
) if atter voltage is less than 11.5 volts and solar voltage rises aove 12.5 volts.
When either of these voltage conditions is met the charger goes into one of the following states:
i) Float state if the atter voltage is greater than the Float voltage;
ii) oost state if the atter voltage is less than the Float voltage and the oost time since the last night time is less than [1 hour];
iii) ulk state if the atter voltage is less than the Float voltage and the oost time since the last night time is greater than [1 hour]
In all 3 cases initiall the controller will use the DCM charging algorithm.
When in the oost DCM or ulk DCM state, the charger can go to OFF state if the solar voltage falls elow (atter voltage + 0.5 Volts).
The charger can go to oost CCM or ulk CCM state if the Solar Power rises aove 10% of the rated power.
The charger can go to the Float state if atter voltage rises aove Float.
The charger can go from oost DCM to ulk DCM if the oost time since the last night is greater than oost duration.
When in the oost CCM or ulk CCM state the charger can go to oost DCM or ulk DCM if the Solar Power falls elow 10% of rated
power.
The charger can go from oost CCM to ulk CCM if the oost time since the last night is greater than oost duration
Float state
The float state is functionall the same as ulk state when the atter voltage reaches Float.
When in Float state the charger keeps just sufficient current flowing to the atter to maintain the atter voltage at Float.
Charging algorithms
CCM algorithm
Continuous Current Mode (CCM) applies when the availale solar power is more than 10% of the rated power (strictl, when the current
in the inductor alwas flows towards the atter, ut this is difficult to measure directl in the software so we use the power level as a
prox estimate).
In this mode, the PWM period is set at 12 microseconds. The PWM dut ccle is set either at a value that achieves maximum power, or
to meet the charging voltage required the atter (see atter management conditions elow). When it is required to reduce the
charging rate so as to limit the atter voltage, the PWM dut is reduced, there increasing the panel voltage aove the maximum
power point and reducing the current accordingl.
The Fast PWM mode of the Arduino is used to generate this PWM. The PWM period of 12 microseconds is 192 clock ccles at 16 MHz.
The PWM period is divided into a Panel Connect phase followed an arth Connect phase. The length of the Panel Connect phase is
controlled PWM Dut.
When maximising power, the power level is measured approximatel ever 0.5 milliseconds and is compared to the previous power
level measurement. The PWM dut ccle is changed up or down 1 CPU clock ccle after ever measurement. After the first
measurement, the PWM dut ccle is increased. On susequent measurements, if the power level is increased or is the same as the
previous measurement, the PWM dut ccle is changed in the same direction as in the previous ccle. If the power level is decreased
from the previous ccle, the PWM dut ccle is changed to go in the opposite direction to that in the previous ccle.
When tracking the allowale atter voltage, the atter voltage is measured approximatel ever 0.5 milliseconds and is compared to
the target value. If the new value is within +0.1 volts of the target value, the PWM dut is left unchanged. If the new value is higher than
the target value more than 0.1 volts, the PWM dut is increased one step. If the new value is lower than the target value more
than 0.1 volts, the PWM dut is decreased one step.
Whether maximising power or tracking atter voltate, the atter charging current must not e allowed to exceed 105% of the rated
current. If the atter charging current voltage reaches 105% of the rated current, the charging rate is reduced to keep within that limit.
DCM algorithm
Discontinuous Current Mode (DCM) applies when the availale solar power is less than 10% of the rated power.
In this mode, the PWM period is set at 100 microseconds which is 1600 clock ccles at 16 MHz. The PWM period is divided into three
phases: a Panel Connect phase, followed an arth Connect phase, followed a Null phase. The length of the Panel Connect phase
is controlled PWM Dut through setting a “1” on oth IN and SD pins of driver IC No. 2 (which drives Q2 and Q3). The length of the
arth Connect phase is controlled setting a “0” on IN and a “1” on SD pins of driver IC No. 2. The Null phase is the remainder of the
PWM period, during which time the SD pin of driver No. 2 are oth “0”, so that oth transistors are OFF.
In this mode the length of the arth Connect phase is set to e Panel Connect phase multiplied the ratio of (Panel voltage - atter
voltage) to Panel voltage. Thus if the atter voltage is 13 and the panel voltage is 19.5 volts, the arth Connect phase is (19.5-13)/19.5 =
1/3 of the Panel Connect phase. So if the Panel connect phase lasts 9 microseconds, the arth connect phase will last 3 microseconds.
In this case the Null phase will e (100 – 9 – 3) = 88 microseconds.
When maximising power, the power level is measured approximatel ever 0.5 milliseconds and is compared to the previous power
level measurement. The Panel Connect time is changed up or down 1 CPU clock ccle after ever measurement. The arth Connect
time is changed to follow the Panel Connect time. After the first measurement, the Panel connect time is increased. On susequent
measurements, if the power level is increased or is the same as the previous measurement, the Panel connect time is changed in the
same direction as in the previous ccle. If the power level is decreased from the previous ccle, the Panel connect time is changed to
go in the opposite direction to that in the previous ccle. Once the new Panel connect time is known, the corresponding arth connect
time is calculated.
Since the Panel connect time and arth connect time are defined in integer numers of clock ccles, it will often not e possile to
make the arth connect time the exact multiple of the Panel connect time required for the ratio of (Panel voltage - atter voltage) /
Panel voltage. In this case the arth connect time should e made the next lowest integer of clock ccles, elow the exact value.
When tracking the allowale atter voltage, the atter voltage is measured approximatel ever 0.5 milliseconds and is compared to
the target value. If the new value is within +0.1 volts of the target value, the Panel connect time is left unchanged. If the new value is
higher than the target value more than 0.1 volts, the Panel connect time is increased one step. If the new value is lower than the
target value more than 0.1 volts, the Panel connect time is decreased one step. Then the corresponding arth connect time is
determined as defined for CCM.
Float algorithm
The algorithm for tracking the float voltage is the same as defined for DCM.
Off algorithm
All MOSFTs (Q1, Q2 and Q3) are turned OFF in this state.
atter management
Float charging :
When atter voltage exceeds the Float value, the charger goes into a Float Charging state which provides just enough current to
keep the atter within 0.1 volts of the Float value.
ulk charging :
When sufficient solar power is availale, the charger goes into a ulk Charging state using the appropriate algorithms (DCM or CCM). In
this state the atter voltage will e allowed to go up to Float voltage and the atter charging current must not e allowed to exceed
105% of the rated current. If the atter voltage reaches Float voltage – 0.1 volts, or the current reaches the rated current, the charging
rate is reduced to sta elow those limits.
oost charging :
For a maximum of oost Duration in each dail charging ccle, the atter voltage will e allowed to go up to oost Voltage, provided
the atter voltage has fallen elow the oost Reconnect voltage since the previous oost charging period. During this state, the
atter charging current must not e allowed to exceed 105% of the rated current. If the atter voltage reaches oost Voltage, or the
charging current reaches the rated current, the charging rate is reduced to sta elow those limits.
The controller will use the following parameters to manage the atter charge and discharge:
The values given aove are the default for 25 degrees Celsius. If a temperature sensor is installed, these voltages should all e
adjusted minus 0.018 volts per degree Celsius. For example, at 0 degrees C the Float voltage would ecome 13.8 + 25*0.018 = 14.25
volts.
If the atter voltage falls elow Low Voltage Disconnect voltage the load is disconnected.
Once the atter voltage rises to the Low Voltage Reconnect voltage the load is reconnected.
ON: Turn on loads at night (when the solar panel is producing less than 5% power) and the atter voltage is not disconnected due to
the Low Voltage Disconnect logic.
OFF: Turn off loads in da time as well as due to the Low Voltage Disconnect logic.
3. Continuous
Turn on the load at all times suject to the Low Voltage Disconnect logic.
LD displa
This function displa the current state of charge of the atter via LD as follows:
1. RD means undervoltage (disconnected due to atter voltage falling elow Low Voltage Disconnect, and still elow Low
Voltage Reconnect voltage)
2. GRN is Normal, ie aove LVD / LVR and at or elow Float voltage.
LCD displa
This function is used to displa the status of solar panel, atter and load of the controller on a 20X4 character I2C LCD displa.
WiFi data logging
This function sends parameters (sol voltage, current, power & atter voltage, charging current etc) to the www.thingspeak.com via a
SP8266 wifi module.
First the wifi module will connect to the wifi router automaticall (User has to set the SSID, Router Password and Thingspeak API ke).
If the Wifi module connects successfull, it will transmit data to wifi @ 15sec intervals (this ma e greatl reduced after development is
complete, to mae once ever 15 minutes or even once per hour).
Current Status : Working ut wifi module has to e first connected to the router using a separate program and using AT command
from serial monitor.
Serial monitor
This function prints software parameters on a computer connected via the Arduino US port useful for deugging.
It also provides a command line interface for changing settale parameters in the controller. Settale parameters are:
In asic operation the default mode is to output data to the serial monitor. The user can put in a command such as "stop" which will stop
the stream of serial data and print a single line with a prompt such as "tpe LIST for a list of commands, tpe START to restart data
logging".
If the user tpes "LIST” or list" the serial monitor puts out a list of parameters and their current values. The user can then put in a
command to change an value.
Hardware interfaces
The following pins will e used for interfacing to the various hardware devices.
// A0 - Voltage divider (solar) 150K / 20 K scale factor 0.04150390625
// A1 - ACS 712 Solar current scale factors for 5A unit: current 0.026393581 Offset 13.5135135
// A3 - ACS 712 atter current scale factors for 5A unit: current 0.026393581 Offset 13.5135135
// A4 - LCD SDA
// A5 - LCD SCL
// A6 - ACS 712 atter current scale factors for 5A unit: current 0.026393581 Offset 13.5135135
// A7 - not used
// D2 - SP8266 Tx
// D6 - Load Control
// D7 - not used
// D8 - not used
Overview of Version3.1
08/30/2015 at 14:50 • 6 comments
After lot testing we oserved that MOSFT ( Q3 ) in ver-3.0 design is urning repeatedl.We tried to modif the existing software ut
not find an satisfactor result.
The other prolem was that MOSFT Q1 ( in V-3.0) conduct even when there is no solar input.
To solve the aove prolems and enhance the power handling capailit we are modifing oth the hardware and software.This is
named as Version-3.1 Charge Controller.This version have 3 options.
1. 5 Amp version :
T94-26 toroid, 48 turns of AWG20 wire to give 135 uH (it takes almost 1.5m of wire)
2. 8 Amp version :
T106-26 toroid wound with 23 turns of a compound wire made from 3 strands of AWG20 wire twisted together to give 47 uH (this takes
aout 3.1 m of wire).
Two ACS712, one on the panel side as per version 3.0 and one in series with the atter.
3 10 Amp version :
T130-26 toroid wound with 23 turns of a compound wire made from 4 strands of AWG18 wire twisted together to give 41 uH (this takes
aout 4.5 m of wire).
Three ACS712, one on the panel side as per version 3.0, one in series with the atter and one in series with the load.
We are working on new PC for V-3.1 Here is the sample of one
The drive circuitr (common to all 3 versions) will use 3 separate IR2104 driver chips, one for each of Q1, Q2 and Q3. We drive the Q1
and Q2 drivers from pin D9 and HO1 and HO2, and drive Q3 from pin D10 and LO3.
In driver chips 1 and 2, pins IN and SD are driven in parallel Arduino output pin D9. In the case of driver 1 (for Q1) there is a low pass
RC filter in series, with a time constant of aout 1 ms. Driver 2 is driven directl (as in the current circuit, ut proal with a slightl
higher series resistor to allow more current for the Q1 driver and its RC filter).
The purpose of using separate drivers for Q2 and Q3 is to enale us to switch Q3 OFF to operate in Asnchronous mode at low
current levels when the controller will e in DCM (Discontinuous Current Mode). There ma e a etter wa to do this ut in the short
time we have availale this is a simple option and eas and reliale to implement.
All 3 versions should have LCD displas, WiFi, LD indicators (mae with a more fanc coding scheme to separatel indicate DCM and
CCM).
All 3 versions should e ale to cope with either 18 V or 30 V panels, and use algorithms that stop them urning out if the panel can
produce more current than the rating allows. This can all e done auto-detect.
All the components exposed to panel voltage need to e rated for at least 40 V (in particular C1 and our uck converter to generate
12V for the drivers and to power the control electronics.
Overview of MPPT algorithm modelling
08/26/2015 at 07:29 • 0 comments
Panel model consists of a simple step-wise linear model of a solar panel.See the aove figure.
In the spread sheet attached elow there are 5 MPPT models.Here is some rief description on each.
1. MPPT model 1 implements the logic flow chart as shown in aove figure
2. MPPT model 2 implements the same logic flow chart with a declining panel power.
3. MPPT model 3 implements the algorithm used in the Arduino software. It is eas to adjust it for fixed or variale panel power and for
various starting conditions.
4. MPPT model 4 is the same as Model 3 except that it used “<=” rather than “<” for the power test.
5. MPPT model 5 is the functionall the same as Model 4. It uses three ranches on the power comparison to the previous iteration,
which has the same result as the comparison in Model 4. The main difference is it uses the equivalent of the integer arithmetic used in
the Arduino for calculation of PWM dut ccles.
The all converge satisfactoril when given a high PWM starting point (aove the MPP) or a lower one with a derived voltage less than
the maximum cut-off voltage of the panel (in the model, 21 V).
None of them work at all when given a low PWM starting point with a derived voltage aove the maximum cut-off voltage.
The MPPT model 4 corrects this last prolem constantl increasing the PWM (ie decreasing the derived voltage) in the case of equal
(ie zero) power. It will alwas find the MPP of the panel model no matter what starting point is used. It ma take more steps than
provided in the examples, ut it alwas converges.
To clarif this: Models 1 to 3 when converged all oscillate at the top or ottom edge of the MPP area, depending on whether the
approached it from aove or elow.
It seems desirale for the tracking to sweep the whole MPP area, irrespective of which direction the approach came. This would etter
deal with cases where the power curve had local flat spots for some reason. Model 4 does this.
MPPT Model 5 provides a tool for exploring the effect of integer arithmetic on the PWM calculations and the resultant voltages and
currents.
At the hardware level, the current software uses Timer1 to produce the PWM signal at a 20 microsecond period.20 microseconds is
320 clock ccles of the Arduino clock (which is 16 MHz, ie with a period of 62.5 ns).ecause the Timer1 lirar uses the “Phase and
Frequenc correct” PWM mode of Timer1, which counts oth up and down, the setting of the TOP level (which defines the 20
microsecond period) is 160. The PWM dut can e changed in units of 2 clock ccles, or 125 ns.The integer calculation of PWM runs like
this (using the current software):The MPPT code uses a 16 it integer variale “pwm” to manage the dut ccle. It runs from 0 to 100 to
represent 0 to 100% dut ccle, and can e stepped up or down 1 unit (ie 1%) in each pass through the MPPT algorithm. The Timer1
lirar accepts PWM dut parameter in the form of a 16 it integer variale which runs etween 0 and 1023 to represent dut ccle as a
fraction of 1024.
As an example we start with a desired PWM dut ccle of 70%, that is the integer “pwm” has a value of 70. To convert this to an integer
etween 0 and 1023 to pass to the Timer1 lirar, the software multiplies pwm (70) 1023 (giving 71610.The MPPT code then divides
this numer 100 giving 716, which it passes to the Timer1 lirar. Note that 716 / 1024 = 0.6992188..., which is a small amount less
than the 70% we started out with.
Note that even if we had multiplied the original 70 1024, it would still have produced 716 as the interface parameter value.When the
Timer1 lirar receives the pwm dut ccle parameter, it multiplies it the counter setting of the TOP register, corresponding in our
case to 160 which is the value for a 20 microsecond period. This gives 716*160 = 114,560.Timer1 then divides that product 1024, in
our case giving 111. This is the value that is put into the register that triggers the transitions from 0 to 1 and then 1 ack to 0 for the PWM
signal. It will give 111/160 = 69.375% or 13.875 microseconds of 1, and the remainder of 0 in the PWM signal.
Thus, from a specified value of 70 (70%) we end up with an actual PWM dut ccle of 69.375%.This is a sstematic change. As we step
the pwm integer up or down, the difference changes.Thus 70% ecomes 69.375%, 71% ecomes 70%, 72% ecomes 71.25%, and so
on. The step size on the input side is alwas 1%, ut the step size on the output side is sometimes 0.625% (which is 1/160), and
sometimes 1.25% (which is 2/160).
It can happen that the ideal pwm dut ccle falls in a spot (like 70.625%) that cannot e accessed ecause of the nature of the integer
arithmetic.
Quarter Final Video
08/15/2015 at 19:43 • 0 comments
Keith Presentation
08/13/2015 at 12:30 • 0 comments
keith.hungerford ( team memer ) from Australia, who is one of the major contriutor to this project.He has experimented a lot on this
project.After m request he made this nice video explaining the efficienc,losses at various load,how DCM will take care at low load
condition, aout the MPPT v4 controller and writing of a new Arduino TimerOne lirar to handle our requirement.
At 100 Watt :
At 80 Watt :
At 1 watt :
In the 100% ( 100W ) graph, the optimum PWM period is 14 microseconds, at which period the decrease in the core loss is alanced
the increase in the switching and capacitive drive loss. When Keith checked, he found that the capacitive drive losses are so nearl
equal to the switching losses that the curves full overlap and ou cannot see the capacitive loss curve. It is more clear at 80% ( 80W )
load where oth curves are visile.
As the load decreases, the resistive losses decrease and the relative influence of these period-dependent losses increases, ut the
pattern remains the same. In the MOSFTS, the importance of the switching losses decreases with decreasing load, since there is less
current flowing and therefore a reduced amount of charge to e asored, even though the voltage excursion is unchanged. The
capacitive losses come to dominate. ecause the switching losses are less, the optimum PWM period decreases with decreasing load.
At 10% load it is down to 11 microseconds.
However the difference etween the total loss at 11 microseconds and 14 microseconds is onl 5% of the loss, so a single PWM period
of around 14 microseconds is quite efficient SO LONG AS TH CONTROLLR IS IN CCM.
Somewhere elow the 10 % load point, ut aove the 5% load point, the controller goes into DCM. That is, there is not enough current
flowing out of the panel to make the current in the inductor alwas flow in the same direction.
His design assumption in this spreadsheet is that the controller algorithms explicitl support DCM. That is, the switch off Q3 at the time
that the current would start flowing "ackwards". So now, in DCM, the controller has 3 phases within the PWM period. There is the
phase when current flows from the panel via Q2 through the inductor, and increases. there is the phase when current flows from arth
via Q3 through the inductor, and decrease. Then there is the Null phase when no current flows through the inductor.
This Null phase is a good one as far as losses in the inductor and MOSFTs are concerned - there is no current and so no loss.
However C1 is receiving all of the current from the panels, and C2 is delivering all of the current to the atter or load. This creates
extra voltage ripple at the panels, and at the atter/load.
So long as the voltage ripple at the panels and atter/load is within reasonale limits, in DCM it is etter to have a much longer PWM
period. Hence the appearance of ver long PWM periods at ver low load levels. The length of the PWM period is mainl limited the
voltage ripple tolerale at the atter, and the reduction in efficienc of the panel caused the ripple there.
Finished the Soldering
08/12/2015 at 03:22 • 3 comments
Purchased all the missing components and started to solder it on PC.After few hours of work, everthing is soldered.I have tested
auxiliar power circuitr,everthing works fine.The next task is to test the charging circuit.I will update it soon.
Soldering the Components on PCB
08/12/2015 at 03:09 • 0 comments
Toda I soldered most of the components on the new PC.ut few components are not availale in m stock.So I can't solder them.I
will solder the remaining components after uing it from m local shop.
1.Fuse Holder
2.TVS Diodes
4.US Port
Improvement in LCD Display Function
08/11/2015 at 15:57 • 1 comment
The LCD displa functionalit is improved.The aove video shows the simulation to test the modified software.
1. Dnamic atter status in atter icon.arlier it was alwas showing aout half full .Now it changes according to the atter SOC, just
like in cell phone.
2. Removing the long if else statement for displaing the atter SOC. Now used a math function to do the jo.
3. Adding a spinner icon to show the charger is running.It stops when program stuck up.
void lcd_display()
{
back_light_pin_State = digitalRead(BACK_LIGHT_PIN);
if (back_light_pin_State == HIGH)
{
time = millis(); // If any of the buttons are pressed, save the time in millis to "time"
}
lcd.setCursor(0, 0);
lcd.print("SOL");
lcd.setCursor(4, 0);
lcd.write(1);
lcd.setCursor(0, 1);
lcd.print(sol_volts);
lcd.print("V");
lcd.setCursor(0, 2);
lcd.print(sol_amps);
lcd.print("A");
lcd.setCursor(0, 3);
lcd.print(sol_watts);
lcd.print("W ");
lcd.setCursor(8, 0);
lcd.print("BAT");
lcd.setCursor(12, 0);
lcd.write(2);
lcd.setCursor(8, 1);
lcd.print(bat_volts);
lcd.setCursor(8,2);
if (charger_state == on)
lcd.print("on");
else if (charger_state == off)
lcd.print("off");
else if (charger_state == bulk)
lcd.print("bulk");
else if (charger_state == bat_float)
lcd.print("float");
//‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
//‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐Battery State Of Charge ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
//‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
lcd.setCursor(8,3);
if ( bat_volts >= 12.7)
lcd.print( "100%");
else if (bat_volts >= 12.5 && bat_volts < 12.7)
lcd.print( "90%");
else if (bat_volts >= 12.42 && bat_volts < 12.5)
lcd.print( "80%");
else if (bat_volts >= 12.32 && bat_volts < 12.42)
lcd.print( "70%");
else if (bat_volts >= 12.2 && bat_volts < 12.32)
lcd.print( "60%");
else if (bat_volts >= 12.06 && bat_volts < 12.2)
lcd.print( "50%");
else if (bat_volts >= 11.90 && bat_volts < 12.06)
lcd.print( "40%");
else if (bat_volts >= 11.75 && bat_volts < 11.90)
lcd.print( "30%");
else if (bat_volts >= 11.58 && bat_volts < 11.75)
lcd.print( "20%");
else if (bat_volts >= 11.31 && bat_volts < 11.58)
lcd.print( "10%");
else if (bat_volts < 11.3)
lcd.print( "0%");
//‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
//‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐Duty Cycle‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
//‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
lcd.setCursor(15,0);
lcd.print("PWM");
lcd.setCursor(19,0);
lcd.write(3);
lcd.setCursor(15,1);
lcd.print(pwm);
lcd.print("%");
//‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
//‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐Load Status‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
//‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
lcd.setCursor(15,2);
lcd.print("Load");
lcd.setCursor(15,3);
if (load_status == 1)
{
lcd.print("On");
}
else
{
lcd.print("Off");
}
backLight_timer(); // call the backlight timer function in every loop
}
void backLight_timer(){
if((millis() ‐ time) <= 15000) // if it's been less than the 15 secs, turn the backlight on
lcd.backlight(); // finish with backlight on
else
lcd.noBacklight(); // if it's been more than 15 secs, turn the backlight off
}
void lcd_display()
{
static bool current_backlight_state = ‐1;
back_light_pin_State = digitalRead(BACK_LIGHT_PIN);
if (current_backlight_state != back_light_pin_State) {
current_backlight_state = back_light_pin_State;
if (back_light_pin_State == HIGH)
lcd.backlight();// finish with backlight on
else
lcd.noBacklight();
}
if (back_light_pin_State == HIGH)
{
time = millis(); // If any of the buttons are pressed, save the time in millis to "time"
}
lcd.setCursor(0, 1);
lcd.print(sol_volts);
lcd.print("V ");
lcd.setCursor(0, 2);
lcd.print(sol_amps);
lcd.print("A");
lcd.setCursor(0, 3);
lcd.print(sol_watts);
lcd.print("W ");
lcd.setCursor(8, 1);
lcd.print(bat_volts);
lcd.setCursor(8,2);
if (charger_state == on)
lcd.print("on ");
else if (charger_state == off)
lcd.print("off ");
else if (charger_state == bulk)
lcd.print("bulk ");
else if (charger_state == bat_float)
{
lcd.print(" ");
lcd.setCursor(8,2);
lcd.print("float");
}
//‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
//‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐Battery State Of Charge ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
//‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
int pct = 100.0*(bat_volts ‐ 11.3)/(12.7 ‐ 11.3);
if (pct < 0)
pct = 0;
else if (pct > 100)
pct = 100;
lcd.setCursor(12,0);
lcd.print((char)(pct*5/100));
lcd.setCursor(8,3);
pct = pct ‐ (pct%10);
lcd.print(pct);
lcd.print("% ");
//‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
//‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐Duty Cycle‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
//‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
lcd.setCursor(15,0);
lcd.print("PWM");
lcd.setCursor(19,0);
lcd.write(PWM_ICON);
lcd.setCursor(15,1);
lcd.print(" ");
lcd.setCursor(15,1);
if( charger_state == off)
lcd.print(0);
else
lcd.print(pwm);
lcd.print("% ");
//‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
//‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐Load Status‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
//‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
lcd.setCursor(15,2);
lcd.print("Load");
lcd.setCursor(15,3);
if (load_status)
{
lcd.print("On ");
}
else
{
lcd.print("Off ");
}
spinner();
backLight_timer(); // call the backlight timer function in every loop
}
void backLight_timer(){
if((millis() ‐ time) <= 15000) // if it's been less than the 15 secs, turn the backlight on
lcd.backlight(); // finish with backlight on
else
lcd.noBacklight(); // if it's been more than 15 secs, turn the backlight off
}
void spinner(void) {
static int cspinner;
static char spinner_chars[] = { '*','*', '*', ' ', ' '};
cspinner++;
lcd.print(spinner_chars[cspinner%sizeof(spinner_chars)]);
}
PCB Arrived
08/11/2015 at 15:27 • 0 comments