Stepper direct push pull driver (#3751)
* Init DC motor through two brain_pin_e only * idle: stepper: allow driving stepper through 4 output_pin_e
This commit is contained in:
parent
5bc9289d74
commit
77fa9929d0
|
@ -131,6 +131,23 @@ DcMotor* initDcMotor(const dc_io& io, size_t index, bool useTwoWires) {
|
||||||
return &hw.dcMotor;
|
return &hw.dcMotor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DcMotor* initDcMotor(brain_pin_e coil_p, brain_pin_e coil_m, size_t index) {
|
||||||
|
auto& hw = dcHardware[index];
|
||||||
|
|
||||||
|
hw.start(
|
||||||
|
true, /* useTwoWires */
|
||||||
|
GPIO_UNASSIGNED, /* pinEnable */
|
||||||
|
coil_p,
|
||||||
|
coil_m,
|
||||||
|
GPIO_UNASSIGNED, /* pinDisable */
|
||||||
|
engineConfiguration->stepperDcInvertedPins,
|
||||||
|
&engine->executor,
|
||||||
|
engineConfiguration->etbFreq /* same in case of stepper? */
|
||||||
|
);
|
||||||
|
|
||||||
|
return &hw.dcMotor;
|
||||||
|
}
|
||||||
|
|
||||||
void setDcMotorFrequency(size_t index, int hz) {
|
void setDcMotorFrequency(size_t index, int hz) {
|
||||||
dcHardware[index].setFrequency(hz);
|
dcHardware[index].setFrequency(hz);
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
class DcMotor;
|
class DcMotor;
|
||||||
|
|
||||||
DcMotor* initDcMotor(const dc_io& io, size_t index, bool useTwoWires);
|
DcMotor* initDcMotor(const dc_io& io, size_t index, bool useTwoWires);
|
||||||
|
DcMotor* initDcMotor(brain_pin_e coil_p, brain_pin_e coil_m, size_t index);
|
||||||
|
|
||||||
// Manual control of motors for use by console commands
|
// Manual control of motors for use by console commands
|
||||||
void setDcMotorFrequency(size_t index, int hz);
|
void setDcMotorFrequency(size_t index, int hz);
|
||||||
|
|
|
@ -76,7 +76,12 @@ bool isIdleHardwareRestartNeeded() {
|
||||||
isConfigurationChanged(useStepperIdle) ||
|
isConfigurationChanged(useStepperIdle) ||
|
||||||
isConfigurationChanged(useETBforIdleControl) ||
|
isConfigurationChanged(useETBforIdleControl) ||
|
||||||
isConfigurationChanged(idle.solenoidPin) ||
|
isConfigurationChanged(idle.solenoidPin) ||
|
||||||
isConfigurationChanged(secondSolenoidPin);
|
isConfigurationChanged(secondSolenoidPin) ||
|
||||||
|
isConfigurationChanged(useRawOutputToDriveIdleStepper) ||
|
||||||
|
isConfigurationChanged(stepper_raw_output[0]) ||
|
||||||
|
isConfigurationChanged(stepper_raw_output[1]) ||
|
||||||
|
isConfigurationChanged(stepper_raw_output[2]) ||
|
||||||
|
isConfigurationChanged(stepper_raw_output[3]);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isIdleMotorBusy() {
|
bool isIdleMotorBusy() {
|
||||||
|
@ -91,9 +96,26 @@ void initIdleHardware() {
|
||||||
if (engineConfiguration->useStepperIdle) {
|
if (engineConfiguration->useStepperIdle) {
|
||||||
StepperHw* hw;
|
StepperHw* hw;
|
||||||
|
|
||||||
if (engineConfiguration->useHbridgesToDriveIdleStepper) {
|
if (engineConfiguration->useRawOutputToDriveIdleStepper) {
|
||||||
auto motorA = initDcMotor(engineConfiguration->stepperDcIo[0], 2, /*useTwoWires*/ true);
|
auto motorA = initDcMotor(engineConfiguration->stepper_raw_output[0],
|
||||||
auto motorB = initDcMotor(engineConfiguration->stepperDcIo[1], 3, /*useTwoWires*/ true);
|
engineConfiguration->stepper_raw_output[1], ETB_COUNT + 0);
|
||||||
|
auto motorB = initDcMotor(engineConfiguration->stepper_raw_output[2],
|
||||||
|
engineConfiguration->stepper_raw_output[3], ETB_COUNT + 1);
|
||||||
|
|
||||||
|
if (motorA && motorB) {
|
||||||
|
iacHbridgeHw.initialize(
|
||||||
|
motorA,
|
||||||
|
motorB,
|
||||||
|
engineConfiguration->idleStepperReactionTime
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
hw = &iacHbridgeHw;
|
||||||
|
} else if (engineConfiguration->useHbridgesToDriveIdleStepper) {
|
||||||
|
auto motorA = initDcMotor(engineConfiguration->stepperDcIo[0],
|
||||||
|
ETB_COUNT + 0, /*useTwoWires*/ true);
|
||||||
|
auto motorB = initDcMotor(engineConfiguration->stepperDcIo[1],
|
||||||
|
ETB_COUNT + 1, /*useTwoWires*/ true);
|
||||||
|
|
||||||
if (motorA && motorB) {
|
if (motorA && motorB) {
|
||||||
iacHbridgeHw.initialize(
|
iacHbridgeHw.initialize(
|
||||||
|
|
|
@ -66,13 +66,20 @@ void idleDebug(const char *msg, percent_t value) {
|
||||||
|
|
||||||
static void showIdleInfo() {
|
static void showIdleInfo() {
|
||||||
const char * idleModeStr = getIdle_mode_e(engineConfiguration->idleMode);
|
const char * idleModeStr = getIdle_mode_e(engineConfiguration->idleMode);
|
||||||
efiPrintf("useStepperIdle=%s useHbridges=%s",
|
efiPrintf("useStepperIdle=%s useHbridges=%s useRawOutput=%s",
|
||||||
boolToString(engineConfiguration->useStepperIdle), boolToString(engineConfiguration->useHbridgesToDriveIdleStepper));
|
boolToString(engineConfiguration->useStepperIdle),
|
||||||
|
boolToString(engineConfiguration->useHbridgesToDriveIdleStepper),
|
||||||
|
boolToString(engineConfiguration->useRawOutputToDriveIdleStepper));
|
||||||
efiPrintf("idleMode=%s position=%.2f",
|
efiPrintf("idleMode=%s position=%.2f",
|
||||||
idleModeStr, getIdlePosition());
|
idleModeStr, getIdlePosition());
|
||||||
|
|
||||||
if (engineConfiguration->useStepperIdle) {
|
if (engineConfiguration->useStepperIdle) {
|
||||||
if (engineConfiguration->useHbridgesToDriveIdleStepper) {
|
if (engineConfiguration->useRawOutputToDriveIdleStepper) {
|
||||||
|
efiPrintf(" A+=%s", hwPortname(engineConfiguration->stepper_raw_output[0]));
|
||||||
|
efiPrintf(" A-=%s", hwPortname(engineConfiguration->stepper_raw_output[1]));
|
||||||
|
efiPrintf(" B+=%s", hwPortname(engineConfiguration->stepper_raw_output[2]));
|
||||||
|
efiPrintf(" B-=%s", hwPortname(engineConfiguration->stepper_raw_output[3]));
|
||||||
|
} else if (engineConfiguration->useHbridgesToDriveIdleStepper) {
|
||||||
efiPrintf("Coil A:");
|
efiPrintf("Coil A:");
|
||||||
efiPrintf(" pin1=%s", hwPortname(engineConfiguration->stepperDcIo[0].directionPin1));
|
efiPrintf(" pin1=%s", hwPortname(engineConfiguration->stepperDcIo[0].directionPin1));
|
||||||
efiPrintf(" pin2=%s", hwPortname(engineConfiguration->stepperDcIo[0].directionPin2));
|
efiPrintf(" pin2=%s", hwPortname(engineConfiguration->stepperDcIo[0].directionPin2));
|
||||||
|
|
Loading…
Reference in New Issue