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
#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
// 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
// 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;
}
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;
+ // }
+ // }
}
}
}
// 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;
// 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 )
int difference = (int)(LPC_TIM0->TC) - (int)(start_tc);
if( difference > 0 ){ this->last_duration = (uint32_t)difference; }
+
}else{
LPC_TIM0->MR0 = this->period;
}
LPC_TIM0->MR0 += this->period;
}
+ #ifdef STEPTICKER_DEBUG_PIN
+ stepticker_debug_pin= 0;
+ #endif
}
}
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);
}
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
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);
# 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
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
void Block::begin()
{
+#ifdef BLOCK_DEBUG_PIN
+ block_debug_pin= 1;
+#endif
+
recalculate_flag = false;
if (!is_ready)
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)
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);
+
}
}
}
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;
int stepped[3];
float trapezoid_adjusted_rate;
int acceleration_ticks_per_second;
- int base_stepping_frequency;
Hook *acceleration_tick_hook;
StepperMotor *main_stepper;