* auxout: manually fill pwm config

(cherry picked from commit a01876bc034264de5d6930bf2cc49cf0fc0cbb0a)

* auxout: some boards use primary PWM outputs instead of complementary

(cherry picked from commit c13b95441e7b284a36445c261199e96580e94ebd)

* auxout: implement ripple cancelation using inverted PWM

(cherry picked from commit 77cbc04990421b24021639b098ea6040af3a12f8)

* f1_common: default AUXOUT value is AFR voltage

with 'default' scaling 8.5 to 18.0 AFR is represented with 0.0 to
5.0V

(cherry picked from commit 0c62ab8f509ff0ab3ab4260e308ad4b55bd64e40)

---------

Co-authored-by: Andrey Gusakov <dron0gus@gmail.com>
This commit is contained in:
rusefillc 2023-04-29 01:01:13 -04:00 committed by GitHub
parent 25c5e249d9
commit 8bd19fcc2c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 60 additions and 7 deletions

View File

@ -15,19 +15,25 @@
#ifdef AUXOUT_DAC_PWM_DEVICE
#ifndef AUXOUT_DAC_PWM_OUTPUT_MODE
#define AUXOUT_DAC_PWM_OUTPUT_MODE PWM_OUTPUT_ACTIVE_HIGH
#endif
#ifndef AUXOUT_DAC_PWM_NC_OUTPUT_MODE
#define AUXOUT_DAC_PWM_NC_OUTPUT_MODE PWM_OUTPUT_ACTIVE_LOW
#endif
// Rev2 low pass filter cut frequency is about 21Hz (sic!)
// 48Mhz / (2 ^ 12) ~= 12 KHz
// 64mhz / (2 ^ 12) ~= 16 KHz
static const PWMConfig auxPwmConfig = {
static PWMConfig auxPwmConfig = {
.frequency = STM32_SYSCLK,
.period = 1 << 12,
.callback = nullptr,
.channels = {
// TODO: do any boards use the "primary" outputs instead of the "complementary" outputs?
[0] = {/*PWM_OUTPUT_ACTIVE_HIGH |*/ PWM_COMPLEMENTARY_OUTPUT_ACTIVE_HIGH, nullptr},
[1] = {/*PWM_OUTPUT_ACTIVE_HIGH |*/ PWM_COMPLEMENTARY_OUTPUT_ACTIVE_HIGH, nullptr},
[2] = {/*PWM_OUTPUT_ACTIVE_HIGH |*/ PWM_COMPLEMENTARY_OUTPUT_ACTIVE_HIGH, nullptr},
[3] = {/*PWM_OUTPUT_ACTIVE_HIGH |*/ PWM_COMPLEMENTARY_OUTPUT_ACTIVE_HIGH, nullptr}
[0] = {0, nullptr},
[1] = {0, nullptr},
[2] = {0, nullptr},
[3] = {0, nullptr}
},
.cr2 = 0,
#if STM32_PWM_USE_ADVANCED
@ -36,15 +42,42 @@ static const PWMConfig auxPwmConfig = {
.dier = 0
};
static void auxDacFillPwmConfig(void)
{
auxPwmConfig.channels[AUXOUT_DAC_PWM_CHANNEL_0].mode = AUXOUT_DAC_PWM_OUTPUT_MODE;
auxPwmConfig.channels[AUXOUT_DAC_PWM_CHANNEL_1].mode = AUXOUT_DAC_PWM_OUTPUT_MODE;
#ifdef AUXOUT_DAC_PWM_CHANNEL_0_NC
auxPwmConfig.channels[AUXOUT_DAC_PWM_CHANNEL_0_NC].mode = AUXOUT_DAC_PWM_NC_OUTPUT_MODE;
#endif
#ifdef AUXOUT_DAC_PWM_CHANNEL_1_NC
auxPwmConfig.channels[AUXOUT_DAC_PWM_CHANNEL_1_NC].mode = AUXOUT_DAC_PWM_NC_OUTPUT_MODE;
#endif
}
static Pwm auxDac(AUXOUT_DAC_PWM_DEVICE);
static const uint8_t auxOutPwmCh[] = {
static const uint8_t auxOutPwmCh[AFR_CHANNELS] = {
AUXOUT_DAC_PWM_CHANNEL_0,
#if (AFR_CHANNELS > 1)
AUXOUT_DAC_PWM_CHANNEL_1,
#endif
};
static const int8_t auxOutPwmChN[AFR_CHANNELS] = {
#ifdef AUXOUT_DAC_PWM_CHANNEL_0_NC
AUXOUT_DAC_PWM_CHANNEL_0_NC,
#else
-1,
#endif
#if (AFR_CHANNELS > 1)
#ifdef AUXOUT_DAC_PWM_CHANNEL_1_NC
AUXOUT_DAC_PWM_CHANNEL_1_NC,
#else
-1,
#endif
#endif
};
void SetAuxDac(int channel, float voltage)
{
voltage = voltage / AUXOUT_GAIN;
@ -53,6 +86,10 @@ void SetAuxDac(int channel, float voltage)
duty = clampF(0, duty, 1);
auxDac.SetDuty(auxOutPwmCh[channel], duty);
// Ripple cancelation channel
if (auxOutPwmChN[channel >= 0]) {
auxDac.SetDuty(auxOutPwmChN[channel], duty);
}
}
#endif
@ -135,6 +172,7 @@ void AuxOutThread(void*)
void InitAuxDac()
{
#if defined(AUXOUT_DAC_PWM_DEVICE)
auxDacFillPwmConfig();
auxDac.Start(auxPwmConfig);
SetAuxDac(0, 0.0);

View File

@ -30,9 +30,20 @@ static Configuration cfg;
// Configuration defaults
void Configuration::LoadDefaults()
{
int i;
CanIndexOffset = 0;
sensorType = BOARD_DEFAULT_SENSOR_TYPE;
/* default auxout curve is 0..5V for AFR 8.5 to 18.0
* default auxout[n] input is AFR[n] */
for (i = 0; i < 8; i++) {
auxOutBins[0][i] = auxOutBins[1][i] = 8.5 + (18.0 - 8.5) / 7 * i;
auxOutValues[0][i] = auxOutValues[1][i] = 0.0 + (5.0 - 0.0) / 7 * i;
}
auxOutputSource[0] = AuxOutputMode::Afr0;
auxOutputSource[1] = AuxOutputMode::Afr1;
/* Finaly */
Tag = ExpectedTag;
}

View File

@ -54,6 +54,8 @@
#define AUXOUT_DAC_PWM_CHANNEL_0 1
// PB15 - TIM1_CH3N
#define AUXOUT_DAC_PWM_CHANNEL_1 2
// CH2N and CH3N are complementary outputs
#define AUXOUT_DAC_PWM_OUTPUT_MODE PWM_COMPLEMENTARY_OUTPUT_ACTIVE_HIGH
#define ID_SEL1_PORT GPIOC
#define ID_SEL1_PIN 13

View File

@ -46,6 +46,8 @@
#define AUXOUT_DAC_PWM_CHANNEL_0 1
// PB15 - TIM1_CH3N
#define AUXOUT_DAC_PWM_CHANNEL_1 2
// CH2N and CH3N are complementary outputs
#define AUXOUT_DAC_PWM_OUTPUT_MODE PWM_COMPLEMENTARY_OUTPUT_ACTIVE_HIGH
#define ID_SEL1_PORT GPIOC
#define ID_SEL1_PIN 13