mirror of https://github.com/rusefi/wideband.git
AUX outputs (#95)
* AUX outputs * Rev2: define AUX output PWM device and channels * Rev2: enalbe TIM1 used for aux outputs * Rev2: define aux output gain Co-authored-by: Andrey Gusakov <dron0gus@gmail.com>
This commit is contained in:
parent
fe50e80a89
commit
1454c10713
|
@ -146,6 +146,7 @@ CPPSRC = $(ALLCPPSRC) \
|
|||
uart.cpp \
|
||||
shared/crc.cpp \
|
||||
interpolation.cpp \
|
||||
auxout.cpp \
|
||||
console/binary/tunerstudio_io_serial.cpp \
|
||||
console/binary/tunerstudio_io.cpp \
|
||||
main.cpp
|
||||
|
|
|
@ -0,0 +1,65 @@
|
|||
#include "pwm.h"
|
||||
#include "lambda_conversion.h"
|
||||
|
||||
#include "wideband_config.h"
|
||||
|
||||
#include "hal.h"
|
||||
|
||||
#ifdef AUXOUT_DAC_PWM_DEVICE
|
||||
|
||||
// Rev2 low pass filter cut frequency is about 21Hz (sic!)
|
||||
// 48Mhz / (2 ^ 12) ~= 12 KHz
|
||||
PWMConfig auxPwmConfig = {
|
||||
48'000'000,
|
||||
1 << 12,
|
||||
nullptr,
|
||||
{
|
||||
{PWM_OUTPUT_ACTIVE_HIGH | PWM_COMPLEMENTARY_OUTPUT_ACTIVE_HIGH, nullptr},
|
||||
{PWM_OUTPUT_ACTIVE_HIGH | PWM_COMPLEMENTARY_OUTPUT_ACTIVE_HIGH, nullptr},
|
||||
{PWM_OUTPUT_ACTIVE_HIGH | PWM_COMPLEMENTARY_OUTPUT_ACTIVE_HIGH, nullptr},
|
||||
{PWM_OUTPUT_ACTIVE_HIGH | PWM_COMPLEMENTARY_OUTPUT_ACTIVE_HIGH, nullptr}
|
||||
},
|
||||
0,
|
||||
0,
|
||||
#if STM32_PWM_USE_ADVANCED
|
||||
0
|
||||
#endif
|
||||
};
|
||||
|
||||
static Pwm auxDac(AUXOUT_DAC_PWM_DEVICE);
|
||||
|
||||
extern float clampF(float min, float clamp, float max);
|
||||
|
||||
void SetAuxDac(int channel, float voltage)
|
||||
{
|
||||
voltage = voltage / AUXOUT_GAIN;
|
||||
auto duty = voltage / VCC_VOLTS;
|
||||
duty = 1.0 - duty;
|
||||
duty = clampF(0, duty, 1);
|
||||
|
||||
auxDac.SetDuty(channel ? AUXOUT_DAC_PWM_CHANNEL_1 : AUXOUT_DAC_PWM_CHANNEL_0, duty);
|
||||
}
|
||||
|
||||
/* TODO: merge with some other communication thread? */
|
||||
static THD_WORKING_AREA(waAuxOutThread, 256);
|
||||
void AuxOutThread(void*)
|
||||
{
|
||||
while(1)
|
||||
{
|
||||
SetAuxDac(0, GetLambda());
|
||||
|
||||
chThdSleepMilliseconds(10);
|
||||
}
|
||||
}
|
||||
|
||||
void InitAuxDac()
|
||||
{
|
||||
auxDac.Start(auxPwmConfig);
|
||||
|
||||
SetAuxDac(0, 0.0);
|
||||
SetAuxDac(1, 0.0);
|
||||
|
||||
chThdCreateStatic(waAuxOutThread, sizeof(waAuxOutThread), NORMALPRIO, AuxOutThread, nullptr);
|
||||
}
|
||||
|
||||
#endif
|
|
@ -0,0 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
void InitAuxDac();
|
||||
void SetAuxDac(int channel, float voltage);
|
|
@ -26,6 +26,13 @@
|
|||
#define PUMP_DAC_PWM_DEVICE PWMD2
|
||||
#define PUMP_DAC_PWM_CHANNEL 1
|
||||
|
||||
// TIM1 - DAC for AUX outputs
|
||||
#define AUXOUT_DAC_PWM_DEVICE PWMD1
|
||||
// PB14 - TIM1_CH2N
|
||||
#define AUXOUT_DAC_PWM_CHANNEL_0 1
|
||||
// PB15 - TIM1_CH3N
|
||||
#define AUXOUT_DAC_PWM_CHANNEL_1 2
|
||||
|
||||
#define ID_SEL1_PORT GPIOC
|
||||
#define ID_SEL1_PIN 13
|
||||
|
||||
|
|
|
@ -133,8 +133,8 @@
|
|||
/*
|
||||
* PWM driver system settings.
|
||||
*/
|
||||
#define STM32_PWM_USE_ADVANCED FALSE
|
||||
#define STM32_PWM_USE_TIM1 FALSE
|
||||
#define STM32_PWM_USE_ADVANCED TRUE
|
||||
#define STM32_PWM_USE_TIM1 TRUE
|
||||
#define STM32_PWM_USE_TIM2 TRUE
|
||||
#define STM32_PWM_USE_TIM3 FALSE
|
||||
#define STM32_PWM_USE_TIM4 TRUE
|
||||
|
|
|
@ -35,3 +35,9 @@
|
|||
// Nernst voltage & ESR sense
|
||||
// *******************************
|
||||
#define VM_RESISTOR_VALUE (0)
|
||||
|
||||
// *******************************
|
||||
// AUX outputs
|
||||
// *******************************
|
||||
// OpAmp with 82K + 160K
|
||||
#define AUXOUT_GAIN ((82.0 + 160.0) / 160.0)
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#include "sampling.h"
|
||||
#include "uart.h"
|
||||
#include "io_pins.h"
|
||||
#include "auxout.h"
|
||||
|
||||
using namespace wbo;
|
||||
|
||||
|
@ -25,6 +26,10 @@ int main() {
|
|||
StartHeaterControl();
|
||||
StartPumpControl();
|
||||
|
||||
#ifdef AUXOUT_DAC_PWM_DEVICE
|
||||
InitAuxDac();
|
||||
#endif
|
||||
|
||||
InitCan();
|
||||
#ifdef ECHO_UART
|
||||
InitUart();
|
||||
|
|
Loading…
Reference in New Issue