// The actual interrupt handler where we do all the work
extern "C" void TIMER0_IRQHandler (void){
- LPC_GPIO1->FIODIR |= 1<<22;
- LPC_GPIO1->FIOSET = 1<<22;
-
-// uint32_t initial_tc = LPC_TIM0->TC;
-
LPC_TIM0->IR |= 1 << 0;
// If no axes enabled, just ignore for now
if( global_step_ticker->active_motor_bm == 0 ){
- LPC_GPIO1->FIOCLR = 1<<22;
return;
}
// This can be OK, if we take notice of it, which we do now
if( LPC_TIM0->TC > global_step_ticker->period ){ // TODO: remove the size condition
- LPC_GPIO1->FIODIR |= 1<<23;
- LPC_GPIO1->FIOSET = 1<<23;
-
uint32_t start_tc = LPC_TIM0->TC;
// How many ticks we want to skip ( this does not include the current tick, but we add the time we spent doing this computation last time )
//if( global_step_ticker->last_duration > 2000 || LPC_TIM0->MR0 > 2000 || LPC_TIM0->TC > 2000 || initial_tc > 2000 ){ __debugbreak(); }
- LPC_GPIO1->FIOCLR = 1<<23;
-
}else{
LPC_TIM0->MR0 = global_step_ticker->period;
}
LPC_TIM0->MR0 += global_step_ticker->period;
}
- LPC_GPIO1->FIOCLR = 1<<22;
}
// Called a great many times per second, to step if we have to now
void StepperMotor::tick(){
- LPC_GPIO1->FIODIR |= 1<<31;
- LPC_GPIO1->FIOSET = 1<<31;
-
// increase the ( fixed point ) counter by one tick 11t
this->fx_counter += (uint64_t)((uint64_t)1<<32);
// if we are to step now 10t
if( this->fx_counter >= this->fx_ticks_per_step ){
- LPC_GPIO1->FIODIR |= 1<<30;
- LPC_GPIO1->FIOSET = 1<<30;
-
// output to pins 37t
this->step_pin->set( 1 );
this->step_ticker->reset_step_pins = true;
this->step_ticker->moves_finished = true;
}
- LPC_GPIO1->FIOCLR = 1<<30;
-
}
- LPC_GPIO1->FIOCLR = 1<<31;
-
}
// If the move is finished, the StepTicker will call this ( because we asked it to in tick() )
// Set the speed at which this steper moves
void StepperMotor::set_speed( double speed ){
-// if( speed <= 1.0 ){
-// this->steps_per_second = 0;
-// this->fx_ticks_per_step = 1ULL<<63;
-// return;
-// }
-
- //if( speed < this->steps_per_second ){
- LPC_GPIO1->FIOSET = 1<<19;
- //}
if (speed < 1.0)
speed = 1.0;