mirror of https://github.com/rusefi/wideband.git
LSU type from settings (#207)
* port: per-board SetupESRDriver() and GetESRSupplyR() functions * Pick sensor type from settings * f1_rev2: build helper for LSU4.2 FW
This commit is contained in:
parent
edd9639957
commit
a9bc33abbd
|
@ -6,8 +6,8 @@
|
|||
#define LED_GREEN_PORT GPIOB
|
||||
#define LED_GREEN_PIN 6
|
||||
|
||||
#define NERNST_ESR_DRIVER_PORT GPIOB
|
||||
#define NERNST_ESR_DRIVER_PIN 7
|
||||
#define NERNST_49_ESR_DRIVER_PORT GPIOB
|
||||
#define NERNST_49_ESR_DRIVER_PIN 7
|
||||
|
||||
// PA7
|
||||
#define HEATER_PWM_DEVICE PWMD1
|
||||
|
|
|
@ -149,3 +149,20 @@ SensorType GetSensorType()
|
|||
{
|
||||
return SensorType::LSU49;
|
||||
}
|
||||
|
||||
void SetupESRDriver(SensorType sensor)
|
||||
{
|
||||
// NOP
|
||||
}
|
||||
|
||||
int GetESRSupplyR()
|
||||
{
|
||||
// Nernst AC injection resistor value
|
||||
return 22000;
|
||||
}
|
||||
|
||||
void ToggleESRDriver(SensorType sensor)
|
||||
{
|
||||
(void)sensor;
|
||||
palTogglePad(NERNST_49_ESR_DRIVER_PORT, NERNST_49_ESR_DRIVER_PIN);
|
||||
}
|
||||
|
|
|
@ -23,10 +23,15 @@ static MFSDriver mfs1;
|
|||
static Configuration cfg;
|
||||
#define MFS_CONFIGURATION_RECORD_ID 1
|
||||
|
||||
#ifndef BOARD_DEFAULT_SENSOR_TYPE
|
||||
#define BOARD_DEFAULT_SENSOR_TYPE SensorType::LSU49
|
||||
#endif
|
||||
|
||||
// Configuration defaults
|
||||
void Configuration::LoadDefaults()
|
||||
{
|
||||
CanIndexOffset = 0;
|
||||
sensorType = BOARD_DEFAULT_SENSOR_TYPE;
|
||||
|
||||
/* Finaly */
|
||||
Tag = ExpectedTag;
|
||||
|
@ -84,13 +89,20 @@ const char *getTsSignature() {
|
|||
|
||||
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
|
||||
return cfg.sensorType;
|
||||
}
|
||||
|
||||
void ToggleESRDriver(SensorType sensor)
|
||||
{
|
||||
switch (sensor) {
|
||||
case SensorType::LSU42:
|
||||
palTogglePad(NERNST_42_ESR_DRIVER_PORT, NERNST_42_ESR_DRIVER_PIN);
|
||||
break;
|
||||
case SensorType::LSU49:
|
||||
palTogglePad(NERNST_49_ESR_DRIVER_PORT, NERNST_49_ESR_DRIVER_PIN);
|
||||
break;
|
||||
case SensorType::LSUADV:
|
||||
palTogglePad(NERNST_ADV_ESR_DRIVER_PORT, NERNST_ADV_ESR_DRIVER_PIN);
|
||||
break;
|
||||
}
|
||||
}
|
|
@ -22,8 +22,11 @@
|
|||
#define NERNST_42_ESR_DRIVER_PIN 12
|
||||
|
||||
// LSU 4.9 - 22K
|
||||
#define NERNST_ESR_DRIVER_PORT GPIOB
|
||||
#define NERNST_ESR_DRIVER_PIN 11
|
||||
#define NERNST_49_ESR_DRIVER_PORT GPIOB
|
||||
#define NERNST_49_ESR_DRIVER_PIN 11
|
||||
|
||||
#define NERNST_49_BIAS_PORT GPIOB
|
||||
#define NERNST_49_BIAS_PIN 2
|
||||
|
||||
// LSU ADV - 47K
|
||||
#define NERNST_ADV_ESR_DRIVER_PORT GPIOB
|
||||
|
|
|
@ -126,3 +126,63 @@ AnalogResult AnalogSample()
|
|||
.VirtualGroundVoltageInt = HALF_VCC,
|
||||
};
|
||||
}
|
||||
|
||||
/* TODO: optimize */
|
||||
void SetupESRDriver(SensorType sensor)
|
||||
{
|
||||
switch (sensor) {
|
||||
case SensorType::LSU42:
|
||||
/* disable bias */
|
||||
palSetPadMode(NERNST_49_BIAS_PORT, NERNST_49_BIAS_PIN,
|
||||
PAL_MODE_INPUT);
|
||||
/* disable all others ESR drivers */
|
||||
palSetPadMode(NERNST_49_ESR_DRIVER_PORT, NERNST_49_ESR_DRIVER_PIN,
|
||||
PAL_MODE_INPUT);
|
||||
palSetPadMode(NERNST_ADV_ESR_DRIVER_PORT, NERNST_ADV_ESR_DRIVER_PIN,
|
||||
PAL_MODE_INPUT);
|
||||
/* enable LSU4.2 */
|
||||
palSetPadMode(NERNST_42_ESR_DRIVER_PORT, NERNST_42_ESR_DRIVER_PIN,
|
||||
PAL_MODE_OUTPUT_PUSHPULL);
|
||||
break;
|
||||
case SensorType::LSU49:
|
||||
/* disable all others ESR drivers */
|
||||
palSetPadMode(NERNST_42_ESR_DRIVER_PORT, NERNST_42_ESR_DRIVER_PIN,
|
||||
PAL_MODE_INPUT);
|
||||
palSetPadMode(NERNST_ADV_ESR_DRIVER_PORT, NERNST_ADV_ESR_DRIVER_PIN,
|
||||
PAL_MODE_INPUT);
|
||||
/* enable LSU4.2 */
|
||||
palSetPadMode(NERNST_49_ESR_DRIVER_PORT, NERNST_49_ESR_DRIVER_PIN,
|
||||
PAL_MODE_OUTPUT_PUSHPULL);
|
||||
/* enable bias */
|
||||
palSetPadMode(NERNST_49_BIAS_PORT, NERNST_49_BIAS_PIN,
|
||||
PAL_MODE_OUTPUT_PUSHPULL);
|
||||
palSetPad(NERNST_49_BIAS_PORT, NERNST_49_BIAS_PIN);
|
||||
break;
|
||||
case SensorType::LSUADV:
|
||||
/* disable bias */
|
||||
palSetPadMode(NERNST_49_BIAS_PORT, NERNST_49_BIAS_PIN,
|
||||
PAL_MODE_INPUT);
|
||||
/* disable all others ESR drivers */
|
||||
palSetPadMode(NERNST_49_ESR_DRIVER_PORT, NERNST_49_ESR_DRIVER_PIN,
|
||||
PAL_MODE_INPUT);
|
||||
palSetPadMode(NERNST_42_ESR_DRIVER_PORT, NERNST_42_ESR_DRIVER_PIN,
|
||||
PAL_MODE_INPUT);
|
||||
/* enable LSU4.2 */
|
||||
palSetPadMode(NERNST_ADV_ESR_DRIVER_PORT, NERNST_ADV_ESR_DRIVER_PIN,
|
||||
PAL_MODE_OUTPUT_PUSHPULL);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int GetESRSupplyR()
|
||||
{
|
||||
switch (GetSensorType()) {
|
||||
case SensorType::LSU42:
|
||||
return 6800;
|
||||
case SensorType::LSU49:
|
||||
return 22000;
|
||||
case SensorType::LSUADV:
|
||||
return 47000;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -99,20 +99,20 @@
|
|||
* Port B setup.
|
||||
* PB0 - Vbatt_sense (analog in).
|
||||
* PB1 - Heater_sense (analog in).
|
||||
* PB2 - Nernsr_4.9_bias (digital output, 2 Mhz)
|
||||
* PB2 - Nernsr_4.9_bias (digital input, no pull) - keep high-Z after power on
|
||||
* PB3 - SWO (digital input)
|
||||
* PB4..PB5 - DISP1..DISP2 - unused
|
||||
* PB6 - heater_pwm (output pushpull, alternate, 2 MHz).
|
||||
* PB7..PB9 - DISP4..DISP6 - unused
|
||||
* PB10 - Nernsr_ADV_esr_drive (digital input, no pull) - keep high-Z after power on
|
||||
* PB11 - Nernsr_4.9_esr_drive (output pushpull, 50 Mhz)
|
||||
* PB11 - Nernsr_4.9_esr_drive (digital input, no pull) - keep high-Z after power on
|
||||
* PB12 - Nernsr_4.2_esr_drive (digital input, no pull) - keep high-Z after power on
|
||||
* PB13 - Blue LED (output pushpull, 2 MHz)
|
||||
* PB14 - PWMout2 (output pushpull, alternate, 2 Mhz).
|
||||
* PB15 - PWMout1 (output pushpull, alternate, 2 Mhz).
|
||||
*/
|
||||
#define VAL_GPIOBCRL 0x8A888200 /* PB7...PB0 */
|
||||
#define VAL_GPIOBCRH 0xAA243488 /* PB15...PB8 */
|
||||
#define VAL_GPIOBCRL 0x8A888400 /* PB7...PB0 */
|
||||
#define VAL_GPIOBCRH 0xAA244488 /* PB15...PB8 */
|
||||
#define VAL_GPIOBODR 0x0000FFFF
|
||||
|
||||
/*
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
#!/bin/bash
|
||||
|
||||
UDEFS="-DBOARD_DEFAULT_SENSOR_TYPE=SensorType::LSU42" \
|
||||
./build_wideband.sh
|
|
@ -22,8 +22,11 @@
|
|||
#define NERNST_42_ESR_DRIVER_PIN 12
|
||||
|
||||
// LSU 4.9 - 22K
|
||||
#define NERNST_ESR_DRIVER_PORT GPIOB
|
||||
#define NERNST_ESR_DRIVER_PIN 11
|
||||
#define NERNST_49_ESR_DRIVER_PORT GPIOB
|
||||
#define NERNST_49_ESR_DRIVER_PIN 11
|
||||
|
||||
#define NERNST_49_BIAS_PORT GPIOB
|
||||
#define NERNST_49_BIAS_PIN 2
|
||||
|
||||
// LSU ADV - 47K
|
||||
#define NERNST_ADV_ESR_DRIVER_PORT GPIOB
|
||||
|
|
|
@ -76,3 +76,63 @@ AnalogResult AnalogSample()
|
|||
.VirtualGroundVoltageInt = HALF_VCC,
|
||||
};
|
||||
}
|
||||
|
||||
/* TODO: optimize */
|
||||
void SetupESRDriver(SensorType sensor)
|
||||
{
|
||||
switch (sensor) {
|
||||
case SensorType::LSU42:
|
||||
/* disable bias */
|
||||
palSetPadMode(NERNST_49_BIAS_PORT, NERNST_49_BIAS_PIN,
|
||||
PAL_MODE_INPUT);
|
||||
/* disable all others ESR drivers */
|
||||
palSetPadMode(NERNST_49_ESR_DRIVER_PORT, NERNST_49_ESR_DRIVER_PIN,
|
||||
PAL_MODE_INPUT);
|
||||
palSetPadMode(NERNST_ADV_ESR_DRIVER_PORT, NERNST_ADV_ESR_DRIVER_PIN,
|
||||
PAL_MODE_INPUT);
|
||||
/* enable LSU4.2 */
|
||||
palSetPadMode(NERNST_42_ESR_DRIVER_PORT, NERNST_42_ESR_DRIVER_PIN,
|
||||
PAL_MODE_OUTPUT_PUSHPULL);
|
||||
break;
|
||||
case SensorType::LSU49:
|
||||
/* disable all others ESR drivers */
|
||||
palSetPadMode(NERNST_42_ESR_DRIVER_PORT, NERNST_42_ESR_DRIVER_PIN,
|
||||
PAL_MODE_INPUT);
|
||||
palSetPadMode(NERNST_ADV_ESR_DRIVER_PORT, NERNST_ADV_ESR_DRIVER_PIN,
|
||||
PAL_MODE_INPUT);
|
||||
/* enable LSU4.2 */
|
||||
palSetPadMode(NERNST_49_ESR_DRIVER_PORT, NERNST_49_ESR_DRIVER_PIN,
|
||||
PAL_MODE_OUTPUT_PUSHPULL);
|
||||
/* enable bias */
|
||||
palSetPadMode(NERNST_49_BIAS_PORT, NERNST_49_BIAS_PIN,
|
||||
PAL_MODE_OUTPUT_PUSHPULL);
|
||||
palSetPad(NERNST_49_BIAS_PORT, NERNST_49_BIAS_PIN);
|
||||
break;
|
||||
case SensorType::LSUADV:
|
||||
/* disable bias */
|
||||
palSetPadMode(NERNST_49_BIAS_PORT, NERNST_49_BIAS_PIN,
|
||||
PAL_MODE_INPUT);
|
||||
/* disable all others ESR drivers */
|
||||
palSetPadMode(NERNST_49_ESR_DRIVER_PORT, NERNST_49_ESR_DRIVER_PIN,
|
||||
PAL_MODE_INPUT);
|
||||
palSetPadMode(NERNST_42_ESR_DRIVER_PORT, NERNST_42_ESR_DRIVER_PIN,
|
||||
PAL_MODE_INPUT);
|
||||
/* enable LSU4.2 */
|
||||
palSetPadMode(NERNST_ADV_ESR_DRIVER_PORT, NERNST_ADV_ESR_DRIVER_PIN,
|
||||
PAL_MODE_OUTPUT_PUSHPULL);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int GetESRSupplyR()
|
||||
{
|
||||
switch (GetSensorType()) {
|
||||
case SensorType::LSU42:
|
||||
return 6800;
|
||||
case SensorType::LSU49:
|
||||
return 22000;
|
||||
case SensorType::LSUADV:
|
||||
return 47000;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -22,8 +22,11 @@
|
|||
#define NERNST_42_ESR_DRIVER_PIN 12
|
||||
|
||||
// LSU 4.9 - 22K
|
||||
#define NERNST_ESR_DRIVER_PORT GPIOB
|
||||
#define NERNST_ESR_DRIVER_PIN 11
|
||||
#define NERNST_49_ESR_DRIVER_PORT GPIOB
|
||||
#define NERNST_49_ESR_DRIVER_PIN 11
|
||||
|
||||
#define NERNST_49_BIAS_PORT GPIOB
|
||||
#define NERNST_49_BIAS_PIN 2
|
||||
|
||||
// LSU ADV - 47K
|
||||
#define NERNST_ADV_ESR_DRIVER_PORT GPIOB
|
||||
|
|
|
@ -73,3 +73,63 @@ AnalogResult AnalogSample()
|
|||
.VirtualGroundVoltageInt = HALF_VCC,
|
||||
};
|
||||
}
|
||||
|
||||
/* TODO: optimize */
|
||||
void SetupESRDriver(SensorType sensor)
|
||||
{
|
||||
switch (sensor) {
|
||||
case SensorType::LSU42:
|
||||
/* disable bias */
|
||||
palSetPadMode(NERNST_49_BIAS_PORT, NERNST_49_BIAS_PIN,
|
||||
PAL_MODE_INPUT);
|
||||
/* disable all others ESR drivers */
|
||||
palSetPadMode(NERNST_49_ESR_DRIVER_PORT, NERNST_49_ESR_DRIVER_PIN,
|
||||
PAL_MODE_INPUT);
|
||||
palSetPadMode(NERNST_ADV_ESR_DRIVER_PORT, NERNST_ADV_ESR_DRIVER_PIN,
|
||||
PAL_MODE_INPUT);
|
||||
/* enable LSU4.2 */
|
||||
palSetPadMode(NERNST_42_ESR_DRIVER_PORT, NERNST_42_ESR_DRIVER_PIN,
|
||||
PAL_MODE_OUTPUT_PUSHPULL);
|
||||
break;
|
||||
case SensorType::LSU49:
|
||||
/* disable all others ESR drivers */
|
||||
palSetPadMode(NERNST_42_ESR_DRIVER_PORT, NERNST_42_ESR_DRIVER_PIN,
|
||||
PAL_MODE_INPUT);
|
||||
palSetPadMode(NERNST_ADV_ESR_DRIVER_PORT, NERNST_ADV_ESR_DRIVER_PIN,
|
||||
PAL_MODE_INPUT);
|
||||
/* enable LSU4.2 */
|
||||
palSetPadMode(NERNST_49_ESR_DRIVER_PORT, NERNST_49_ESR_DRIVER_PIN,
|
||||
PAL_MODE_OUTPUT_PUSHPULL);
|
||||
/* enable bias */
|
||||
palSetPadMode(NERNST_49_BIAS_PORT, NERNST_49_BIAS_PIN,
|
||||
PAL_MODE_OUTPUT_PUSHPULL);
|
||||
palSetPad(NERNST_49_BIAS_PORT, NERNST_49_BIAS_PIN);
|
||||
break;
|
||||
case SensorType::LSUADV:
|
||||
/* disable bias */
|
||||
palSetPadMode(NERNST_49_BIAS_PORT, NERNST_49_BIAS_PIN,
|
||||
PAL_MODE_INPUT);
|
||||
/* disable all others ESR drivers */
|
||||
palSetPadMode(NERNST_49_ESR_DRIVER_PORT, NERNST_49_ESR_DRIVER_PIN,
|
||||
PAL_MODE_INPUT);
|
||||
palSetPadMode(NERNST_42_ESR_DRIVER_PORT, NERNST_42_ESR_DRIVER_PIN,
|
||||
PAL_MODE_INPUT);
|
||||
/* enable LSU4.2 */
|
||||
palSetPadMode(NERNST_ADV_ESR_DRIVER_PORT, NERNST_ADV_ESR_DRIVER_PIN,
|
||||
PAL_MODE_OUTPUT_PUSHPULL);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int GetESRSupplyR()
|
||||
{
|
||||
switch (GetSensorType()) {
|
||||
case SensorType::LSU42:
|
||||
return 6800;
|
||||
case SensorType::LSU49:
|
||||
return 22000;
|
||||
case SensorType::LSUADV:
|
||||
return 47000;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -76,3 +76,6 @@ const char *getTsSignature();
|
|||
|
||||
// LSU4.2, LSU4.9 or LSU_ADV
|
||||
SensorType GetSensorType();
|
||||
void SetupESRDriver(SensorType sensor);
|
||||
void ToggleESRDriver(SensorType sensor);
|
||||
int GetESRSupplyR();
|
||||
|
|
|
@ -45,6 +45,7 @@ static void SamplingThread(void*)
|
|||
|
||||
chRegSetThreadName("Sampling");
|
||||
|
||||
SetupESRDriver(GetSensorType());
|
||||
|
||||
/* GD32: Insert 20us delay after ADC enable */
|
||||
chThdSleepMilliseconds(1);
|
||||
|
@ -54,7 +55,7 @@ static void SamplingThread(void*)
|
|||
auto result = AnalogSample();
|
||||
|
||||
// Toggle the pin after sampling so that any switching noise occurs while we're doing our math instead of when sampling
|
||||
palTogglePad(NERNST_ESR_DRIVER_PORT, NERNST_ESR_DRIVER_PIN);
|
||||
ToggleESRDriver(GetSensorType());
|
||||
|
||||
for (int ch = 0; ch < AFR_CHANNELS; ch++) {
|
||||
measure_results &res = results[ch];
|
||||
|
@ -109,8 +110,8 @@ float GetNernstAc(int ch)
|
|||
|
||||
float GetSensorInternalResistance(int ch)
|
||||
{
|
||||
// Sensor is the lowside of a divider, top side is 22k, and 3.3v AC pk-pk is injected
|
||||
float totalEsr = ESR_SUPPLY_R / (VCC_VOLTS / GetNernstAc(ch) - 1);
|
||||
// Sensor is the lowside of a divider, top side is GetESRSupplyR(), and 3.3v AC pk-pk is injected
|
||||
float totalEsr = GetESRSupplyR() / (VCC_VOLTS / GetNernstAc(ch) - 1);
|
||||
|
||||
// There is a resistor between the opamp and Vm sensor pin. Remove the effect of that
|
||||
// resistor so that the remainder is only the ESR of the sensor itself
|
||||
|
|
|
@ -14,9 +14,6 @@
|
|||
// Nernst voltage & ESR sense
|
||||
// *******************************
|
||||
|
||||
// Nernst AC injection resistor value
|
||||
#define ESR_SUPPLY_R (22000)
|
||||
|
||||
// Heater low pass filter
|
||||
#define ESR_SENSE_ALPHA (0.002f)
|
||||
|
||||
|
|
Loading…
Reference in New Issue