add debug pins to makefile, ignored if not set origin/fix/trapezoid-symmetry
authorJim Morris <morris@wolfman.com>
Sun, 23 Nov 2014 08:24:02 +0000 (00:24 -0800)
committerJim Morris <morris@wolfman.com>
Sun, 23 Nov 2014 08:24:02 +0000 (00:24 -0800)
src/libs/Kernel.cpp
src/libs/StepTicker.cpp
src/libs/StepperMotor.cpp
src/main.cpp
src/makefile
src/modules/robot/Block.cpp
src/modules/robot/Stepper.cpp
src/modules/robot/Stepper.h

index 0a03e9b..3c28210 100644 (file)
@@ -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
index 9347228..1fdb00d 100644 (file)
 #include <math.h>
 #include <mri.h>
 
+#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
     }
 
 }
index e0c0f7b..e3e5a6a 100644 (file)
@@ -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);
 }
 
index 136d8ba..6589fa3 100644 (file)
@@ -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);
index 54524d5..bb5f9e4 100644 (file)
@@ -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
index ff2a806..3c5977a 100644 (file)
 using std::string;
 #include <vector>
 
+#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);
+
         }
     }
 }
index fee3550..b0074d3 100644 (file)
@@ -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;
index 3c326ed..ada2a26 100644 (file)
@@ -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;