Hi
first of all sorry, but my english is not good.
I have a spindle with encoder (200 pulses/RPM);
stepper driver + motor;
serial LCD;
my sketch
setting vars.....
setup() {
.......
attach interrupt(encoder_pin, read_encoder, CHANGE); // CHNAGE - 200 pulses rising + 200 falling = 400P/RPM
}
read_encoder() { pulse++;}
loop() {
if (pulse >= 10) { digital_writhe(stepper_pin, HIGH); digital_writhe(stepper_pin, LOW); pulse=0; position+=1.25;}
if (millis() - prev_time >= print_delay_time) { prev_time = millis(); Serial_print( position); }
}
The problem :
when need to put more data to LCD, printing take a time and stepper loses a pulses while printing especially when the spindle rotation going fastt
You shouldn't be doing serial I/O in your interrupt handler, its orders of magnitude slower
than anything else in the handler.
[ whoops - think that's not actually an issue - but if you post the code in code
tags it would be substantially easier to decipher - please do so ]