board
Solar MPPT Power System
Public Unreviewedby TylerK
A 30 W solar battery charger with regulated 5 V and 3.3 V rails: an STM32G031 running perturb & observe MPPT and a CC/CV charge state machine, steering a TI LM5175 4-switch buck-boost through a single analog control input. Four-layer KiCad board, schematic and PCB generated from Python, with an electrothermal simulation run against the published board file.
main
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
/*
* plant.h -- a physical model of the panel, the LM5175 converter and the
* battery, good enough to exercise charge_control.c on a host PC.
*
* This is not a circuit simulator. It exists to answer control questions:
* does the state machine reach the right states, does the arbitrator ever
* let a current exceed its limit, does P&O converge on the maximum power
* point and stay there. For that, what matters is that the plant reproduces
* the one relationship the controller actually steers by -- charge current
* as a function of commanded battery-bus voltage, with a genuine maximum in
* the middle of the range, which is what makes P&O a non-trivial problem.
*/
#ifndef PLANT_H
#define PLANT_H
#include <stdint.h>
typedef struct {
/* panel */
float voc; /* open-circuit voltage at present irradiance */
float isc; /* short-circuit current at present irradiance */
/* battery */
float batt_ocv; /* open-circuit (rest) voltage, rises with charge */
float batt_rint; /* internal resistance, ohms */
float batt_capacity_ah;
/* converter */
float efficiency;
/* externally applied load current drawn from the battery bus */
float load_a;
/* power-good inputs the controller reads */
uint8_t mppt_pgood;
uint8_t bias_pgood;
/* --- outputs, updated by plant_step() --- */
float vbus; /* actual battery-bus voltage achieved */
float ichg; /* actual current into the battery */
float iin; /* actual panel current */
float ppanel; /* actual power drawn from the panel */
float panel_v; /* panel operating voltage */
} plant_t;
void plant_init(plant_t *p);
/* Panel power available at a given operating voltage. */
float plant_panel_power_at(const plant_t *p, float v);
/* The panel's true maximum power point, found by sweep -- the value P&O is
* supposed to discover on its own, used only by the tests to grade it. */
float plant_panel_pmax(const plant_t *p, float *v_at_max);
/* Advance the plant by dt_ms with the converter commanded to vbatt_cmd. */
void plant_step(plant_t *p, float vbatt_cmd, uint32_t dt_ms);
#endif /* PLANT_H */