time to save again, added delay_ms, implemented cooling fan, tons of updates in gcode interpreter
This commit is contained in:
parent
ef09d62c00
commit
f27e79aaf2
|
|
@ -7,6 +7,7 @@
|
||||||
#include "serial.h"
|
#include "serial.h"
|
||||||
#include "sermsg.h"
|
#include "sermsg.h"
|
||||||
#include "temp.h"
|
#include "temp.h"
|
||||||
|
#include "timer.h"
|
||||||
|
|
||||||
uint8_t option_bitfield;
|
uint8_t option_bitfield;
|
||||||
|
|
||||||
|
|
@ -94,7 +95,7 @@ void scan_char(uint8_t c) {
|
||||||
c &= ~32;
|
c &= ~32;
|
||||||
|
|
||||||
// process field
|
// process field
|
||||||
if (indexof(c, "GMXYZEFS\n") >= 0) {
|
if (indexof(c, "GMXYZEFSP\n") >= 0) {
|
||||||
if (last_field) {
|
if (last_field) {
|
||||||
switch (last_field) {
|
switch (last_field) {
|
||||||
case 'G':
|
case 'G':
|
||||||
|
|
@ -120,7 +121,20 @@ void scan_char(uint8_t c) {
|
||||||
next_target.target.F = read_digit.mantissa;
|
next_target.target.F = read_digit.mantissa;
|
||||||
break;
|
break;
|
||||||
case 'S':
|
case 'S':
|
||||||
next_target.S = decfloat_to_int(&read_digit, 1, 1);
|
// if this is temperature, multiply by 4 to convert to quarter-degree units
|
||||||
|
// cosmetically this should be done in the temperature section,
|
||||||
|
// but it takes less code, less memory and loses no precision if we do it here instead
|
||||||
|
if (next_target.M == 104)
|
||||||
|
next_target.S = decfloat_to_int(&read_digit, 4, 1);
|
||||||
|
else
|
||||||
|
next_target.S = decfloat_to_int(&read_digit, 1, 1);
|
||||||
|
break;
|
||||||
|
case 'P':
|
||||||
|
// if this is dwell, multiply by 1 million to convert seconds to milliseconds
|
||||||
|
if (next_target.G == 4)
|
||||||
|
next_target.P = decfloat_to_int(&read_digit, 1000, 1);
|
||||||
|
else
|
||||||
|
next_target.P = decfloat_to_int(&read_digit, 1, 1);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
read_digit.sign = 0;
|
read_digit.sign = 0;
|
||||||
|
|
@ -152,6 +166,10 @@ void scan_char(uint8_t c) {
|
||||||
break;
|
break;
|
||||||
case 'S':
|
case 'S':
|
||||||
next_target.seen |= SEEN_S;
|
next_target.seen |= SEEN_S;
|
||||||
|
break;
|
||||||
|
case 'P':
|
||||||
|
next_target.seen |= SEEN_P;
|
||||||
|
break;
|
||||||
case '\n':
|
case '\n':
|
||||||
// process
|
// process
|
||||||
process_gcode_command(&next_target);
|
process_gcode_command(&next_target);
|
||||||
|
|
@ -161,9 +179,7 @@ void scan_char(uint8_t c) {
|
||||||
|
|
||||||
// reset variables
|
// reset variables
|
||||||
last_field = 0;
|
last_field = 0;
|
||||||
// memset(&next_target, 0, sizeof(GCODE_COMMAND));
|
|
||||||
next_target.seen = 0;
|
next_target.seen = 0;
|
||||||
// next_target.option = option_bitfield;
|
|
||||||
|
|
||||||
serial_writeblock((uint8_t *) "OK\n", 3);
|
serial_writeblock((uint8_t *) "OK\n", 3);
|
||||||
break;
|
break;
|
||||||
|
|
@ -189,40 +205,44 @@ void process_gcode_command(GCODE_COMMAND *gcmd) {
|
||||||
gcmd->target.Z += startpoint.Z;
|
gcmd->target.Z += startpoint.Z;
|
||||||
gcmd->target.E += startpoint.E;
|
gcmd->target.E += startpoint.E;
|
||||||
}
|
}
|
||||||
// if ((gcmd->seen & SEEN_X) == 0)
|
|
||||||
// gcmd->target.X = startpoint.X;
|
|
||||||
// if ((gcmd->seen & SEEN_Y) == 0)
|
|
||||||
// gcmd->target.X = startpoint.Y;
|
|
||||||
// if ((gcmd->seen & SEEN_Z) == 0)
|
|
||||||
// gcmd->target.X = startpoint.Z;
|
|
||||||
// if ((gcmd->seen & SEEN_E) == 0)
|
|
||||||
// gcmd->target.X = startpoint.E;
|
|
||||||
|
|
||||||
if (gcmd->seen & SEEN_G) {
|
if (gcmd->seen & SEEN_G) {
|
||||||
switch (gcmd->G) {
|
switch (gcmd->G) {
|
||||||
// G0 - rapid, unsynchronised motion
|
// G0 - rapid, unsynchronised motion
|
||||||
|
// since it would be a major hassle to force the dda to not synchronise, just provide a fast feedrate and hope it's close enough to what host expects
|
||||||
case 0:
|
case 0:
|
||||||
gcmd->target.F = FEEDRATE_FAST_XY;
|
gcmd->target.F = FEEDRATE_FAST_XY;
|
||||||
enqueue(&gcmd->target);
|
enqueue(&gcmd->target);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// G1 - synchronised motion
|
// G1 - synchronised motion
|
||||||
case 1:
|
case 1:
|
||||||
enqueue(&gcmd->target);
|
enqueue(&gcmd->target);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// G2 - Arc Clockwise
|
// G2 - Arc Clockwise
|
||||||
|
|
||||||
// G3 - Arc Counter-clockwise
|
// G3 - Arc Counter-clockwise
|
||||||
|
|
||||||
// G4 - Dwell
|
// G4 - Dwell
|
||||||
|
case 4:
|
||||||
|
delay_ms(gcmd->P);
|
||||||
|
break;
|
||||||
|
|
||||||
// G20 - inches as units
|
// G20 - inches as units
|
||||||
case 20:
|
case 20:
|
||||||
gcmd->option |= OPTION_UNIT_INCHES;
|
gcmd->option |= OPTION_UNIT_INCHES;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// G21 - mm as units
|
// G21 - mm as units
|
||||||
case 21:
|
case 21:
|
||||||
gcmd->option &= ~OPTION_UNIT_INCHES;
|
gcmd->option &= ~OPTION_UNIT_INCHES;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// G30 - go home via point
|
// G30 - go home via point
|
||||||
case 30:
|
case 30:
|
||||||
enqueue(&gcmd->target);
|
enqueue(&gcmd->target);
|
||||||
|
// no break here, G30 is move and then go home
|
||||||
// G28 - go home
|
// G28 - go home
|
||||||
case 28:
|
case 28:
|
||||||
/*
|
/*
|
||||||
|
|
@ -269,18 +289,22 @@ void process_gcode_command(GCODE_COMMAND *gcmd) {
|
||||||
startpoint.E = current_position.E = 0;
|
startpoint.E = current_position.E = 0;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// G90 - absolute positioning
|
// G90 - absolute positioning
|
||||||
case 90:
|
case 90:
|
||||||
gcmd->option &= ~OPTION_RELATIVE;
|
gcmd->option &= ~OPTION_RELATIVE;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// G91 - relative positioning
|
// G91 - relative positioning
|
||||||
case 91:
|
case 91:
|
||||||
gcmd->option |= OPTION_RELATIVE;
|
gcmd->option |= OPTION_RELATIVE;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// G92 - set home
|
// G92 - set home
|
||||||
case 92:
|
case 92:
|
||||||
startpoint.X = startpoint.Y = startpoint.Z = 0;
|
startpoint.X = startpoint.Y = startpoint.Z = 0;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// TODO: spit an error
|
// TODO: spit an error
|
||||||
default:
|
default:
|
||||||
serial_writeblock((uint8_t *) "E: Bad G-code ", 14);
|
serial_writeblock((uint8_t *) "E: Bad G-code ", 14);
|
||||||
|
|
@ -294,20 +318,53 @@ void process_gcode_command(GCODE_COMMAND *gcmd) {
|
||||||
case 101:
|
case 101:
|
||||||
SpecialMoveE(E_STARTSTOP_STEPS, FEEDRATE_FAST_E);
|
SpecialMoveE(E_STARTSTOP_STEPS, FEEDRATE_FAST_E);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
// M102- extruder reverse
|
||||||
|
|
||||||
// M103- extruder off
|
// M103- extruder off
|
||||||
case 103:
|
case 103:
|
||||||
SpecialMoveE(-E_STARTSTOP_STEPS, FEEDRATE_FAST_E);
|
SpecialMoveE(-E_STARTSTOP_STEPS, FEEDRATE_FAST_E);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// M104- set temperature
|
// M104- set temperature
|
||||||
case 104:
|
case 104:
|
||||||
temp_set(gcmd->S);
|
temp_set(gcmd->S);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// M105- get temperature
|
// M105- get temperature
|
||||||
case 105:
|
case 105:
|
||||||
serial_writeblock((uint8_t *) "T: ", 3);
|
// do .. while block here to provide local scope for temp
|
||||||
serwrite_uint16(temp_get());
|
do {
|
||||||
serial_writechar('\n');
|
uint16_t t = temp_get();
|
||||||
|
serial_writeblock((uint8_t *) "T: ", 3);
|
||||||
|
serwrite_uint16(t >> 2);
|
||||||
|
serial_writechar('.');
|
||||||
|
if (t & 3) {
|
||||||
|
if ((t & 3) == 1)
|
||||||
|
serial_writechar('2');
|
||||||
|
else if ((t & 3) == 3)
|
||||||
|
serial_writechar('7');
|
||||||
|
serial_writechar('5');
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
serial_writechar('0');
|
||||||
|
}
|
||||||
|
serial_writechar('\n');
|
||||||
|
} while (0);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
// M106- fan on
|
||||||
|
#ifdef FAN_PIN
|
||||||
|
case 106:
|
||||||
|
WRITE(FAN_PIN, 1);
|
||||||
|
break;
|
||||||
|
|
||||||
|
// M107- fan off
|
||||||
|
case 107:
|
||||||
|
WRITE(FAN_PIN, 0);
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
|
|
||||||
// TODO: spit an error
|
// TODO: spit an error
|
||||||
default:
|
default:
|
||||||
serial_writeblock((uint8_t *) "E: Bad M-code ", 14);
|
serial_writeblock((uint8_t *) "E: Bad M-code ", 14);
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ typedef struct {
|
||||||
} decfloat;
|
} decfloat;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint8_t seen;
|
uint16_t seen;
|
||||||
#define SEEN_G 1
|
#define SEEN_G 1
|
||||||
#define SEEN_M 2
|
#define SEEN_M 2
|
||||||
#define SEEN_X 4
|
#define SEEN_X 4
|
||||||
|
|
@ -27,6 +27,7 @@ typedef struct {
|
||||||
#define SEEN_E 32
|
#define SEEN_E 32
|
||||||
#define SEEN_F 64
|
#define SEEN_F 64
|
||||||
#define SEEN_S 128
|
#define SEEN_S 128
|
||||||
|
#define SEEN_P 256
|
||||||
|
|
||||||
uint8_t option;
|
uint8_t option;
|
||||||
#define OPTION_RELATIVE 1
|
#define OPTION_RELATIVE 1
|
||||||
|
|
@ -38,6 +39,7 @@ typedef struct {
|
||||||
TARGET target;
|
TARGET target;
|
||||||
|
|
||||||
uint16_t S;
|
uint16_t S;
|
||||||
|
uint16_t P;
|
||||||
} GCODE_COMMAND;
|
} GCODE_COMMAND;
|
||||||
|
|
||||||
int8_t indexof(uint8_t c, char *string);
|
int8_t indexof(uint8_t c, char *string);
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,10 @@ int main (void)
|
||||||
|
|
||||||
WRITE(HEATER_PIN, 0); SET_OUTPUT(HEATER_PIN);
|
WRITE(HEATER_PIN, 0); SET_OUTPUT(HEATER_PIN);
|
||||||
|
|
||||||
|
#ifdef FAN_PIN
|
||||||
|
WRITE(FAN_PIN, 0); SET_OUTPUT(FAN_PIN);
|
||||||
|
#endif
|
||||||
|
|
||||||
WRITE(SCK, 0); SET_OUTPUT(SCK);
|
WRITE(SCK, 0); SET_OUTPUT(SCK);
|
||||||
WRITE(MISO, 1); SET_INPUT(MISO);
|
WRITE(MISO, 1); SET_INPUT(MISO);
|
||||||
WRITE(SS, 0); SET_OUTPUT(SS);
|
WRITE(SS, 0); SET_OUTPUT(SS);
|
||||||
|
|
|
||||||
|
|
@ -24,8 +24,8 @@
|
||||||
#define Y_MIN_PIN AIO5
|
#define Y_MIN_PIN AIO5
|
||||||
|
|
||||||
#define Z_STEP_PIN DIO5
|
#define Z_STEP_PIN DIO5
|
||||||
#define Z_DIR_PIN DIO6
|
#define Z_DIR_PIN DIO7
|
||||||
#define Z_MIN_PIN DIO7
|
#define Z_MIN_PIN DIO8
|
||||||
|
|
||||||
#define E_STEP_PIN DIO2
|
#define E_STEP_PIN DIO2
|
||||||
#define E_DIR_PIN DIO3
|
#define E_DIR_PIN DIO3
|
||||||
|
|
@ -41,6 +41,8 @@
|
||||||
#define HEATER_PIN DIO6
|
#define HEATER_PIN DIO6
|
||||||
#define HEATER_PIN_PWM OC0A
|
#define HEATER_PIN_PWM OC0A
|
||||||
|
|
||||||
|
#define FAN_PIN DIO9
|
||||||
|
|
||||||
#define SCK DIO13
|
#define SCK DIO13
|
||||||
#define MISO DIO12
|
#define MISO DIO12
|
||||||
#define MOSI DIO11
|
#define MOSI DIO11
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,17 @@
|
||||||
/*
|
/*
|
||||||
temp.c
|
temp.c
|
||||||
|
|
||||||
This file currently reads temp from a MAX6675 on the SPI bus
|
This file currently reads temp from a MAX6675 on the SPI bus.
|
||||||
|
|
||||||
|
ALL VALUES are in units of 0.25 degrees celsius, so temp_set(500) will set the temperature to 125 celsius, and temp_get() = 600 is reporting a temperature of 150 celsius.
|
||||||
|
|
||||||
|
the conversion to/from this unit is done in gcode.c, near:
|
||||||
|
if (next_target.M == 104)
|
||||||
|
next_target.S = decfloat_to_int(&read_digit, 4, 1);
|
||||||
|
and
|
||||||
|
// M105- get temperature
|
||||||
|
case 105:
|
||||||
|
uint16_t t = temp_get();
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "temp.h"
|
#include "temp.h"
|
||||||
|
|
|
||||||
|
|
@ -135,12 +135,20 @@ void setTimer(uint32_t delay)
|
||||||
|
|
||||||
void delay(uint32_t delay) {
|
void delay(uint32_t delay) {
|
||||||
while (delay > 65535) {
|
while (delay > 65535) {
|
||||||
delayMicrosecondsInterruptible(delay);
|
delayMicrosecondsInterruptible(65534);
|
||||||
delay -= 65535;
|
delay -= 65535;
|
||||||
}
|
}
|
||||||
delayMicrosecondsInterruptible(delay & 0xFFFF);
|
delayMicrosecondsInterruptible(delay & 0xFFFF);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void delay_ms(uint32_t delay) {
|
||||||
|
while (delay > 65) {
|
||||||
|
delayMicrosecondsInterruptible(64999);
|
||||||
|
delay -= 65;
|
||||||
|
}
|
||||||
|
delayMicrosecondsInterruptible(delay * 1000);
|
||||||
|
}
|
||||||
|
|
||||||
// from reprap project 5D firmware
|
// from reprap project 5D firmware
|
||||||
void delayMicrosecondsInterruptible(uint16_t us)
|
void delayMicrosecondsInterruptible(uint16_t us)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,10 @@ uint16_t getTimerCeiling(const uint32_t delay);
|
||||||
void setTimer(uint32_t delay);
|
void setTimer(uint32_t delay);
|
||||||
|
|
||||||
void delay(uint32_t delay);
|
void delay(uint32_t delay);
|
||||||
|
|
||||||
|
void delay_ms(uint32_t delay);
|
||||||
|
|
||||||
|
#define delay_us(d) delayMicrosecondsInterruptible(d)
|
||||||
void delayMicrosecondsInterruptible(unsigned int us);
|
void delayMicrosecondsInterruptible(unsigned int us);
|
||||||
|
|
||||||
inline void enableTimerInterrupt(void)
|
inline void enableTimerInterrupt(void)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue