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

atsamd51 at 120mhz

parent 756276fd
Branches
Tags
No related merge requests found
......@@ -22,6 +22,8 @@ This stepdriver is part of another project on networked machine control (I am ca
[Mechaduino](http://tropical-labs.com/index.php/mechaduino) is a really excellent project that Sam and I are fond of. They use an AS5047 encoder to resolve more-steps-than-should-be-possible-with-a-stepper. In combining this with the fancy drive technology in the TMC chip, we can basically arrive at a low cost closed-loop motion control solution, so that's pretty rad. I'm familiar with this chip and use it in my brushless motor controller, so it's feeling quite likely I will implement it here as well. My one quam is the added complexity, etc. I could mount it right in dead-center of the board, use side-mount leds for indication and then have a nice clean backplate... (I am trying to avoid a two sided board). I had also thought I would perhaps have the possibility for an external encoder-only board... but, again, less complexity the better. Backplate mounter. OK.
Also [smartstepper](https://hackaday.io/project/18468-smart-stepper)
## Form Factor
A-la [Mechaduino](http://tropical-labs.com/index.php/mechaduino) and many other solutions, this beckons to be mounted on the arse-side of the motor it is responsible for... that way, it looks neat, and we can just glue a magnet on the back of the shaft to read position with our encoder. In the future, I really want to also control NEMA8 and NEMA11 motors (because they're cute as heck) but for the immediate future NEMA17s are OK and I can always use a laser-cut adapter to mount the same board onto a NEMA23. OK, again, simplicity wins, we go for the NEMA17 board, but spec drivers to NEMA23 size.
......
......@@ -9,8 +9,13 @@ AutoSaveProject=1
UsedLibraryUrn="urn:adsk.eagle:library:217"
UsedLibraryUrn="urn:adsk.eagle:library:325"
UsedLibraryUrn="urn:adsk.eagle:library:371"
UsedLibrary="D:/Dropbox (Personal)/CBA/doc/libraries/eagle/connector.lbr"
UsedLibrary="D:/Dropbox (Personal)/CBA/doc/libraries/eagle/fab.lbr"
UsedLibrary="D:/Dropbox (Personal)/CBA/doc/libraries/eagle/lights.lbr"
UsedLibrary="D:/Dropbox (Personal)/CBA/doc/libraries/eagle/microcontrollers.lbr"
UsedLibrary="D:/Dropbox (Personal)/CBA/doc/libraries/eagle/motors.lbr"
UsedLibrary="D:/Dropbox (Personal)/CBA/doc/libraries/eagle/power.lbr"
UsedLibrary="D:/Dropbox (Personal)/CBA/doc/libraries/eagle/sensor.lbr"
UsedLibrary="D:/Dropbox (Personal)/CBA/doc/libraries_jake/eagle/sparkfun/SparkFun-Connectors.lbr"
UsedLibrary="D:/Dropbox (Personal)/CBA/doc/libraries_jake/eagle/marekr/borkedlabs-passives.lbr"
UsedLibrary="D:/Dropbox (Personal)/CBA/doc/libraries_jake/eagle/jake/tag-connect-2050.lbr"
......@@ -32,12 +37,58 @@ UsedLibrary="C:/EAGLE 8.3.2/lbr/ltspice/rload.lbr"
UsedLibrary="C:/EAGLE 8.3.2/lbr/ltspice/sym.lbr"
[Win_1]
Type="Library Editor"
Loc="0 0 1919 1039"
State=1
Number=3
File="D:/Dropbox (Personal)/CBA/doc/libraries_jake/eagle/sparkfun/SparkFun-Connectors.lbr"
View="-2.33078 -5.6861 6.58531 3.73563"
WireWidths=" 0.0762 0.1016 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 0.127"
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"
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.4224 1.6764 1.9304 2.1844 2.54 3.81 5.08 6.4516 1.778 1.27"
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"
PolygonIsolates=" 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"
MiterRadiuss=" 0.254 0.3175 0.635 1.27 2.54 1 2 2.5 5 7.5 10 0"
DimensionWidths=" 0 0.127 0.254 0.1 0.26 0.13"
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.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 5 0.76"
WireBend=5
WireBendSet=0
WireCap=1
MiterStyle=0
PadShape=0
ViaShape=1
PolygonPour=0
PolygonRank=0
PolygonThermals=1
PolygonOrphans=0
TextRatio=8
DimensionUnit=1
DimensionPrecision=2
DimensionShowUnit=0
PinDirection=3
PinFunction=0
PinLength=2
PinVisible=3
SwapLevel=0
ArcDirection=0
AddLevel=2
PadsSameType=0
Layer=51
[Win_2]
Type="Schematic Editor"
Loc="0 0 1199 639"
State=0
Loc="0 0 1919 1039"
State=1
Number=1
File="mkstepper.sch"
View="-58.884 -6.96508 330.664 324.401"
View="25.2163 35.6215 155.675 146.596"
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"
......@@ -76,23 +127,23 @@ ArcDirection=0
AddLevel=2
PadsSameType=0
Layer=91
Views=" 1: -58.884 -6.96508 330.664 324.401"
Views=" 1: 25.2163 35.6215 155.675 146.596"
Sheet="1"
[Win_2]
[Win_3]
Type="Board Editor"
Loc="0 0 1919 1016"
State=1
Number=2
File="mkstepper.brd"
View="-9.65867 9.69013 85.7374 37.7009"
WireWidths=" 0.0762 0.1016 0.127 0.4064 0.15 0.2032 0.508 1.016 0.254 0.2 2.54 0.1524 1.27 0.8128 0.6096 0.3048"
PadDiameters=" 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 0.55 0.45 0.425"
PadDrills=" 0.2 0.25 0.4 0.45 0.5 0.55 0.65 0.7 0.75 0.8 0.85 0.9 1 0.6 0.35 0.3"
ViaDiameters=" 0.7 0.75 0.8 0.85 0.9 0.95 1 1.05 1.1 1.15 1.2 1.3 0 0.55 0.45 0.425"
ViaDrills=" 0.45 0.5 0.55 0.6 0.65 0.7 0.75 0.8 0.85 0.9 1 0.2 0.25 0.35 0.3 0.4"
HoleDrills=" 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"
TextSizes=" 0.254 0.3048 0.4064 1.016 1.4224 1.6764 1.9304 2.1844 2.54 3.81 5.08 6.4516 1.778 0.8128 1.27 0.6096"
View="1.28827 14.4541 62.3512 59.9496"
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.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"
PolygonIsolates=" 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"
MiterRadiuss=" 0.254 0.3175 0.635 1.27 2.54 1 2 2.5 5 7.5 10 0"
......@@ -101,7 +152,7 @@ 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=2
WireBend=1
WireBendSet=0
WireCap=1
MiterStyle=0
......@@ -120,19 +171,20 @@ PinFunction=0
PinLength=2
PinVisible=3
SwapLevel=0
ArcDirection=1
ArcDirection=0
AddLevel=2
PadsSameType=0
Layer=16
Layer=1
[Win_3]
[Win_4]
Type="Control Panel"
Loc="0 0 1919 1016"
State=1
Number=0
[Desktop]
Screen="6000 2160"
Screen="1920 1080"
Window="Win_1"
Window="Win_2"
Window="Win_3"
Window="Win_4"
File deleted
File added
This diff is collapsed.
This diff is collapsed.
......@@ -526,3 +526,10 @@ void SysTick_Handler(void){
```
OK, this is done now - both timers, and a step to position @ speed command. Next is networks for this board.
## Network Code
Packet Handling and Passing, oh my!
I'll take most of this from the code I've already written for the Router.
No preview for this file type
......@@ -27,6 +27,11 @@ ringbuffer_t up2_rbtx;
uartport_t up1;
uartport_t up2;
// array of ptrs to uartports
// inits in main.c
#define NUM_UPS 2
uartport_t *ups[NUM_UPS];
spiport_t spi_tmc;
pin_t step_pin;
......
......@@ -52,28 +52,44 @@ void clock_init(void){
// for 120mhz do https://github.com/adafruit/ArduinoCore-samd/blob/samd51/cores/arduino/startup.c
// something?
NVMCTRL->CTRLA.reg |= NVMCTRL_CTRLA_RWS(0);
// reset
GCLK->CTRLA.bit.SWRST = 1;
while(GCLK->SYNCBUSY.reg & GCLK_SYNCBUSY_SWRST);
// Setup internal reference to gclk gen 3
GCLK->GENCTRL[3].reg = GCLK_GENCTRL_SRC(GCLK_GENCTRL_SRC_OSCULP32K) | GCLK_GENCTRL_GENEN;
while(GCLK->SYNCBUSY.reg & GCLK_SYNCBUSY_GENCTRL3);
GCLK->GENCTRL[0].reg = GCLK_GENCTRL_SRC(GCLK_GENCTRL_SRC_OSCULP32K) | GCLK_GENCTRL_GENEN;
while(GCLK->SYNCBUSY.reg & GCLK_SYNCBUSY_GENCTRL0);
// enable DFLL48M clock
OSCCTRL->DFLLCTRLA.reg = 0;
OSCCTRL->DFLLMUL.reg = OSCCTRL_DFLLMUL_CSTEP(0x1) | OSCCTRL_DFLLMUL_FSTEP(0x1) | OSCCTRL_DFLLMUL_MUL(0);
while(OSCCTRL->DFLLSYNC.reg & OSCCTRL_DFLLSYNC_DFLLMUL);
OSCCTRL->DFLLCTRLB.reg = 0;
while(OSCCTRL->DFLLSYNC.reg & OSCCTRL_DFLLSYNC_DFLLCTRLB);
OSCCTRL->DFLLCTRLA.reg |= OSCCTRL_DFLLCTRLA_ENABLE;
while(OSCCTRL->DFLLSYNC.reg & OSCCTRL_DFLLSYNC_ENABLE);
OSCCTRL->DFLLCTRLB.reg = OSCCTRL_DFLLCTRLB_WAITLOCK | OSCCTRL_DFLLCTRLB_CCDIS | OSCCTRL_DFLLCTRLB_USBCRM;
while(!OSCCTRL->STATUS.bit.DFLLRDY);
OSCCTRL->DFLLMUL.reg = OSCCTRL_DFLLMUL_MUL(20) | OSCCTRL_DFLLMUL_CSTEP(12) | OSCCTRL_DFLLMUL_FSTEP(5);
while(OSCCTRL->DFLLSYNC.reg & OSCCTRL_DFLLSYNC_DFLLMUL){
// wait
}
OSCCTRL->DFLLCTRLA.reg = OSCCTRL_DFLLCTRLA_ENABLE | OSCCTRL_DFLLCTRLA_RUNSTDBY;
while(OSCCTRL->DFLLSYNC.reg & OSCCTRL_DFLLSYNC_ENABLE){
// wait
}
OSCCTRL->DFLLVAL.reg = OSCCTRL_DFLLVAL_COARSE(12) | OSCCTRL_DFLLVAL_FINE(12);
while(OSCCTRL->DFLLSYNC.reg & OSCCTRL_DFLLSYNC_DFLLVAL){
// wait
}
GCLK->GENCTRL[5].reg = GCLK_GENCTRL_SRC(GCLK_GENCTRL_SRC_DFLL_Val) | GCLK_GENCTRL_GENEN | GCLK_GENCTRL_DIV(24u);
while(GCLK->SYNCBUSY.bit.GENCTRL5);
OSCCTRL->DFLLCTRLB.reg = OSCCTRL_DFLLCTRLB_MODE | OSCCTRL_DFLLCTRLB_WAITLOCK;
while(OSCCTRL->DFLLSYNC.reg & OSCCTRL_DFLLSYNC_DFLLCTRLB){
// wait
}
// setup DPLL0 to 120MHz
GCLK->PCHCTRL[OSCCTRL_GCLK_ID_FDPLL0].reg = (1 << GCLK_PCHCTRL_CHEN_Pos) | GCLK_PCHCTRL_GEN(GCLK_PCHCTRL_GEN_GCLK5_Val);
OSCCTRL->Dpll[0].DPLLRATIO.reg = OSCCTRL_DPLLRATIO_LDRFRAC(0x00) | OSCCTRL_DPLLRATIO_LDR(59);
while(OSCCTRL->Dpll[0].DPLLSYNCBUSY.bit.DPLLRATIO);
OSCCTRL->Dpll[0].DPLLCTRLB.reg = OSCCTRL_DPLLCTRLB_REFCLK_GCLK | OSCCTRL_DPLLCTRLB_LBYPASS;
OSCCTRL->Dpll[0].DPLLCTRLA.reg = OSCCTRL_DPLLCTRLA_ENABLE;
while(OSCCTRL->Dpll[0].DPLLSTATUS.bit.CLKRDY == 0 || OSCCTRL->Dpll[0].DPLLSTATUS.bit.LOCK == 0);
// set clock to use dpll0
while(!OSCCTRL->STATUS.bit.DFLLRDY);
GCLK->GENCTRL[0].reg = GCLK_GENCTRL_SRC(GCLK_GENCTRL_SRC_DPLL0) | GCLK_GENCTRL_IDC | GCLK_GENCTRL_GENEN;
while(GCLK->SYNCBUSY.reg & GCLK_SYNCBUSY_GENCTRL0);
MCLK->CPUDIV.reg = MCLK_CPUDIV_DIV_DIV1;
}
......@@ -142,7 +158,11 @@ int main(void)
{
/* Initialize the SAM system */
SystemInit();
SysTick_Config(2500000); // making ticks about 2us
clock_init();
SysTick_Config(5000000);
pin_t clockpin = pin_new(&PORT->Group[1], 2);
pin_output(&clockpin);
// lights
stlb = pin_new(&PORT->Group[1], 14);
......@@ -222,6 +242,10 @@ int main(void)
while (1)
{
pin_toggle(&clockpin);
}
}
/*
next steps (haha)
- poll uart receive line, look for network packets
......@@ -236,13 +260,14 @@ int main(void)
- get up to 120MHz for very happy stepping
- bring baud rate to 1M, at least! what the heck, FTDI!
*/
}
}
uint8_t lpcnt = 0;
uint8_t stpcnt = 0;
void SysTick_Handler(void){
// slow ticker
lpcnt ++;
pin_toggle(&stlb);
/*
......@@ -255,14 +280,15 @@ void SysTick_Handler(void){
uint8_t w2 = watch >> 16;
uint8_t w3 = watch >> 8;
uint8_t w4 = watch;
/*
uart_sendchar_buffered(&up1, w1);
uart_sendchar_buffered(&up1, w2);
uart_sendchar_buffered(&up1, w3);
uart_sendchar_buffered(&up1, w4);
*/
if(stepper.position_ticks_target == stepper.position_ticks){
stpcnt ++;
stepper_goto(&stepper, 360 * (stpcnt % 2), 720);
stepper_goto(&stepper, 360 * (stpcnt % 2), 1200);
}
}
......
images/gndplane.png

56.5 KiB | W: | H:

images/gndplane.png

118 KiB | W: | H:

images/gndplane.png
images/gndplane.png
images/gndplane.png
images/gndplane.png
  • 2-up
  • Swipe
  • Onion skin
images/routed.png

93.1 KiB | W: | H:

images/routed.png

183 KiB | W: | H:

images/routed.png
images/routed.png
images/routed.png
images/routed.png
  • 2-up
  • Swipe
  • Onion skin
images/schematic.png

92.8 KiB | W: | H:

images/schematic.png

297 KiB | W: | H:

images/schematic.png
images/schematic.png
images/schematic.png
images/schematic.png
  • 2-up
  • Swipe
  • Onion skin
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment