pump_dac: fixes for multi-channel mode

This commit is contained in:
Andrey Gusakov 2022-06-19 14:56:47 +03:00
parent 665648e015
commit 8882ef2b23
1 changed files with 28 additions and 4 deletions

View File

@ -7,17 +7,41 @@
#include "hal.h"
// 48MHz / 1024 = 46.8khz PWM
static Pwm pumpDac(PUMP_DAC_PWM_DEVICE, PUMP_DAC_PWM_CHANNEL, 48'000'000, 1024);
PWMConfig pumpDacConfig = {
48'000'000,
1024,
nullptr,
{
{PWM_OUTPUT_ACTIVE_HIGH, nullptr},
{PWM_OUTPUT_ACTIVE_HIGH, nullptr},
{PWM_OUTPUT_ACTIVE_HIGH, nullptr},
{PWM_OUTPUT_ACTIVE_HIGH, nullptr}
},
0,
0,
#if STM32_PWM_USE_ADVANCED
0
#endif
};
static Pwm pumpDac(PUMP_DAC_PWM_DEVICE);
struct pump_dac_state {
int32_t curIpump;
};
static const uint8_t pumpDacPwmCh[] = {
PUMP_DAC_PWM_CHANNEL_0,
#if (AFR_CHANNELS > 1)
PUMP_DAC_PWM_CHANNEL_1,
#endif
};
static struct pump_dac_state state[AFR_CHANNELS];
void InitPumpDac()
{
pumpDac.Start();
pumpDac.Start(&pumpDacConfig);
for (int ch = 0; ch < AFR_CHANNELS; ch++)
{
@ -45,12 +69,12 @@ void SetPumpCurrentTarget(int ch, int32_t microampere)
// offset by half vcc
volts += HALF_VCC;
pumpDac.SetDuty(volts / VCC_VOLTS);
pumpDac.SetDuty(pumpDacPwmCh[ch], volts / VCC_VOLTS);
}
float GetPumpOutputDuty(int ch)
{
return pumpDac.GetLastDuty();
return pumpDac.GetLastDuty(ch);
}
float GetPumpCurrent(int ch)