Lock and unlock


The control lock is a kind of physical protection function. This function is to connect a limit switch to the digital input port and disable further control if the switch is closed. Therefore, the operating range of the stepper motor can be limited.

Control lock

If the operation of the motor is stopped by the limit switch, the motor status is locked and no further control is possible until the lock is released.

Setting the control lock

Set the input mode of the digital input port to control lock referring to Settings chapter.

Unlock

You can unlock a stepper motor by using unlock() function.

step.unlock()

When you execute the unlock function, the motor status changes from the lock state to the stop state and the input mode of the digital input port is reset to the normal input mode from the control lock mode.

That means you can control the motor normally after executing unlock().

Example

#include <PhpocExpansion.h>
#include <Phpoc.h>

byte spcId = 1;

ExpansionStepper step(spcId);

int state;

void setup() {
    Serial.begin(9600);
    while(!Serial)
        ;

    Phpoc.begin(PF_LOG_SPI | PF_LOG_NET);
    Expansion.begin();

    Serial.println(step.getPID());
    Serial.println(step.getName());

    step.setMode(4);
    step.setVrefStop(2);
    step.setVrefDrive(8);
    step.setVrefLock(8);
    step.setSpeed(400);
    step.setAccel(4000);

    step.setEioMode(0, 1);
    step.setEioMode(1, 1);
    step.setEioMode(2, 1);
    step.setEioMode(3, 1);

    step.stepGoto(4000);

    while(step.getState() > 1) {
        delay(1);
    }

    // state: 0 - stop, 1 - locked
    Serial.print("step_state ");
    Serial.println(step.getState());

    step.unlock();

    // state: 0 - stop, 1 - locked
    Serial.print("step_state ");
    Serial.println(step.getState());
}

void loop() {

}
step_state 1
step_state 0