Fix stepper motor (#541)

This commit is contained in:
andreika-git 2018-01-23 00:48:12 +02:00 committed by rusefi
parent 4765c0a861
commit ac43689791
1 changed files with 8 additions and 2 deletions

View File

@ -30,8 +30,6 @@ static int loadStepperPos() {
static msg_t stThread(StepperMotor *motor) {
chRegSetThreadName("stepper");
motor->directionPin.setValue(false);
// try to get saved stepper position (-1 for no data)
motor->currentPosition = loadStepperPos();
@ -60,6 +58,10 @@ static msg_t stThread(StepperMotor *motor) {
saveStepperPos(motor->currentPosition);
}
// The initial target position should correspond to the saved stepper position.
// Idle thread starts later and sets a new target position.
motor->setTargetPosition(motor->currentPosition);
while (true) {
int targetPosition = motor->getTargetPosition();
int currentPosition = motor->currentPosition;
@ -142,6 +144,10 @@ void StepperMotor::initialize(brain_pin_e stepPin, brain_pin_e directionPin, pin
efiSetPadMode("stepper enable", enablePin, PAL_MODE_OUTPUT_PUSHPULL);
palWritePad(this->enablePort, enablePin, true); // disable stepper
// All pins must be 0 for correct hardware startup (e.g. stepper auto-disabling circuit etc.).
palWritePad(this->stepPort, this->stepPin, false);
this->directionPin.setValue(false);
chThdCreateStatic(stThreadStack, sizeof(stThreadStack), NORMALPRIO, (tfunc_t) stThread, this);
}