Robin2:
If the Arduino has been running for 100 millisecs I don't understand your thinking when you assume that the value in the variable count will be zero?If you explain your thinking it will be easier to help.
...R
Yes I don't know why this is so hard either as I am fairly intelligent (!) but programming is simply not my forte, to put it mildly...
My (flawed) thinking:
Before I start, there a couple of things I realised: 2 counts per rev on the encoder and so a readout of 20, 20, 20, etc means 20/2 = 10 pulses per 100 ms i.e. 100 per sec and so 6000 rpm
Lets say the motor starts (~6000 rpm, which is ~100 revs/sec (200 pulses/sec), or 20 per 0.1 sec) and the encoder starts ticking, the first pulse means the IRS is called and a count is incremented in integer 'count'.
As someone said above, the programme returns to the last place it left in the if loop so as the loop is running so quickly then I assume it must get to the point where the count = 0 is set before the ISR is triggered again as the loop runs faster than the encoder triggering... obviously this is wrong, but I don't get why, I just can't 'see' what the controller is 'thinking'.
Hope you can help walk through hat logic.