added some comments and minor refactor of steppermotor - re 32bit fixed point vs...
authorJim Morris <morris@wolfman.com>
Sun, 3 Aug 2014 19:31:41 +0000 (12:31 -0700)
committerJim Morris <morris@wolfman.com>
Sun, 3 Aug 2014 19:31:41 +0000 (12:31 -0700)
src/libs/StepperMotor.cpp
src/libs/StepperMotor.h

index 1bdc4e5..f214dca 100644 (file)
@@ -148,15 +148,16 @@ void StepperMotor::move( bool direction, unsigned int steps ){
 // Set the speed at which this steper moves
 void StepperMotor::set_speed( float speed ){
 
-    if (speed < 20.0)
-        speed = 20.0;
+    if (speed < 20.0F)
+        speed = 20.0F;
 
     // How many steps we must output per second
     this->steps_per_second = speed;
 
-    // How many ticks ( base steps ) between each actual step at this speed, in fixed point 64
+    // How many ticks ( base steps ) between each actual step at this speed, in fixed point 64 <--- REALLY? I don't think it is at the moment looks like 32bit fixed point
     float ticks_per_step = (float)( (float)this->step_ticker->frequency / speed );
-    float double_fx_ticks_per_step = (float)(1<<8) * ( (float)(1<<8) * ticks_per_step ); // 8x8 because we had to do 16x16 because 32 did not work
+    //float double_fx_ticks_per_step = (float)(1<<8) * ( (float)(1<<8) * ticks_per_step ); // 8x8 because we had to do 16x16 because 32 did not work
+    float double_fx_ticks_per_step = 65536.0F * ticks_per_step; // isn't this better on a 32bit machine?
     this->fx_ticks_per_step = (uint32_t)( floor(double_fx_ticks_per_step) );
 
 }
index 1b72bbd..dbe62a7 100644 (file)
@@ -19,15 +19,6 @@ class StepperMotor {
         StepperMotor();
         StepperMotor(Pin& step, Pin& dir, Pin& en);
 
-        // Called a great many times per second, to step if we have to now
-        inline void tick() {
-            // increase the ( fixed point ) counter by one tick 11t
-            fx_counter += (uint32_t)(1<<16);
-
-            // if we are to step now 10t
-            if (fx_counter >= fx_ticks_per_step)
-                step();
-        };
 
         void step();
         inline void unstep() { step_pin.set(0); };
@@ -104,6 +95,16 @@ class StepperMotor {
         bool remove_from_active_list_next_reset;
 
         bool is_move_finished; // Whether the move just finished
+
+        // Called a great many times per second, to step if we have to now
+        inline void tick() {
+            // increase the ( fixed point ) counter by one tick 11t
+            fx_counter += (uint32_t)(1<<16);
+
+            // if we are to step now 10t
+            if (fx_counter >= fx_ticks_per_step)
+                step();
+        };
 };
 
 #endif