Quadrature Encoder Readings Highly Irregular After Working; No Apparent Cause

Disable interrupts on access to count1 and count2, because these variables are updated in the ISRs. Volatile is correct but not sufficient to implement atomic access.