Hi guys,
I am working on an MPPT controller. There is a 40W solar panel which will be connected to a DC-DC converter which then powers a 12V LED strip at the moment. The DC-Dc converter is controlled via PWM output from the Arduino. The Arduino also senses voltage and currents to calculate power. These will also be displayed on the 16x2 LCD. I am having a few issues.
Issue 1: Only the second row of the LCD updates every 500ms. The first row never updates.
Issue 2: The MPPT code does not work. The duty cycle does not change based on the power. I believe this is a problem with my programming logic.
I have posted the code below. Could someone please help?
// include the library code:
#include <LiquidCrystal.h> // For the LCD
#include <PWM.h> // For PWN control
int duty = 180; // dutycycle = 0.706*255
int32_t frequency = 490000; // switching frequency
float Po_old = 0.00;
float Po_new = 0.00;
float inc = 1; // duty cycle increment value
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup()
{
InitTimersSafe();
bool success = SetPinFrequencySafe(9, frequency);
if (success) //If success, then light up LED on pin 13
{
pinMode (13, OUTPUT);
digitalWrite(13, HIGH);
}
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
}
void loop()
{
pwmWrite(9, duty); // PWM output through pin 9
// Read values from the sensors
float VinValue = analogRead(A0);
float CinValue = analogRead(A1);
float VoValue = analogRead(A2);
float CoValue = analogRead(A3);
float Vin = VinValue*25/1023;
float Cin = CinValue*5/1023;
float Vo = VoValue*25/1023;
float Co = CoValue*5/1023;
// Calculate powers
float Pin = Vin*Cin;
float Po_new = Vo*Co;
// MPPT algorithm
if(Po_new >= Po_old)
{
duty = duty + inc;
}
else
{
duty = duty - inc;
}
Po_old = Po_new;
// Print values
lcd.print(Vin);
lcd.print(" ");
lcd.print(Cin);
lcd.print(" ");
lcd.print(Pin);
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
lcd.setCursor(0, 1);
lcd.print(Vo);
lcd.print(" ");
lcd.print(Co);
lcd.print(" ");
lcd.print(Po_new);
delay(500);
}