   if(useRef == true){
     //generating an offset based off of the reference voltage sent from motor controller
     double referenceVoltage = analogRead(referencePin);
-    voltageOffset = int(realReference - referenceVoltage);
+    voltageOffset = int(referenceVoltage-realReference);
   }  
   else{
     voltageOffset = 0;
   }
   
   //Motor Calculations
-  double encoderVoltage = ( analogRead(encoderPin) + voltageOffset ) * 0.0049; //.0049 convert to real voltage values
-  double scaledVoltage = encoderVoltage - scaleOffset;
-  double finalRpm = scaledVoltage * rpmMultiplier;
-  
+  double encoderVoltage = ( analogRead(encoderPin) + voltageOffset ); //.0049 convert to real voltage values
+  double scaledVoltage = (encoderVoltage - scaleOffset) * .0049;
+  double finalRpm = scaledVoltage * rpmMultiplier + rpmOffset;
+
   if((scaledVoltage < -1.5) && (scaledVoltage > -2.0)){  
-    finalRpm = -1000.0;  }
+    finalRpm = minRpm;  }
   else if (scaledVoltage < -2.0){
+    finalRpm = 0.0; }
+  else if (scaledVoltage > 1.5){
+    finalRpm = maxRpm;  }
+  
+  if(abs(finalRpm) < (maxRpm / 10.0) ){
     finalRpm = 0.0;
   }
-  else if (scaledVoltage > 1.5){
-    finalRpm = 1000;  }
     
   //System Voltage Calculations
   double inputV = analogRead(voltagePin) + voltageOffset;
-  double finalV = inputV * voltageMultiplier;
+  double finalV = (double)inputV * (double)voltageMultiplier;
   
   //System Current Calculations
-  double inputI = analogRead(currentPin) + voltageOffset;
-  double finalI = inputI * currentMultiplier;
+  double inputI = (double)analogRead(currentPin) + (double)voltageOffset;
+  double finalI =  (double)inputI * (double)currentMultiplier;
+//  Serial.println(finalI);
+  if(finalI < 5.0){
+    finalI = 5.0;
+  }
+    
 
   //Distance Calculations
-  int irPin = directionOfTravel == '0' ? backIrPin : frontIrPin;
-  double distance = ir_distance(irPin, voltageOffset);
+  double distance;
+  if(directionOfTravel == 1){
+    distance = ir_distance(backIrPin, voltageOffset);  
+  }
+  else {
+    distance = ir_distance(frontIrPin, voltageOffset);  
+  }
+  
 
 
  //assigning values to daqTelemetry object  

  /*
   * updates the watchdog timer 
   */
  watchdogTimer = watchdogTimer + ( millis() - lastTime );
  lastTime = millis();
  return watchdogTimer;
}


                     String(daqTelemetry->systemCurrent) + "," +
                     String(outputDistance) + "," +
                     logs + "," +
                     ( (millis() / clockCorrection) / 1000.0 );
  Serial.println(daqString);
}

