release the include directive if found in config
[clinton/Smoothieware.git] / src / libs / StepTicker.cpp
index f768a5c..0fc72c6 100644 (file)
@@ -37,12 +37,12 @@ StepTicker::StepTicker()
 
     // Configure the timer
     LPC_TIM0->MR0 = 10000000;       // Initial dummy value for Match Register
-    LPC_TIM0->MCR = 3;              // Match on MR0, reset on MR0, match on MR1
+    LPC_TIM0->MCR = 3;              // Match on MR0, reset on MR0
     LPC_TIM0->TCR = 0;              // Disable interrupt
 
     LPC_SC->PCONP |= (1 << 2);      // Power Ticker ON
     LPC_TIM1->MR0 = 1000000;
-    LPC_TIM1->MCR = 1;
+    LPC_TIM1->MCR = 5;              // match on Mr0, stop on match
     LPC_TIM1->TCR = 0;              // Disable interrupt
 
     // Default start values
@@ -71,6 +71,7 @@ void StepTicker::start()
 {
     NVIC_EnableIRQ(TIMER0_IRQn);     // Enable interrupt handler
     NVIC_EnableIRQ(TIMER1_IRQn);     // Enable interrupt handler
+    current_tick= 0;
 }
 
 // Set the base stepping frequency
@@ -83,11 +84,13 @@ void StepTicker::set_frequency( float frequency )
     LPC_TIM0->TCR = 1;  // start
 }
 
-// Set the reset delay
+// Set the reset delay, must be called after set_frequency
 void StepTicker::set_unstep_time( float microseconds )
 {
     uint32_t delay = floorf((SystemCoreClock / 4.0F) * (microseconds / 1000000.0F)); // SystemCoreClock/4 = Timer increments in a second
     LPC_TIM1->MR0 = delay;
+
+    // TODO check that the unstep time is less than the step period, if not slow down step ticker
 }
 
 // Reset step pins on any motor that was stepped
@@ -130,8 +133,6 @@ void StepTicker::handle_finish (void)
 // step clock
 void StepTicker::step_tick (void)
 {
-    static uint32_t current_tick = 0;
-
     //SET_STEPTICKER_DEBUG_PIN(running ? 1 : 0);
 
     // if nothing has been setup we ignore the ticks
@@ -147,6 +148,8 @@ void StepTicker::step_tick (void)
 
     if(THEKERNEL->is_halted()) {
         running= false;
+        current_tick = 0;
+        current_block= nullptr;
         return;
     }
 
@@ -217,7 +220,7 @@ void StepTicker::step_tick (void)
 
     // see if any motors are still moving
     if(!still_moving) {
-        SET_STEPTICKER_DEBUG_PIN(0);
+        //SET_STEPTICKER_DEBUG_PIN(0);
 
         // all moves finished
         current_tick = 0;
@@ -259,8 +262,10 @@ bool StepTicker::start_next_block()
         motor[m]->start_moving(); // also let motor know it is moving now
     }
 
+    current_tick= 0;
+
     if(ok) {
-        SET_STEPTICKER_DEBUG_PIN(1);
+        //SET_STEPTICKER_DEBUG_PIN(1);
         return true;
 
     }else{