stepper signals looks good on scope

This commit is contained in:
Simen Svale Skogsrud 2009-02-03 23:36:04 +01:00
parent 5797812f4a
commit 7f9a9d27e2
5 changed files with 7097 additions and 157 deletions

View File

@ -323,7 +323,7 @@ void execute_go_home()
} }
void mc_execute() { void mc_execute() {
st_set_pace(mc.pace); // st_set_pace(mc.pace);
printByte('~'); printByte('~');
while(mc.mode) { // Loop because one task might start another task while(mc.mode) { // Loop because one task might start another task
switch(mc.mode) { switch(mc.mode) {

View File

@ -30,7 +30,7 @@
#define true 1 #define true 1
// Decide the sign of a value // Decide the sign of a value
#define signof(a) ((a>0) ? 1 : ((a<0) ? -1 : 0)) #define signof(a) (((a)>0) ? 1 : (((a)<0) ? -1 : 0))
#define clear_vector(a) memset(a, 0, sizeof(a)) #define clear_vector(a) memset(a, 0, sizeof(a))

View File

@ -29,7 +29,7 @@
#include "wiring_serial.h" #include "wiring_serial.h"
#define TICKS_PER_MICROSECOND F_CPU/1000000 #define TICKS_PER_MICROSECOND (F_CPU/1000000)
#define STEP_BUFFER_SIZE 100 #define STEP_BUFFER_SIZE 100
volatile uint8_t step_buffer[STEP_BUFFER_SIZE]; // A buffer for step instructions volatile uint8_t step_buffer[STEP_BUFFER_SIZE]; // A buffer for step instructions
@ -45,12 +45,14 @@ uint8_t echo_steps = true;
SIGNAL(SIG_OUTPUT_COMPARE1A) SIGNAL(SIG_OUTPUT_COMPARE1A)
{ {
if (step_buffer_head != step_buffer_tail) { if (step_buffer_head != step_buffer_tail) {
// Set the stepper port according to the instructions // Set the direction pins a nanosecond or two before you step the steppers
STEPPING_PORT = (STEPPING_PORT & ~STEPPING_MASK) | step_buffer[step_buffer_tail]; STEPPING_PORT = (STEPPING_PORT & ~DIRECTION_MASK) | (step_buffer[step_buffer_tail] & DIRECTION_MASK);
// Then pulse the stepping pins
STEPPING_PORT = (STEPPING_PORT & ~STEP_MASK) | step_buffer[step_buffer_tail];
// Reset and start timer 2 which will reset the motor port after 5 microsecond // Reset and start timer 2 which will reset the motor port after 5 microsecond
// TCNT2 = 0; // reset counter TCNT2 = 0; // reset counter
// OCR2A = 5*TICKS_PER_MICROSECOND; // set the time OCR2A = 5*TICKS_PER_MICROSECOND; // set the time
// TIMSK2 |= (1<<OCIE2A); // enable interrupt TIMSK2 |= (1<<OCIE2A); // enable interrupt
// move the step buffer tail to the next instruction // move the step buffer tail to the next instruction
step_buffer_tail = (step_buffer_tail + 1) % STEP_BUFFER_SIZE; step_buffer_tail = (step_buffer_tail + 1) % STEP_BUFFER_SIZE;
} }
@ -60,7 +62,7 @@ SIGNAL(SIG_OUTPUT_COMPARE1A)
// the motor port after a short period (5us) completing one step cycle. // the motor port after a short period (5us) completing one step cycle.
SIGNAL(SIG_OUTPUT_COMPARE2A) SIGNAL(SIG_OUTPUT_COMPARE2A)
{ {
STEPPING_PORT = STEPPING_PORT & ~STEPPING_MASK; // reset stepper pins STEPPING_PORT = STEPPING_PORT & ~STEP_MASK; // reset stepping pins (leave the direction pins)
TIMSK2 &= ~(1<<OCIE2A); // disable this timer interrupt until next time TIMSK2 &= ~(1<<OCIE2A); // disable this timer interrupt until next time
} }
@ -90,7 +92,7 @@ void st_init()
sei(); sei();
// start off with a slow pace // start off with a slow pace
st_set_pace(1000000); st_set_pace(20000);
st_start(); st_start();
} }
@ -107,7 +109,7 @@ void st_buffer_step(uint8_t motor_port_bits)
// Nap until there is room for more steps. // Nap until there is room for more steps.
while(step_buffer_tail == i) { sleep_mode(); } while(step_buffer_tail == i) { sleep_mode(); }
// step_buffer[step_buffer_head] = motor_port_bits; step_buffer[step_buffer_head] = motor_port_bits;
step_buffer_head = i; step_buffer_head = i;
} }
@ -152,13 +154,10 @@ void st_set_pace(uint32_t microseconds)
printString("pace = "); printString("pace = ");
printInteger(microseconds); printInteger(microseconds);
printString("\n\r"); printString("\n\r");
if (microseconds <= 500) {
microseconds = 500;
}
uint32_t ticks = microseconds*TICKS_PER_MICROSECOND; uint32_t ticks = microseconds*TICKS_PER_MICROSECOND;
uint16_t ceiling; uint16_t ceiling;
uint16_t prescaler; uint16_t prescaler;
if (ticks <= 65535L) { if (ticks <= 0xffffL) {
ceiling = ticks; ceiling = ticks;
prescaler = 0; // prescaler: 0 prescaler = 0; // prescaler: 0
} else if (ticks <= 0x7ffffL) { } else if (ticks <= 0x7ffffL) {
@ -178,7 +177,6 @@ void st_set_pace(uint32_t microseconds)
ceiling = 0xffff; ceiling = 0xffff;
prescaler = 4; prescaler = 4;
} }
// Set prescaler // Set prescaler
TCCR1B = (TCCR1B & ~(0x07<<CS10)) | ((prescaler+1)<<CS10); TCCR1B = (TCCR1B & ~(0x07<<CS10)) | ((prescaler+1)<<CS10);
// Set ceiling // Set ceiling

File diff suppressed because it is too large Load Diff

BIN
testbench/gcodetest.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB