synchronize acceleration timer with start of block
authorJim Morris <morris@wolfman.com>
Mon, 8 Dec 2014 09:22:20 +0000 (01:22 -0800)
committerJim Morris <morris@wolfman.com>
Mon, 8 Dec 2014 09:22:20 +0000 (01:22 -0800)
src/libs/StepTicker.cpp
src/libs/StepTicker.h
src/modules/robot/Stepper.cpp

index a0c0ccd..155c244 100644 (file)
@@ -100,6 +100,12 @@ void StepTicker::set_acceleration_ticks_per_second(uint32_t acceleration_ticks_p
     LPC_RIT->RICTRL |= (8L); // Enable rit
 }
 
+// Synchronise the acceleration timer with the new block
+void StepTicker::synchronize_acceleration() {
+    LPC_RIT->RICOUNTER = 0;
+}
+
+
 // Call signal_move_finished() on each active motor that asked to be signaled. We do this instead of inside of tick() so that
 // all tick()s are called before we do the move finishing
 void StepTicker::signal_a_move_finished(){
@@ -122,9 +128,9 @@ inline void StepTicker::unstep_tick(){
     for (int i = 0; i < num_motors; i++) {
         if(this->unstep[i]){
             this->motor[i]->unstep();
-            this->unstep[i]= 0;
         }
     }
+    this->unstep.reset();
 }
 
 extern "C" void TIMER1_IRQHandler (void){
@@ -236,5 +242,6 @@ void StepTicker::remove_motor_from_active_list(StepperMotor* motor)
     // If we have no motor to work on, disable the whole interrupt
     if(this->active_motor.none()){
         LPC_TIM0->TCR = 0;               // Disable interrupt
+        tick_cnt= 0;
     }
 }
index 3373a1e..cfadc52 100644 (file)
@@ -42,6 +42,8 @@ class StepTicker{
             acceleration_tick_handlers.push_back(cb);
         }
         void acceleration_tick();
+        void synchronize_acceleration();
+
         void start();
 
         friend class StepperMotor;
index bbdefca..ccbe1ee 100644 (file)
@@ -194,6 +194,9 @@ void Stepper::on_block_begin(void *argument)
 
     // Set the initial speed for this move
     this->trapezoid_generator_tick();
+
+    // synchronize the acceleration timer with the start of the new block so it does not drift and randomly fire during the block
+    THEKERNEL->step_ticker->synchronize_acceleration();
 }
 
 // Current block is discarded