Hello everyone. used a simple code to print to a DTG printer. but when I started printing blanks, or with a little filling of the picture, the picture began to shrink and stretch. since the synchronization of the encoder with the motor is not in real time, it can be seen from the code. did a bunch of work on the rest of the sensor signal code on the printer. and it turned out during the test. who can suggest or help how to implement. synchronization of an optical encoder with a stepper motor in real time with a full transfer of speed (acceleration). thank you all for your help
reading encoder
void encoderPinChangeA(){ if (digitalRead(encoder_a) == digitalRead(encoder_b)){ encoder--; } else{ encoder++; } } void encoderPinChangeB(){ if (digitalRead(encoder_a) != digitalRead(encoder_b)){ encoder--; } else{ encoder++; } }
stepper control
if (encoder > 0){ digitalWrite(motor_direction, HIGH); digitalWrite(motor_step, HIGH); digitalWrite(motor_step, LOW); _delay_us(800); motor_position++; encoder = 0; } else if (encoder < 0){ digitalWrite(motor_direction, LOW); digitalWrite(motor_step, HIGH); digitalWrite(motor_step, LOW); _delay_us(800); motor_position--; encoder = 0; }
As I understand it, while the delay 800 encoder is not read as there is a delay. but if even to implement on millis there the coefficient needs to be put down? as there should be synchronization. information has not yet been found. I ask for help.
I don't even think about software protection against pulsation, interference or inertia and other things yet. for now I need to make friends with an encoder
motor_position++;
also I do not understand why this line may have been an upgrade but not about it now