Allow custom DC/DC control functions
A Kconfig CUSTOM_DCDC_CONTROLLER is introduced to enable implementation of more sophisticated control functions than the standard perturb and observe. A function dcdc_low_level_controller() must be implemented and is called from the DMA interrupt after each new current sensor reading. The default Dcdc::control() function is defined __weak.
This commit is contained in:
@@ -196,4 +196,12 @@ config CUSTOM_DATA_NODES_FILE
|
||||
Use a custom file instead of default data_nodes.cpp for
|
||||
ThingSet configuration.
|
||||
|
||||
config CUSTOM_DCDC_CONTROLLER
|
||||
bool "Custom implementation of DC/DC controller"
|
||||
depends on $(dt_compat_enabled,dcdc)
|
||||
default n
|
||||
help
|
||||
Use a custom implementation instead of the default perturb & observe
|
||||
MPPT control.
|
||||
|
||||
endif
|
||||
|
||||
-10
@@ -34,16 +34,6 @@ static volatile AdcAlert adc_alerts_lower[NUM_ADC_CH] = {};
|
||||
|
||||
extern DeviceStatus dev_stat;
|
||||
|
||||
#ifdef CONFIG_SOC_SERIES_STM32G4X
|
||||
// Using internal reference buffer at VREF+ pin, set to 2048 mV
|
||||
#define VREF (2048)
|
||||
#else
|
||||
// internal STM reference voltage
|
||||
#define VREF (VREFINT_VALUE * VREFINT_CAL / adc_value(ADC_POS_VREF_MCU))
|
||||
#endif
|
||||
|
||||
#define ADC_GAIN(name) ((float)DT_ADC_GAIN_##name##_NUMERATOR / DT_ADC_GAIN_##name##_DENOMINATOR)
|
||||
|
||||
/**
|
||||
* Average value for ADC channel
|
||||
*
|
||||
|
||||
@@ -24,6 +24,18 @@ extern "C" {
|
||||
|
||||
#define ADC_FILTER_CONST 5 // filter multiplier = 1/(2^ADC_FILTER_CONST)
|
||||
|
||||
#ifdef CONFIG_SOC_SERIES_STM32G4X
|
||||
// Using internal reference buffer at VREF+ pin, set to 2048 mV
|
||||
#define VREF (2048)
|
||||
#elif defined(UNIT_TEST)
|
||||
#define VREF (3300)
|
||||
#else
|
||||
// internal STM reference voltage
|
||||
#define VREF (VREFINT_VALUE * VREFINT_CAL / adc_value(ADC_POS_VREF_MCU))
|
||||
#endif
|
||||
|
||||
#define ADC_GAIN(name) ((float)DT_ADC_GAIN_##name##_NUMERATOR / DT_ADC_GAIN_##name##_DENOMINATOR)
|
||||
|
||||
/**
|
||||
* Struct to definie upper and lower limit alerts for any ADC channel
|
||||
*/
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
#include <stm32g4xx_ll_bus.h>
|
||||
#endif
|
||||
|
||||
#include "dcdc.h" // for low-level control function called by DMA
|
||||
#include "board.h"
|
||||
#include "debug.h"
|
||||
|
||||
@@ -226,6 +227,12 @@ static void DMA2_Channel1_IRQHandler(void *args)
|
||||
}
|
||||
}
|
||||
DMA2->IFCR |= 0x0FFFFFFF; // clear all interrupt registers
|
||||
|
||||
#ifdef CONFIG_CUSTOM_DCDC_CONTROLLER
|
||||
// Implement this function e.g. for cycle-by-cylce current limitation.
|
||||
// As it runs in an ISR with high frequency, it must be VERY fast!
|
||||
dcdc_low_level_controller();
|
||||
#endif
|
||||
}
|
||||
#endif // CONFIG_SOC_SERIES_STM32G4X
|
||||
|
||||
|
||||
+1
-1
@@ -162,7 +162,7 @@ int Dcdc::check_start_conditions()
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Dcdc::control()
|
||||
__weak void Dcdc::control()
|
||||
{
|
||||
if (half_bridge_enabled()) {
|
||||
const char *stop_reason = NULL;
|
||||
|
||||
+27
@@ -15,6 +15,8 @@
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
#include "power_port.h"
|
||||
|
||||
/** DC/DC basic operation mode
|
||||
@@ -130,4 +132,29 @@ private:
|
||||
int perturb_observe_controller();
|
||||
};
|
||||
|
||||
#endif // __cplusplus
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_CUSTOM_DCDC_CONTROLLER
|
||||
|
||||
/**
|
||||
* Low-level control function
|
||||
*
|
||||
* Implement this function e.g. for cycle-by-cylce current limitation.
|
||||
*
|
||||
* It is called from the DMA after each new current reading, i.e. it runs in ISR context with
|
||||
* high frequency and must be VERY fast!
|
||||
*/
|
||||
void dcdc_low_level_controller();
|
||||
|
||||
#endif // CONFIG_CUSTOM_DCDC_CONTROLLER
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* DCDC_H */
|
||||
|
||||
@@ -10,3 +10,10 @@
|
||||
* @brief Mock necessary functions and generated Devicetree or Kconfig defines from Zephyr
|
||||
* for unit tests
|
||||
*/
|
||||
|
||||
#ifndef __deprecated
|
||||
#define __deprecated __attribute__((deprecated))
|
||||
#endif
|
||||
#ifndef __weak
|
||||
#define __weak __attribute__((__weak__))
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user