fix step counter logic
authorJim Morris <morris@wolfman.com>
Wed, 19 Nov 2014 21:43:48 +0000 (13:43 -0800)
committerJim Morris <morris@wolfman.com>
Wed, 19 Nov 2014 21:43:48 +0000 (13:43 -0800)
src/libs/StepTicker.cpp
src/libs/StepTicker.h
src/libs/StepperMotor.cpp
src/libs/StepperMotor.h
src/modules/utils/simpleshell/SimpleShell.cpp

index a5b681f..b5c9f8c 100644 (file)
@@ -47,6 +47,7 @@ StepTicker::StepTicker(int nmotors){
     this->set_frequency(0.001);
     this->set_reset_delay(100);
     this->last_duration = 0;
+    //this->overruns= 0;
     this->num_motors= nmotors;
     this->active_motors= new StepperMotor*[num_motors];
     for (int i = 0; i < num_motors; i++){
@@ -185,6 +186,7 @@ void StepTicker::TIMER0_IRQHandler (void){
         // That can happen typically when we change blocks, where more than usual computation is done
         // This can be OK, if we take notice of it, which we do now
         if( LPC_TIM0->TC > this->period ){ // TODO: remove the size condition
+            //overruns++;
 
             uint32_t start_tc = LPC_TIM0->TC;
 
@@ -198,9 +200,14 @@ void StepTicker::TIMER0_IRQHandler (void){
             uint32_t bm;
             for (i = 0, bm = 1; i < num_motors; i++, bm <<= 1)
             {
-                if( (this->active_motor_bm & bm) && (this->active_motors[i]->fx_ticks_per_step >= this->active_motors[i]->fx_counter) )
-                    ticks_we_actually_can_skip =
-                        min(ticks_we_actually_can_skip, (uint32_t)((active_motors[i]->fx_ticks_per_step - active_motors[i]->fx_counter) >> active_motors[i]->fx_shift));
+                if((this->active_motor_bm & bm) != 0) {
+                    if(this->active_motors[i]->fx_ticks_per_step > this->active_motors[i]->fx_counter) {
+                        ticks_we_actually_can_skip =
+                            min(ticks_we_actually_can_skip, (uint32_t)((active_motors[i]->fx_ticks_per_step - active_motors[i]->fx_counter) >> active_motors[i]->fx_shift));
+                    }else{
+                        ticks_we_actually_can_skip= 0;
+                    }
+                }
             }
 
             // Adding to MR0 for this time is not enough, we must also increment the counters ourself artificially
index dc4c226..c213983 100644 (file)
@@ -32,6 +32,7 @@ class StepTicker{
         void add_motor_to_active_list(StepperMotor* motor);
         void remove_motor_from_active_list(StepperMotor* motor);
         void TIMER0_IRQHandler (void);
+        //uint32_t overruns;
 
     private:
         float frequency;
index f6b7119..6b3a342 100644 (file)
@@ -35,7 +35,6 @@ void StepperMotor::init()
     this->stepped = 0;
     this->fx_ticks_per_step = 0;
     this->steps_to_move = 0;
-    this->remove_from_active_list_next_reset = false;
     this->is_move_finished = false;
     this->signal_step = false;
     this->step_signal_hook = new Hook();
@@ -96,7 +95,6 @@ void StepperMotor::signal_move_finished()
     this->end_hook->call();
 
     // We only need to do this if we were not instructed to move
-    // NOTE this is always true
     if( this->moving == false ) {
         this->update_exit_tick();
     }
@@ -109,7 +107,6 @@ inline void StepperMotor::update_exit_tick()
 {
     if( !this->moving || this->paused || this->steps_to_move == 0 ) {
         // We must exit tick() after setting the pins, no bresenham is done
-        //this->remove_from_active_list_next_reset = true;
         this->step_ticker->remove_motor_from_active_list(this);
     } else {
         // We must do the bresenham in tick()
index 9518d71..1b9ea1c 100644 (file)
@@ -94,7 +94,6 @@ class StepperMotor {
 
         struct {
             bool direction:1;
-            bool remove_from_active_list_next_reset:1;
             bool is_move_finished:1; // Whether the move just finished
             bool signal_step:1;
             bool paused:1;
index 85248be..3942503 100644 (file)
@@ -21,6 +21,7 @@
 #include "checksumm.h"
 #include "PublicData.h"
 #include "Gcode.h"
+//#include "StepTicker.h"
 
 #include "modules/tools/temperaturecontrol/TemperatureControlPublicAccess.h"
 #include "modules/robot/RobotPublicAccess.h"
@@ -475,6 +476,8 @@ void SimpleShell::mem_command( string parameters, StreamOutput *stream)
         AHB0.debug(stream);
         AHB1.debug(stream);
     }
+
+    //stream->printf("overruns: %lu\n", THEKERNEL->step_ticker->overruns);
 }
 
 static uint32_t getDeviceType()