From: Jim Morris Date: Sun, 23 Nov 2014 08:24:02 +0000 (-0800) Subject: add debug pins to makefile, ignored if not set X-Git-Url: http://git.hcoop.net/clinton/Smoothieware.git/commitdiff_plain/9e0899784b21a7d0e397f05813c49965329575a5?ds=sidebyside;hp=c8f4ee77e4b12186f0714ebee3d0e319fa516eaf add debug pins to makefile, ignored if not set --- diff --git a/src/libs/Kernel.cpp b/src/libs/Kernel.cpp index 0a03e9bb..3c282100 100644 --- a/src/libs/Kernel.cpp +++ b/src/libs/Kernel.cpp @@ -124,7 +124,7 @@ Kernel::Kernel(){ float microseconds_per_step_pulse = this->config->value(microseconds_per_step_pulse_checksum )->by_default(5 )->as_number(); // Configure the step ticker ( TODO : shouldnt this go into stepticker's code ? ) - this->step_ticker->set_reset_delay( microseconds_per_step_pulse / 1000000L ); + this->step_ticker->set_reset_delay( microseconds_per_step_pulse / 1000000.0F ); this->step_ticker->set_frequency( this->base_stepping_frequency ); // Core modules diff --git a/src/libs/StepTicker.cpp b/src/libs/StepTicker.cpp index 93472286..1fdb00d5 100644 --- a/src/libs/StepTicker.cpp +++ b/src/libs/StepTicker.cpp @@ -17,6 +17,11 @@ #include #include +#ifdef STEPTICKER_DEBUG_PIN +#include "gpio.h" +extern GPIO stepticker_debug_pin; +#endif + extern bool _isr_context; // StepTicker handles the base frequency ticking for the Stepper Motors / Actuators @@ -63,7 +68,7 @@ StepTicker::~StepTicker() { // Set the base stepping frequency void StepTicker::set_frequency( float frequency ){ this->frequency = frequency; - this->period = floorf((SystemCoreClock/4)/frequency); // SystemCoreClock/4 = Timer increments in a second + this->period = floorf((SystemCoreClock/4.0F)/frequency); // SystemCoreClock/4 = Timer increments in a second LPC_TIM0->MR0 = this->period; if( LPC_TIM0->TC > LPC_TIM0->MR0 ){ LPC_TIM0->TCR = 3; // Reset @@ -73,7 +78,7 @@ void StepTicker::set_frequency( float frequency ){ // Set the reset delay void StepTicker::set_reset_delay( float seconds ){ - this->delay = floorf(float(SystemCoreClock/4)*( seconds )); // SystemCoreClock/4 = Timer increments in a second + this->delay = floorf((SystemCoreClock/4.0F)*seconds); // SystemCoreClock/4 = Timer increments in a second LPC_TIM1->MR0 = this->delay; } @@ -101,12 +106,13 @@ void StepTicker::signal_a_move_finished(){ if (this->active_motor_bm & bitmask){ if(this->active_motors[motor]->is_move_finished){ this->active_motors[motor]->signal_move_finished(); - if(this->active_motors[motor]->moving == false){ - if (motor > 0){ - motor--; - bitmask >>= 1; - } - } + // Theoretically this does nothing and the reason for it is currently unknown and/or forgotten + // if(this->active_motors[motor]->moving == false){ + // if (motor > 0){ + // motor--; + // bitmask >>= 1; + // } + // } } } } @@ -167,6 +173,10 @@ void StepTicker::TIMER0_IRQHandler (void){ // If a move finished in this tick, we have to tell the actuator to act accordingly if( this->a_move_finished ){ + #ifdef STEPTICKER_DEBUG_PIN + stepticker_debug_pin= 1; + #endif + // Do not get out of here before everything is nice and tidy LPC_TIM0->MR0 = 20000000; @@ -175,9 +185,8 @@ void StepTicker::TIMER0_IRQHandler (void){ // If we went over the duration an interrupt is supposed to last, we have a problem // 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 + if(LPC_TIM0->TC > this->period ){ // TODO: remove the size condition //overruns++; - 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 ) @@ -214,6 +223,7 @@ void StepTicker::TIMER0_IRQHandler (void){ int difference = (int)(LPC_TIM0->TC) - (int)(start_tc); if( difference > 0 ){ this->last_duration = (uint32_t)difference; } + }else{ LPC_TIM0->MR0 = this->period; } @@ -222,6 +232,9 @@ void StepTicker::TIMER0_IRQHandler (void){ LPC_TIM0->MR0 += this->period; } + #ifdef STEPTICKER_DEBUG_PIN + stepticker_debug_pin= 0; + #endif } } diff --git a/src/libs/StepperMotor.cpp b/src/libs/StepperMotor.cpp index e0c0f7b1..e3e5a6a9 100644 --- a/src/libs/StepperMotor.cpp +++ b/src/libs/StepperMotor.cpp @@ -159,7 +159,9 @@ void StepperMotor::move( bool direction, unsigned int steps, float initial_speed void StepperMotor::set_step_rate(float requested_rate, uint32_t block_steps_event_count) { float rate= requested_rate * ((float)steps_to_move / (float)block_steps_event_count); - if(rate < minimum_step_rate) rate= minimum_step_rate; + if(rate < minimum_step_rate) { + rate= minimum_step_rate; + } set_speed(rate); } diff --git a/src/main.cpp b/src/main.cpp index 136d8baf..6589fa34 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -82,6 +82,15 @@ GPIO leds[5] = { GPIO(P4_28) }; +// debug pins, only used if defined in src/makefile +#ifdef BLOCK_DEBUG_PIN +GPIO block_debug_pin(BLOCK_DEBUG_PIN); +#endif + +#ifdef STEPTICKER_DEBUG_PIN +GPIO stepticker_debug_pin(STEPTICKER_DEBUG_PIN); +#endif + void init() { // Default pins to low status @@ -90,6 +99,15 @@ void init() { leds[i]= 0; } +#ifdef BLOCK_DEBUG_PIN + block_debug_pin.output(); + block_debug_pin= 0; +#endif +#ifdef STEPTICKER_DEBUG_PIN + stepticker_debug_pin.output(); + stepticker_debug_pin= 0; +#endif + Kernel* kernel = new Kernel(); kernel->streams->printf("Smoothie Running @%ldMHz\r\n", SystemCoreClock / 1000000); diff --git a/src/makefile b/src/makefile index 54524d54..bb5f9e46 100644 --- a/src/makefile +++ b/src/makefile @@ -53,6 +53,12 @@ endif # use c++11 features for the checksums and set default baud rate for serial uart DEFINES += -DCHECKSUM_USE_CPP -DDEFAULT_SERIAL_BAUD_RATE=$(DEFAULT_SERIAL_BAUD_RATE) +# Set a Pin here that toggles high on block begin and low on block end for debugging with logic analyzer +#DEFINES += -DBLOCK_DEBUG_PIN=P4_29 + +# Set a Pin here that toggles on Stepticker overrun for debugging with logic analyzer +DEFINES += -DSTEPTICKER_DEBUG_PIN=P4_29 + # add any modules that you do not want included in the build export EXCLUDED_MODULES = tools/touchprobe # e.g for a CNC machine diff --git a/src/modules/robot/Block.cpp b/src/modules/robot/Block.cpp index ff2a806d..3c5977a0 100644 --- a/src/modules/robot/Block.cpp +++ b/src/modules/robot/Block.cpp @@ -22,6 +22,11 @@ using std::string; #include +#ifdef BLOCK_DEBUG_PIN +#include "gpio.h" +extern GPIO block_debug_pin; +#endif + // A block represents a movement, it's length for each stepper motor, and the corresponding acceleration curves. // It's stacked on a queue, and that queue is then executed in order, to move the motors. // Most of the accel math is also done in this class @@ -247,6 +252,10 @@ void Block::append_gcode(Gcode* gcode) void Block::begin() { +#ifdef BLOCK_DEBUG_PIN + block_debug_pin= 1; +#endif + recalculate_flag = false; if (!is_ready) @@ -258,6 +267,7 @@ void Block::begin() for(unsigned int index = 0; index < gcodes.size(); index++) THEKERNEL->call_event(ON_GCODE_EXECUTE, &(gcodes[index])); + THEKERNEL->call_event(ON_BLOCK_BEGIN, this); if (times_taken < 0) @@ -286,11 +296,15 @@ void Block::release() times_taken = 0; if (is_ready) { +#ifdef BLOCK_DEBUG_PIN + block_debug_pin= 0; +#endif is_ready = false; THEKERNEL->call_event(ON_BLOCK_END, this); // ensure conveyor gets called last THEKERNEL->conveyor->on_block_end(this); + } } } diff --git a/src/modules/robot/Stepper.cpp b/src/modules/robot/Stepper.cpp index fee3550d..b0074d38 100644 --- a/src/modules/robot/Stepper.cpp +++ b/src/modules/robot/Stepper.cpp @@ -341,7 +341,7 @@ uint32_t Stepper::synchronize_acceleration(uint32_t dummy) this->main_stepper->attach_signal_step(this->current_block->decelerate_after, this, &Stepper::synchronize_acceleration); } } else { - // If we are called not at the first steps, this means we are beginning deceleration + // If we are called not at the first steps, this means we are beginning deceleratingration NVIC_SetPendingIRQ(TIMER2_IRQn); // Synchronize both counters LPC_TIM2->TC = LPC_TIM0->TC; diff --git a/src/modules/robot/Stepper.h b/src/modules/robot/Stepper.h index 3c326ed7..ada2a265 100644 --- a/src/modules/robot/Stepper.h +++ b/src/modules/robot/Stepper.h @@ -47,7 +47,6 @@ private: int stepped[3]; float trapezoid_adjusted_rate; int acceleration_ticks_per_second; - int base_stepping_frequency; Hook *acceleration_tick_hook; StepperMotor *main_stepper;