Skip to content
Snippets Groups Projects
Commit 12f55342 authored by Jake Read's avatar Jake Read
Browse files

add bugfix for step timing misses on wait moves

parent 337e7f09
Branches
No related tags found
No related merge requests found
......@@ -9,3 +9,9 @@ The circuit uses an ATXmega256A3U microcontroller and a TMC2130 step driver to d
The TMC2130 is a popular step driver, and can sink ~ 1.5A of current.
Power is bussed into the board with two M3 Screw Terminals. The board is not polarity protected. Data is delivered on an Automatakit Port, which includes a data line (uart TX / RX) and clock lines (CLKIN and CLKOUT)
## Next Circuit
- on current scaling, get rid of PWM circuit and line out, use internal ref, and choose resistors with math: want 0.5 - 1.2A to be inside of 16-32 selection
- go to 2oz copper bc u fancy, etc
- get rid of this split gnd
\ No newline at end of file
......@@ -37,15 +37,15 @@ UsedLibrary="C:/EAGLE 8.3.2/lbr/ltspice/sym.lbr"
UsedLibrary="D:/Dropbox (Personal)/CBA/doc/libraries_jake/eagle/marekr/borkedlabs-passives.lbr"
[Win_1]
Type="Board Editor"
Number=2
File="atkstepper17.brd"
View="8.16562 -7.32526 61.43 47.2931"
WireWidths=" 0.0762 0.1016 0.127 0.15 0.2 0.254 0.3048 0.4064 0.508 0.6096 1.016 2.54 0.8128 1.27 0.2032 0.1524"
Type="Schematic Editor"
Number=1
File="atkstepper17.sch"
View="171.068 63.2152 445.42 258.351"
WireWidths=" 0.0762 0.1016 0.127 0.15 0.2 0.2032 0.254 0.3048 0.4064 0.508 0.6096 0.8128 1.016 1.27 2.54 0.1524"
PadDiameters=" 0.254 0.3048 0.4064 0.6096 0.8128 1.016 1.27 1.4224 1.6764 1.778 1.9304 2.1844 2.54 3.81 6.4516 0"
PadDrills=" 0.2 0.25 0.3 0.35 0.4 0.45 0.5 0.55 0.65 0.7 0.75 0.8 0.85 0.9 1 0.6"
ViaDiameters=" 0.55 0.6 0.65 0.7 0.75 0.8 0.85 0.9 0.95 1 1.05 1.1 1.15 1.2 1.3 0"
ViaDrills=" 0.2 0.25 0.4 0.45 0.5 0.55 0.6 0.65 0.7 0.75 0.8 0.85 0.9 1 0.35 0.3"
ViaDrills=" 0.2 0.25 0.3 0.4 0.45 0.5 0.55 0.6 0.65 0.7 0.75 0.8 0.85 0.9 1 0.35"
HoleDrills=" 0.2 0.25 0.3 0.4 0.45 0.5 0.55 0.6 0.65 0.7 0.75 0.8 0.85 0.9 1 0.35"
TextSizes=" 0.254 0.3048 0.4064 0.6096 0.8128 1.016 1.27 1.4224 1.6764 1.9304 2.1844 2.54 3.81 5.08 6.4516 1.778"
PolygonSpacings=" 0.254 0.3048 0.4064 0.6096 0.8128 1.016 1.4224 1.6764 1.778 1.9304 2.1844 2.54 3.81 5.08 6.4516 1.27"
......@@ -56,14 +56,14 @@ DimensionExtWidths=" 0.127 0.254 0.1 0.13 0.26 0"
DimensionExtLengths=" 1.27 2.54 1 2 3 0"
DimensionExtOffsets=" 1.27 2.54 1 2 3 0"
SmdSizes=" 0.3048 0.1524 0.4064 0.2032 0.6096 0.3048 0.8128 0.4064 1.016 0.508 1.27 0.6604 1.4224 0.7112 1.6764 0.8128 1.778 0.9144 1.9304 0.9652 2.1844 1.0668 2.54 1.27 3.81 1.9304 5.08 2.54 6.4516 3.2512 1.27 0.635"
WireBend=3
WireBendSet=0
WireBend=0
WireBendSet=31
WireCap=1
MiterStyle=0
PadShape=0
ViaShape=1
PolygonPour=0
PolygonRank=1
PolygonRank=0
PolygonThermals=1
PolygonOrphans=0
TextRatio=8
......@@ -78,18 +78,20 @@ SwapLevel=0
ArcDirection=0
AddLevel=2
PadsSameType=0
Layer=1
Layer=91
Views=" 1: 171.068 63.2152 445.42 258.351"
Sheet="1"
[Win_2]
Type="Schematic Editor"
Number=1
File="atkstepper17.sch"
View="-345.366 -191.587 473.844 391.086"
WireWidths=" 0.0762 0.1016 0.127 0.15 0.2 0.2032 0.254 0.3048 0.4064 0.508 0.6096 0.8128 1.016 1.27 2.54 0.1524"
Type="Board Editor"
Number=2
File="atkstepper17.brd"
View="2.39114 -2.88041 55.6555 51.738"
WireWidths=" 0.0762 0.1016 0.127 0.15 0.2 0.254 0.3048 0.4064 0.508 0.6096 1.016 2.54 0.8128 1.27 0.2032 0.1524"
PadDiameters=" 0.254 0.3048 0.4064 0.6096 0.8128 1.016 1.27 1.4224 1.6764 1.778 1.9304 2.1844 2.54 3.81 6.4516 0"
PadDrills=" 0.2 0.25 0.3 0.35 0.4 0.45 0.5 0.55 0.65 0.7 0.75 0.8 0.85 0.9 1 0.6"
ViaDiameters=" 0.55 0.6 0.65 0.7 0.75 0.8 0.85 0.9 0.95 1 1.05 1.1 1.15 1.2 1.3 0"
ViaDrills=" 0.2 0.25 0.3 0.4 0.45 0.5 0.55 0.6 0.65 0.7 0.75 0.8 0.85 0.9 1 0.35"
ViaDrills=" 0.2 0.25 0.4 0.45 0.5 0.55 0.6 0.65 0.7 0.75 0.8 0.85 0.9 1 0.35 0.3"
HoleDrills=" 0.2 0.25 0.3 0.4 0.45 0.5 0.55 0.6 0.65 0.7 0.75 0.8 0.85 0.9 1 0.35"
TextSizes=" 0.254 0.3048 0.4064 0.6096 0.8128 1.016 1.27 1.4224 1.6764 1.9304 2.1844 2.54 3.81 5.08 6.4516 1.778"
PolygonSpacings=" 0.254 0.3048 0.4064 0.6096 0.8128 1.016 1.4224 1.6764 1.778 1.9304 2.1844 2.54 3.81 5.08 6.4516 1.27"
......@@ -100,14 +102,14 @@ DimensionExtWidths=" 0.127 0.254 0.1 0.13 0.26 0"
DimensionExtLengths=" 1.27 2.54 1 2 3 0"
DimensionExtOffsets=" 1.27 2.54 1 2 3 0"
SmdSizes=" 0.3048 0.1524 0.4064 0.2032 0.6096 0.3048 0.8128 0.4064 1.016 0.508 1.27 0.6604 1.4224 0.7112 1.6764 0.8128 1.778 0.9144 1.9304 0.9652 2.1844 1.0668 2.54 1.27 3.81 1.9304 5.08 2.54 6.4516 3.2512 1.27 0.635"
WireBend=0
WireBendSet=31
WireBend=3
WireBendSet=0
WireCap=1
MiterStyle=0
PadShape=0
ViaShape=1
PolygonPour=0
PolygonRank=0
PolygonRank=1
PolygonThermals=1
PolygonOrphans=0
TextRatio=8
......@@ -122,16 +124,14 @@ SwapLevel=0
ArcDirection=0
AddLevel=2
PadsSameType=0
Layer=91
Views=" 1: -345.366 -191.587 473.844 391.086"
Sheet="1"
Layer=1
[Win_3]
Type="Control Panel"
Number=0
[Desktop]
Screen="3840 1080"
Screen="1920 1080"
Window="Win_1"
Window="Win_2"
Window="Win_3"
......@@ -10,3 +10,4 @@ Two hardware timers run step timing, one fires every time a step is to be taken,
- step-delay on first step causing issues?
- trinamic fiddling... need different sense resistors?
- check missing break; on wait case statement in handler?
\ No newline at end of file
......@@ -37,7 +37,9 @@ void atk_handle_packet(uint8_t *packet, uint8_t length){
break;
case DELIM_KEY_RESET:
// TODO
CCP = CCP_IOREG_gc;
RST.CTRL = RST_SWRST_bm;
i ++;
break;
case DELIM_KEY_TRAPEZOID:
......@@ -45,6 +47,8 @@ void atk_handle_packet(uint8_t *packet, uint8_t length){
if(i + 12 > length){
i ++;
} else {
// to move or not to move
uint8_t is_wait = 0;
// in steps (discrete)
steps = ((int32_t)packet[i+1] << 24) | ((int32_t)packet[i+2] << 16) | ((int32_t)packet[i+3] << 8) | (int32_t)packet[i+4];
// in steps/s
......@@ -57,7 +61,7 @@ void atk_handle_packet(uint8_t *packet, uint8_t length){
uint32_t deccellength = ((int32_t)packet[i+17] << 24) | ((int32_t)packet[i+18] << 16) | (int32_t)(packet[i+19] << 8) | (int32_t)packet[i+20];
// do the business
i += 21;
stepper_new_block(packet, &stepper, steps, entryspeed, accel, accellength, deccellength);
stepper_new_block(packet, &stepper, is_wait, steps, entryspeed, accel, accellength, deccellength);
}
break;
......@@ -65,11 +69,21 @@ void atk_handle_packet(uint8_t *packet, uint8_t length){
if(i + 8 > length){
i ++;
} else {
// to move or not to move
uint8_t is_wait = 1;
// in steps (discrete)
steps = ((int32_t)packet[i+1] << 24) | ((int32_t)packet[i+2] << 16) | ((int32_t)packet[i+3] << 8) | (int32_t)packet[i+4];
// in steps/s
uint32_t speed = ((int32_t)packet[i+5] << 24) | ((int32_t)packet[i+6] << 16) | ((int32_t)packet[i+7] << 8) | (int32_t)packet[i+8];
i += 8;
stepper_new_wait(packet, &stepper, steps, speed);
uint32_t entryspeed = ((int32_t)packet[i+5] << 24) | ((int32_t)packet[i+6] << 16) | ((int32_t)packet[i+7] << 8) | (int32_t)packet[i+8];
// in steps/min/s
uint32_t accel = ((int32_t)packet[i+9] << 24) | ((int32_t)packet[i+10] << 16) | ((int32_t)packet[i+11] << 8) | (int32_t)packet[i+12];
// in steps/min
uint32_t accellength = ((int32_t)packet[i+13] << 24) | ((int32_t)packet[i+14] << 16) | ((int32_t)packet[i+15] << 8) | (int32_t)packet[i+16];
// in steps/min
uint32_t deccellength = ((int32_t)packet[i+17] << 24) | ((int32_t)packet[i+18] << 16) | (int32_t)(packet[i+19] << 8) | (int32_t)packet[i+20];
// do the business
i += 21;
stepper_new_block(packet, &stepper, is_wait, steps, entryspeed, accel, accellength, deccellength);
}
default:
......
......@@ -94,6 +94,10 @@ int main(void)
uarts_init();
atkps_init();
// problem step?
// err. on linking wait and non-wait moves
// do wait / no wait commands: same params, ship from same code
// enable interrupts
sei();
PMIC.CTRL |= PMIC_LOLVLEN_bm | PMIC_MEDLVLEN_bm | PMIC_HILVLEN_bm;
......@@ -119,7 +123,7 @@ int main(void)
atkport_scan(&atkp0, 2);
// just... as fast as we can
tck++;
if(!(fastModulo(tck, 16384))){
if(!(fastModulo(tck, 4096))){
pin_toggle(&stlclk);
}
}
......
......@@ -37,7 +37,7 @@ void stepper_steps(stepper_t *stepper, int32_t steps, uint32_t speed){
// not implemented atm
}
void stepper_new_block(uint8_t *packet, stepper_t *stepper, int32_t steps, uint32_t entryspeed, uint32_t accel, uint32_t accellength, uint32_t deccellength){
void stepper_new_block(uint8_t *packet, stepper_t *stepper, uint8_t is_wait, int32_t steps, uint32_t entryspeed, uint32_t accel, uint32_t accellength, uint32_t deccellength){
// does assignments and adds to queue
// track this address so that we can ack to it when the move is complete
// a sloppy copy, I'm sure
......@@ -45,15 +45,15 @@ void stepper_new_block(uint8_t *packet, stepper_t *stepper, int32_t steps, uint3
stepper->block[stepper->blockhead].packet[i] = packet[i];
}
// a real move
stepper->block[stepper->blockhead].is_nomove = 0;
// a real move, or a wait placeholder?
stepper->block[stepper->blockhead].is_wait = is_wait;
// TODO: should block the execution of this block while we do this, so that we
// have an interrupt safe ringbuffer
// enforce no div/0
(entryspeed < 3) ? entryspeed = 3 : (0); //(0) is NOP: 3 is min steps/s due to timer resolution
(entryspeed > 187500) ? entryspeed = 187500 : (0); // no faster than this pls, else underneat timer resolution
(entryspeed > 187500) ? entryspeed = 187500 : (0); // no faster than this pls, else below timer resolution
// going to have to catch blocks which cause deceleration to 0 during deceleration phases !
stepper->block[stepper->blockhead].entry_speed = entryspeed;
......@@ -81,54 +81,17 @@ void stepper_new_block(uint8_t *packet, stepper_t *stepper, int32_t steps, uint3
// otherwise we're taking for granted that we've set this properly following the last move
if(stepper->blockhead == stepper->blocktail){
uint16_t newper = STEPTICKER_ONE_SECOND / entryspeed;
stepticker_restart();
stepticker_newperiod(newper);
stepticker_reset();
uint16_t accper = STEPTICKER_ONE_SECOND / accel;
accelticker_restart();
accelticker_newperiod(accper);
accelticker_reset();
pin_clear(&stlerr);
}
// increment block head ptr: should catch full queue HERE but not bothering
stepper->blockhead = fastModulo((stepper->blockhead + 1), BLOCKS_QUEUE_SIZE);
}
void stepper_new_wait(uint8_t *packet, stepper_t *stepper, int32_t steps, uint32_t speed){
for(int i = 0; i < packet[0]; i ++){
stepper->block[stepper->blockhead].packet[i] = packet[i];
}
// we have a waiting block, we'll say accel is now = speed for supposed steps
stepper->block[stepper->blockhead].is_nomove = 1;
// still need to check this
(speed < 3) ? speed = 3 : (0);
(speed > 187500) ? speed = 187500 : (0);
// but we're going to wrap everything else in update() to avoid accel etc checks, we're just going to be counting
stepper->block[stepper->blockhead].entry_speed = speed;
stepper->block[stepper->blockhead].position_end = abs(steps);
stepper->block[stepper->blockhead].accel_period = STEPTICKER_ONE_SECOND - 1;
stepper->block[stepper->blockhead].position_accel_to = 0;
stepper->block[stepper->blockhead].position_deccel_from = abs(steps);
// ready set
stepper->block[stepper->blockhead].is_new = 1;
// if there are currently no steps to make, we're not sure about the current step frequency, we'll set the period
// otherwise we're taking for granted that we've set this properly following the last move
if(stepper->blockhead == stepper->blocktail){
pin_clear(&stlerr);
// could we just call stepper_update now?
uint16_t newper = STEPTICKER_ONE_SECOND / speed;
stepticker_newperiod(newper);
stepticker_reset();
uint16_t accper = STEPTICKER_ONE_SECOND - 1; // gets 16-bit truncated
accelticker_newperiod(accper);
accelticker_reset();
pin_clear(&stlerr);
}
stepper->blockhead = fastModulo((stepper->blockhead + 1), BLOCKS_QUEUE_SIZE);
}
void stepper_updatesteps(stepper_t *stepper){
if(stepper->blockhead == stepper->blocktail){
// no steps to make, ringbuffer is empty
......@@ -139,12 +102,12 @@ void stepper_updatesteps(stepper_t *stepper){
// if we're just starting this block, set the speed
stepper->speed = stepper->block[stepper->blocktail].entry_speed;
stepper->speed_period = STEPTICKER_ONE_SECOND / stepper->speed;
stepticker_restart(); // restart sets cc register to zero, so we do this first
stepticker_newperiod(stepper->speed_period);
stepticker_reset();
// and set the accel ticker
accelticker_restart();
accelticker_newperiod(stepper->block[stepper->blocktail].accel_period);
accelticker_reset();
// and set the dir
if(stepper->block[stepper->blocktail].dir > 0){
......@@ -158,7 +121,7 @@ void stepper_updatesteps(stepper_t *stepper){
}
// if there's steps to make, and this timer is firing, it's time to step!
if(!stepper->block[stepper->blocktail].is_nomove){
if(!stepper->block[stepper->blocktail].is_wait){
pin_toggle(stepper->step_pin);
}
......@@ -181,7 +144,7 @@ void stepper_updatesteps(stepper_t *stepper){
// apa_return_packet(stepper->block[stepper->blocktail].packet, 25);
uint8_t reply[12];
int8_t replyLength;
if(stepper->block[stepper->blocktail].is_nomove){
if(stepper->block[stepper->blocktail].is_wait){
reply[0] = DELIM_KEY_WAIT;
reply[1] = 12;
replyLength = 2;
......@@ -233,7 +196,7 @@ void stepticker_newperiod(uint16_t per){
TCC0.PERBUFH = (uint8_t) (per >> 8);
}
void stepticker_reset(void){
void stepticker_restart(void){
TCC0.CTRLFSET = TC_CMD_RESTART_gc;
}
......@@ -242,6 +205,6 @@ void accelticker_newperiod(uint16_t per){
TCC1.PERBUFH = (uint8_t) (per >> 8);
}
void accelticker_reset(void){
void accelticker_restart(void){
TCC1.CTRLFSET = TC_CMD_RESTART_gc;
}
\ No newline at end of file
......@@ -24,7 +24,7 @@ typedef struct {
// tracking
uint8_t is_new;
uint8_t is_nomove;
uint8_t is_wait;
// for what you do
uint8_t dir; // 0 or 1
......@@ -70,9 +70,7 @@ void stepper_reset(stepper_t *stepper);
void stepper_steps(stepper_t *stepper, int32_t steps, uint32_t speed);
// steps discrete, mm/min, mm/min/s (mm/s better but we want more discrete resolution)
void stepper_new_block(uint8_t *packet, stepper_t *stepper, int32_t steps, uint32_t entryspeed, uint32_t accel, uint32_t accellength, uint32_t deccellength);
void stepper_new_wait(uint8_t *packet, stepper_t *stepper, int32_t steps, uint32_t speed);
void stepper_new_block(uint8_t *packet, stepper_t *stepper, uint8_t is_wait, int32_t steps, uint32_t entryspeed, uint32_t accel, uint32_t accellength, uint32_t deccellength);
void stepper_updatesteps(stepper_t *stepper);
......@@ -80,11 +78,11 @@ void stepper_updateaccel(stepper_t *stepper);
void stepticker_newperiod(uint16_t per);
void stepticker_reset(void);
void stepticker_restart(void);
void accelticker_newperiod(uint16_t per);
void accelticker_reset(void);
void accelticker_restart(void);
/*
step to-do
......
......@@ -41,7 +41,7 @@ void tmc2130_start(tmc2130_t *tmc){
tmc2130_write(tmc, writeGConf, gConf);
// this writes to IHOLD_IRUN register
tmc2130_setCurrents(tmc, 16, 20);
tmc2130_setCurrents(tmc, 12, 18);
// Write CHOPCONF
uint8_t writeChopConf = 0x6C | 0b10000000;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment