MPPT Implementation: Charging and Discharging in ISIS Proteus

Lefouilleur Posted messages 1 Status Member -  
jeannets Posted messages 28374 Registration date   Status Contributor Last intervention   -
I'm turning to you today after long reflection on my topic that dates back already.

Indeed, I need to implement an MPPT. For this, I have chosen the following tools:

A solar panel
An Arduino Mega 2560 board
A buck converter
A battery
I am currently in the simulation phase and I am encountering several problems, so I would like to solve them one by one.

The first one that is really blocking me is that I cannot simulate the charging and discharging of my battery. For that, I implore your help to resolve this issue.

NB: For my simulation, I tried to connect the battery in series with a resistor, but I am not observing anything. I even tried using a voltage generator in series with a resistor, but still nothing.

Thank you in advance, and I am available for any misunderstanding.



Here is the code used with Arduino Mega 2560

#include <LiquidCrystal.h>
#include "TimerOne.h" // using Timer1 library from https://playground.arduino.cc/Code/Timer1/

#include <LiquidCrystal.h>
#include "TimerOne.h" // using Timer1 library from https://playground.arduino.cc/Code/Timer1/

// Definition of the purpose of the pins
#define PWM10 10 // 10 Timer 2
#define Led13 13 // 13 for the yellow led on the board
#define BP1 30 // 30 BP1
#define BP2 31 // 31 BP2
#define PWM_MAX 100 // the value for pwm duty cyle 0-100%
#define PWM_MIN 60 // the value for pwm duty cyle 0-100%
#define PWM_START 90 // the value for pwm duty cyle 0-100%

LiquidCrystal monEcran(27,28,25,24,23,22); // creating the screen object

/* Example code for the analogRead() function.
  • /


float Vn ; // Pn_1 Represents Pn which is the value of the panel voltage
float Vb ; // Pn Represents Pn which is the value of the battery voltage
float In; // This is the current from the panel
float Pn ; // panel power
float Pn_1 = 0; // Pn_1 Represents Pn-1 which is the previous value of Pn
float Vn_1 = 0; // Pn_1 Represents Pn-1 which is the previous value of Pn
byte K=1;
byte pwm ; // pwm duty cycle 0-100%
//int consigne = 8;

// Setup function, called at startup of the Arduino board
void setup()
{

monEcran.begin(20,4); // initialize communication with 20 columns and four rows

TCCR2B = TCCR2B & 0b11111000 | 0x01; //Frequency division by 1 //frequency: 32500Hz, 7692Hz,

pinMode(PWM10, OUTPUT );
pinMode(Led13, OUTPUT); // Arduino board led
Timer1.initialize(300000); // initialize timer1, and set a 0.1 second period => 100 000 for 0.01s 10 000
Timer1.attachInterrupt(callback); // attaches callback() as a timer overflow interrupt

// analogWrite(PWM10, 128);
// which is at the new chosen frequency

}

// Function to adjust the PWM

//void Rapport_cyclic_pwm(void)
//{
// if (pwm > PWM_MAX) // check limits of PWM duty cyle and set to PWM_MAX
// {
// pwm = PWM_MAX;
// }
// else if (pwm < PWM_MIN) // if pwm is less than PWM_MIN then set it to PWM_MIN
// {
// pwm = PWM_MIN;
// }
//
// if (pwm < PWM_MAX)
// {
// Timer1.pwm(PWM10,(PWM_FULL * (long)pwm / 100), 20); // use Timer1 routine to set pwm duty cycle at 20uS period
// //FlexiTimer2.pwm(PWM_PIN,(PWM_FULL * (long)pwm / 100));
// }
// else if (pwm == PWM_MAX) // if pwm set to 100% it will be on full but we have
// {
// Timer1.pwm(PWM10,(PWM_FULL - 1), 1000); // keep switching so set duty cycle at 99.9% and slow down to 1000uS period
// //FlexiTimer2.pwm(PWM_PIN,(PWM_FULL - 1));
// }
//} // End of the function to adjust the PWM

// Loop function, called continuously in a loop as long as the Arduino board is powered
/* Data reading function*/
void callback() {
digitalWrite(Led13,HIGH); // measure the time of the routine
// Measures the voltage on pin A0
Vn = analogRead(A0);

// Measures the current on pin A1
In = analogRead(A1);

// Converts the measured value (integer) into the voltage of the photovoltaic panel via cross-multiplication
Vn = Vn*25;
Vn = Vn/1023;

// Converts the measured value (integer) into the panel current
In = In*5;
In = In/1023;

// Measures the voltage on pin A0
Vb = analogRead(A2);

// Converts the measured value (integer) into the voltage of the photovoltaic panel via cross-multiplication
Vb = Vb*25;
Vb = Vb/1023;

// just writes the value of 0 to 255 of the duty cycle of the signal

if(Pn>Pn_1)
{
if(Vn>Vn_1)
{
pwm = pwm-1;
//Rapport_cyclic_pwm();
}
else
{
pwm = pwm + 1;
//Rapport_cyclic_pwm();
}
}
else
{
if(Vn>Vn_1)
{
pwm = pwm+1;
// Rapport_cyclic_pwm();
}
else
{
pwm = pwm-1;
//Rapport_cyclic_pwm();
}
}

// delay(30); // using timer0
Pn_1 = Pn;
Vn_1 = Vn;

digitalWrite(Led13,LOW); // measure the time of the routine
} // end of routine

/* Function to display the data*/

void Affich_data(void)
{
monEcran.setCursor(0,0);
monEcran.print("Up");
monEcran.setCursor(5,0);
monEcran.print("Ip");

monEcran.setCursor(10,0);
monEcran.print("P");

monEcran.setCursor(15,0);
monEcran.print("pwm"); // Display the duty cycle

monEcran.setCursor(0,2);
monEcran.print("Vb");

// Sends the measurement to (Vn,1);
// LCD for display

monEcran.setCursor(0,1); // clear 1 line
monEcran.print(" ");
monEcran.setCursor(0,1);
monEcran.print(Vn,1);
// Sends the measurement to the LCD for display
monEcran.setCursor(5,1);
monEcran.print(In, 1);

// Calculation of nominal power
Pn= Vn*In;
monEcran.setCursor(10,1);
monEcran.print(Pn, 1); // Display to one decimal

monEcran.setCursor(15,1);
monEcran.print(pwm); // Display to one decimal

monEcran.setCursor(0,3);
monEcran.print( Vb, 1); // Display to one decimal
monEcran.setCursor(15,2); // column, line
monEcran.print("BP1"); // display BP1
}

void loop()
{

Affich_data();

} // end loop

1 answer

jeannets Posted messages 28374 Registration date   Status Contributor Last intervention   Ambassadeur 6 599
 
Hello,

1° -- I can't read your diagram, it's too small and can't be enlarged, you should rather upload it to cjoint.com and then paste the link here.

2° -- Your battery... lead or lithium?? The series resistance is more for lead.

3° -- To establish the potential difference that will allow the charge current, your charging voltage must be higher than that of the battery at its highest point... e.g. charge 18 volts for a 12-volt battery which will be around 14.4v when fully charged.

4° -- Your resistance should be such that it allows a current of 1/10th of the battery power, e.g. a 45A/h battery charged at 4.5A for 14 hours... (here 0.8 ohm for this example)

--- This is not an elaborate formula, it's more of an empirical rule, but it works quite well... So 1/10th of the current for 14 hours.

If you can do that, you will also be able to do the rest or do it differently.

As for your Arduino language, I'm not familiar with it, there may be mistakes...?? I'm only giving you the help I know..
0