2009-01-28 23:48:21 +01:00
|
|
|
/*
|
2011-01-14 16:45:18 +01:00
|
|
|
stepper.c - stepper motor driver: executes motion plans using stepper motors
|
2009-01-28 23:48:21 +01:00
|
|
|
Part of Grbl
|
|
|
|
|
2011-01-14 16:45:18 +01:00
|
|
|
Copyright (c) 2009-2011 Simen Svale Skogsrud
|
2009-01-28 23:48:21 +01:00
|
|
|
|
|
|
|
Grbl is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
Grbl is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with Grbl. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2009-01-29 09:58:29 +01:00
|
|
|
/* The timer calculations of this module informed by the 'RepRap cartesian firmware' by Zack Smith
|
2010-03-14 23:45:31 +01:00
|
|
|
and Philipp Tiefenbacher. The ring buffer implementation gleaned from the wiring_serial library
|
2009-02-03 09:56:45 +01:00
|
|
|
by David A. Mellis */
|
2009-01-29 09:58:29 +01:00
|
|
|
|
2009-01-28 23:48:21 +01:00
|
|
|
#include "stepper.h"
|
|
|
|
#include "config.h"
|
2009-02-11 00:37:33 +01:00
|
|
|
#include <math.h>
|
2010-03-03 00:26:48 +01:00
|
|
|
#include <stdlib.h>
|
2010-02-27 19:55:09 +01:00
|
|
|
#include <util/delay.h>
|
2009-01-28 23:48:21 +01:00
|
|
|
#include "nuts_bolts.h"
|
|
|
|
#include <avr/interrupt.h>
|
2011-01-15 00:27:08 +01:00
|
|
|
#include "stepper_plan.h"
|
2009-02-03 09:56:45 +01:00
|
|
|
#include "wiring_serial.h"
|
|
|
|
|
2011-01-31 23:04:39 +01:00
|
|
|
|
|
|
|
// Some useful constants
|
|
|
|
#define STEP_MASK ((1<<X_STEP_BIT)|(1<<Y_STEP_BIT)|(1<<Z_STEP_BIT)) // All step bits
|
|
|
|
#define DIRECTION_MASK ((1<<X_DIRECTION_BIT)|(1<<Y_DIRECTION_BIT)|(1<<Z_DIRECTION_BIT)) // All direction bits
|
|
|
|
#define STEPPING_MASK (STEP_MASK | DIRECTION_MASK) // All stepping-related bits (step/direction)
|
|
|
|
#define LIMIT_MASK ((1<<X_LIMIT_BIT)|(1<<Y_LIMIT_BIT)|(1<<Z_LIMIT_BIT)) // All limit bits
|
2010-06-28 23:29:58 +02:00
|
|
|
|
2011-02-04 22:09:09 +01:00
|
|
|
#define MINIMUM_STEPS_PER_MINUTE 1200 // The stepper subsystem will never run slower than this, exept when sleeping
|
|
|
|
#define CYCLES_PER_ACCELERATION_TICK ((TICKS_PER_MICROSECOND*1000000)/ACCELERATION_TICKS_PER_SECOND)
|
|
|
|
|
2010-12-20 14:01:38 +01:00
|
|
|
#define ENABLE_STEPPER_DRIVER_INTERRUPT() TIMSK1 |= (1<<OCIE1A)
|
|
|
|
#define DISABLE_STEPPER_DRIVER_INTERRUPT() TIMSK1 &= ~(1<<OCIE1A)
|
|
|
|
|
2011-01-25 23:33:19 +01:00
|
|
|
static block_t *current_block; // A convenience pointer to the block currently being traced
|
2010-12-20 14:01:38 +01:00
|
|
|
|
|
|
|
// Variables used by The Stepper Driver Interrupt
|
2011-01-25 23:33:19 +01:00
|
|
|
static uint8_t out_bits; // The next stepping-bits to be output
|
|
|
|
static int32_t counter_x, // Counter variables for the bresenham line tracer
|
|
|
|
counter_y,
|
|
|
|
counter_z;
|
|
|
|
static uint32_t step_events_completed; // The number of step events executed in the current block
|
|
|
|
volatile int busy; // TRUE when SIG_OUTPUT_COMPARE1A is being serviced. Used to avoid retriggering that handler.
|
2011-01-03 00:36:33 +01:00
|
|
|
|
2011-01-25 14:27:28 +01:00
|
|
|
// Variables used by the trapezoid generation
|
2011-01-25 23:33:19 +01:00
|
|
|
static uint32_t cycles_per_step_event; // The number of machine cycles between each step event
|
|
|
|
static uint32_t trapezoid_tick_cycle_counter; // The cycles since last trapezoid_tick. Used to generate ticks at a steady
|
|
|
|
// pace without allocating a separate timer
|
|
|
|
static uint32_t trapezoid_adjusted_rate; // The current rate of step_events according to the trapezoid generator
|
2011-01-22 23:29:02 +01:00
|
|
|
|
2011-01-03 00:36:33 +01:00
|
|
|
// __________________________
|
|
|
|
// /| |\ _________________ ^
|
|
|
|
// / | | \ /| |\ |
|
|
|
|
// / | | \ / | | \ s
|
|
|
|
// / | | | | | \ p
|
|
|
|
// / | | | | | \ e
|
|
|
|
// +-----+------------------------+---+--+---------------+----+ e
|
|
|
|
// | BLOCK 1 | BLOCK 2 | d
|
|
|
|
//
|
|
|
|
// time ----->
|
|
|
|
//
|
2011-01-24 20:55:25 +01:00
|
|
|
// The trapezoid is the shape the speed curve over time. It starts at block->initial_rate, accelerates by block->rate_delta
|
2011-01-25 14:27:28 +01:00
|
|
|
// during the first block->accelerate_until step_events_completed, then keeps going at constant speed until
|
|
|
|
// step_events_completed reaches block->decelerate_after after which it decelerates until the trapezoid generator is reset.
|
2011-01-24 20:55:25 +01:00
|
|
|
// The slope of acceleration is always +/- block->rate_delta and is applied at a constant rate by trapezoid_generator_tick()
|
|
|
|
// that is called ACCELERATION_TICKS_PER_SECOND times per second.
|
2011-01-14 12:10:18 +01:00
|
|
|
|
2011-01-31 23:04:39 +01:00
|
|
|
void set_step_events_per_minute(uint32_t steps_per_minute);
|
|
|
|
|
2011-01-14 16:45:18 +01:00
|
|
|
// Initializes the trapezoid generator from the current block. Called whenever a new
|
|
|
|
// block begins.
|
2011-01-24 20:55:25 +01:00
|
|
|
inline void trapezoid_generator_reset() {
|
2011-01-25 14:27:28 +01:00
|
|
|
trapezoid_adjusted_rate = current_block->initial_rate;
|
|
|
|
set_step_events_per_minute(trapezoid_adjusted_rate);
|
2011-01-03 00:36:33 +01:00
|
|
|
}
|
2010-12-20 14:01:38 +01:00
|
|
|
|
2011-01-03 00:36:33 +01:00
|
|
|
// This is called ACCELERATION_TICKS_PER_SECOND times per second by the step_event
|
|
|
|
// interrupt. It can be assumed that the trapezoid-generator-parameters and the
|
|
|
|
// current_block stays untouched by outside handlers for the duration of this function call.
|
|
|
|
inline void trapezoid_generator_tick() {
|
2011-01-22 23:29:02 +01:00
|
|
|
if (current_block) {
|
2011-01-25 14:02:34 +01:00
|
|
|
if (step_events_completed < current_block->accelerate_until) {
|
2011-01-25 14:27:28 +01:00
|
|
|
trapezoid_adjusted_rate += current_block->rate_delta;
|
|
|
|
set_step_events_per_minute(trapezoid_adjusted_rate);
|
2011-01-25 14:02:34 +01:00
|
|
|
} else if (step_events_completed > current_block->decelerate_after) {
|
2011-01-23 21:14:38 +01:00
|
|
|
// NOTE: We will only reduce speed if the result will be > 0. This catches small
|
|
|
|
// rounding errors that might leave steps hanging after the last trapezoid tick.
|
2011-01-25 14:27:28 +01:00
|
|
|
if(current_block->rate_delta < trapezoid_adjusted_rate) {
|
|
|
|
trapezoid_adjusted_rate -= current_block->rate_delta;
|
2011-01-23 21:14:38 +01:00
|
|
|
}
|
2011-01-25 14:27:28 +01:00
|
|
|
set_step_events_per_minute(trapezoid_adjusted_rate);
|
2011-01-03 00:36:33 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-12-20 14:01:38 +01:00
|
|
|
|
2010-03-03 01:39:44 +01:00
|
|
|
// Add a new linear movement to the buffer. steps_x, _y and _z is the signed, relative motion in
|
2011-01-03 00:36:33 +01:00
|
|
|
// steps. Microseconds specify how many microseconds the move should take to perform. To aid acceleration
|
2010-06-28 23:29:58 +02:00
|
|
|
// calculation the caller must also provide the physical length of the line in millimeters.
|
|
|
|
void st_buffer_line(int32_t steps_x, int32_t steps_y, int32_t steps_z, uint32_t microseconds, double millimeters) {
|
2011-01-15 00:27:08 +01:00
|
|
|
plan_buffer_line(steps_x, steps_y, steps_z, microseconds, millimeters);
|
2010-12-20 14:01:38 +01:00
|
|
|
// Ensure that block processing is running by enabling The Stepper Driver Interrupt
|
|
|
|
ENABLE_STEPPER_DRIVER_INTERRUPT();
|
|
|
|
}
|
|
|
|
|
|
|
|
// "The Stepper Driver Interrupt" - This timer interrupt is the workhorse of Grbl. It is executed at the rate set with
|
|
|
|
// config_step_timer. It pops blocks from the block_buffer and executes them by pulsing the stepper pins appropriately.
|
|
|
|
// It is supported by The Stepper Port Reset Interrupt which it uses to reset the stepper port after each pulse.
|
2010-03-14 23:45:31 +01:00
|
|
|
SIGNAL(TIMER1_COMPA_vect)
|
2011-01-24 20:55:25 +01:00
|
|
|
{
|
|
|
|
// TODO: Check if the busy-flag can be eliminated by just disabeling this interrupt while we are in it
|
|
|
|
|
2010-03-04 21:18:55 +01:00
|
|
|
if(busy){ return; } // The busy-flag is used to avoid reentering this interrupt
|
2010-03-02 21:46:51 +01:00
|
|
|
// Set the direction pins a cuple of nanoseconds before we step the steppers
|
|
|
|
STEPPING_PORT = (STEPPING_PORT & ~DIRECTION_MASK) | (out_bits & DIRECTION_MASK);
|
|
|
|
// Then pulse the stepping pins
|
|
|
|
STEPPING_PORT = (STEPPING_PORT & ~STEP_MASK) | out_bits;
|
2010-12-20 14:01:38 +01:00
|
|
|
// Reset step pulse reset timer so that The Stepper Port Reset Interrupt can reset the signal after
|
2010-03-07 20:29:18 +01:00
|
|
|
// exactly settings.pulse_microseconds microseconds.
|
|
|
|
TCNT2 = -(((settings.pulse_microseconds-2)*TICKS_PER_MICROSECOND)/8);
|
2010-03-03 23:18:39 +01:00
|
|
|
|
2010-03-03 22:55:45 +01:00
|
|
|
busy = TRUE;
|
2010-03-04 21:18:55 +01:00
|
|
|
sei(); // Re enable interrupts (normally disabled while inside an interrupt handler)
|
2011-01-03 00:36:33 +01:00
|
|
|
// ((We re-enable interrupts in order for SIG_OVERFLOW2 to be able to be triggered
|
|
|
|
// at exactly the right time even if we occasionally spend a lot of time inside this handler.))
|
2010-03-02 21:46:51 +01:00
|
|
|
|
2011-01-03 00:36:33 +01:00
|
|
|
// If there is no current block, attempt to pop one from the buffer
|
|
|
|
if (current_block == NULL) {
|
2010-03-02 21:46:51 +01:00
|
|
|
// Anything in the buffer?
|
2011-01-03 00:36:33 +01:00
|
|
|
if (block_buffer_head != block_buffer_tail) {
|
2010-03-02 21:46:51 +01:00
|
|
|
// Retrieve a new line and get ready to step it
|
2011-01-03 00:36:33 +01:00
|
|
|
current_block = &block_buffer[block_buffer_tail];
|
2011-01-24 20:55:25 +01:00
|
|
|
trapezoid_generator_reset();
|
2011-01-03 00:36:33 +01:00
|
|
|
counter_x = -(current_block->step_event_count >> 1);
|
2010-03-02 21:46:51 +01:00
|
|
|
counter_y = counter_x;
|
|
|
|
counter_z = counter_x;
|
2011-01-25 14:02:34 +01:00
|
|
|
step_events_completed = 0;
|
2010-03-03 00:26:48 +01:00
|
|
|
} else {
|
2011-01-03 00:36:33 +01:00
|
|
|
DISABLE_STEPPER_DRIVER_INTERRUPT();
|
2010-03-03 00:26:48 +01:00
|
|
|
}
|
|
|
|
}
|
2010-03-02 21:46:51 +01:00
|
|
|
|
2011-01-03 00:36:33 +01:00
|
|
|
if (current_block != NULL) {
|
|
|
|
out_bits = current_block->direction_bits;
|
|
|
|
counter_x += current_block->steps_x;
|
2010-03-02 21:46:51 +01:00
|
|
|
if (counter_x > 0) {
|
|
|
|
out_bits |= (1<<X_STEP_BIT);
|
2011-01-03 00:36:33 +01:00
|
|
|
counter_x -= current_block->step_event_count;
|
2010-03-02 21:46:51 +01:00
|
|
|
}
|
2011-01-03 00:36:33 +01:00
|
|
|
counter_y += current_block->steps_y;
|
2010-03-02 21:46:51 +01:00
|
|
|
if (counter_y > 0) {
|
|
|
|
out_bits |= (1<<Y_STEP_BIT);
|
2011-01-03 00:36:33 +01:00
|
|
|
counter_y -= current_block->step_event_count;
|
2010-03-02 21:46:51 +01:00
|
|
|
}
|
2011-01-03 00:36:33 +01:00
|
|
|
counter_z += current_block->steps_z;
|
2010-03-02 21:46:51 +01:00
|
|
|
if (counter_z > 0) {
|
|
|
|
out_bits |= (1<<Z_STEP_BIT);
|
2011-01-03 00:36:33 +01:00
|
|
|
counter_z -= current_block->step_event_count;
|
2010-03-02 21:46:51 +01:00
|
|
|
}
|
2011-01-03 00:36:33 +01:00
|
|
|
// If current block is finished, reset pointer
|
2011-01-25 14:02:34 +01:00
|
|
|
step_events_completed += 1;
|
|
|
|
if (step_events_completed >= current_block->step_event_count) {
|
2011-02-04 22:09:09 +01:00
|
|
|
// printInteger(current_block->exit_rate);
|
|
|
|
// printString(" == ");
|
|
|
|
// printInteger(trapezoid_adjusted_rate);
|
|
|
|
// printString(" <-- exit, actual\n\r");
|
|
|
|
// printInteger(current_block->rate_delta);
|
|
|
|
// printString(" <-- delta\n\r");
|
2011-01-03 00:36:33 +01:00
|
|
|
current_block = NULL;
|
|
|
|
// move the block buffer tail to the next instruction
|
|
|
|
block_buffer_tail = (block_buffer_tail + 1) % BLOCK_BUFFER_SIZE;
|
2009-02-08 20:40:24 +01:00
|
|
|
}
|
2010-03-02 08:19:21 +01:00
|
|
|
} else {
|
2010-03-02 21:46:51 +01:00
|
|
|
out_bits = 0;
|
2011-01-03 00:36:33 +01:00
|
|
|
}
|
2010-03-07 20:29:18 +01:00
|
|
|
out_bits ^= settings.invert_mask;
|
2011-01-03 00:36:33 +01:00
|
|
|
|
|
|
|
// In average this generates a trapezoid_generator_tick every CYCLES_PER_ACCELERATION_TICK by keeping track
|
|
|
|
// of the number of elapsed cycles. The code assumes that step_events occur significantly more often than
|
|
|
|
// trapezoid_generator_ticks as they well should.
|
|
|
|
trapezoid_tick_cycle_counter += cycles_per_step_event;
|
|
|
|
if(trapezoid_tick_cycle_counter > CYCLES_PER_ACCELERATION_TICK) {
|
|
|
|
trapezoid_tick_cycle_counter -= CYCLES_PER_ACCELERATION_TICK;
|
|
|
|
trapezoid_generator_tick();
|
|
|
|
}
|
|
|
|
|
2010-03-03 22:55:45 +01:00
|
|
|
busy=FALSE;
|
2009-01-28 23:48:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// This interrupt is set up by SIG_OUTPUT_COMPARE1A when it sets the motor port bits. It resets
|
2010-03-07 20:29:18 +01:00
|
|
|
// the motor port after a short period (settings.pulse_microseconds) completing one step cycle.
|
2010-03-14 23:45:31 +01:00
|
|
|
SIGNAL(TIMER2_OVF_vect)
|
2009-01-28 23:48:21 +01:00
|
|
|
{
|
2010-02-27 19:55:09 +01:00
|
|
|
// reset stepping pins (leave the direction pins)
|
2010-03-07 20:29:18 +01:00
|
|
|
STEPPING_PORT = (STEPPING_PORT & ~STEP_MASK) | (settings.invert_mask & STEP_MASK);
|
2009-01-28 23:48:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Initialize and start the stepper motor subsystem
|
|
|
|
void st_init()
|
|
|
|
{
|
|
|
|
// Configure directions of interface pins
|
2009-02-03 09:56:45 +01:00
|
|
|
STEPPING_DDR |= STEPPING_MASK;
|
2010-03-07 20:29:18 +01:00
|
|
|
STEPPING_PORT = (STEPPING_PORT & ~STEPPING_MASK) | settings.invert_mask;
|
2009-01-28 23:48:21 +01:00
|
|
|
LIMIT_DDR &= ~(LIMIT_MASK);
|
|
|
|
STEPPERS_ENABLE_DDR |= 1<<STEPPERS_ENABLE_BIT;
|
2010-02-27 19:55:09 +01:00
|
|
|
|
2009-01-28 23:48:21 +01:00
|
|
|
// waveform generation = 0100 = CTC
|
|
|
|
TCCR1B &= ~(1<<WGM13);
|
|
|
|
TCCR1B |= (1<<WGM12);
|
|
|
|
TCCR1A &= ~(1<<WGM11);
|
|
|
|
TCCR1A &= ~(1<<WGM10);
|
|
|
|
|
|
|
|
// output mode = 00 (disconnected)
|
|
|
|
TCCR1A &= ~(3<<COM1A0);
|
|
|
|
TCCR1A &= ~(3<<COM1B0);
|
|
|
|
|
|
|
|
// Configure Timer 2
|
2011-01-03 00:36:33 +01:00
|
|
|
TCCR2A = 0; // Normal operation
|
2010-02-27 19:55:09 +01:00
|
|
|
TCCR2B = (1<<CS21); // Full speed, 1/8 prescaler
|
2010-03-03 13:04:51 +01:00
|
|
|
TIMSK2 |= (1<<TOIE2);
|
2011-01-22 23:29:02 +01:00
|
|
|
|
|
|
|
set_step_events_per_minute(6000);
|
|
|
|
DISABLE_STEPPER_DRIVER_INTERRUPT();
|
|
|
|
trapezoid_tick_cycle_counter = 0;
|
2010-03-03 22:11:50 +01:00
|
|
|
|
|
|
|
// set enable pin
|
2010-03-03 13:04:51 +01:00
|
|
|
STEPPERS_ENABLE_PORT |= 1<<STEPPERS_ENABLE_BIT;
|
2009-01-28 23:48:21 +01:00
|
|
|
|
2011-01-22 23:29:02 +01:00
|
|
|
DDRD |= (1<<2);
|
2011-01-24 23:18:07 +01:00
|
|
|
PORTD &= ~(1<<2);
|
2011-01-22 23:29:02 +01:00
|
|
|
|
2009-01-30 11:26:08 +01:00
|
|
|
sei();
|
2009-01-28 23:48:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Block until all buffered steps are executed
|
|
|
|
void st_synchronize()
|
|
|
|
{
|
2011-01-03 00:36:33 +01:00
|
|
|
while(block_buffer_tail != block_buffer_head) { sleep_mode(); }
|
2009-01-28 23:48:21 +01:00
|
|
|
}
|
|
|
|
|
2010-03-03 13:04:51 +01:00
|
|
|
// Cancel all buffered steps
|
2009-01-28 23:48:21 +01:00
|
|
|
void st_flush()
|
|
|
|
{
|
2009-01-30 11:26:08 +01:00
|
|
|
cli();
|
2011-01-03 00:36:33 +01:00
|
|
|
block_buffer_tail = block_buffer_head;
|
|
|
|
current_block = NULL;
|
2009-01-30 11:26:08 +01:00
|
|
|
sei();
|
2009-01-28 23:48:21 +01:00
|
|
|
}
|
|
|
|
|
2010-03-04 21:18:55 +01:00
|
|
|
// Configures the prescaler and ceiling of timer 1 to produce the given rate as accurately as possible.
|
2011-01-03 00:36:33 +01:00
|
|
|
// Returns the actual number of cycles per interrupt
|
|
|
|
uint32_t config_step_timer(uint32_t cycles)
|
2009-01-28 23:48:21 +01:00
|
|
|
{
|
|
|
|
uint16_t ceiling;
|
|
|
|
uint16_t prescaler;
|
2011-01-03 00:36:33 +01:00
|
|
|
uint32_t actual_cycles;
|
|
|
|
if (cycles <= 0xffffL) {
|
|
|
|
ceiling = cycles;
|
2009-01-28 23:48:21 +01:00
|
|
|
prescaler = 0; // prescaler: 0
|
2011-01-03 00:36:33 +01:00
|
|
|
actual_cycles = ceiling;
|
|
|
|
} else if (cycles <= 0x7ffffL) {
|
|
|
|
ceiling = cycles >> 3;
|
2009-01-28 23:48:21 +01:00
|
|
|
prescaler = 1; // prescaler: 8
|
2011-01-22 23:29:02 +01:00
|
|
|
actual_cycles = ceiling * 8L;
|
2011-01-03 00:36:33 +01:00
|
|
|
} else if (cycles <= 0x3fffffL) {
|
|
|
|
ceiling = cycles >> 6;
|
2009-01-28 23:48:21 +01:00
|
|
|
prescaler = 2; // prescaler: 64
|
2011-01-22 23:29:02 +01:00
|
|
|
actual_cycles = ceiling * 64L;
|
2011-01-03 00:36:33 +01:00
|
|
|
} else if (cycles <= 0xffffffL) {
|
|
|
|
ceiling = (cycles >> 8);
|
2009-01-28 23:48:21 +01:00
|
|
|
prescaler = 3; // prescaler: 256
|
2011-01-22 23:29:02 +01:00
|
|
|
actual_cycles = ceiling * 256L;
|
2011-01-03 00:36:33 +01:00
|
|
|
} else if (cycles <= 0x3ffffffL) {
|
|
|
|
ceiling = (cycles >> 10);
|
2009-01-28 23:48:21 +01:00
|
|
|
prescaler = 4; // prescaler: 1024
|
2011-01-22 23:29:02 +01:00
|
|
|
actual_cycles = ceiling * 1024L;
|
2009-01-28 23:48:21 +01:00
|
|
|
} else {
|
2009-01-30 11:26:08 +01:00
|
|
|
// Okay, that was slower than we actually go. Just set the slowest speed
|
2009-01-28 23:48:21 +01:00
|
|
|
ceiling = 0xffff;
|
|
|
|
prescaler = 4;
|
2011-01-03 00:36:33 +01:00
|
|
|
actual_cycles = 0xffff * 1024;
|
2009-01-28 23:48:21 +01:00
|
|
|
}
|
|
|
|
// Set prescaler
|
|
|
|
TCCR1B = (TCCR1B & ~(0x07<<CS10)) | ((prescaler+1)<<CS10);
|
|
|
|
// Set ceiling
|
|
|
|
OCR1A = ceiling;
|
2011-01-03 00:36:33 +01:00
|
|
|
return(actual_cycles);
|
2009-01-28 23:48:21 +01:00
|
|
|
}
|
|
|
|
|
2010-06-28 23:29:58 +02:00
|
|
|
void set_step_events_per_minute(uint32_t steps_per_minute) {
|
2011-01-22 23:29:02 +01:00
|
|
|
if (steps_per_minute < MINIMUM_STEPS_PER_MINUTE) { steps_per_minute = MINIMUM_STEPS_PER_MINUTE; }
|
2011-01-03 00:36:33 +01:00
|
|
|
cycles_per_step_event = config_step_timer((TICKS_PER_MICROSECOND*1000000*60)/steps_per_minute);
|
2010-06-28 23:29:58 +02:00
|
|
|
}
|
|
|
|
|
2009-01-28 23:48:21 +01:00
|
|
|
void st_go_home()
|
|
|
|
{
|
|
|
|
// Todo: Perform the homing cycle
|
|
|
|
}
|