From 9cfc5ce2ec406f73c802b1a6395b5037a5d1c393 Mon Sep 17 00:00:00 2001 From: Josh Stewart Date: Sat, 2 Nov 2013 21:54:32 +1100 Subject: [PATCH] Add smoothing on the timePerDegree calculation --- kartduino.ino | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kartduino.ino b/kartduino.ino index 07f2433a..83143635 100644 --- a/kartduino.ino +++ b/kartduino.ino @@ -213,8 +213,8 @@ void loop() if (crankAngle > 360) { crankAngle -= 360; } //How fast are we going? Can possibly work this out from RPM, but I don't think it's going to take a lot of CPU - //unsigned long timePerDegree = (toothLastToothTime - toothLastMinusOneToothTime) / triggerToothAngle; //The time (uS) it is currently taking to move 1 degree - unsigned long timePerDegree = fastDivide32( (toothLastToothTime - toothLastMinusOneToothTime), triggerToothAngle); //The time (uS) it is currently taking to move 1 degree (fastDivide version) + //unsigned long timePerDegree = (toothLastToothTime - toothLastMinusOneToothTime) / (triggerToothAngle * configPage2.triggerTeeth); //The time (uS) it is currently taking to move 1 degree + unsigned long timePerDegree = fastDivide32( (toothOneTime - toothOneMinusOneTime), (triggerToothAngle * configPage2.triggerTeeth)); //The time (uS) it is currently taking to move 1 degree (fastDivide version) //crankAngle += (micros() - toothLastToothTime) / timePerDegree; //Estimate the number of degrees travelled since the last tooth crankAngle += fastDivide32( (micros() - toothLastToothTime), timePerDegree); //Estimate the number of degrees travelled since the last tooth (fastDivide version)