mirror of https://github.com/rusefi/wideband.git
Smaller version of heater settings for other types of sensors (#183)
* heater settings for other types of sensors * port: GetSensorType * fancier C++ version * fancier C++ version * Why not a function --------- Co-authored-by: Andrey Gusakov <dron0gus@gmail.com> Co-authored-by: rusefillc <sdfsdfqsf2334234234>
This commit is contained in:
parent
f365492565
commit
f4bd1a4197
|
@ -144,3 +144,8 @@ void SetConfiguration()
|
||||||
sizeof(Configuration)
|
sizeof(Configuration)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SensorType GetSensorType()
|
||||||
|
{
|
||||||
|
return SensorType::LSU49;
|
||||||
|
}
|
||||||
|
|
|
@ -81,3 +81,16 @@ size_t GetConfigurationSize()
|
||||||
const char *getTsSignature() {
|
const char *getTsSignature() {
|
||||||
return TS_SIGNATURE;
|
return TS_SIGNATURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SensorType GetSensorType()
|
||||||
|
{
|
||||||
|
/* TODO: load from settings */
|
||||||
|
#if defined(BOARD_SENSOR_LSU42)
|
||||||
|
return SensorType::LSU42;
|
||||||
|
#elif defined(BOARD_SENSOR_LSUADV)
|
||||||
|
return SensorType::LSUADV;
|
||||||
|
#else
|
||||||
|
/* default is LSU4.9 */
|
||||||
|
return SensorType::LSU49;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
|
@ -73,3 +73,6 @@ uint8_t *GetConfiguratiuonPtr();
|
||||||
size_t GetConfigurationSize();
|
size_t GetConfigurationSize();
|
||||||
void SaveConfiguration();
|
void SaveConfiguration();
|
||||||
const char *getTsSignature();
|
const char *getTsSignature();
|
||||||
|
|
||||||
|
// LSU4.2, LSU4.9 or LSU_ADV
|
||||||
|
SensorType GetSensorType();
|
||||||
|
|
|
@ -4,12 +4,47 @@
|
||||||
#include "ch.h"
|
#include "ch.h"
|
||||||
#include "hal.h"
|
#include "hal.h"
|
||||||
|
|
||||||
|
#include "port.h"
|
||||||
#include "fault.h"
|
#include "fault.h"
|
||||||
#include "pwm.h"
|
#include "pwm.h"
|
||||||
#include "sampling.h"
|
#include "sampling.h"
|
||||||
#include "pid.h"
|
#include "pid.h"
|
||||||
#include "can.h"
|
#include "can.h"
|
||||||
|
|
||||||
|
struct sensorHeaterParams {
|
||||||
|
uint16_t closedLoopThresholdESR;
|
||||||
|
uint16_t targetESR;
|
||||||
|
uint16_t overheatESR;
|
||||||
|
uint16_t underheatESR;
|
||||||
|
};
|
||||||
|
|
||||||
|
static const struct sensorHeaterParams heaterParams49 = {
|
||||||
|
.closedLoopThresholdESR = LSU49_HEATER_CLOSED_LOOP_THRESHOLD_ESR,
|
||||||
|
.targetESR = LSU49_HEATER_TARGET_ESR,
|
||||||
|
.overheatESR = LSU49_HEATER_OVERHEAT_ESR,
|
||||||
|
.underheatESR = LSU49_HEATER_UNDERHEAT_ESR,
|
||||||
|
};
|
||||||
|
static const struct sensorHeaterParams heaterParams42 = {
|
||||||
|
.closedLoopThresholdESR = LSU42_HEATER_CLOSED_LOOP_THRESHOLD_ESR,
|
||||||
|
.targetESR = LSU42_HEATER_TARGET_ESR,
|
||||||
|
.overheatESR = LSU42_HEATER_OVERHEAT_ESR,
|
||||||
|
.underheatESR = LSU42_HEATER_UNDERHEAT_ESR,
|
||||||
|
};
|
||||||
|
static const struct sensorHeaterParams heaterParamsAdv = {
|
||||||
|
//TODO
|
||||||
|
};
|
||||||
|
|
||||||
|
static const sensorHeaterParams *getHeaterParams(SensorType type) {
|
||||||
|
switch (type) {
|
||||||
|
case SensorType::LSU49:
|
||||||
|
return &heaterParams49;
|
||||||
|
case SensorType::LSU42:
|
||||||
|
return &heaterParams42;
|
||||||
|
case SensorType::LSUADV:
|
||||||
|
return &heaterParamsAdv;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
using namespace wbo;
|
using namespace wbo;
|
||||||
|
|
||||||
// 400khz / 1024 = 390hz PWM
|
// 400khz / 1024 = 390hz PWM
|
||||||
|
@ -33,6 +68,7 @@ static const PWMConfig heaterPwmConfig = {
|
||||||
|
|
||||||
static constexpr int preheatTimeCounter = HEATER_PREHEAT_TIME / HEATER_CONTROL_PERIOD;
|
static constexpr int preheatTimeCounter = HEATER_PREHEAT_TIME / HEATER_CONTROL_PERIOD;
|
||||||
static constexpr int batteryStabTimeCounter = HEATER_BATTERY_STAB_TIME / HEATER_CONTROL_PERIOD;
|
static constexpr int batteryStabTimeCounter = HEATER_BATTERY_STAB_TIME / HEATER_CONTROL_PERIOD;
|
||||||
|
static const struct sensorHeaterParams *heater;
|
||||||
|
|
||||||
struct heater_state {
|
struct heater_state {
|
||||||
Pid heaterPid;
|
Pid heaterPid;
|
||||||
|
@ -113,7 +149,7 @@ static HeaterState GetNextState(struct heater_state &s, HeaterAllow heaterAllowS
|
||||||
s.timeCounter--;
|
s.timeCounter--;
|
||||||
|
|
||||||
// If preheat timeout, or sensor is already hot (engine running?)
|
// If preheat timeout, or sensor is already hot (engine running?)
|
||||||
if (s.timeCounter <= 0 || sensorEsr < HEATER_CLOSED_LOOP_THRESHOLD_ESR)
|
if (s.timeCounter <= 0 || sensorEsr < heater->closedLoopThresholdESR)
|
||||||
{
|
{
|
||||||
// If enough time has elapsed, start the ramp
|
// If enough time has elapsed, start the ramp
|
||||||
// Start the ramp at 4 volts
|
// Start the ramp at 4 volts
|
||||||
|
@ -128,7 +164,7 @@ static HeaterState GetNextState(struct heater_state &s, HeaterAllow heaterAllowS
|
||||||
// Stay in preheat - wait for time to elapse
|
// Stay in preheat - wait for time to elapse
|
||||||
break;
|
break;
|
||||||
case HeaterState::WarmupRamp:
|
case HeaterState::WarmupRamp:
|
||||||
if (sensorEsr < HEATER_CLOSED_LOOP_THRESHOLD_ESR)
|
if (sensorEsr < heater->closedLoopThresholdESR)
|
||||||
{
|
{
|
||||||
return HeaterState::ClosedLoop;
|
return HeaterState::ClosedLoop;
|
||||||
}
|
}
|
||||||
|
@ -143,12 +179,12 @@ static HeaterState GetNextState(struct heater_state &s, HeaterAllow heaterAllowS
|
||||||
break;
|
break;
|
||||||
case HeaterState::ClosedLoop:
|
case HeaterState::ClosedLoop:
|
||||||
// Check that the sensor's ESR is acceptable for normal operation
|
// Check that the sensor's ESR is acceptable for normal operation
|
||||||
if (sensorEsr < HEATER_OVERHEAT_ESR)
|
if (sensorEsr < heater->overheatESR)
|
||||||
{
|
{
|
||||||
SetFault(s.ch, Fault::SensorOverheat);
|
SetFault(s.ch, Fault::SensorOverheat);
|
||||||
return HeaterState::Stopped;
|
return HeaterState::Stopped;
|
||||||
}
|
}
|
||||||
else if (sensorEsr > HEATER_UNDERHEAT_ESR)
|
else if (sensorEsr > heater->underheatESR)
|
||||||
{
|
{
|
||||||
SetFault(s.ch, Fault::SensorUnderheat);
|
SetFault(s.ch, Fault::SensorUnderheat);
|
||||||
return HeaterState::Stopped;
|
return HeaterState::Stopped;
|
||||||
|
@ -181,7 +217,7 @@ static float GetVoltageForState(struct heater_state &s, float heaterEsr)
|
||||||
case HeaterState::ClosedLoop:
|
case HeaterState::ClosedLoop:
|
||||||
// "nominal" heater voltage is 7.5v, so apply correction around that point (instead of relying on integrator so much)
|
// "nominal" heater voltage is 7.5v, so apply correction around that point (instead of relying on integrator so much)
|
||||||
// Negated because lower resistance -> hotter
|
// Negated because lower resistance -> hotter
|
||||||
return 7.5f - s.heaterPid.GetOutput(HEATER_TARGET_ESR, heaterEsr);
|
return 7.5f - s.heaterPid.GetOutput(heater->targetESR, heaterEsr);
|
||||||
case HeaterState::Stopped:
|
case HeaterState::Stopped:
|
||||||
// Something has gone wrong, turn off the heater.
|
// Something has gone wrong, turn off the heater.
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -202,6 +238,9 @@ static void HeaterThread(void*)
|
||||||
// immediately think we overshot the target temperature
|
// immediately think we overshot the target temperature
|
||||||
chThdSleepMilliseconds(1000);
|
chThdSleepMilliseconds(1000);
|
||||||
|
|
||||||
|
// Get sensor type and settings
|
||||||
|
heater = getHeaterParams(GetSensorType());
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
auto heaterAllowState = GetHeaterAllowed();
|
auto heaterAllowState = GetHeaterAllowed();
|
||||||
|
|
|
@ -39,6 +39,7 @@ static void SamplingThread(void*)
|
||||||
|
|
||||||
chRegSetThreadName("Sampling");
|
chRegSetThreadName("Sampling");
|
||||||
|
|
||||||
|
|
||||||
/* GD32: Insert 20us delay after ADC enable */
|
/* GD32: Insert 20us delay after ADC enable */
|
||||||
chThdSleepMilliseconds(1);
|
chThdSleepMilliseconds(1);
|
||||||
|
|
||||||
|
|
|
@ -52,10 +52,18 @@
|
||||||
// mininal battery voltage to continue heating
|
// mininal battery voltage to continue heating
|
||||||
#define HEATER_BATTETY_OFF_VOLTAGE 8.5
|
#define HEATER_BATTETY_OFF_VOLTAGE 8.5
|
||||||
|
|
||||||
#define HEATER_CLOSED_LOOP_THRESHOLD_ESR 500
|
//LSU 4.9
|
||||||
#define HEATER_TARGET_ESR 300
|
#define LSU49_HEATER_CLOSED_LOOP_THRESHOLD_ESR 500
|
||||||
#define HEATER_OVERHEAT_ESR 150
|
#define LSU49_HEATER_TARGET_ESR 300
|
||||||
#define HEATER_UNDERHEAT_ESR 700
|
#define LSU49_HEATER_OVERHEAT_ESR 150
|
||||||
|
#define LSU49_HEATER_UNDERHEAT_ESR 700
|
||||||
|
|
||||||
|
//LSU 4.2
|
||||||
|
// TODO: check this!!!
|
||||||
|
#define LSU42_HEATER_CLOSED_LOOP_THRESHOLD_ESR 150
|
||||||
|
#define LSU42_HEATER_TARGET_ESR 90
|
||||||
|
#define LSU42_HEATER_OVERHEAT_ESR 45
|
||||||
|
#define LSU42_HEATER_UNDERHEAT_ESR 250
|
||||||
|
|
||||||
// *******************************
|
// *******************************
|
||||||
// TunerStudio configuration
|
// TunerStudio configuration
|
||||||
|
|
Loading…
Reference in New Issue