проект запущен шим идет, нужно запустить с пид регулятором вывести все измерения в структуру
This commit is contained in:
@@ -6,20 +6,29 @@
|
||||
#include "retarget.h"
|
||||
#include "stm32g474xx.h"
|
||||
|
||||
/*
|
||||
## Main loop
|
||||
|
||||
The application is intentionally small:
|
||||
|
||||
- board clocks and UART start first;
|
||||
- `DCDC_Init()` prepares ADC and HRTIM;
|
||||
- `DCDC_Service1ms()` applies live edits from `g_dcdc_config`;
|
||||
- terminal output prints the current measurements and active runtime mode.
|
||||
*/
|
||||
#if DCDC_GPIO_PIN_TEST_ENABLE
|
||||
static void GpioPinTest_Init(void);
|
||||
static void GpioPinTest_SetPhase(bool phase);
|
||||
#endif
|
||||
|
||||
int main(void)
|
||||
{
|
||||
uint32_t last_control_ms = 0U;
|
||||
uint32_t last_print_ms = 0U;
|
||||
volatile uint32_t debug_attach_delay;
|
||||
|
||||
/*
|
||||
* Short rescue window after reset. It lets ST-LINK attach before the
|
||||
* firmware reconfigures clocks and power peripherals.
|
||||
*/
|
||||
for (debug_attach_delay = 0U; debug_attach_delay < DEBUG_ATTACH_DELAY_LOOPS; debug_attach_delay++)
|
||||
{
|
||||
__NOP();
|
||||
}
|
||||
#if DCDC_GPIO_PIN_TEST_ENABLE
|
||||
uint32_t last_gpio_test_ms = 0U;
|
||||
bool gpio_test_phase = false;
|
||||
#endif
|
||||
|
||||
Board_Init();
|
||||
Retarget_Init(USART3_BAUDRATE);
|
||||
@@ -32,23 +41,40 @@ int main(void)
|
||||
(unsigned long)DCDC_PWM_FREQUENCY_HZ,
|
||||
(unsigned long)DCDC_GetPeriodTicks());
|
||||
printf("HRTIM DLL: %s\n", DCDC_IsHrtimReady() ? "ready" : "not ready");
|
||||
printf("Runtime mode: %s; edit g_dcdc_config in Keil Watch.\n",
|
||||
DCDC_ModeText(DCDC_GetMode()));
|
||||
printf("Runtime PWM: freq=%luHz duty=%lu/1000 deadtime=%lu rise=%lu fall=%lu ticks\n",
|
||||
(unsigned long)g_dcdc_config.pwm.frequency_hz,
|
||||
(unsigned long)g_dcdc_config.pwm.test_duty_permille,
|
||||
(unsigned long)g_dcdc_config.pwm.deadtime_enable,
|
||||
(unsigned long)g_dcdc_config.pwm.deadtime_rising_ticks,
|
||||
(unsigned long)g_dcdc_config.pwm.deadtime_falling_ticks);
|
||||
|
||||
#if DCDC_POWER_STAGE_ENABLE
|
||||
printf("Power stage: ENABLED. Check VIN/current limit before flashing.\n");
|
||||
DCDC_Start();
|
||||
#if DCDC_GPIO_PIN_TEST_ENABLE
|
||||
printf("GPIO pin test: PB12/PB13 toggle as ordinary outputs.\n");
|
||||
GpioPinTest_Init();
|
||||
#else
|
||||
printf("Power stage: disabled in app_config.h; ADC monitor only.\n");
|
||||
printf("Runtime service active. mode=0 monitor, 1 pwm-test, 2 closed-loop.\n");
|
||||
#endif
|
||||
|
||||
while (1)
|
||||
{
|
||||
uint32_t now = Board_Millis();
|
||||
|
||||
#if DCDC_GPIO_PIN_TEST_ENABLE
|
||||
if ((now - last_gpio_test_ms) >= DCDC_GPIO_PIN_TEST_HALF_PERIOD_MS)
|
||||
{
|
||||
last_gpio_test_ms = now;
|
||||
gpio_test_phase = !gpio_test_phase;
|
||||
GpioPinTest_SetPhase(gpio_test_phase);
|
||||
}
|
||||
#else
|
||||
if ((now - last_control_ms) >= 1U)
|
||||
{
|
||||
last_control_ms = now;
|
||||
DCDC_ControlStep();
|
||||
DCDC_Service1ms();
|
||||
}
|
||||
#endif
|
||||
|
||||
if ((now - last_print_ms) >= 500U)
|
||||
{
|
||||
@@ -56,7 +82,8 @@ int main(void)
|
||||
last_print_ms = now;
|
||||
DCDC_ReadMeasurements(&m);
|
||||
|
||||
printf("state=%s fault=%s hrtim=%s vin=%lumV iin=%lumA vout=%lumV duty=%lu/%lu\n",
|
||||
printf("mode=%s state=%s fault=%s hrtim=%s vin=%lumV iin=%lumA vout=%lumV duty=%lu/%lu dt=%lu/%lu\n",
|
||||
DCDC_ModeText(DCDC_GetMode()),
|
||||
DCDC_StateText(DCDC_GetState()),
|
||||
DCDC_FaultText(DCDC_GetFault()),
|
||||
DCDC_IsHrtimReady() ? "ready" : "not-ready",
|
||||
@@ -64,7 +91,37 @@ int main(void)
|
||||
(unsigned long)m.iin_ma,
|
||||
(unsigned long)m.vout_mv,
|
||||
(unsigned long)DCDC_GetDutyTicks(),
|
||||
(unsigned long)DCDC_GetPeriodTicks());
|
||||
(unsigned long)DCDC_GetPeriodTicks(),
|
||||
(unsigned long)g_dcdc_config.pwm.deadtime_rising_ticks,
|
||||
(unsigned long)g_dcdc_config.pwm.deadtime_falling_ticks);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if DCDC_GPIO_PIN_TEST_ENABLE
|
||||
static void GpioPinTest_Init(void)
|
||||
{
|
||||
RCC->AHB2ENR |= RCC_AHB2ENR_GPIOBEN;
|
||||
(void)RCC->AHB2ENR;
|
||||
|
||||
GPIOB->MODER &= ~((3UL << (12U * 2U)) | (3UL << (13U * 2U)));
|
||||
GPIOB->MODER |= ((1UL << (12U * 2U)) | (1UL << (13U * 2U)));
|
||||
GPIOB->OTYPER &= ~((1UL << 12U) | (1UL << 13U));
|
||||
GPIOB->OSPEEDR |= ((3UL << (12U * 2U)) | (3UL << (13U * 2U)));
|
||||
GPIOB->PUPDR &= ~((3UL << (12U * 2U)) | (3UL << (13U * 2U)));
|
||||
|
||||
GpioPinTest_SetPhase(false);
|
||||
}
|
||||
|
||||
static void GpioPinTest_SetPhase(bool phase)
|
||||
{
|
||||
if (phase)
|
||||
{
|
||||
GPIOB->BSRR = (1UL << 12U) | (1UL << (13U + 16U));
|
||||
}
|
||||
else
|
||||
{
|
||||
GPIOB->BSRR = (1UL << 13U) | (1UL << (12U + 16U));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user