setting up new branch

This commit is contained in:
Michael Moon 2010-08-10 14:24:01 +10:00
parent bce08901d8
commit 994fa1b4c7
14 changed files with 240 additions and 219 deletions

86
mendel/calc.pl Normal file
View File

@ -0,0 +1,86 @@
#!/usr/bin/perl
my ($ss, $es, $f, $dn, $dt, $a, $n0, $nn, $np, $c0, $cn, $cp, $n, $c, $t, $tp, $v, $vp);
my ($c0_exact, $cn_exact, $v_exact, $t_exact, $vp_exact, $tp_exact);
my ($n_pre);
$ss = 300;
$es = 400;
$f = 16000000;
$dn = 50000;
$ssq = $ss * $ss;
$esq = $es * $es;
$dsq = ($esq - $ssq);
# $a = $dsq / ($dn << 1);
#$n0 = int(($ss * $ss) / (2 * $a));
#$nn = int(($es * $es) / (2 * $a));
# $n0 = int($ssq * $dn / $dsq);
# $nn = int($esq * $dn / $dsq);
$c0 = int($f / $ss);
# $c0_exact = $f * sqrt(2 / abs($a));
# $dt = ($es - $ss) / $a;
# printf "A:\t%d-%d/%g: %d\n", $es, $ss, $dt, $a;
# printf "N:\t%d-%d %d:%d\n", $n0, $nn, $nn - $n0, $dn, $a;
# printf "C:\t%d\t%g\n", $c0, $c0_exact * (sqrt(abs($n0) + 1) - sqrt(abs($n0)));
# $n = $np = $n0;
$c = $cp = int($f / $ss);
$end_c = int($f / $es);
$t = $tp = $t_exact = 0;
# $v = $vp = $ss;
$n_pre = int(4 * $ssq * $dn / $dsq) | 1;
# $cn_exact = $c0_exact * (sqrt(abs($n0) + 1) - sqrt(abs($n0)));
# $v_exact = $vp_exact = $f / $cn_exact;
printf "\tt:i\t\t\tdt\tn\tV\t\ta\n";
for (0..$dn) {
# approximation
# $c = int($c * 1000) / 1000;
printf "Approx:\t%8.6f:%i\t%10d\t%d\t%12.3f\t%12.3f\n", $t, $_, $c, ($n_pre / 4) - 1, $f / $c, ($t > 0)?($v - $ss) / ($t):0;
# $tp = $t;
# $cp = $c;
# $np = $n;
# $vp = $v;
$t += $c / $f;
if (
(($n_pre > 0) && ($c > $end_c)) ||
(($n_pre < 0) && ($c < $end_c))
) {
$c = int($c - ((2 * $c) / $n_pre));
$n_pre += 4;
}
# $v = $f / $c;
# exact
# printf "Exact:\t%8.6f:%i\t%10.3f\t%i\t%12.3f\t%12.3f\n\n", $t_exact, $_, $cn_exact, $n, $v_exact, ($t_exact > 0)?($v_exact - $ss) / ($t_exact):0
# if ($_ % 10 == 0);
#
# $vp_exact = $v_exact;
# $tp_exact = $t_exact;
#
# $t_exact += $cn_exact / $f;
# $cn_exact = $c0_exact * (sqrt(abs($n) + 1) - sqrt(abs($n)));
# $v_exact = $f / $cn_exact;
# loop increment
# if ($nn > $n0) {
# $n++;
$n_pre += 4;
# }
# else {
# $n--;
# $n_pre -= 4;
# }
}
printf "dt:%8.3f\tv:%8.3f\n", int(($f / $es) + 0.5), $f / int(($f / $es) + 0.5);

View File

@ -126,7 +126,7 @@ void dda_create(DDA *dda, TARGET *target) {
// initialise DDA to a known state // initialise DDA to a known state
dda->live = 0; dda->live = 0;
dda->total_steps = 0; // dda->total_steps = 0;
dda->waitfor_temp = 0; dda->waitfor_temp = 0;
if (debug_flags & DEBUG_DDA) if (debug_flags & DEBUG_DDA)
@ -162,7 +162,7 @@ void dda_create(DDA *dda, TARGET *target) {
serial_writestr_P(PSTR("] [")); serial_writestr_P(PSTR("] ["));
} }
if (dda->x_delta > dda->total_steps) // if (dda->x_delta > dda->total_steps)
dda->total_steps = dda->x_delta; dda->total_steps = dda->x_delta;
if (dda->y_delta > dda->total_steps) if (dda->y_delta > dda->total_steps)
dda->total_steps = dda->y_delta; dda->total_steps = dda->y_delta;
@ -449,7 +449,7 @@ void dda_step(DDA *dda) {
// else we are already at target speed // else we are already at target speed
} }
if (step_option & DID_STEP) { if (step_option) {
// we stepped, reset timeout // we stepped, reset timeout
steptimeout = 0; steptimeout = 0;

View File

@ -1,10 +1,12 @@
#include "dda_queue.h" #include "dda_queue.h"
#include <string.h> #include <string.h>
#include <avr/interrupt.h>
#include "timer.h" #include "timer.h"
#include "serial.h" #include "serial.h"
#include "sermsg.h" #include "sermsg.h"
#include "temp.h"
uint8_t mb_head = 0; uint8_t mb_head = 0;
uint8_t mb_tail = 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; 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) { 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 // 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()) while (queue_full())
@ -47,10 +84,11 @@ void enqueue_temp_wait() {
while (queue_full()) while (queue_full())
delay(WAITING_DELAY); delay(WAITING_DELAY);
uint8_t h = mb_head; uint8_t h = mb_head + 1;
h++; // h++;
if (h == MOVEBUFFER_SIZE) // if (h == MOVEBUFFER_SIZE)
h = 0; // h = 0;
h &= (MOVEBUFFER_SIZE - 1);
// wait for temp flag // wait for temp flag
movebuffer[h].waitfor_temp = 1; movebuffer[h].waitfor_temp = 1;
@ -76,16 +114,13 @@ void enqueue_temp_wait() {
} }
void next_move() { void next_move() {
if (queue_empty()) { if (queue_empty() == 0) {
// memcpy(&startpoint, &current_position, sizeof(TARGET));
startpoint.E = current_position.E = 0;
}
else {
// next item // next item
uint8_t t = mb_tail; uint8_t t = mb_tail + 1;
t++; // t++;
if (t == MOVEBUFFER_SIZE) // if (t == MOVEBUFFER_SIZE)
t = 0; // t = 0;
t &= (MOVEBUFFER_SIZE - 1);
dda_start(&movebuffer[t]); dda_start(&movebuffer[t]);
mb_tail = t; mb_tail = t;
} }

View File

@ -20,6 +20,9 @@ extern DDA movebuffer[MOVEBUFFER_SIZE];
uint8_t queue_full(void); uint8_t queue_full(void);
uint8_t queue_empty(void); uint8_t queue_empty(void);
// take one step
void queue_step(void);
// add a new target to the queue // add a new target to the queue
void enqueue(TARGET *t); void enqueue(TARGET *t);

97
mendel/func.sh Normal file → Executable file
View File

@ -98,11 +98,15 @@ mendel_reset() {
mendel_setup mendel_setup
} }
mendel_talk() {
( cat <&3 & cat >&3; kill $! ; ) 3<>/dev/arduino
}
mendel_cmd() { mendel_cmd() {
( (
IFS=$' \t\n' local IFS=$' \t\n'
RSC=0 local RSC=0
cmd="$*" local cmd="$*"
echo "$cmd" >&3; echo "$cmd" >&3;
while [ "$REPLY" != "OK" ] while [ "$REPLY" != "OK" ]
do do
@ -122,28 +126,27 @@ mendel_cmd() {
echo "Too many retries: aborting" >&2 echo "Too many retries: aborting" >&2
fi fi
fi fi
LN=$(( $LN + 1 ))
done done
) 3<>/dev/arduino; ) 3<>/dev/arduino;
} }
mendel_cmd_hr() { mendel_cmd_hr() {
( (
IFS=$' \t\n' local IFS=$' \t\n'
cmd="$*" local cmd="$*"
RSC=0 local RSC=0
echo "$cmd" >&3 echo "$cmd" >&3
echo "> $cmd" echo "S> $cmd"
while [ "$REPLY" != "OK" ] while [ "$REPLY" != "OK" ]
do do
read -u 3 read -u 3
echo "< $REPLY" echo "<R $REPLY"
if [[ "$REPLY" =~ ^RESEND ]] if [[ "$REPLY" =~ ^RESEND ]]
then then
if [ "$RSC" -le 3 ] if [ "$RSC" -le 3 ]
then then
echo "$cmd" >&3 echo "$cmd" >&3
echo "> $cmd" echo "S> $cmd"
RSC=$(( $RSC + 1)) RSC=$(( $RSC + 1))
else else
REPLY="OK" REPLY="OK"
@ -158,7 +161,7 @@ mendel_print() {
( (
for F in "$@" for F in "$@"
do do
IFS=$'\n' local IFS=$'\n'
for L in $(< $F) for L in $(< $F)
do do
mendel_cmd_hr "$L" mendel_cmd_hr "$L"
@ -169,14 +172,14 @@ mendel_print() {
mendel_readsym() { mendel_readsym() {
( (
IFS=$' \t\n' local IFS=$' \t\n'
sym=$1 local sym=$1
if [ -n "$sym" ] if [ -n "$sym" ]
then then
if [[ "$sym" =~ ^(0?x?[0-9A-Fa-f]+)(:([0-9]+))?$ ]] if [[ "$sym" =~ ^(0?x?[0-9A-Fa-f]+)(:([0-9]+))?$ ]]
then then
ADDR=$(( ${BASH_REMATCH[1]} )) local ADDR=$(( ${BASH_REMATCH[1]} ))
SIZE=$(( ${BASH_REMATCH[3]} )) local SIZE=$(( ${BASH_REMATCH[3]} ))
if [ "$SIZE" -le 1 ] if [ "$SIZE" -le 1 ]
then then
SIZE=1 SIZE=1
@ -186,8 +189,8 @@ mendel_readsym() {
make mendel.sym &>/dev/null make mendel.sym &>/dev/null
if egrep -q '\b'$sym'\b' mendel.sym if egrep -q '\b'$sym'\b' mendel.sym
then then
ADDR=$(( $(egrep '\b'$sym'\b' mendel.sym | cut -d\ -f1) )) local ADDR=$(( $(egrep '\b'$sym'\b' mendel.sym | cut -d\ -f1) ))
SIZE=$(egrep '\b'$sym'\b' mendel.sym | cut -d+ -f2) local SIZE=$(egrep '\b'$sym'\b' mendel.sym | cut -d+ -f2)
mendel_cmd "M253 S$ADDR P$SIZE" mendel_cmd "M253 S$ADDR P$SIZE"
else else
echo "unknown symbol: $sym" echo "unknown symbol: $sym"
@ -200,44 +203,44 @@ mendel_readsym() {
} }
mendel_readsym_uint8() { mendel_readsym_uint8() {
sym=$1 local sym=$1
val=$(mendel_readsym $sym) local val=$(mendel_readsym $sym)
perl -e 'printf "%u\n", eval "0x".$ARGV[0]' $val perl -e 'printf "%u\n", eval "0x".$ARGV[0]' $val
} }
mendel_readsym_int8() { mendel_readsym_int8() {
sym=$1 local sym=$1
val=$(mendel_readsym $sym) local val=$(mendel_readsym $sym)
perl -e 'printf "%d\n", ((eval "0x".$ARGV[0]) & 0x7F) - (((eval "0x".$ARGV[0]) & 0x80)?0x80:0)' $val perl -e 'printf "%d\n", ((eval "0x".$ARGV[0]) & 0x7F) - (((eval "0x".$ARGV[0]) & 0x80)?0x80:0)' $val
} }
mendel_readsym_uint16() { mendel_readsym_uint16() {
sym=$1 local sym=$1
val=$(mendel_readsym $sym) local val=$(mendel_readsym $sym)
perl -e '$ARGV[0] =~ m#(..)(..)# && printf "%u\n", eval "0x$2$1"' $val perl -e '$ARGV[0] =~ m#(..)(..)# && printf "%u\n", eval "0x$2$1"' $val
} }
mendel_readsym_int16() { mendel_readsym_int16() {
sym=$1 local sym=$1
val=$(mendel_readsym $sym) 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 perl -e '$ARGV[0] =~ m#(..)(..)# && printf "%d\n", ((eval "0x$2$1") & 0x7FFF) - (((eval "0x$2$1") & 0x8000)?0x8000:0)' $val
} }
mendel_readsym_uint32() { mendel_readsym_uint32() {
sym=$1 local sym=$1
val=$(mendel_readsym $sym) local val=$(mendel_readsym $sym)
perl -e '$ARGV[0] =~ m#(..)(..)(..)(..)# && printf "%u\n", eval "0x$4$3$2$1"' $val perl -e '$ARGV[0] =~ m#(..)(..)(..)(..)# && printf "%u\n", eval "0x$4$3$2$1"' $val
} }
mendel_readsym_int32() { mendel_readsym_int32() {
sym=$1 local sym=$1
val=$(mendel_readsym $sym) local val=$(mendel_readsym $sym)
perl -e '$ARGV[0] =~ m#(..)(..)(..)(..)# && printf "%d\n", eval "0x$4$3$2$1"' $val perl -e '$ARGV[0] =~ m#(..)(..)(..)(..)# && printf "%d\n", eval "0x$4$3$2$1"' $val
} }
mendel_readsym_target() { mendel_readsym_target() {
sym=$1 local sym=$1
val=$(mendel_readsym "$sym") local val=$(mendel_readsym "$sym")
if [ -n "$val" ] if [ -n "$val" ]
then 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" 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() { mendel_readsym_mb() {
val=$(mendel_readsym movebuffer) local val=$(mendel_readsym movebuffer)
mbhead=$(mendel_readsym mb_head) local mbhead=$(mendel_readsym mb_head)
mbtail=$(mendel_readsym mb_tail) local mbtail=$(mendel_readsym mb_tail)
perl - <<'ENDPERL' -- $val $mbhead $mbtail perl - <<'ENDPERL' -- $val $mbhead $mbtail
$i = -1; $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/; @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() { mendel_heater_pid() {
P=$(mendel_readsym_int16 heater_p) local P=$(mendel_readsym_int16 heater_p)
I=$(mendel_readsym_int16 heater_i) local I=$(mendel_readsym_int16 heater_i)
D=$(mendel_readsym_int16 heater_d) local D=$(mendel_readsym_int16 heater_d)
PF=$(mendel_readsym_int32 p_factor) local PF=$(mendel_readsym_int32 p_factor)
IF=$(mendel_readsym_int32 i_factor) local IF=$(mendel_readsym_int32 i_factor)
DF=$(mendel_readsym_int32 d_factor) local DF=$(mendel_readsym_int32 d_factor)
O=$(mendel_readsym_uint8 0x27) local O=$(mendel_readsym_uint8 0x27)
T=$(mendel_cmd M105 | cut -d\ -f2 | cut -d/ -f1) local T=$(mendel_cmd M105 | cut -d\ -f2 | cut -d/ -f1)
echo "P=$P pf=$PF r="$(($P * $PF)) echo "P=$P pf=$PF r="$(($P * $PF))
echo "I=$I if=$IF r="$(($I * $IF)) 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 "R="$(( $(( $(( $(($P * $PF)) + $(($I * $IF)) + $(($D * $DF)) )) / 1024 )) + 128 ))
echo "O=$O T=$T" 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

View File

@ -523,7 +523,7 @@ void process_gcode_command(GCODE_COMMAND *gcmd) {
// backup feedrate, move E very quickly then restore feedrate // backup feedrate, move E very quickly then restore feedrate
uint32_t f = startpoint.F; uint32_t f = startpoint.F;
startpoint.F = FEEDRATE_FAST_E; startpoint.F = FEEDRATE_FAST_E;
SpecialMoveE(startpoint.E + E_STARTSTOP_STEPS, FEEDRATE_FAST_E); SpecialMoveE(E_STARTSTOP_STEPS, FEEDRATE_FAST_E);
startpoint.F = f; startpoint.F = f;
} while (0); } while (0);
break; break;
@ -536,7 +536,7 @@ void process_gcode_command(GCODE_COMMAND *gcmd) {
// backup feedrate, move E very quickly then restore feedrate // backup feedrate, move E very quickly then restore feedrate
uint32_t f = startpoint.F; uint32_t f = startpoint.F;
startpoint.F = FEEDRATE_FAST_E; startpoint.F = FEEDRATE_FAST_E;
SpecialMoveE(startpoint.E - E_STARTSTOP_STEPS, FEEDRATE_FAST_E); SpecialMoveE(-E_STARTSTOP_STEPS, FEEDRATE_FAST_E);
startpoint.F = f; startpoint.F = f;
} while (0); } while (0);
break; break;

View File

@ -64,7 +64,7 @@
// does this refer to filament or extrudate? extrudate depends on XY distance vs E distance.. hm lets go with filament // 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_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 // 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)) #define STEPS_PER_IN_X ((uint32_t) ((25.4 * X_STEPS_PER_REV / X_COG_CIRCUMFERENCE) + 0.5))

View File

@ -117,31 +117,9 @@ void clock_250ms(void) {
ifclock(CLOCK_FLAG_1S) { ifclock(CLOCK_FLAG_1S) {
if (debug_flags & DEBUG_POSITION) { if (debug_flags & DEBUG_POSITION) {
// current 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); 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 // 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); 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 // Queue

1
mendel/mendel_cmd Symbolic link
View File

@ -0,0 +1 @@
func.sh

26
mendel/sender.sh Executable file
View File

@ -0,0 +1,26 @@
#!/bin/bash
DEV=/dev/arduino
BAUD=115200
waitfor avrdude
stty $BAUD raw ignbrk -hup -echo ixon < $DEV
(
read -t 0.1; RV=$?
while [ $RV -eq 0 ] || [ $RV -ge 128 ]
do
if [ $RV -eq 0 ]
then
echo "> $REPLY"
echo "$REPLY" >&3
fi
while [ "$REPLY" != "OK" ]
do
read -s -u 3
echo "< $REPLY"
done
read -t 1
$RV = $?
done
) 3<>$DEV

View File

@ -152,9 +152,10 @@ void serial_writeblock(void *data, int datalen)
void serial_writestr(uint8_t *data) 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 // 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); serial_writechar(r);
} }

View File

@ -13,9 +13,8 @@ void sersendf(char *format, ...) {
va_start(args, format); va_start(args, format);
uint16_t i = 0; uint16_t i = 0;
uint8_t c = 1, j = 0; uint8_t c, j = 0;
for (; c != 0; i++) { while ((c = format[i++])) {
c = format[i];
if (j) { if (j) {
switch(c) { switch(c) {
case 'l': case 'l':
@ -74,8 +73,7 @@ void sersendf_P(PGM_P format, ...) {
uint16_t i = 0; uint16_t i = 0;
uint8_t c = 1, j = 0; uint8_t c = 1, j = 0;
for (; c != 0; i++) { while ((c = pgm_read_byte(&format[i++]))) {
c = pgm_read_byte(&format[i]);
if (j) { if (j) {
switch(c) { switch(c) {
case 's': case 's':

View File

@ -13,7 +13,7 @@
case 105: case 105:
uint16_t t = temp_get(); 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" #include "temp.h"
@ -37,10 +37,10 @@ int16_t heater_p = 0;
int16_t heater_i = 0; int16_t heater_i = 0;
int16_t heater_d = 0; int16_t heater_d = 0;
#define DEFAULT_P 4096 #define DEFAULT_P 8192
#define DEFAULT_I 256 #define DEFAULT_I 512
#define DEFAULT_D -14336 #define DEFAULT_D -24576
#define DEFAULT_I_LIMIT 768 #define DEFAULT_I_LIMIT 384
int32_t p_factor = 0; int32_t p_factor = 0;
int32_t i_factor = 0; int32_t i_factor = 0;
int32_t d_factor = 0; int32_t d_factor = 0;
@ -151,66 +151,22 @@ uint8_t temp_achieved() {
} }
void temp_print() { void temp_print() {
// serial_writestr_P(PSTR("T: "));
if (temp_flags & TEMP_FLAG_TCOPEN) { if (temp_flags & TEMP_FLAG_TCOPEN) {
serial_writestr_P(PSTR("T: no thermocouple!\n")); serial_writestr_P(PSTR("T: no thermocouple!\n"));
} }
else { 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; uint8_t c = 0, t = 0;
if (current_temp & 3) c = (current_temp & 3) * 25;
c = 5; t = (target_temp & 3) * 25;
if ((current_temp & 3) == 1) sersendf_P(PSTR("T: %u.%u/%u.%u :%u\n"), current_temp >> 2, c, target_temp >> 2, t, temp_residency);
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);
} }
// serial_writechar('\n');
} }
void temp_tick() { void temp_tick() {
if (target_temp) { if (target_temp) {
steptimeout = 0; steptimeout = 0;
// uint16_t last_temp = current_temp;
temp_read(); temp_read();
temp_history[th_p++] = current_temp; temp_history[th_p++] = current_temp;
@ -221,16 +177,8 @@ void temp_tick() {
else if (temp_residency < TEMP_RESIDENCY_TIME) else if (temp_residency < TEMP_RESIDENCY_TIME)
temp_residency++; temp_residency++;
// if (debug_flags & DEBUG_PID)
// serial_writestr_P(PSTR("T{"));
int16_t t_error = target_temp - current_temp; int16_t t_error = target_temp - current_temp;
// if (debug_flags & DEBUG_PID) {
// serial_writestr_P(PSTR("E:"));
// serwrite_int16(t_error);
// }
// PID stuff // PID stuff
// proportional // proportional
heater_p = t_error; heater_p = t_error;
@ -245,30 +193,8 @@ void temp_tick() {
// derivative // derivative
// note: D follows temp rather than error so there's no large derivative when the target changes // 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]; 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 // combine factors
int32_t pid_output_intermed = ( int32_t pid_output_intermed = (
( (
@ -278,11 +204,6 @@ void temp_tick() {
) / PID_SCALE ) / PID_SCALE
); );
// if (debug_flags & DEBUG_PID) {
// serial_writestr_P(PSTR(" # O: "));
// serwrite_int32(pid_output_intermed);
// }
// rebase and limit factors // rebase and limit factors
uint8_t pid_output; uint8_t pid_output;
if (pid_output_intermed > 255) if (pid_output_intermed > 255)
@ -292,11 +213,6 @@ void temp_tick() {
else else
pid_output = pid_output_intermed & 0xFF; pid_output = pid_output_intermed & 0xFF;
// if (debug_flags & DEBUG_PID) {
// serial_writestr_P(PSTR(" = "));
// serwrite_uint8(pid_output);
// }
if (debug_flags & DEBUG_PID) 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); 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 else
disable_heater(); disable_heater();
#endif #endif
// if (debug_flags & DEBUG_PID)
// serial_writestr_P(PSTR("}\n"));
} }
} }

View File

@ -12,41 +12,8 @@
ISR(TIMER1_COMPA_vect) { ISR(TIMER1_COMPA_vect) {
WRITE(SCK, 1); 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); WRITE(SCK, 0);
} }