first commit
This commit is contained in:
110
ESP32_XY6020L_TEST/ESP32_XY6020L_TEST.ino
Normal file
110
ESP32_XY6020L_TEST/ESP32_XY6020L_TEST.ino
Normal file
@@ -0,0 +1,110 @@
|
||||
/**
|
||||
* @file dcdcmbus.ino
|
||||
* @brief usage of XY6020L DCDC for simple max power point tracking of
|
||||
* a solar module driving a electrolytic cell
|
||||
* Cells voltage start from ~3 V and current will rise up to ~3A at 4 V.
|
||||
* At ~19 V the 20V pannel has its maximum power.
|
||||
* Simple I-controler increases the cell voltage till the power consumption
|
||||
* from the solar panel drives its voltage below 19 V.
|
||||
Hardware: Arduino Pro Micro Clone from China
|
||||
*
|
||||
* @author Jens Gleissberg
|
||||
* @date 2024
|
||||
* @license GNU Lesser General Public License v3.0 or later
|
||||
*/
|
||||
|
||||
#include "xy6020l.h"
|
||||
#define PIN_SOFTWARE_SERIAL_RX2 25
|
||||
#define PIN_SOFTWARE_SERIAL_TX2 26
|
||||
// dcdc's MBus is connected to Serial2 of Arduino
|
||||
xy6020l xy(Serial2, 0x01, 50, XY6020_OPT_SKIP_SAME_HREG_VALUE | XY6020_OPT_NO_HREG_UPDATE);
|
||||
|
||||
long ts;
|
||||
byte MemIdx;
|
||||
tMemory Mem;
|
||||
|
||||
void setup() {
|
||||
// debug messages via USB
|
||||
Serial.begin( 115200);
|
||||
// MBus serial
|
||||
// Serial2.begin( 115200);
|
||||
Serial2.begin(115200, SERIAL_8N1, PIN_SOFTWARE_SERIAL_RX2, PIN_SOFTWARE_SERIAL_TX2); // Rx = 4, Tx = 5 will work for ESP32, S2, S3 and C3
|
||||
|
||||
|
||||
|
||||
ts = millis();
|
||||
MemIdx = 0;
|
||||
|
||||
//18:51:25.551 -> V-SET = 1200 (Voltage setting)
|
||||
//18:51:25.551 -> I-SET = 500 (Current setting)
|
||||
//18:51:25.551 -> S-LVP = 1000 (Low voltage protection value)
|
||||
//18:51:25.551 -> S-OVP = 1300 (Overvoltage protection value)
|
||||
//18:51:25.551 -> S-OCP = 620 (Overcurrent protection value)
|
||||
//18:51:25.551 -> S-OPP = 1040 (Over power protection value)
|
||||
//18:51:25.551 -> S-OHP_H = 0 (Maximum output time - hours)
|
||||
//18:51:25.551 -> S-OHP_M = 0 (Maximum output time - minutes)
|
||||
//18:51:25.551 -> S-OAH = 0 (Maximum output charge Ah)
|
||||
//18:51:25.551 -> S-OWH = 0 (Maximum output energy Wh)
|
||||
//18:51:25.551 -> S-OTP = 110 (Over temperature protection)
|
||||
//18:51:25.551 -> S-INI = 0 (Power-on output switch)
|
||||
Mem.Nr = MemIdx;
|
||||
Mem.VSet = 1200;
|
||||
Mem.ISet = 500;
|
||||
Mem.sLVP = 1000;
|
||||
Mem.sOVP = 1300;
|
||||
Mem.sOCP = 620;
|
||||
Mem.sOPP = 1040;
|
||||
Mem.sOHPh= 0;
|
||||
Mem.sOHPm= 0;
|
||||
Mem.sOAH = 0;
|
||||
Mem.sOWH = 0;
|
||||
Mem.sOTP = 110;
|
||||
Mem.sINI = 1;
|
||||
xy.SetMemory(Mem);
|
||||
xy.PrintMemory(Mem);
|
||||
|
||||
// xy.setOutput(false);
|
||||
// xy.setCV(0);
|
||||
// xy.setCC(0);
|
||||
xy.ReadAllHRegs();
|
||||
while(!xy.HRegUpdated())
|
||||
xy.task();
|
||||
}
|
||||
|
||||
int cc=1;
|
||||
int v = 100;
|
||||
void loop() {
|
||||
int vDiff;
|
||||
char tmpBuf[30]; // text buffer for serial messages
|
||||
word tmpW1, tmpW2;
|
||||
|
||||
xy.task();
|
||||
|
||||
// 100 ms control period
|
||||
if (millis() > ts + 10000)
|
||||
{
|
||||
xy.setCC(100);
|
||||
///v+=100;
|
||||
xy.setCV(1100);
|
||||
xy.setOutput(true);
|
||||
Mem.sINI = 1;
|
||||
xy.SetMemory(Mem);
|
||||
Serial.print("Vin = "); Serial.println(xy.getInV());
|
||||
|
||||
Serial.print("V = "); Serial.print(xy.getCV()); Serial.print(" isV = "); Serial.println(xy.isCV());
|
||||
|
||||
Serial.print("C = "); Serial.print(xy.getCC());Serial.print(" isC = "); Serial.println(xy.isCC());
|
||||
|
||||
Serial.print("ActV = "); Serial.println(xy.getActV());
|
||||
|
||||
Serial.print("ActC = "); Serial.println(xy.getActC());
|
||||
Serial.print("ActP = "); Serial.println(xy.getActP());
|
||||
|
||||
ts = millis();
|
||||
// Mem.Nr=MemIdx;
|
||||
// if( xy.GetMemory(&Mem) )
|
||||
// {
|
||||
// xy.PrintMemory(Mem);
|
||||
// }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user