From 82caa886841c21840ded80c3be955518d4442248 Mon Sep 17 00:00:00 2001 From: "Christian L. V. Madsen" Date: Sat, 13 Sep 2025 08:41:33 +0200 Subject: [PATCH] last commit before gitea mirror --- .gitmodules | 3 +++ buck_specs.h | 4 ++-- cm_mppt_regulator | 1 + main.c | 25 ++++++++++++++++++++++--- 4 files changed, 28 insertions(+), 5 deletions(-) create mode 160000 cm_mppt_regulator diff --git a/.gitmodules b/.gitmodules index 48eac84..de67d46 100644 --- a/.gitmodules +++ b/.gitmodules @@ -2,3 +2,6 @@ path = cm_pid_regulator url = https://OZ1CM@bitbucket.org/oz1cm/cm_pid_regulator.git branch = master +[submodule "cm_mppt_regulator"] + path = cm_mppt_regulator + url = https://OZ1CM@bitbucket.org/oz1cm/cm_mppt_regulator.git diff --git a/buck_specs.h b/buck_specs.h index 35b11ac..a8ed8d7 100644 --- a/buck_specs.h +++ b/buck_specs.h @@ -23,10 +23,10 @@ // Load -#define R_LOAD 10 // Ohm +#define R_LOAD 10.0 // Ohm // Simulation parameters -#define SIMULATION_TIME 0.6 // Seconds +#define SIMULATION_TIME 2.6 // Seconds // Plot specific diff --git a/cm_mppt_regulator b/cm_mppt_regulator new file mode 160000 index 0000000..f782202 --- /dev/null +++ b/cm_mppt_regulator @@ -0,0 +1 @@ +Subproject commit f78220273e39ed0f4ab36835b5a77446e01f3216 diff --git a/main.c b/main.c index 02f211c..ccf956c 100644 --- a/main.c +++ b/main.c @@ -7,12 +7,15 @@ #include #include "buck_specs.h" #include "buck_emulator.h" -#include "cm_pid_regulator/cm_pid_regulator.h" #include "file_print.h" #include +#include "cm_pid_regulator/cm_pid_regulator.h" +#include "cm_mppt_regulator/cm_mppt_regulator.h" + BuckEmulator_t buck_converter; cm_pid_regulator_float_t Voltreg; +cm_mppt_regulator_t mppt_reg; float kp = 0.00550; float ki = 1.0; @@ -32,6 +35,21 @@ float pid_regulator(float Vout){ } +float mppt_regulator(float Vout){ + + static uint32_t run_ctr = 0; + static float duty = 0.0; + + if((run_ctr++ % 10) != 0)return duty; + + duty = (float)cm_mppt_regulator_Compute(&mppt_reg, Vout*1000.0, (Vout*1000.0)/R_LOAD, 200.0) / 65535.0; + + printf("duty: %f \r\n",duty); + + return duty; + +} + int printResult(float duty, float Vout, float time){ showProcentInCmd(time, SIMULATION_TIME); @@ -45,10 +63,11 @@ int main(void){ buck_emulator_init(&buck_converter, VIN,L_INDUCTOR,C_CAPACITOR,R_LOAD,SAMPLE_TIME, SIMULATION_TIME); - buck_emulator_RegRegulationEvt(&buck_converter,(regulate_evt_t)pid_regulator); + buck_emulator_RegRegulationEvt(&buck_converter,(regulate_evt_t)mppt_regulator); buck_emulator_RegGetResultEvt(&buck_converter,(getResult_evt_t)printResult); - cm_PIDRegulatorf_Init(&Voltreg, kp, ki, kd, 0.0, 1.0); + //cm_PIDRegulatorf_Init(&Voltreg, kp, ki, kd, 0.0, 1.0); + cm_mppt_regulator_init(&mppt_reg, (VOUT_TARGET*1000.0), 500.0); cm_file_open(BUCK_OUTPUT_FILE,VOUT_TARGET);