// 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
{
NVIC_EnableIRQ(TIMER0_IRQn); // Enable interrupt handler
NVIC_EnableIRQ(TIMER1_IRQn); // Enable interrupt handler
+ current_tick= 0;
}
// Set the base stepping 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
// 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
if(THEKERNEL->is_halted()) {
running= false;
+ current_tick = 0;
+ current_block= nullptr;
return;
}
// 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;
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{