Hi Robin2,
If I leave the rest and just replace with this code works but I have not faster.
Work this code
void loop() {
//do stuff dependent on encoder position here
//such as move a stepper motor to match encoder position
//if you want to make it 1:1 ensure the encoder res matches the motor res by dividing/multiplying
if (encoder > 0) {
digitalWrite(motor_direction, HIGH);// move stepper in reverse
digitalWrite(motor_step, HIGH);
digitalWrite(motor_step, LOW);
delayMicroseconds(600); //_delay_us(200); //modify to alter speed
motor_position++;
encoder = 0; //encoder--;
}
else if (encoder < 0) {
digitalWrite (motor_direction, LOW); //move stepper forward
digitalWrite (motor_step, HIGH);
digitalWrite (motor_step, LOW);
delayMicroseconds(600); //_delay_us(200); //modify to alter speed
motor_position--;
encoder = 0; //encoder++;
}
}
This not work
void loop() {
//do stuff dependent on encoder position here
//such as move a stepper motor to match encoder position
//if you want to make it 1:1 ensure the encoder res matches the motor res by dividing/multiplying
if (encoder > 0) {
//digitalWrite(motor_direction, HIGH);// move stepper in reverse
PORTD = PORTD | 0b00100000;
//digitalWrite(motor_step, HIGH);
PORTD = PORTD | 0b00010000;
//digitalWrite(motor_step, LOW);
PORTD = PORTD & 0b11101111;
delayMicroseconds(600); //_delay_us(200); //modify to alter speed
motor_position++;
encoder = 0; //encoder--;
}
else if (encoder < 0) {
//digitalWrite (motor_direction, LOW); //move stepper forward
PORTD = PORTD & 0b11011111;
//digitalWrite (motor_step, HIGH);
PORTD = PORTD | 0b00010000;
//digitalWrite (motor_step, LOW);
PORTD = PORTD & 0b11101111;
delayMicroseconds(600); //_delay_us(200); //modify to alter speed
motor_position--;
encoder = 0; //encoder++;
}
}