improved the serial protocol, added some debug pins for a while
This commit is contained in:
parent
551b4ed274
commit
36fd3a9bfb
2
main.c
2
main.c
@ -41,6 +41,8 @@ int main(void)
|
|||||||
|
|
||||||
st_start(); // start the stepper subsystem
|
st_start(); // start the stepper subsystem
|
||||||
|
|
||||||
|
DDRD |= (1<<3)|(1<<4)|(1<<5);
|
||||||
|
|
||||||
for(;;){
|
for(;;){
|
||||||
sleep_mode();
|
sleep_mode();
|
||||||
sp_process(); // process the serial protocol
|
sp_process(); // process the serial protocol
|
||||||
|
@ -90,34 +90,44 @@ void mc_line(double x, double y, double z, float feed_rate, int invert_feed_rate
|
|||||||
maximum_steps; // The larges absolute step-count of any axis
|
maximum_steps; // The larges absolute step-count of any axis
|
||||||
|
|
||||||
// Setup ---------------------------------------------------------------------------------------------------
|
// Setup ---------------------------------------------------------------------------------------------------
|
||||||
|
PORTD |= (1<<4);
|
||||||
|
PORTD |= (1<<5);
|
||||||
target[X_AXIS] = round(x*X_STEPS_PER_MM);
|
target[X_AXIS] = round(x*X_STEPS_PER_MM);
|
||||||
target[Y_AXIS] = round(y*Y_STEPS_PER_MM);
|
target[Y_AXIS] = round(y*Y_STEPS_PER_MM);
|
||||||
target[Z_AXIS] = round(z*Z_STEPS_PER_MM);
|
target[Z_AXIS] = round(z*Z_STEPS_PER_MM);
|
||||||
|
PORTD ^= (1<<5);
|
||||||
// Determine direction and travel magnitude for each axis
|
// Determine direction and travel magnitude for each axis
|
||||||
for(axis = X_AXIS; axis <= Z_AXIS; axis++) {
|
for(axis = X_AXIS; axis <= Z_AXIS; axis++) {
|
||||||
step_count[axis] = labs(target[axis] - position[axis]);
|
step_count[axis] = labs(target[axis] - position[axis]);
|
||||||
direction[axis] = signof(target[axis] - position[axis]);
|
direction[axis] = signof(target[axis] - position[axis]);
|
||||||
}
|
}
|
||||||
|
PORTD ^= (1<<5);
|
||||||
// Find the magnitude of the axis with the longest travel
|
// Find the magnitude of the axis with the longest travel
|
||||||
maximum_steps = max(step_count[Z_AXIS],
|
maximum_steps = max(step_count[Z_AXIS],
|
||||||
max(step_count[X_AXIS], step_count[Y_AXIS]));
|
max(step_count[X_AXIS], step_count[Y_AXIS]));
|
||||||
|
PORTD ^= (1<<5);
|
||||||
// Nothing to do?
|
// Nothing to do?
|
||||||
if (maximum_steps == 0) { return; }
|
if (maximum_steps == 0) { PORTD &= ~(1<<4); PORTD |= (1<<5); return; }
|
||||||
|
PORTD ^= (1<<5);
|
||||||
// Set up a neat counter for each axis
|
// Set up a neat counter for each axis
|
||||||
for(axis = X_AXIS; axis <= Z_AXIS; axis++) {
|
for(axis = X_AXIS; axis <= Z_AXIS; axis++) {
|
||||||
counter[axis] = -maximum_steps/2;
|
counter[axis] = -maximum_steps/2;
|
||||||
}
|
}
|
||||||
|
PORTD ^= (1<<5);
|
||||||
// Set our direction pins
|
// Set our direction pins
|
||||||
set_stepper_directions(direction);
|
set_stepper_directions(direction);
|
||||||
|
PORTD ^= (1<<5);
|
||||||
|
|
||||||
// Ask old Phytagoras to estimate how many mm our next move is going to take us
|
// Ask old Phytagoras to estimate how many mm our next move is going to take us
|
||||||
double millimeters_of_travel =
|
double millimeters_of_travel =
|
||||||
sqrt(square(X_STEPS_PER_MM*step_count[X_AXIS]) +
|
sqrt(square(X_STEPS_PER_MM*step_count[X_AXIS]) +
|
||||||
square(Y_STEPS_PER_MM*step_count[Y_AXIS]) +
|
square(Y_STEPS_PER_MM*step_count[Y_AXIS]) +
|
||||||
square(Z_STEPS_PER_MM*step_count[Z_AXIS]));
|
square(Z_STEPS_PER_MM*step_count[Z_AXIS]));
|
||||||
|
PORTD ^= (1<<5);
|
||||||
// And set the step pace
|
// And set the step pace
|
||||||
compute_and_set_step_pace(feed_rate, millimeters_of_travel, maximum_steps, invert_feed_rate);
|
compute_and_set_step_pace(feed_rate, millimeters_of_travel, maximum_steps, invert_feed_rate);
|
||||||
|
PORTD &= ~(1<<5);
|
||||||
|
PORTD &= ~(1<<4);
|
||||||
|
|
||||||
// Execution -----------------------------------------------------------------------------------------------
|
// Execution -----------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@ -77,7 +77,7 @@ void sp_process()
|
|||||||
char c;
|
char c;
|
||||||
while((c = serialRead()) != -1)
|
while((c = serialRead()) != -1)
|
||||||
{
|
{
|
||||||
if((c < 32)) { // Line is complete. Then execute!
|
if((c == '\n')) { // Line is complete. Then execute!
|
||||||
line[line_counter] = 0;
|
line[line_counter] = 0;
|
||||||
// printString("->");
|
// printString("->");
|
||||||
// printString(line);
|
// printString(line);
|
||||||
@ -85,7 +85,7 @@ void sp_process()
|
|||||||
gc_execute_line(line);
|
gc_execute_line(line);
|
||||||
line_counter = 0;
|
line_counter = 0;
|
||||||
prompt();
|
prompt();
|
||||||
} else if (c == ' ' || c == '\t') { // Throw away whitepace
|
} else if (c <= ' ') { // Throw away whitepace and control characters
|
||||||
} else if (c >= 'a' && c <= 'z') { // Upcase lowercase
|
} else if (c >= 'a' && c <= 'z') { // Upcase lowercase
|
||||||
line[line_counter++] = c-'a'+'A';
|
line[line_counter++] = c-'a'+'A';
|
||||||
} else {
|
} else {
|
||||||
|
@ -53,6 +53,7 @@ void config_pace_timer(uint32_t microseconds);
|
|||||||
SIGNAL(SIG_OUTPUT_COMPARE1A)
|
SIGNAL(SIG_OUTPUT_COMPARE1A)
|
||||||
{
|
{
|
||||||
if (step_buffer_head != step_buffer_tail) {
|
if (step_buffer_head != step_buffer_tail) {
|
||||||
|
PORTD &= ~(1<<3);
|
||||||
uint8_t popped = step_buffer[step_buffer_tail];
|
uint8_t popped = step_buffer[step_buffer_tail];
|
||||||
if(popped == PACE_CHANGE_MARKER) {
|
if(popped == PACE_CHANGE_MARKER) {
|
||||||
// This is not a step-instruction, but a pace-change-marker: change pace
|
// This is not a step-instruction, but a pace-change-marker: change pace
|
||||||
@ -69,6 +70,8 @@ SIGNAL(SIG_OUTPUT_COMPARE1A)
|
|||||||
}
|
}
|
||||||
// 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;
|
||||||
|
} else {
|
||||||
|
PORTD |= (1<<3);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user