-
Battery Temperature and Charging Voltage Compensation
09/16/2015 at 09:45 • 0 commentsAll chemical reactions are affected by temperature. Battery charging is also an electrochemical reaction, so it too is affected by temperature. As the battery gets warmer, the gassing increases. As the battery gets colder,it becomes more resistant to charging. So battery charging voltages should be corrected based on battery temperature. This adjustment is referred to as temperature compensation, a charging feature that helps ensure that a battery is neither undercharged nor overcharged regardless of battery temperature.
Using normal target voltages to charge a battery that is colder than approximately 25ºC (77ºF) will result in an undercharged battery, which will deliver lower performance, reduced life and a higher life cycle cost. Applying normal target voltages to a battery that is hotter than 25ºC may result in an overcharged battery. This condition could lead to the drying out of VRLA battery cells. With flooded cells, the result will be excessive outgassing, increased battery maintenance in the form of more frequent watering and reduced battery life due to thermal stress. In fact, some battery manufacturers and charger manufacturers recommend not charging a battery that is 50ºC (122ºF) or hotter.
Temperature Sensor :
To monitor the battery temperature a DS18B20 1-Wire digital temperature sensor from Maxim IC will be used. It can measures temperatures from -55°C to +125°C. Fahrenheit equivalent is -67°F to +257°F with ±0.5°C accuracy.
We choose a waterproofed version of the DS18B20 Temperature sensor. It is quite handy to measure something far away, or in wet conditions.
You can see it here
You can see the Data Sheet
Temperature Compensation Formula:
minus 0.018 volts per degree Celsius
Example :
1. Let the battery temperature is 0 degC and float voltage is 13.8V ( STC : at 25degC )
Compensation Required = ( 0 - 25) * ( - 0.018 ) = + 0.45V
Compensated Float Voltage = 13.8 + 0.45 = 14.25 V
2. Let the battery temperature is 35 degC and float voltage is 13.8V ( STC : at 25degC )
Compensation Required = ( 35 - 25) * ( - 0.018 ) = - 0.18V
Compensated Float Voltage = 13.8 - 0.18= 13.62 V
So cold batteries ( example-1) require a higher charge voltage in order to push current into the battery plates and electrolyte, and warmer batteries( example-2 ) require a lower charge voltage to eliminate potential damage to valve regulated lead acid (VRLA) cells and reduce unnecessary gassing if flooded cells are used.
Reference : http://solarprofessional.com
-
Software requirements for MPPT controller V3.1
08/30/2015 at 15:06 • 2 commentsSoftware requirements for MPPT controller V3.1
Draft by Keith Hungerford, updated 12th September 2015
Charging states
The charger operates in one of several charging states, depending on the sunlight level.
Charger OFF state
At nil or low sunlight levels, as indicated by solar voltage below battery voltage + 0.5 Volts, the charger state is OFF.
Transition from the OFF state occurs when
a) if battery voltage is greater than 11.5 volts and solar voltage rises above battery voltage + 0.5 Volts
b) if battery voltage is less than 11.5 volts and solar voltage rises above 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 battery voltage is greater than the Float voltage;
ii) Boost state if the battery voltage is less than the Float voltage and the Boost time since the last night time is less than [1 hour];
iii) Bulk state if the battery voltage is less than the Float voltage and the Boost time since the last night time is greater than [1 hour]
In all 3 cases initially the controller will use the DCM charging algorithm.
Boost DCM and Bulk DCM states
When in the Boost DCM or Bulk DCM state, the charger can go to OFF state if the solar voltage falls below (battery voltage + 0.5 Volts).
The charger can go to Boost CCM or Bulk CCM state if the Solar Power rises above 10% of the rated power.
The charger can go to the Float state if Battery voltage rises above Float.
The charger can go from Boost DCM to Bulk DCM if the Boost time since the last night is greater than Boost duration.
Boost CCM and Bulk CCM states
When in the Boost CCM or Bulk CCM state the charger can go to Boost DCM or Bulk DCM if the Solar Power falls below 10% of rated power.
- The charger can go from Boost CCM to Bulk CCM if the Boost time since the last night is greater than Boost duration
Float stateThe float state is functionally the same as Bulk state when the battery voltage reaches Float.
When in Float state the charger keeps just sufficient current flowing to the battery to maintain the battery voltage at Float.
Charging algorithms
CCM algorithm
Continuous Current Mode (CCM) applies when the available solar power is more than 10% of the rated power (strictly, when the current in the inductor always flows towards the battery, but this is difficult to measure directly in the software so we use the power level as a proxy estimate).
In this mode, the PWM period is set at 12 microseconds. The PWM duty cycle is set either at a value that achieves maximum power, or to meet the charging voltage required by the battery (see battery management conditions below). When it is required to reduce the charging rate so as to limit the battery voltage, the PWM duty is reduced, thereby increasing the panel voltage above the maximum power point and reducing the current accordingly.
The Fast PWM mode of the Arduino is used to generate this PWM. The PWM period of 12 microseconds is 192 clock cycles at 16 MHz. The PWM period is divided into a Panel Connect phase followed by an Earth Connect phase. The length of the Panel Connect phase is controlled by PWM Duty.
When maximising power, the power level is measured approximately every 0.5 milliseconds and is compared to the previous power level measurement. The PWM duty cycle is changed up or down by 1 CPU clock cycle after every measurement. After the first measurement, the PWM duty cycle is increased. On subsequent measurements, if the power level is increased or is the same as the previous measurement, the PWM duty cycle is changed in the same direction as in the previous cycle. If the power level is decreased from the previous cycle, the PWM duty cycle is changed to go in the opposite direction to that in the previous cycle.
When tracking the allowable battery voltage, the battery voltage is measured approximately every 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 duty is left unchanged. If the new value is higher than the target value by more than 0.1 volts, the PWM duty is increased by one step. If the new value is lower than the target value by more than 0.1 volts, the PWM duty is decreased by one step.
Whether maximising power or tracking battery voltate, the battery charging current must not be allowed to exceed 105% of the rated current. If the battery 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 available 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 cycles at 16 MHz. The PWM period is divided into three phases: a Panel Connect phase, followed by an Earth Connect phase, followed by a Null phase. The length of the Panel Connect phase is controlled by PWM Duty through setting a “1” on both IN and SD pins of driver IC No. 2 (which drives Q2 and Q3). The length of the Earth Connect phase is controlled by 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 both “0”, so that both transistors are OFF.
In this mode the length of the Earth Connect phase is set to be Panel Connect phase multiplied by the ratio of (Panel voltage - Battery voltage) to Panel voltage. Thus if the battery voltage is 13 and the panel voltage is 19.5 volts, the Earth 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 Earth connect phase will last 3 microseconds. In this case the Null phase will be (100 – 9 – 3) = 88 microseconds.
When maximising power, the power level is measured approximately every 0.5 milliseconds and is compared to the previous power level measurement. The Panel Connect time is changed up or down by 1 CPU clock cycle after every measurement. The Earth Connect time is changed to follow the Panel Connect time. After the first measurement, the Panel connect time is increased. On subsequent 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 cycle. If the power level is decreased from the previous cycle, the Panel connect time is changed to go in the opposite direction to that in the previous cycle. Once the new Panel connect time is known, the corresponding Earth connect time is calculated.
Since the Panel connect time and Earth connect time are defined in integer numbers of clock cycles, it will often not be possible to make the Earth connect time the exact multiple of the Panel connect time required for the ratio of (Panel voltage - Battery voltage) / Panel voltage. In this case the Earth connect time should be made the next lowest integer of clock cycles, below the exact value.
When tracking the allowable battery voltage, the battery voltage is measured approximately every 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 by more than 0.1 volts, the Panel connect time is increased by one step. If the new value is lower than the target value by more than 0.1 volts, the Panel connect time is decreased by one step. Then the corresponding Earth 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 MOSFETs (Q1, Q2 and Q3) are turned OFF in this state.
Battery management
Float charging :
When battery voltage exceeds the Float value, the charger goes into a Float Charging state which provides just enough current to keep the battery within 0.1 volts of the Float value.
Bulk charging :
When sufficient solar power is available, the charger goes into a Bulk Charging state using the appropriate algorithms (DCM or CCM). In this state the battery voltage will be allowed to go up to Float voltage and the battery charging current must not be allowed to exceed 105% of the rated current. If the battery voltage reaches Float voltage – 0.1 volts, or the current reaches the rated current, the charging rate is reduced to stay below those limits.
Boost charging :
For a maximum of Boost Duration in each daily charging cycle, the battery voltage will be allowed to go up to Boost Voltage, provided the battery voltage has fallen below the Boost Reconnect voltage since the previous boost charging period. During this state, the battery charging current must not be allowed to exceed 105% of the rated current. If the battery voltage reaches Boost Voltage, or the charging current reaches the rated current, the charging rate is reduced to stay below those limits.
Battery management parameters
The controller will use the following parameters to manage the battery charge and discharge:
Float voltage 13.8 volts
Boost voltage 14.2 volts
Boost reconnect voltage 13.2 volts
Low Voltage Disconnect 11.1 volts
Low Voltage Reconnect 12.6 volts
Boost duration 1 hour
The values given above are the default for 25 degrees Celsius. If a temperature sensor is installed, these voltages should all be adjusted by minus 0.018 volts per degree Celsius. For example, at 0 degrees C the Float voltage would become 13.8 + 25*0.018 = 14.25 volts.
Load control states
This function controls the load MOSFET(Q4).
Via the serial monitor, the user can select either After Dark Lighting mode or Continuous mode.
Load control algorithms
1. Battery discharge protection
If the battery voltage falls below Low Voltage Disconnect voltage the load is disconnected.
Once the battery voltage rises to the Low Voltage Reconnect voltage the load is reconnected.
2. After dark Lighting
ON: Turn on loads at night (when the solar panel is producing less than 5% power) and the battery voltage is not disconnected due to the Low Voltage Disconnect logic.
OFF: Turn off loads in day time as well as due to the Low Voltage Disconnect logic.
3. Continuous
Turn on the load at all times subject to the Low Voltage Disconnect logic.
LED display
This function display the current state of charge of the battery via LED as follows:
- YELLOW means overvoltage (over Float voltage)
- RED means undervoltage (disconnected due to battery voltage falling below Low Voltage Disconnect, and still below Low Voltage Reconnect voltage)
- GREEN is Normal, ie above LVD / LVR and at or below Float voltage.
LCD displayThis function is used to display the status of solar panel, battery and load of the controller on a 20X4 character I2C LCD display.
WiFi data logging
This function sends parameters (sol voltage, current, power & battery voltage, charging current etc) to the www.thingspeak.com via a ESP8266 wifi module.
First the wifi module will connect to the wifi router automatically (User has to set the SSID, Router Password and Thingspeak API key).
If the Wifi module connects successfully, it will transmit data to wifi @ 15sec intervals (this may be greatly reduced after development is complete, to maybe once every 15 minutes or even once per hour).
Current Status : Working but wifi module has to be first connected to the router by 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 USB port useful for debugging.
It also provides a command line interface for changing settable parameters in the controller. Settable parameters are:
Load control mode (After Dark or Continuous);
Battery management values (see battery management section).
In basic 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 "type LIST for a list of commands, type START to restart data logging".
If the user types "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 any value.
Hardware interfaces
The following pins will be 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
// A2 - Voltage divider (battery) 100K / 20 K scale factor 0.029296875
// A3 - ACS 712 Battery current scale factors for 5A unit: current 0.026393581 Offset 13.5135135
// A4 - LCD SDA
// A5 - LCD SCL
// A6 - ACS 712 Battery current scale factors for 5A unit: current 0.026393581 Offset 13.5135135
// A7 - not used
// D0, D1 - reserved, USB port
// D2 - ESP8266 Tx
// D3 - ESP8266 Rx through the voltage divider
// D4 - temperature from DS18B20 probe
// D5 - LCD back light control button
// D6 - Load Control
// D7 - not used
// D8 - not used
// D9 – IR2104 MOSFET driver IN
// D10 – IR2104 MOSFET driver SD
// D11- Green LED
// D12- Yellow LED
// D13- Red LED
-
Overview of Version-3.1
08/30/2015 at 14:50 • 7 commentsAfter lot testing we observed that MOSFET ( Q3 ) in ver-3.0 design is burning repeatedly.We tried to modify the existing software but not find any satisfactory result.
The other problem was that MOSFET Q1 ( in V-3.0) conduct even when there is no solar input.
To solve the above problems and enhance the power handling capability we are modifying both 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)
Q1, Q2 and Q3 all pairs of IRFZ44N MOSFETs (6 in all).
C1 will be 3 * 220 uF low ESR capacitors in parallel,
C2 will be a single 220 uF low ESR capacitor
Single ACS712 on the panel side as per version 3.0
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 about 3.1 m of wire).
Q2 will be a pair of FDP150N10A MOSFETs in parallel.
C1 will be 5 * 220 uF low ESR capacitors in parallel,
C2 will be a single 220 uF low ESR capacitorTwo ACS712, one on the panel side as per version 3.0 and one in series with the battery.
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 about 4.5 m of wire).
Q2 will be a pair of FDP150N10A MOSFETs in parallel.
C1 will be 6 * 220 uF low ESR capacitors in parallel,
C2 will be 2 * 220 uF low ESR capacitors in parallel.Three ACS712, one on the panel side as per version 3.0, one in series with the battery and one in series with the load.
Here is a rough sketch for V-3.1
You can download the complete schematic from here
We are working on new PCB for V-3.1 Here is the sample of one
The drive circuitry (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 by 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 about 1 ms. Driver 2 is driven directly (as in the current circuit, but probably with a slightly higher series resistor to allow more current for the Q1 driver and its RC filter).
In driver chip 3, IN is driven by D9 and SD is driven by D10.
The purpose of using separate drivers for Q2 and Q3 is to enable us to switch Q3 OFF to operate in Asynchronous mode at low current levels when the controller will be in DCM (Discontinuous Current Mode). There may be a better way to do this but in the short time we have available this is a simple option and easy and reliable to implement.
All 3 versions should have LCD displays, WiFi, LED indicators (maybe with a more fancy coding scheme to separately indicate DCM and CCM).
All 3 versions should be able to cope with either 18 V or 30 V panels, and use algorithms that stop them burning out if the panel can produce more current than the rating allows. This can all be done auto-detect.
All the components exposed to panel voltage need to be rated for at least 40 V (in particular C1 and our buck 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 commentsPanel model consists of a simple step-wise linear model of a solar panel.See the above figure.
1. Constant Current : up to 18 volts
2. Constant Power : between 18 and 19 volts
3. Power decline linearly to zero : between 19 and 21 volts
4. Zero Current and Power : above 21 volts
In the spread sheet attached below there are 5 MPPT models.Here is some brief description on each.
1. MPPT model 1 implements the logic flow chart as shown in above 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 easy to adjust it for fixed or variable 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 functionally the same as Model 4. It uses three branches 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 duty cycles.
Models 1 to 3 all exhibit similar characteristics, as follows:
They all converge satisfactorily when given a high PWM starting point (above 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 above the maximum cut-off voltage.
The MPPT model 4 corrects this last problem by constantly increasing the PWM (ie decreasing the derived voltage) in the case of equal (ie zero) power. It will always find the MPP of the panel model no matter what starting point is used. It may take more steps than provided in the examples, but it always converges.
MPPT model 4 also sweeps the total maximum power area.
To clarify this: Models 1 to 3 when converged all oscillate at the top or bottom edge of the MPP area, depending on whether they approached it from above or below.
It seems desirable for the tracking to sweep the whole MPP area, irrespective of which direction the approach came. This would better 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.
Integer arithmetic in PWM calculations :
At the hardware level, the current software uses Timer1 to produce the PWM signal at a 20 microsecond period.20 microseconds is 320 clock cycles of the Arduino clock (which is 16 MHz, ie with a period of 62.5 ns).Because the Timer1 library uses the “Phase and Frequency correct” PWM mode of Timer1, which counts both up and down, the setting of the TOP level (which defines the 20 microsecond period) is 160. The PWM duty can be changed in units of 2 clock cycles, or 125 ns.The integer calculation of PWM runs like this (using the current software):The MPPT code uses a 16 bit integer variable “pwm” to manage the duty cycle. It runs from 0 to 100 to represent 0 to 100% duty cycle, and can be stepped up or down by 1 unit (ie 1%) in each pass through the MPPT algorithm. The Timer1 library accepts PWM duty parameter in the form of a 16 bit integer variable which runs between 0 and 1023 to represent duty cycle as a fraction of 1024.
I will use an example to illustrate how the calculations run.
As an example we start with a desired PWM duty cycle of 70%, that is the integer “pwm” has a value of 70. To convert this to an integer between 0 and 1023 to pass to the Timer1 library, the software multiplies pwm (70) by 1023 (giving 71610.The MPPT code then divides this number by 100 giving 716, which it passes to the Timer1 library. 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 by 1024, it would still have produced 716 as the interface parameter value.When the Timer1 library receives the pwm duty cycle parameter, it multiplies it by 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 by 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 back 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 duty cycle of 69.375%.This is a systematic change. As we step the pwm integer up or down, the difference changes.Thus 70% becomes 69.375%, 71% becomes 70%, 72% becomes 71.25%, and so on. The step size on the input side is always 1%, but 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 duty cycle falls in a spot (like 70.625%) that cannot be accessed because of the nature of the integer arithmetic.
Download the Spreadsheet analysis from here
-
Quarter Final Video
08/15/2015 at 19:43 • 0 comments -
Keith Presentation
08/13/2015 at 12:30 • 0 commentskeith.hungerford ( team member ) from Australia, who is one of the major contributor to this project.He has experimented a lot on this project.After my request he made this nice video explaining the efficiency,losses at various load,how DCM will take care at low load condition, about the MPPT v4 controller and writing of a new Arduino TimerOne library to handle our requirement.
These are the loss analysis curves at different load condition.
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 balanced by the increase in the switching and capacitive drive loss. When Keith checked, he found that the capacitive drive losses are so nearly equal to the switching losses that the curves fully overlap and you cannot see the capacitive loss curve. It is more clear at 80% ( 80W ) load where both curves are visible.
As the load decreases, the resistive losses decrease and the relative influence of these period-dependent losses increases, but the pattern remains the same. In the MOSFETS, the importance of the switching losses decreases with decreasing load, since there is less current flowing and therefore a reduced amount of charge to be absorbed, even though the voltage excursion is unchanged. The capacitive losses come to dominate. Because 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 between the total loss at 11 microseconds and 14 microseconds is only 5% of the loss, so a single PWM period of around 14 microseconds is quite efficient SO LONG AS THE CONTROLLER IS IN CCM.
Somewhere below the 10 % load point, but above 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 always flow in the same direction.
His design assumption in this spreadsheet is that the controller algorithms explicitly support DCM. That is, they switch off Q3 at the time that the current would start flowing "backwards". 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 Earth 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 MOSFETs 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 battery or load. This creates extra voltage ripple at the panels, and at the battery/load.
So long as the voltage ripple at the panels and battery/load is within reasonable limits, in DCM it is better to have a much longer PWM period. Hence the appearance of very long PWM periods at very low load levels. The length of the PWM period is mainly limited by the voltage ripple tolerable at the battery, and the reduction in efficiency of the panel caused by the ripple there.
-
Finished the Soldering
08/12/2015 at 03:22 • 3 commentsPurchased all the missing components and started to solder it on PCB.After few hours of work, everything is soldered.I have tested auxiliary power circuitry,everything 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 commentsToday I soldered most of the components on the new PCB.But few components are not available in my stock.So I can't solder them.I will solder the remaining components after buying it from my local shop.
The following components are missing
1.Fuse Holder
2.TVS Diodes
3.5.1V Zener Diode
4.USB Port
-
Improvement in LCD Display Function
08/11/2015 at 15:57 • 1 commentThe LCD display functionality is improved.The above video shows the simulation to test the modified software.
These are the improvements
1. Dynamic battery status in battery icon.Earlier it was always showing about half full .Now it changes according to the battery SOC, just like in cell phone.
2. Removing the long if else statement for displaying the battery SOC. Now used a math function to do the job.
3. Adding a spinner icon to show the charger is running.It stops when program stuck up.
Code before Modification :
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 }
Code After Modification :
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 • 1 commentOn 4th August 2015, I received the PCB from fab house.It is manufactured locally at PCB Power.The board are looking really nice.The size of the board is 12.5mm x 10mm.
This is 3D out look of the board after soldering the components.