support ETB disable pin (#1273)

* config & hand gen

* board configs

* add dc motor support

* initialization

* also set duty to zero

* use disable in etb

* fix proteus default

* add TS fields

* I guess we needed 8 bytes

* :D

* comment

Co-authored-by: Matthew Kennedy <makenne@microsoft.com>
This commit is contained in:
Matthew Kennedy 2020-04-10 14:27:13 -07:00 committed by GitHub
parent 16c52b68c8
commit 001ef27eb8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 61 additions and 36 deletions

View File

@ -495,7 +495,7 @@ struct etb_io {
/**
* offset 3
*/
uint8_t pad;
brain_pin_e disablePin;
/** total size 4*/
};

View File

@ -109,25 +109,15 @@ static void setupEtb() {
engineConfiguration->etbIo[0].controlPin1 = GPIOC_7;
// DIR pin
engineConfiguration->etbIo[0].directionPin1 = GPIOA_8;
// set_fsio_output_pin 7 PC8
#if EFI_FSIO
// set_rpn_expression 8 "1"
// disable ETB by default
setFsio(7, GPIOC_8, "1" PASS_CONFIG_PARAMETER_SUFFIX);
// enable ETB
// set_rpn_expression 8 "0"
//setFsio(7, GPIOC_8, "0" PASS_CONFIG_PARAMETER_SUFFIX);
#endif /* EFI_FSIO */
// Disable pin
engineConfiguration->etbIo[0].disablePin = GPIOC_8;
// Unused
engineConfiguration->etbIo[0].directionPin2 = GPIO_UNASSIGNED;
// set_analog_input_pin pps PA7
// EFI_ADC_7: "31 - AN volt 3" - PA7
// engineConfiguration->throttlePedalPositionAdcChannel = EFI_ADC_7;
// Unused
engineConfiguration->etbIo[0].directionPin2 = GPIO_UNASSIGNED;
// we only have pwm/dir, no dira/dirb
engineConfiguration->etb_use_two_wires = false;

View File

@ -86,6 +86,8 @@ static void setupEtb() {
engineConfiguration->etbIo[0].controlPin1 = GPIOD_12;
// DIR pin
engineConfiguration->etbIo[0].directionPin1 = GPIOD_10;
// Disable pin
engineConfiguration->etbIo[0].disablePin = GPIOD_11;
// Unused
engineConfiguration->etbIo[0].directionPin2 = GPIO_UNASSIGNED;
@ -94,15 +96,11 @@ static void setupEtb() {
engineConfiguration->etbIo[1].controlPin1 = GPIOD_13;
// DIR pin
engineConfiguration->etbIo[1].directionPin1 = GPIOD_9;
// Disable pin
engineConfiguration->etbIo[1].disablePin = GPIOD_8;
// Unused
engineConfiguration->etbIo[1].directionPin2 = GPIO_UNASSIGNED;
#if EFI_FSIO
// disable ETB by default
setFsio(7, GPIOD_8, "1" PASS_CONFIG_PARAMETER_SUFFIX);
setFsio(8, GPIOD_11, "1" PASS_CONFIG_PARAMETER_SUFFIX);
#endif /* EFI_FSIO */
// we only have pwm/dir, no dira/dirb
engineConfiguration->etb_use_two_wires = false;
engineConfiguration->etbFreq = 800;

View File

@ -349,11 +349,11 @@ void setTle8888TestConfiguration(DECLARE_CONFIG_PARAMETER_SIGNATURE) {
// SF PF11
#if defined(STM32_HAS_GPIOF) && STM32_HAS_GPIOF
#if EFI_FSIO
setFsio(12, GPIOF_12, "0" PASS_CONFIG_PARAMETER_SUFFIX);
setFsio(14, GPIOF_13, "1" PASS_CONFIG_PARAMETER_SUFFIX);
#endif /* EFI_FSIO */
CONFIG(etbIo[0].directionPin1) = GPIOF_15;
CONFIG(etbIo[0].directionPin2) = GPIOF_14;
CONFIG(etbIo[0].disablePin) = GPIOF_12;
#endif /* STM32_HAS_GPIOF */
CONFIG(etb_use_two_wires) = true;
engineConfiguration->isHip9011Enabled = false;
@ -365,11 +365,11 @@ void setTle8888TestConfiguration(DECLARE_CONFIG_PARAMETER_SIGNATURE) {
// IN2 PE4
// SF PE3
#if EFI_FSIO
setFsio(13, GPIOE_5, "0" PASS_CONFIG_PARAMETER_SUFFIX);
setFsio(15, GPIOE_6, "1" PASS_CONFIG_PARAMETER_SUFFIX);
#endif
CONFIG(etbIo[0].directionPin1) = GPIOE_2;
CONFIG(etbIo[0].directionPin2) = GPIOE_4;
CONFIG(etbIo[0].disablePin) = GPIOE_5;
engineConfiguration->tps1_1AdcChannel = EFI_ADC_3; // PA3

View File

@ -134,7 +134,6 @@ void vag_18_Turbo(DECLARE_CONFIG_PARAMETER_SIGNATURE) {
#if EFI_FSIO
#if defined(STM32_HAS_GPIOF) && STM32_HAS_GPIOF
setFsio (12, GPIOF_12, "0" PASS_CONFIG_PARAMETER_SUFFIX);
setFsio (14, GPIOF_13, "1" PASS_CONFIG_PARAMETER_SUFFIX);
#endif /* STM32_HAS_GPIOF */
setFsioExt (3, GPIOE_0, "0.15 90 coolant 120 min max 90 - 30 / 0.8 * +", 25 PASS_CONFIG_PARAMETER_SUFFIX);
@ -144,15 +143,16 @@ void vag_18_Turbo(DECLARE_CONFIG_PARAMETER_SIGNATURE) {
#if defined(STM32_HAS_GPIOF) && STM32_HAS_GPIOF
CONFIG(etbIo[0].directionPin1) = GPIOF_15;
CONFIG(etbIo[0].directionPin2) = GPIOF_14;
CONFIG(etbIo[0].disablePin) = GPIOF_12;
#endif /* STM32_HAS_GPIOF */
engineConfiguration->isHip9011Enabled = false;
#if EFI_FSIO
setFsio (13, GPIOE_5, "0" PASS_CONFIG_PARAMETER_SUFFIX);
setFsio (15, GPIOE_6, "1" PASS_CONFIG_PARAMETER_SUFFIX);
#endif
CONFIG(etbIo[1].directionPin1) = GPIOE_2;
CONFIG(etbIo[1].directionPin2) = GPIOE_4;
CONFIG(etbIo[1].disablePin) = GPIOE_5;
engineConfiguration->etb.pFactor = 1.07;
engineConfiguration->etb.iFactor = 0.18;

View File

@ -24,6 +24,7 @@ private:
OutputPin m_pinEnable;
OutputPin m_pinDir1;
OutputPin m_pinDir2;
OutputPin m_disablePin;
SimplePwm m_pwmEnable;
SimplePwm m_pwmDir1;
@ -32,7 +33,7 @@ private:
SimplePwm etbPwmUp;
public:
EtbHardware() : etbPwmUp("etbUp"), dcMotor(&m_pwmEnable, &m_pwmDir1, &m_pwmDir2) {}
EtbHardware() : etbPwmUp("etbUp"), dcMotor(&m_pwmEnable, &m_pwmDir1, &m_pwmDir2, &m_disablePin) {}
TwoPinDcMotor dcMotor;
@ -47,10 +48,14 @@ public:
// since we have pointer magic here we cannot simply have value parameter
brain_pin_e pinDir1,
brain_pin_e pinDir2,
brain_pin_e pinDisable,
ExecutorInterface* executor,
int frequency) {
dcMotor.setType(useTwoWires ? TwoPinDcMotor::ControlType::PwmDirectionPins : TwoPinDcMotor::ControlType::PwmEnablePin);
// Configure the disable pin first - ensure things are in a safe state
m_disablePin.initPin("ETB Disable", pinDisable);
m_pinEnable.initPin("ETB Enable", pinEnable);
m_pinDir1.initPin("ETB Dir 1", pinDir1);
m_pinDir2.initPin("ETB Dir 2", pinDir2);
@ -96,6 +101,7 @@ DcMotor* initDcMotor(size_t index DECLARE_ENGINE_PARAMETER_SUFFIX)
io.controlPin1,
io.directionPin1,
io.directionPin2,
io.disablePin,
&ENGINE(executor),
CONFIG(etbFreq)
);

View File

@ -160,7 +160,7 @@ void EtbController::PeriodicTask() {
}
if (startupPositionError) {
m_motor->set(0);
m_motor->disable();
return;
}
@ -175,21 +175,21 @@ void EtbController::PeriodicTask() {
}
if (engineConfiguration->pauseEtbControl) {
m_motor->set(0);
m_motor->disable();
return;
}
auto pedalPosition = Sensor::get(SensorType::AcceleratorPedal);
if (!pedalPosition.Valid) {
m_motor->set(0);
m_motor->disable();
return;
}
SensorResult actualThrottlePosition = Sensor::get(indexToTpsSensor(m_myIndex));
if (!actualThrottlePosition.Valid) {
m_motor->set(0);
m_motor->disable();
return;
}
@ -239,6 +239,7 @@ void EtbController::PeriodicTask() {
currentEtbDuty = engine->engineState.etbFeedForward +
m_pid.getOutput(targetPosition, actualThrottlePosition.Value);
m_motor->enable();
m_motor->set(ETB_PERCENT_TO_DUTY(currentEtbDuty));
if (engineConfiguration->isVerboseETB) {

View File

@ -695,7 +695,7 @@ void initEngineContoller(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_SUFFIX)
// help to notice when RAM usage goes up - if a code change adds to RAM usage these variables would fail
// linking process which is the way to raise the alarm
#ifndef RAM_UNUSED_SIZE
#define RAM_UNUSED_SIZE 13850
#define RAM_UNUSED_SIZE 13800
#endif
#ifndef CCM_UNUSED_SIZE
#define CCM_UNUSED_SIZE 4100

View File

@ -495,7 +495,7 @@ struct etb_io {
/**
* offset 3
*/
uint8_t pad;
brain_pin_e disablePin;
/** total size 4*/
};

View File

@ -7,13 +7,31 @@
*/
#include "dc_motor.h"
#include "efi_gpio.h"
#include "pwm_generator_logic.h"
TwoPinDcMotor::TwoPinDcMotor(SimplePwm* enable, SimplePwm* dir1, SimplePwm* dir2)
TwoPinDcMotor::TwoPinDcMotor(SimplePwm* enable, SimplePwm* dir1, SimplePwm* dir2, OutputPin* disablePin)
: m_enable(enable)
, m_dir1(dir1)
, m_dir2(dir2)
, m_disable(disablePin)
{
disable();
}
void TwoPinDcMotor::enable() {
if (m_disable) {
m_disable->setValue(false);
}
}
void TwoPinDcMotor::disable() {
if (m_disable) {
m_disable->setValue(true);
}
// Also set the duty to zero
set(0);
}
bool TwoPinDcMotor::isOpenDirection() const {

View File

@ -32,10 +32,14 @@ public:
*/
virtual float get() const = 0;
virtual void disable() = 0;
virtual void enable() = 0;
virtual bool isOpenDirection() const = 0;
};
class SimplePwm;
class OutputPin;
/**
* @brief Represents a DC motor controller (H-bridge) with some combination of PWM and on/off control pins.
@ -70,6 +74,7 @@ private:
SimplePwm* const m_enable;
SimplePwm* const m_dir1;
SimplePwm* const m_dir2;
OutputPin* const m_disable;
float m_value = 0;
ControlType m_type;
@ -79,11 +84,14 @@ public:
* @param dir1 Enable 1 or direction 1 pin. Gets set high to rotate forward.
* @param dir2 Enable 2 or direction 2 pin. Gets set high to rotate backward.
*/
TwoPinDcMotor(SimplePwm* enable, SimplePwm* dir1, SimplePwm* dir2);
TwoPinDcMotor(SimplePwm* enable, SimplePwm* dir1, SimplePwm* dir2, OutputPin* disable);
virtual bool set(float duty) override;
float get() const override;
bool isOpenDirection() const override;
void enable();
void disable();
void setType(ControlType type) { m_type = type; }
};

View File

@ -525,7 +525,7 @@ struct etb_io
brain_pin_e directionPin1;
brain_pin_e directionPin2;
brain_pin_e controlPin1;
uint8_t pad;
brain_pin_e disablePin;
end_struct
idle_hardware_s idle;

View File

@ -1773,10 +1773,12 @@ cmd_set_engine_type_default = "w\x00\x31\x00\x00"
field = "Fuel Pump Pin", fuelPumpPin
field = "ETB#1 Dir #1", etbIo1_directionPin1 @@if_ts_show_etb_pins
field = "ETB#1 Dir #2", etbIo1_directionPin2 @@if_ts_show_etb_pins
field = "ETB#1 Control #1", etbIo1_controlPin1 @@if_ts_show_etb_pins
field = "ETB#1 Control #1", etbIo1_controlPin1 @@if_ts_show_etb_pins
field = "ETB#1 Disable", etbIo1_disablePin @@if_ts_show_etb_pins
field = "ETB#2 Dir #1", etbIo2_directionPin1 @@if_ts_show_etb_pins
field = "ETB#2 Dir #2", etbIo2_directionPin2 @@if_ts_show_etb_pins
field = "ETB#2 Control #1", etbIo2_controlPin1 @@if_ts_show_etb_pins
field = "ETB#2 Disable", etbIo2_disablePin @@if_ts_show_etb_pins
field = "SD CS Pin", sdCardCsPin @@if_ts_show_sd_card
field = "MIL / Check Engine Pin", malfunctionIndicatorPin
field = "Aux Pin #1", auxPidPins1
@ -2055,9 +2057,11 @@ cmd_set_engine_type_default = "w\x00\x31\x00\x00"
field = "No1 Direction #1", etbIo1_directionPin1
field = "No1 Direction #2", etbIo1_directionPin2
field = "No1 Control #1", etbIo1_controlPin1, { etb_use_two_wires == 0 }
field = "No1 Disable", etbIo1_disablePin
field = "No2 Direction #1", etbIo2_directionPin1
field = "No2 Direction #2", etbIo2_directionPin2
field = "No2 Control #1", etbIo2_controlPin1, { etb_use_two_wires == 0}
field = "No2 Disable", etbIo2_disablePin
dialog = idleStepperHw, "Stepper Hardware"
field = "Idle Stepper Step Pin", idle_stepperStepPin