Diagram As

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

Diagramas

uint8_t Bateria[8] = {0x0E, 0x1B, 0x11, 0x11, 0x1F, 0x1F, 0x1F, 0x1F};
uint8_t Panel[8] = {0x1F, 0x15, 0x1F, 0x15, 0x1F, 0x15, 0x1F, 0x00};
uint8_t Pwm[8] = {0x1D, 0x15, 0x15, 0x15, 0x15,0x15, 0x15, 0x17};
uint8_t flash[8] = {0x01, 0x02, 0x04, 0x1F, 0x1F, 0x02, 0x04, 0x08};

Definición de Constante
#define bulk_voltaje_max 14.5
#define bulk_voltaje_min 13
#define absorcion_voltaje 14.7
#define float_voltaje_max 13
#define bateria_min_voltaje 10
#define solar_min_voltaje 19
#define carga_current 2.0
#define absorcion_max_current 2.0
#define absorcion_min_current 0.1
#define float_voltaje_min 13.2
#define float_voltaje 13.4
#define float_max_current 0.1
#define LCD_refresh_rate 1000
byte BULK = 0;
byte ABSORCION = 1;
byte FLOAT = 2;
byte mode = 0;

Definición de Entradas para los puertos digitales del módulo Arduino nano A0 –
A2
#define solar_voltaje_in A1
#define solar_current_in A0
#define bateria_voltaje_in A2

Definición de Salidas para los puertos digitales del módulo Arduino nano
#define PWM_out 10
#define load_enable 2

Definición de Variables
float bat_voltaje = 0;
int pwm_value = 0;
float solar_current = 0;
float current_factor = 0.185;
float solar_voltaje = 0;
float solar_power = 0;
String load_status = "OFF";
int pwm_porcentaje = 0;
unsigned int before_millis = 0;
unsigned int now_millis = 0;
String mode_str = "BULK";

Cuerpo de la Programación
void setup(){
pinMode(solar_voltaje_in,INPUT);
pinMode(solar_current_in,INPUT);
pinMode(bateria_voltage_in,INPUT);
pinMode(PWM_out,OUTPUT);
digitalWrite(PWM_out,LOW);
pinMode(load_enable,OUTPUT);
digitalWrite(load_enable,LOW);
TCCR1B = TCCR1B & B11111000 | B00000001;
Serial.begin(9600);
lcd.init();
lcd.backlight();
lcd.createChar(0, Bateria);
lcd.createChar(1, Panel);
lcd.createChar(2, Pwm);
lcd.createChar(3, Flash);
before_millis = millis; //Used for LCD refresh rate
}

void loop(){
solar_voltaje = get_solar_voltaje(15);
bat_voltaje = get_bateria_voltaje(15);
solar_current = get_solar_current(15);
solar_power = bat_voltaje * solar_current;
pwm_porcentaje = map(pwm_value,0,255,0,100);
now_millis = millis();
if(now_millis - before_millis > LCD_refresh_rate)
{
before_millis = now_millis;
lcd.clear();
lcd.setCursor(0,0);
lcd.write(1);
lcd.print(" ");
lcd.print(solar_voltage,2);
lcd.print("V");
lcd.print(" ");
lcd.write(0);
lcd.print(" ");
lcd.print(bat_voltage,2);
lcd.print("V");
lcd.setCursor(0,1);
lcd.print(" ");
lcd.print(solar_current,2);
lcd.print("A");
lcd.print(" LOAD ");
lcd.print(load_status);
lcd.setCursor(0,2);
lcd.print(" ");
lcd.print(solar_power,2);
lcd.print("W");
lcd.print(" PWM ");
lcd.print(pwm_percentaje);
lcd.print("%");
lcd.setCursor(0,3);
lcd.print(mode_str);
}
if(bat_voltaje < bateria_min_voltaje){
digitalWrite(load_enable,LOW);
}
else{
digitalWrite(load_enable,HIGH);
}

Flotante

if(mode == FLOAT){
if(bat_voltaje < float_voltaje_min){
mode = BULK;
mode_str = "BULK";
}
else{
if(solar_current > float_max_current){
mode = BULK;
mode_str = "BULK";
}//End if >
else{
if(bat_voltaje > float_voltaje){
pwm_value--;
pwm_value = constrain(pwm_value,0,254);
}

else {
pwm_value++;
pwm_value = constrain(pwm_value,0,254);
}
}//End else > float_max_current
analogWrite(PWM_out,pwm_value);
}
}//END of mode == FLOAT

Absorción de la Energía
else{
if(bat_voltaje < bulk_voltaje_min){
mode = BULK;
mode_str = "BULK";
}
else if(bat_voltaje > bulk_voltaje_max){
mode_str = "ABSORCIÓN";
mode = ABSORCIÓN;
}

Bulk

if(mode == BULK){
if(solar_current > charging_current){
pwm_value--;
pwm_value = constrain(pwm_value,0,254);
}
else {
pwm_value++;
pwm_value = constrain(pwm_value,0,254);
}
analogWrite(PWM_out,pwm_value);
}

Absorción de la Energía

if(mode == ABSORCIÓN){
if(solar_current > absorcion_max_current){
pwm_value--;
pwm_value = constrain(pwm_value,0,254);
}
else{
if(bat_voltaje > absorcion_voltage){
pwm_value++;
pwm_value = constrain(pwm_value,0,254);
}
else {
pwm_value--;
pwm_value = constrain(pwm_value,0,254);
}
if(solar_current < absorcion_min_current){
mode = FLOAT;
mode_str = "FLOAT";
}
}
analogWrite(PWM_out,pwm_value);
}
}
}

Función

float get_solar_voltaje(int n_samples)


{
float voltaje = 0;
for(int i=0; i < n_samples; i++)
{
voltaje += (analogRead(solar_voltaje_in) * (5.0 / 1023.0) * 8.0);
}
voltaje = voltaje/n_samples;
if(voltaje < 0){voltaje = 0;}
return(voltaje);
}
float get_bateria_voltaje(int n_samples)
{
float voltaje = 0;
for(int i=0; i < n_samples; i++)
{
voltaje += (analogRead(batia_voltaje_in) * (5.0 / 1023.0) * 7.85);
}
voltaje = voltaje/n_samples;
if(voltaje < 0){voltaje = 0;}
return(voltaje);
}
float get_solar_current(int n_samples)
{
float Sensor_voltaje;
float current =0;
for(int i=0; i < n_samples; i++)
{
Sensor_voltaje = analogRead(solar_current_in) * (5.0 / 1023.0);
current = current + (Sensor_voltage-2.5)/current_factor;
}
current = current/n_samples;
if(current < 0){current = 0;}
return(current);
}

You might also like