Let's Make Robots!

When is zero not zero?

Update -> I think the answer is that there is an interrupt resetting these values in between setting them to zero and printing them.

I am trying to calibrate my motors and am having trouble.  In particular, how is this output:

Resetting Quadrature: 0: 92072 1: 92083

possible for this function:

void processQuadrature(){
  long now = millis();
  
  Serial.print("Quadrature 0  = ");
  Serial.print(float(quadrature0Pulses*1000)/(now-quadrature0Start) );
  Serial.print(" pulses per second  over ");
  Serial.print(now-quadrature0Start);
  Serial.println(" milliseconds");
  
  Serial.print("Quadrature 1  = ");
  Serial.print(float(quadrature1Pulses*1000)/(now-quadrature1Start) );
  Serial.print(" pulses per second over ");
  Serial.print(now-quadrature1Start);
  Serial.println(" milliseconds");
  
  quadrature0Start = 0l;
  quadrature1Start = 0l;

  quadrature0Pulses = 0l;
  quadrature1Pulses = 0l;
  
  Serial.print("Resetting Quadrature: 0: ");
  Serial.print(quadrature0Start);
  Serial.print(" 1: ");
  Serial.println(quadrature1Start);
  
}

That is, haven't I just set these two variables to zero before I print them out?

Can this have something to do with interrupts?

TIA

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.