This commit is contained in:
rusefi 2020-03-10 19:12:53 -04:00
commit 70c2f6990f
4 changed files with 99 additions and 9 deletions

View File

@ -42,8 +42,10 @@
#if ! EFI_UNIT_TEST
#include "stepper.h"
#include "dc_motors.h"
#include "pin_repository.h"
static StepDirectionStepper iacStepperHw;
static DualHBridgeStepper iacHbridgeHw;
static StepperMotor iacMotor;
#endif /* EFI_UNIT_TEST */
@ -558,16 +560,35 @@ void stopIdleHardware(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
void initIdleHardware(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
if (CONFIG(useStepperIdle)) {
iacStepperHw.initialize(
CONFIG(idle).stepperStepPin,
CONFIG(idle).stepperDirectionPin,
CONFIG(stepperDirectionPinMode),
CONFIG(idleStepperReactionTime),
CONFIG(stepperEnablePin),
CONFIG(stepperEnablePinMode)
);
StepperHw* hw;
iacMotor.initialize(&iacStepperHw, CONFIG(idleStepperTotalSteps), logger);
if (CONFIG(useHbridges)) {
auto motorA = initDcMotor(0 PASS_ENGINE_PARAMETER_SUFFIX);
auto motorB = initDcMotor(1 PASS_ENGINE_PARAMETER_SUFFIX);
if (motorA && motorB) {
iacHbridgeHw.initialize(
motorA,
motorB,
CONFIG(idleStepperReactionTime)
);
}
hw = &iacHbridgeHw;
} else {
iacStepperHw.initialize(
CONFIG(idle).stepperStepPin,
CONFIG(idle).stepperDirectionPin,
CONFIG(stepperDirectionPinMode),
CONFIG(idleStepperReactionTime),
CONFIG(stepperEnablePin),
CONFIG(stepperEnablePinMode)
);
hw = &iacStepperHw;
}
iacMotor.initialize(hw, CONFIG(idleStepperTotalSteps), logger);
// This greatly improves PID accuracy for steppers with a small number of steps
idlePositionSensitivityThreshold = 1.0f / engineConfiguration->idleStepperTotalSteps;

View File

@ -32,6 +32,7 @@ HW_LAYER_EMS_CPP = $(HW_LAYER_EGT_CPP) \
$(PROJECT_DIR)/hw_layer/hip9011_logic.cpp \
$(PROJECT_DIR)/hw_layer/vehicle_speed.cpp \
$(PROJECT_DIR)/hw_layer/stepper.cpp \
$(PROJECT_DIR)/hw_layer/stepper_dual_hbridge.cpp \
$(PROJECT_DIR)/hw_layer/servo.cpp \
$(PROJECT_DIR)/hw_layer/io_pins.cpp \
$(PROJECT_DIR)/hw_layer/rtc_helper.cpp \

View File

@ -40,6 +40,21 @@ private:
pin_output_mode_e directionPinMode, stepPinMode, enablePinMode;
};
class DcMotor;
class DualHBridgeStepper final : public StepperHw {
public:
void initialize(DcMotor* motorPhaseA, DcMotor* motorPhaseB, float reactionTime);
void step(bool positive) override;
private:
DcMotor* m_motorPhaseA;
DcMotor* m_motorPhaseB;
uint8_t m_phase = 0;
};
class StepperMotor final : private ThreadController<UTILITY_THREAD_STACK_SIZE> {
public:
StepperMotor();

View File

@ -0,0 +1,53 @@
#include "efifeatures.h"
#if !EFI_UNIT_TEST
#include "stepper.h"
#include "dc_motor.h"
static const int8_t phaseA[] =
{
1,
1,
-1,
-1
};
static const int8_t phaseB[] =
{
-1,
1,
1,
-1
};
void DualHBridgeStepper::initialize(DcMotor* motorPhaseA, DcMotor* motorPhaseB, float reactionTime)
{
setReactionTime(reactionTime);
m_motorPhaseA = motorPhaseA;
m_motorPhaseB = motorPhaseB;
}
void DualHBridgeStepper::step(bool positive) {
// Check that we've been initialized
if (!m_motorPhaseA || !m_motorPhaseB) {
return;
}
// step phase, wrapping
if (positive) {
m_phase = (m_phase + 1) & 0x03;
} else {
m_phase = (m_phase - 1) & 0x03;
}
// Set phases according to the table
m_motorPhaseA->set(phaseA[m_phase]);
m_motorPhaseB->set(phaseB[m_phase]);
pause();
}
#endif