time to save
This commit is contained in:
parent
bce08901d8
commit
505a744d54
|
|
@ -126,7 +126,7 @@ void dda_create(DDA *dda, TARGET *target) {
|
|||
|
||||
// initialise DDA to a known state
|
||||
dda->live = 0;
|
||||
dda->total_steps = 0;
|
||||
// dda->total_steps = 0;
|
||||
dda->waitfor_temp = 0;
|
||||
|
||||
if (debug_flags & DEBUG_DDA)
|
||||
|
|
@ -162,7 +162,7 @@ void dda_create(DDA *dda, TARGET *target) {
|
|||
serial_writestr_P(PSTR("] ["));
|
||||
}
|
||||
|
||||
if (dda->x_delta > dda->total_steps)
|
||||
// if (dda->x_delta > dda->total_steps)
|
||||
dda->total_steps = dda->x_delta;
|
||||
if (dda->y_delta > dda->total_steps)
|
||||
dda->total_steps = dda->y_delta;
|
||||
|
|
@ -449,7 +449,7 @@ void dda_step(DDA *dda) {
|
|||
// else we are already at target speed
|
||||
}
|
||||
|
||||
if (step_option & DID_STEP) {
|
||||
if (step_option) {
|
||||
// we stepped, reset timeout
|
||||
steptimeout = 0;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,10 +1,12 @@
|
|||
#include "dda_queue.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <avr/interrupt.h>
|
||||
|
||||
#include "timer.h"
|
||||
#include "serial.h"
|
||||
#include "sermsg.h"
|
||||
#include "temp.h"
|
||||
|
||||
uint8_t mb_head = 0;
|
||||
uint8_t mb_tail = 0;
|
||||
|
|
@ -18,6 +20,41 @@ uint8_t queue_empty() {
|
|||
return ((mb_tail == mb_head) && (movebuffer[mb_tail].live == 0))?255:0;
|
||||
}
|
||||
|
||||
void queue_step() {
|
||||
disableTimerInterrupt();
|
||||
|
||||
// do our next step
|
||||
// NOTE: dda_step makes this interrupt interruptible after steps have been sent but before new speed is calculated.
|
||||
if (movebuffer[mb_tail].live) {
|
||||
if (movebuffer[mb_tail].waitfor_temp) {
|
||||
if (temp_achieved()) {
|
||||
movebuffer[mb_tail].live = movebuffer[mb_tail].waitfor_temp = 0;
|
||||
serial_writestr_P(PSTR("Temp achieved\n"));
|
||||
}
|
||||
|
||||
#if STEP_INTERRUPT_INTERRUPTIBLE
|
||||
sei();
|
||||
#endif
|
||||
}
|
||||
else {
|
||||
dda_step(&(movebuffer[mb_tail]));
|
||||
}
|
||||
}
|
||||
|
||||
// serial_writechar('!');
|
||||
|
||||
// fall directly into dda_start instead of waiting for another step
|
||||
if (movebuffer[mb_tail].live == 0)
|
||||
next_move();
|
||||
|
||||
#if STEP_INTERRUPT_INTERRUPTIBLE
|
||||
cli();
|
||||
#endif
|
||||
// check queue, if empty we don't need to interrupt again until re-enabled in dda_create
|
||||
if (queue_empty() == 0)
|
||||
enableTimerInterrupt();
|
||||
}
|
||||
|
||||
void enqueue(TARGET *t) {
|
||||
// don't call this function when the queue is full, but just in case, wait for a move to complete and free up the space for the passed target
|
||||
while (queue_full())
|
||||
|
|
@ -47,10 +84,11 @@ void enqueue_temp_wait() {
|
|||
while (queue_full())
|
||||
delay(WAITING_DELAY);
|
||||
|
||||
uint8_t h = mb_head;
|
||||
h++;
|
||||
if (h == MOVEBUFFER_SIZE)
|
||||
h = 0;
|
||||
uint8_t h = mb_head + 1;
|
||||
// h++;
|
||||
// if (h == MOVEBUFFER_SIZE)
|
||||
// h = 0;
|
||||
h &= (MOVEBUFFER_SIZE - 1);
|
||||
|
||||
// wait for temp flag
|
||||
movebuffer[h].waitfor_temp = 1;
|
||||
|
|
@ -76,16 +114,13 @@ void enqueue_temp_wait() {
|
|||
}
|
||||
|
||||
void next_move() {
|
||||
if (queue_empty()) {
|
||||
// memcpy(&startpoint, ¤t_position, sizeof(TARGET));
|
||||
startpoint.E = current_position.E = 0;
|
||||
}
|
||||
else {
|
||||
if (queue_empty() == 0) {
|
||||
// next item
|
||||
uint8_t t = mb_tail;
|
||||
t++;
|
||||
if (t == MOVEBUFFER_SIZE)
|
||||
t = 0;
|
||||
uint8_t t = mb_tail + 1;
|
||||
// t++;
|
||||
// if (t == MOVEBUFFER_SIZE)
|
||||
// t = 0;
|
||||
t &= (MOVEBUFFER_SIZE - 1);
|
||||
dda_start(&movebuffer[t]);
|
||||
mb_tail = t;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,6 +20,9 @@ extern DDA movebuffer[MOVEBUFFER_SIZE];
|
|||
uint8_t queue_full(void);
|
||||
uint8_t queue_empty(void);
|
||||
|
||||
// take one step
|
||||
void queue_step(void);
|
||||
|
||||
// add a new target to the queue
|
||||
void enqueue(TARGET *t);
|
||||
|
||||
|
|
|
|||
|
|
@ -98,11 +98,15 @@ mendel_reset() {
|
|||
mendel_setup
|
||||
}
|
||||
|
||||
mendel_talk() {
|
||||
( cat <&3 & cat >&3; kill $! ; ) 3<>/dev/arduino
|
||||
}
|
||||
|
||||
mendel_cmd() {
|
||||
(
|
||||
IFS=$' \t\n'
|
||||
RSC=0
|
||||
cmd="$*"
|
||||
local IFS=$' \t\n'
|
||||
local RSC=0
|
||||
local cmd="$*"
|
||||
echo "$cmd" >&3;
|
||||
while [ "$REPLY" != "OK" ]
|
||||
do
|
||||
|
|
@ -122,28 +126,27 @@ mendel_cmd() {
|
|||
echo "Too many retries: aborting" >&2
|
||||
fi
|
||||
fi
|
||||
LN=$(( $LN + 1 ))
|
||||
done
|
||||
) 3<>/dev/arduino;
|
||||
}
|
||||
|
||||
mendel_cmd_hr() {
|
||||
(
|
||||
IFS=$' \t\n'
|
||||
cmd="$*"
|
||||
RSC=0
|
||||
local IFS=$' \t\n'
|
||||
local cmd="$*"
|
||||
local RSC=0
|
||||
echo "$cmd" >&3
|
||||
echo "> $cmd"
|
||||
echo "S> $cmd"
|
||||
while [ "$REPLY" != "OK" ]
|
||||
do
|
||||
read -u 3
|
||||
echo "< $REPLY"
|
||||
echo "<R $REPLY"
|
||||
if [[ "$REPLY" =~ ^RESEND ]]
|
||||
then
|
||||
if [ "$RSC" -le 3 ]
|
||||
then
|
||||
echo "$cmd" >&3
|
||||
echo "> $cmd"
|
||||
echo "S> $cmd"
|
||||
RSC=$(( $RSC + 1))
|
||||
else
|
||||
REPLY="OK"
|
||||
|
|
@ -158,7 +161,7 @@ mendel_print() {
|
|||
(
|
||||
for F in "$@"
|
||||
do
|
||||
IFS=$'\n'
|
||||
local IFS=$'\n'
|
||||
for L in $(< $F)
|
||||
do
|
||||
mendel_cmd_hr "$L"
|
||||
|
|
@ -169,14 +172,14 @@ mendel_print() {
|
|||
|
||||
mendel_readsym() {
|
||||
(
|
||||
IFS=$' \t\n'
|
||||
sym=$1
|
||||
local IFS=$' \t\n'
|
||||
local sym=$1
|
||||
if [ -n "$sym" ]
|
||||
then
|
||||
if [[ "$sym" =~ ^(0?x?[0-9A-Fa-f]+)(:([0-9]+))?$ ]]
|
||||
then
|
||||
ADDR=$(( ${BASH_REMATCH[1]} ))
|
||||
SIZE=$(( ${BASH_REMATCH[3]} ))
|
||||
local ADDR=$(( ${BASH_REMATCH[1]} ))
|
||||
local SIZE=$(( ${BASH_REMATCH[3]} ))
|
||||
if [ "$SIZE" -le 1 ]
|
||||
then
|
||||
SIZE=1
|
||||
|
|
@ -186,8 +189,8 @@ mendel_readsym() {
|
|||
make mendel.sym &>/dev/null
|
||||
if egrep -q '\b'$sym'\b' mendel.sym
|
||||
then
|
||||
ADDR=$(( $(egrep '\b'$sym'\b' mendel.sym | cut -d\ -f1) ))
|
||||
SIZE=$(egrep '\b'$sym'\b' mendel.sym | cut -d+ -f2)
|
||||
local ADDR=$(( $(egrep '\b'$sym'\b' mendel.sym | cut -d\ -f1) ))
|
||||
local SIZE=$(egrep '\b'$sym'\b' mendel.sym | cut -d+ -f2)
|
||||
mendel_cmd "M253 S$ADDR P$SIZE"
|
||||
else
|
||||
echo "unknown symbol: $sym"
|
||||
|
|
@ -200,44 +203,44 @@ mendel_readsym() {
|
|||
}
|
||||
|
||||
mendel_readsym_uint8() {
|
||||
sym=$1
|
||||
val=$(mendel_readsym $sym)
|
||||
local sym=$1
|
||||
local val=$(mendel_readsym $sym)
|
||||
perl -e 'printf "%u\n", eval "0x".$ARGV[0]' $val
|
||||
}
|
||||
|
||||
mendel_readsym_int8() {
|
||||
sym=$1
|
||||
val=$(mendel_readsym $sym)
|
||||
local sym=$1
|
||||
local val=$(mendel_readsym $sym)
|
||||
perl -e 'printf "%d\n", ((eval "0x".$ARGV[0]) & 0x7F) - (((eval "0x".$ARGV[0]) & 0x80)?0x80:0)' $val
|
||||
}
|
||||
|
||||
mendel_readsym_uint16() {
|
||||
sym=$1
|
||||
val=$(mendel_readsym $sym)
|
||||
local sym=$1
|
||||
local val=$(mendel_readsym $sym)
|
||||
perl -e '$ARGV[0] =~ m#(..)(..)# && printf "%u\n", eval "0x$2$1"' $val
|
||||
}
|
||||
|
||||
mendel_readsym_int16() {
|
||||
sym=$1
|
||||
val=$(mendel_readsym $sym)
|
||||
local sym=$1
|
||||
local val=$(mendel_readsym $sym)
|
||||
perl -e '$ARGV[0] =~ m#(..)(..)# && printf "%d\n", ((eval "0x$2$1") & 0x7FFF) - (((eval "0x$2$1") & 0x8000)?0x8000:0)' $val
|
||||
}
|
||||
|
||||
mendel_readsym_uint32() {
|
||||
sym=$1
|
||||
val=$(mendel_readsym $sym)
|
||||
local sym=$1
|
||||
local val=$(mendel_readsym $sym)
|
||||
perl -e '$ARGV[0] =~ m#(..)(..)(..)(..)# && printf "%u\n", eval "0x$4$3$2$1"' $val
|
||||
}
|
||||
|
||||
mendel_readsym_int32() {
|
||||
sym=$1
|
||||
val=$(mendel_readsym $sym)
|
||||
local sym=$1
|
||||
local val=$(mendel_readsym $sym)
|
||||
perl -e '$ARGV[0] =~ m#(..)(..)(..)(..)# && printf "%d\n", eval "0x$4$3$2$1"' $val
|
||||
}
|
||||
|
||||
mendel_readsym_target() {
|
||||
sym=$1
|
||||
val=$(mendel_readsym "$sym")
|
||||
local sym=$1
|
||||
local val=$(mendel_readsym "$sym")
|
||||
if [ -n "$val" ]
|
||||
then
|
||||
perl -e '@a = qw/X Y Z E F/; $c = 0; while (length $ARGV[0]) { $ARGV[0] =~ s#^(..)(..)(..)(..)##; printf "%s: %d\n", $a[$c], eval "0x$4$3$2$1"; $c++; }' "$val"
|
||||
|
|
@ -245,9 +248,9 @@ mendel_readsym_target() {
|
|||
}
|
||||
|
||||
mendel_readsym_mb() {
|
||||
val=$(mendel_readsym movebuffer)
|
||||
mbhead=$(mendel_readsym mb_head)
|
||||
mbtail=$(mendel_readsym mb_tail)
|
||||
local val=$(mendel_readsym movebuffer)
|
||||
local mbhead=$(mendel_readsym mb_head)
|
||||
local mbtail=$(mendel_readsym mb_tail)
|
||||
perl - <<'ENDPERL' -- $val $mbhead $mbtail
|
||||
$i = -1;
|
||||
@a = qw/eX 4 eY 4 eZ 4 eE 4 eF 4 flags 9 dX 12 dY 4 dZ 4 dE 4 cX 12 cY 4 cZ 4 cE 4 ts 12 c 12 ec 4 n 4/;
|
||||
|
|
@ -279,16 +282,16 @@ ENDPERL
|
|||
}
|
||||
|
||||
mendel_heater_pid() {
|
||||
P=$(mendel_readsym_int16 heater_p)
|
||||
I=$(mendel_readsym_int16 heater_i)
|
||||
D=$(mendel_readsym_int16 heater_d)
|
||||
local P=$(mendel_readsym_int16 heater_p)
|
||||
local I=$(mendel_readsym_int16 heater_i)
|
||||
local D=$(mendel_readsym_int16 heater_d)
|
||||
|
||||
PF=$(mendel_readsym_int32 p_factor)
|
||||
IF=$(mendel_readsym_int32 i_factor)
|
||||
DF=$(mendel_readsym_int32 d_factor)
|
||||
local PF=$(mendel_readsym_int32 p_factor)
|
||||
local IF=$(mendel_readsym_int32 i_factor)
|
||||
local DF=$(mendel_readsym_int32 d_factor)
|
||||
|
||||
O=$(mendel_readsym_uint8 0x27)
|
||||
T=$(mendel_cmd M105 | cut -d\ -f2 | cut -d/ -f1)
|
||||
local O=$(mendel_readsym_uint8 0x27)
|
||||
local T=$(mendel_cmd M105 | cut -d\ -f2 | cut -d/ -f1)
|
||||
|
||||
echo "P=$P pf=$PF r="$(($P * $PF))
|
||||
echo "I=$I if=$IF r="$(($I * $IF))
|
||||
|
|
@ -298,3 +301,13 @@ mendel_heater_pid() {
|
|||
echo "R="$(( $(( $(( $(($P * $PF)) + $(($I * $IF)) + $(($D * $DF)) )) / 1024 )) + 128 ))
|
||||
echo "O=$O T=$T"
|
||||
}
|
||||
|
||||
if [[ "$0" =~ ^mendel_(setup|reset|cmd|readsym|heater_pid) ]]
|
||||
then
|
||||
eval "$0" "$@"
|
||||
fi
|
||||
|
||||
if [[ "$1" =~ ^mendel_(setup|reset|cmd|readsym|heater_pid) ]]
|
||||
then
|
||||
eval "$@"
|
||||
fi
|
||||
|
|
|
|||
|
|
@ -523,7 +523,7 @@ void process_gcode_command(GCODE_COMMAND *gcmd) {
|
|||
// backup feedrate, move E very quickly then restore feedrate
|
||||
uint32_t f = startpoint.F;
|
||||
startpoint.F = FEEDRATE_FAST_E;
|
||||
SpecialMoveE(startpoint.E + E_STARTSTOP_STEPS, FEEDRATE_FAST_E);
|
||||
SpecialMoveE(E_STARTSTOP_STEPS, FEEDRATE_FAST_E);
|
||||
startpoint.F = f;
|
||||
} while (0);
|
||||
break;
|
||||
|
|
@ -536,7 +536,7 @@ void process_gcode_command(GCODE_COMMAND *gcmd) {
|
|||
// backup feedrate, move E very quickly then restore feedrate
|
||||
uint32_t f = startpoint.F;
|
||||
startpoint.F = FEEDRATE_FAST_E;
|
||||
SpecialMoveE(startpoint.E - E_STARTSTOP_STEPS, FEEDRATE_FAST_E);
|
||||
SpecialMoveE(-E_STARTSTOP_STEPS, FEEDRATE_FAST_E);
|
||||
startpoint.F = f;
|
||||
} while (0);
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@
|
|||
// does this refer to filament or extrudate? extrudate depends on XY distance vs E distance.. hm lets go with filament
|
||||
// #define STEPS_PER_MM_E ((uint32_t) ((E_STEPS_PER_REV / (EXTRUDER_SHAFT_RADIUS * PI * EXTRUDER_INLET_DIAMETER / EXTRUDER_NOZZLE_DIAMETER)) + 0.5))
|
||||
|
||||
#define STEPS_PER_MM_E ((uint32_t) ((E_STEPS_PER_REV * EXTRUDER_NOZZLE_DIAMETER / (EXTRUDER_SHAFT_RADIUS * PI * EXTRUDER_INLET_DIAMETER)) + 0.5))
|
||||
#define STEPS_PER_MM_E ((uint32_t) ((E_STEPS_PER_REV * EXTRUDER_NOZZLE_DIAMETER / EXTRUDER_SHAFT_RADIUS / PI / EXTRUDER_INLET_DIAMETER) + 0.5))
|
||||
|
||||
// same as above with 25.4 scale factor
|
||||
#define STEPS_PER_IN_X ((uint32_t) ((25.4 * X_STEPS_PER_REV / X_COG_CIRCUMFERENCE) + 0.5))
|
||||
|
|
|
|||
|
|
@ -117,31 +117,9 @@ void clock_250ms(void) {
|
|||
ifclock(CLOCK_FLAG_1S) {
|
||||
if (debug_flags & DEBUG_POSITION) {
|
||||
// current position
|
||||
// serial_writestr_P(PSTR("Pos: "));
|
||||
// serwrite_int32(current_position.X);
|
||||
// serial_writechar(',');
|
||||
// serwrite_int32(current_position.Y);
|
||||
// serial_writechar(',');
|
||||
// serwrite_int32(current_position.Z);
|
||||
// serial_writechar(',');
|
||||
// serwrite_int32(current_position.E);
|
||||
// serial_writechar(',');
|
||||
// serwrite_uint32(current_position.F);
|
||||
// serial_writechar('\n');
|
||||
sersendf_P(PSTR("Pos: %ld,%ld,%ld,%ld,%lu\n"), current_position.X, current_position.Y, current_position.Z, current_position.E, current_position.F);
|
||||
|
||||
// target position
|
||||
// serial_writestr_P(PSTR("Dst: "));
|
||||
// serwrite_int32(movebuffer[mb_tail].endpoint.X);
|
||||
// serial_writechar(',');
|
||||
// serwrite_int32(movebuffer[mb_tail].endpoint.Y);
|
||||
// serial_writechar(',');
|
||||
// serwrite_int32(movebuffer[mb_tail].endpoint.Z);
|
||||
// serial_writechar(',');
|
||||
// serwrite_int32(movebuffer[mb_tail].endpoint.E);
|
||||
// serial_writechar(',');
|
||||
// serwrite_uint32(movebuffer[mb_tail].endpoint.F);
|
||||
// serial_writechar('\n');
|
||||
sersendf_P(PSTR("Dst: %ld,%ld,%ld,%ld,%lu\n"), movebuffer[mb_tail].endpoint.X, movebuffer[mb_tail].endpoint.Y, movebuffer[mb_tail].endpoint.Z, movebuffer[mb_tail].endpoint.E, movebuffer[mb_tail].endpoint.F);
|
||||
|
||||
// Queue
|
||||
|
|
|
|||
|
|
@ -152,9 +152,10 @@ void serial_writeblock(void *data, int datalen)
|
|||
|
||||
void serial_writestr(uint8_t *data)
|
||||
{
|
||||
uint8_t i = 0;
|
||||
uint8_t i = 0, r;
|
||||
// yes, this is *supposed* to be assignment rather than comparison, so we break when r is assigned zero
|
||||
for (uint8_t r; (r = data[i]); i++)
|
||||
// for (uint8_t r; (r = data[i]); i++)
|
||||
while ((r = data[i++]))
|
||||
serial_writechar(r);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -13,9 +13,8 @@ void sersendf(char *format, ...) {
|
|||
va_start(args, format);
|
||||
|
||||
uint16_t i = 0;
|
||||
uint8_t c = 1, j = 0;
|
||||
for (; c != 0; i++) {
|
||||
c = format[i];
|
||||
uint8_t c, j = 0;
|
||||
while ((c = format[i++])) {
|
||||
if (j) {
|
||||
switch(c) {
|
||||
case 'l':
|
||||
|
|
@ -74,8 +73,7 @@ void sersendf_P(PGM_P format, ...) {
|
|||
|
||||
uint16_t i = 0;
|
||||
uint8_t c = 1, j = 0;
|
||||
for (; c != 0; i++) {
|
||||
c = pgm_read_byte(&format[i]);
|
||||
while ((c = pgm_read_byte(&format[i++]))) {
|
||||
if (j) {
|
||||
switch(c) {
|
||||
case 's':
|
||||
|
|
|
|||
103
mendel/temp.c
103
mendel/temp.c
|
|
@ -13,7 +13,7 @@
|
|||
case 105:
|
||||
uint16_t t = temp_get();
|
||||
|
||||
note that the MAX6675 can't do more than approx 4 conversions per second
|
||||
note that the MAX6675 can't do more than approx 5 conversions per second- we go for 4 so the timing isn't too tight
|
||||
*/
|
||||
|
||||
#include "temp.h"
|
||||
|
|
@ -37,10 +37,10 @@ int16_t heater_p = 0;
|
|||
int16_t heater_i = 0;
|
||||
int16_t heater_d = 0;
|
||||
|
||||
#define DEFAULT_P 4096
|
||||
#define DEFAULT_I 256
|
||||
#define DEFAULT_D -14336
|
||||
#define DEFAULT_I_LIMIT 768
|
||||
#define DEFAULT_P 8192
|
||||
#define DEFAULT_I 512
|
||||
#define DEFAULT_D -24576
|
||||
#define DEFAULT_I_LIMIT 384
|
||||
int32_t p_factor = 0;
|
||||
int32_t i_factor = 0;
|
||||
int32_t d_factor = 0;
|
||||
|
|
@ -151,66 +151,22 @@ uint8_t temp_achieved() {
|
|||
}
|
||||
|
||||
void temp_print() {
|
||||
// serial_writestr_P(PSTR("T: "));
|
||||
if (temp_flags & TEMP_FLAG_TCOPEN) {
|
||||
serial_writestr_P(PSTR("T: no thermocouple!\n"));
|
||||
}
|
||||
else {
|
||||
// serwrite_uint16(current_temp >> 2);
|
||||
// serial_writechar('.');
|
||||
// if (current_temp & 3) {
|
||||
// if ((current_temp & 3) == 3)
|
||||
// serial_writechar('7');
|
||||
// else if ((current_temp & 3) == 1)
|
||||
// serial_writechar('2');
|
||||
// serial_writechar('5');
|
||||
// }
|
||||
// else {
|
||||
// serial_writechar('0');
|
||||
// }
|
||||
// // serial_writestr_P(PSTR("°C"));
|
||||
// serial_writechar('/');
|
||||
// serwrite_uint16(target_temp >> 2);
|
||||
// serial_writechar('.');
|
||||
// if (target_temp & 3) {
|
||||
// if ((target_temp & 3) == 3)
|
||||
// serial_writechar('7');
|
||||
// else if ((target_temp & 3) == 1)
|
||||
// serial_writechar('2');
|
||||
// serial_writechar('5');
|
||||
// }
|
||||
// else {
|
||||
// serial_writechar('0');
|
||||
// }
|
||||
//
|
||||
// serial_writestr_P(PSTR(" :"));
|
||||
// serwrite_uint8(temp_residency);
|
||||
uint8_t c = 0, t = 0;
|
||||
|
||||
if (current_temp & 3)
|
||||
c = 5;
|
||||
if ((current_temp & 3) == 1)
|
||||
c += 20;
|
||||
else if ((current_temp & 3) == 3)
|
||||
c += 70;
|
||||
|
||||
if (target_temp & 3)
|
||||
t = 5;
|
||||
if ((target_temp & 3) == 1)
|
||||
t += 20;
|
||||
else if ((target_temp & 3) == 3)
|
||||
t += 70;
|
||||
|
||||
sersendf_P(PSTR("%u.%u/%u.%u :%u\n"), current_temp >> 2, c, target_temp >> 2, t, temp_residency);
|
||||
c = (current_temp & 3) * 25;
|
||||
t = (target_temp & 3) * 25;
|
||||
sersendf_P(PSTR("T: %u.%u/%u.%u :%u\n"), current_temp >> 2, c, target_temp >> 2, t, temp_residency);
|
||||
}
|
||||
// serial_writechar('\n');
|
||||
}
|
||||
|
||||
void temp_tick() {
|
||||
if (target_temp) {
|
||||
steptimeout = 0;
|
||||
|
||||
// uint16_t last_temp = current_temp;
|
||||
temp_read();
|
||||
|
||||
temp_history[th_p++] = current_temp;
|
||||
|
|
@ -221,16 +177,8 @@ void temp_tick() {
|
|||
else if (temp_residency < TEMP_RESIDENCY_TIME)
|
||||
temp_residency++;
|
||||
|
||||
// if (debug_flags & DEBUG_PID)
|
||||
// serial_writestr_P(PSTR("T{"));
|
||||
|
||||
int16_t t_error = target_temp - current_temp;
|
||||
|
||||
// if (debug_flags & DEBUG_PID) {
|
||||
// serial_writestr_P(PSTR("E:"));
|
||||
// serwrite_int16(t_error);
|
||||
// }
|
||||
|
||||
// PID stuff
|
||||
// proportional
|
||||
heater_p = t_error;
|
||||
|
|
@ -245,30 +193,8 @@ void temp_tick() {
|
|||
|
||||
// derivative
|
||||
// note: D follows temp rather than error so there's no large derivative when the target changes
|
||||
// heater_d = (current_temp - last_temp);
|
||||
heater_d = current_temp - temp_history[th_p];
|
||||
|
||||
// if (debug_flags & DEBUG_PID) {
|
||||
// serial_writestr_P(PSTR(", P:"));
|
||||
// serwrite_int16(heater_p);
|
||||
// serial_writestr_P(PSTR(" * "));
|
||||
// serwrite_int32(p_factor);
|
||||
// serial_writestr_P(PSTR(" = "));
|
||||
// serwrite_int32((int32_t) heater_p * p_factor / PID_SCALE);
|
||||
// serial_writestr_P(PSTR(" / I:"));
|
||||
// serwrite_int16(heater_i);
|
||||
// serial_writestr_P(PSTR(" * "));
|
||||
// serwrite_int32(i_factor);
|
||||
// serial_writestr_P(PSTR(" = "));
|
||||
// serwrite_int32((int32_t) heater_i * i_factor / PID_SCALE);
|
||||
// serial_writestr_P(PSTR(" / D:"));
|
||||
// serwrite_int16(heater_d);
|
||||
// serial_writestr_P(PSTR(" * "));
|
||||
// serwrite_int32(d_factor);
|
||||
// serial_writestr_P(PSTR(" = "));
|
||||
// serwrite_int32((int32_t) heater_d * d_factor / PID_SCALE);
|
||||
// }
|
||||
|
||||
// combine factors
|
||||
int32_t pid_output_intermed = (
|
||||
(
|
||||
|
|
@ -278,11 +204,6 @@ void temp_tick() {
|
|||
) / PID_SCALE
|
||||
);
|
||||
|
||||
// if (debug_flags & DEBUG_PID) {
|
||||
// serial_writestr_P(PSTR(" # O: "));
|
||||
// serwrite_int32(pid_output_intermed);
|
||||
// }
|
||||
|
||||
// rebase and limit factors
|
||||
uint8_t pid_output;
|
||||
if (pid_output_intermed > 255)
|
||||
|
|
@ -292,11 +213,6 @@ void temp_tick() {
|
|||
else
|
||||
pid_output = pid_output_intermed & 0xFF;
|
||||
|
||||
// if (debug_flags & DEBUG_PID) {
|
||||
// serial_writestr_P(PSTR(" = "));
|
||||
// serwrite_uint8(pid_output);
|
||||
// }
|
||||
|
||||
if (debug_flags & DEBUG_PID)
|
||||
sersendf_P(PSTR("T{E:%d, P:%d * %ld = %ld / I:%d * %ld = %ld / D:%d * %ld = %ld # O: %ld = %u}\n"), t_error, heater_p, p_factor, (int32_t) heater_p * p_factor / PID_SCALE, heater_i, i_factor, (int32_t) heater_i * i_factor / PID_SCALE, heater_d, d_factor, (int32_t) heater_d * d_factor / PID_SCALE, pid_output_intermed, pid_output);
|
||||
|
||||
|
|
@ -308,8 +224,5 @@ void temp_tick() {
|
|||
else
|
||||
disable_heater();
|
||||
#endif
|
||||
|
||||
// if (debug_flags & DEBUG_PID)
|
||||
// serial_writestr_P(PSTR("}\n"));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,41 +12,8 @@
|
|||
ISR(TIMER1_COMPA_vect) {
|
||||
WRITE(SCK, 1);
|
||||
|
||||
disableTimerInterrupt();
|
||||
queue_step();
|
||||
|
||||
// do our next step
|
||||
// NOTE: dda_step makes this interrupt interruptible after steps have been sent but before new speed is calculated.
|
||||
if (movebuffer[mb_tail].live) {
|
||||
if (movebuffer[mb_tail].waitfor_temp) {
|
||||
#if STEP_INTERRUPT_INTERRUPTIBLE
|
||||
// this interrupt can now be interruptible
|
||||
// disableTimerInterrupt();
|
||||
sei();
|
||||
#endif
|
||||
|
||||
if (temp_achieved()) {
|
||||
movebuffer[mb_tail].live = 0;
|
||||
serial_writestr_P(PSTR("Temp achieved, next move\n"));
|
||||
}
|
||||
}
|
||||
else {
|
||||
dda_step(&(movebuffer[mb_tail]));
|
||||
}
|
||||
}
|
||||
|
||||
// serial_writechar('!');
|
||||
|
||||
// fall directly into dda_start instead of waiting for another step
|
||||
if (movebuffer[mb_tail].live == 0)
|
||||
next_move();
|
||||
|
||||
#if STEP_INTERRUPT_INTERRUPTIBLE
|
||||
// return from interrupt in a way that prevents this interrupt nesting with itself at high step rates
|
||||
cli();
|
||||
#endif
|
||||
// check queue, if empty we don't need to interrupt again until re-enabled in dda_create
|
||||
if (queue_empty() == 0)
|
||||
enableTimerInterrupt();
|
||||
WRITE(SCK, 0);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue