diff --git a/documentation/Smart Stepper Manual.pdf b/documentation/Smart Stepper Manual.pdf new file mode 100644 index 0000000..18bcac9 Binary files /dev/null and b/documentation/Smart Stepper Manual.pdf differ diff --git a/firmware/stepper_nano_zero/A1333.cpp b/firmware/stepper_nano_zero/A1333.cpp new file mode 100644 index 0000000..168493d --- /dev/null +++ b/firmware/stepper_nano_zero/A1333.cpp @@ -0,0 +1,152 @@ +/********************************************************************** + Copyright (C) 2019 MisfitTech LLC, All rights reserved. + + MisfitTech uses a dual license model that allows the software to be used under + a standard GPL open source license, or a commercial license. The standard GPL + license requires that all software statically linked with MisfitTec Code is + also distributed under the same GPL V2 license terms. Details of both license + options follow: + + - Open source licensing - + MisfitTech is a free download and may be used, modified, evaluated and + distributed without charge provided the user adheres to version two of the GNU + General Public License (GPL) and does not remove the copyright notice or this + text. The GPL V2 text is available on the gnu.org web site + + - Commercial licensing - + Businesses and individuals that for commercial or other reasons cannot comply + with the terms of the GPL V2 license must obtain a low cost commercial license + before incorporating MisfitTech code into proprietary software for distribution in + any form. Commercial licenses can be purchased from www.misfittech.net + and do not require any source files to be changed. + + + This code is distributed in the hope that it will be useful. You cannot + use MisfitTech's code unless you agree that you use the software 'as is'. + MisfitTech's code is provided WITHOUT ANY WARRANTY; without even the implied + warranties of NON-INFRINGEMENT, MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. MisfitTech LLC disclaims all conditions and terms, be they + implied, expressed, or statutory. + + + Written by Trampas Stern for MisfitTech. + + Misfit Tech invests time and resources providing this open source code, + please support MisfitTech and open-source hardware by purchasing + products from MisfitTech, www.misifittech.net! + *********************************************************************/ +#include +#include "syslog.h" +#include "A1333.h" +#include "SPI.h" +#include +#include "board.h" + + +#define A1333_CMD_NOP (0x0000) +#define A1333_ANG15 (0x3200) + +SPISettings settingsA(500000, MSBFIRST, SPI_MODE3); ///400000, MSBFIRST, SPI_MODE1); + +boolean A1333::begin(int csPin) +{ + + digitalWrite(PIN_AS5047D_CS,LOW); //pull CS LOW by default (chip powered off) + digitalWrite(PIN_MOSI,LOW); + digitalWrite(PIN_SCK,LOW); + digitalWrite(PIN_MISO,LOW); + pinMode(PIN_MISO,OUTPUT); + delay(1000); + + + digitalWrite(PIN_AS5047D_CS,HIGH); //pull CS high + + pinMode(PIN_MISO,INPUT); + + + chipSelectPin=csPin; + + LOG("csPin is %d",csPin); + pinMode(chipSelectPin,OUTPUT); + digitalWrite(chipSelectPin,HIGH); //pull CS high by default + delay(1); + + SPI.begin(); //AS5047D SPI uses mode=1 (CPOL=0, CPHA=1) + + LOG("Begin A1333..."); + + LOG("Address is 0x%04X",readAddress(A1333_ANG15)); +} + + +//read the encoders +int16_t A1333::readAddress(uint16_t addr) +{ + uint16_t data; + //make sure it is a write by setting bit 14 + //addr=addr | 0x4000; + + SPI.beginTransaction(settingsA); + digitalWrite(chipSelectPin, LOW); + delayMicroseconds(1); + //clock out the address to read + //LOG("address 0x%04X",addr); + SPI.transfer16(addr); + digitalWrite(chipSelectPin, HIGH); + delayMicroseconds(1); + digitalWrite(chipSelectPin, LOW); + //clock out zeros to read in the data from address + data=SPI.transfer16(0x00); + + digitalWrite(chipSelectPin, HIGH); + SPI.endTransaction(); + + return data; +} + +//read the encoders +int16_t A1333::readEncoderAngle(void) +{ + + return readAddress(A1333_ANG15)>>1; +} + +int16_t A1333::readEncoderAnglePipeLineRead(void) +{ + static bool first=true; + uint16_t addr = A1333_ANG15; + uint16_t addr2; + uint16_t data; + + if (first) + { + //make sure it is a write by setting bit 14 + //addr2=addr | 0x4000; + SPI.beginTransaction(settingsA); + digitalWrite(chipSelectPin, LOW); + delayMicroseconds(1); + //clock out the address to read + SPI.transfer16(addr); + digitalWrite(chipSelectPin, HIGH); + delayMicroseconds(1); + digitalWrite(chipSelectPin, LOW); + delayMicroseconds(1); + //clock out zeros to read in the data from address + data=SPI.transfer16(addr); + + digitalWrite(chipSelectPin, HIGH); + SPI.endTransaction(); + first=false; + return data>>1; + } + + SPI.beginTransaction(settingsA); + digitalWrite(chipSelectPin, LOW); + delayMicroseconds(1); + //clock out zeros to read in the data from address + data=SPI.transfer16(addr); + + digitalWrite(chipSelectPin, HIGH); + SPI.endTransaction(); + return data>>1; +} diff --git a/firmware/stepper_nano_zero/A1333.h b/firmware/stepper_nano_zero/A1333.h new file mode 100644 index 0000000..ee9ee68 --- /dev/null +++ b/firmware/stepper_nano_zero/A1333.h @@ -0,0 +1,59 @@ +/********************************************************************** + Copyright (C) 2019 MisfitTech LLC, All rights reserved. + + MisfitTech uses a dual license model that allows the software to be used under + a standard GPL open source license, or a commercial license. The standard GPL + license requires that all software statically linked with MisfitTec Code is + also distributed under the same GPL V2 license terms. Details of both license + options follow: + + - Open source licensing - + MisfitTech is a free download and may be used, modified, evaluated and + distributed without charge provided the user adheres to version two of the GNU + General Public License (GPL) and does not remove the copyright notice or this + text. The GPL V2 text is available on the gnu.org web site + + - Commercial licensing - + Businesses and individuals that for commercial or other reasons cannot comply + with the terms of the GPL V2 license must obtain a low cost commercial license + before incorporating MisfitTech code into proprietary software for distribution in + any form. Commercial licenses can be purchased from www.misfittech.net + and do not require any source files to be changed. + + + This code is distributed in the hope that it will be useful. You cannot + use MisfitTech's code unless you agree that you use the software 'as is'. + MisfitTech's code is provided WITHOUT ANY WARRANTY; without even the implied + warranties of NON-INFRINGEMENT, MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. MisfitTech LLC disclaims all conditions and terms, be they + implied, expressed, or statutory. + + + Written by Trampas Stern for MisfitTech. + + Misfit Tech invests time and resources providing this open source code, + please support MisfitTech and open-source hardware by purchasing + products from MisfitTech, www.misifittech.net! + *********************************************************************/ +#ifndef A1333_H_ +#define A1333_H_ + +#include + +#define A1333_DEGREES_PER_BIT (360.0/(float)(0x7FFF)) + +class A1333 { + private: + int chipSelectPin; + public: + boolean begin(int csPin); + int16_t readEncoderAngle(void); + int16_t readAddress(uint16_t addr); + int16_t readEncoderAnglePipeLineRead(void); + void diagnostics(char *ptrStr) {return;}; + bool getError(void) {return false;}; +}; + + + +#endif /* A1333_H_ */ diff --git a/firmware/stepper_nano_zero/A4954.cpp b/firmware/stepper_nano_zero/A4954.cpp index c231e34..61388a4 100644 --- a/firmware/stepper_nano_zero/A4954.cpp +++ b/firmware/stepper_nano_zero/A4954.cpp @@ -1,19 +1,39 @@ /********************************************************************** - Copyright (C) 2018 MisfitTech, All rights reserved. + Copyright (C) 2018 MisfitTech LLC, All rights reserved. - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License. + MisfitTech uses a dual license model that allows the software to be used under + a standard GPL open source license, or a commercial license. The standard GPL + license requires that all software statically linked with MisfitTec Code is + also distributed under the same GPL V2 license terms. Details of both license + options follow: - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. + - Open source licensing - + MisfitTech is a free download and may be used, modified, evaluated and + distributed without charge provided the user adheres to version two of the GNU + General Public License (GPL) and does not remove the copyright notice or this + text. The GPL V2 text is available on the gnu.org web site + + - Commercial licensing - + Businesses and individuals that for commercial or other reasons cannot comply + with the terms of the GPL V2 license must obtain a low cost commercial license + before incorporating MisfitTech code into proprietary software for distribution in + any form. Commercial licenses can be purchased from www.misfittech.net + and do not require any source files to be changed. + + + This code is distributed in the hope that it will be useful. You cannot + use MisfitTech's code unless you agree that you use the software 'as is'. + MisfitTech's code is provided WITHOUT ANY WARRANTY; without even the implied + warranties of NON-INFRINGEMENT, MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. MisfitTech LLC disclaims all conditions and terms, be they + implied, expressed, or statutory. - You should have received a copy of the GNU General Public License - along with this program. If not, see . Written by Trampas Stern for MisfitTech. + + Misfit Tech invests time and resources providing this open source code, + please support MisfitTech and open-source hardware by purchasing + products from MisfitTech, www.misifittech.net! *********************************************************************/ #include "A4954.h" #include "wiring_private.h" diff --git a/firmware/stepper_nano_zero/A4954.h b/firmware/stepper_nano_zero/A4954.h index 336f66a..c66decb 100644 --- a/firmware/stepper_nano_zero/A4954.h +++ b/firmware/stepper_nano_zero/A4954.h @@ -1,19 +1,39 @@ /********************************************************************** - Copyright (C) 2018 MisfitTech, All rights reserved. + Copyright (C) 2019 MisfitTech LLC, All rights reserved. - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License. + MisfitTech uses a dual license model that allows the software to be used under + a standard GPL open source license, or a commercial license. The standard GPL + license requires that all software statically linked with MisfitTec Code is + also distributed under the same GPL V2 license terms. Details of both license + options follow: - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. + - Open source licensing - + MisfitTech is a free download and may be used, modified, evaluated and + distributed without charge provided the user adheres to version two of the GNU + General Public License (GPL) and does not remove the copyright notice or this + text. The GPL V2 text is available on the gnu.org web site + + - Commercial licensing - + Businesses and individuals that for commercial or other reasons cannot comply + with the terms of the GPL V2 license must obtain a low cost commercial license + before incorporating MisfitTech code into proprietary software for distribution in + any form. Commercial licenses can be purchased from www.misfittech.net + and do not require any source files to be changed. + + + This code is distributed in the hope that it will be useful. You cannot + use MisfitTech's code unless you agree that you use the software 'as is'. + MisfitTech's code is provided WITHOUT ANY WARRANTY; without even the implied + warranties of NON-INFRINGEMENT, MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. MisfitTech LLC disclaims all conditions and terms, be they + implied, expressed, or statutory. - You should have received a copy of the GNU General Public License - along with this program. If not, see . Written by Trampas Stern for MisfitTech. + + Misfit Tech invests time and resources providing this open source code, + please support MisfitTech and open-source hardware by purchasing + products from MisfitTech, www.misifittech.net! *********************************************************************/ #ifndef __A4954__H__ #define __A4954__H__ diff --git a/firmware/stepper_nano_zero/A5995.cpp b/firmware/stepper_nano_zero/A5995.cpp index b56634c..f2b8a9f 100644 --- a/firmware/stepper_nano_zero/A5995.cpp +++ b/firmware/stepper_nano_zero/A5995.cpp @@ -1,20 +1,40 @@ -/* - Copyright (C) 2018 MisfitTech, All rights reserved. +/********************************************************************** + Copyright (C) 2018 MisfitTech LLC, All rights reserved. - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License. + MisfitTech uses a dual license model that allows the software to be used under + a standard GPL open source license, or a commercial license. The standard GPL + license requires that all software statically linked with MisfitTec Code is + also distributed under the same GPL V2 license terms. Details of both license + options follow: - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. + - Open source licensing - + MisfitTech is a free download and may be used, modified, evaluated and + distributed without charge provided the user adheres to version two of the GNU + General Public License (GPL) and does not remove the copyright notice or this + text. The GPL V2 text is available on the gnu.org web site + + - Commercial licensing - + Businesses and individuals that for commercial or other reasons cannot comply + with the terms of the GPL V2 license must obtain a low cost commercial license + before incorporating MisfitTech code into proprietary software for distribution in + any form. Commercial licenses can be purchased from www.misfittech.net + and do not require any source files to be changed. + + + This code is distributed in the hope that it will be useful. You cannot + use MisfitTech's code unless you agree that you use the software 'as is'. + MisfitTech's code is provided WITHOUT ANY WARRANTY; without even the implied + warranties of NON-INFRINGEMENT, MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. MisfitTech LLC disclaims all conditions and terms, be they + implied, expressed, or statutory. - You should have received a copy of the GNU General Public License - along with this program. If not, see . Written by Trampas Stern for MisfitTech. - */ + + Misfit Tech invests time and resources providing this open source code, + please support MisfitTech and open-source hardware by purchasing + products from MisfitTech, www.misifittech.net! + *********************************************************************/ #include "A5995.h" diff --git a/firmware/stepper_nano_zero/A5995.h b/firmware/stepper_nano_zero/A5995.h index ddc65cb..756513c 100644 --- a/firmware/stepper_nano_zero/A5995.h +++ b/firmware/stepper_nano_zero/A5995.h @@ -1,20 +1,40 @@ -/* - Copyright (C) 2018 MisfitTech, All rights reserved. +/********************************************************************** + Copyright (C) 2018 MisfitTech LLC, All rights reserved. + + MisfitTech uses a dual license model that allows the software to be used under + a standard GPL open source license, or a commercial license. The standard GPL + license requires that all software statically linked with MisfitTec Code is + also distributed under the same GPL V2 license terms. Details of both license + options follow: + + - Open source licensing - + MisfitTech is a free download and may be used, modified, evaluated and + distributed without charge provided the user adheres to version two of the GNU + General Public License (GPL) and does not remove the copyright notice or this + text. The GPL V2 text is available on the gnu.org web site - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License. + - Commercial licensing - + Businesses and individuals that for commercial or other reasons cannot comply + with the terms of the GPL V2 license must obtain a low cost commercial license + before incorporating MisfitTech code into proprietary software for distribution in + any form. Commercial licenses can be purchased from www.misfittech.net + and do not require any source files to be changed. - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - You should have received a copy of the GNU General Public License - along with this program. If not, see . + This code is distributed in the hope that it will be useful. You cannot + use MisfitTech's code unless you agree that you use the software 'as is'. + MisfitTech's code is provided WITHOUT ANY WARRANTY; without even the implied + warranties of NON-INFRINGEMENT, MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. MisfitTech LLC disclaims all conditions and terms, be they + implied, expressed, or statutory. + Written by Trampas Stern for MisfitTech. - */ + + Misfit Tech invests time and resources providing this open source code, + please support MisfitTech and open-source hardware by purchasing + products from MisfitTech, www.misifittech.net! + *********************************************************************/ #ifndef A5995_H_ #define A5995_H_ diff --git a/firmware/stepper_nano_zero/Flash.cpp b/firmware/stepper_nano_zero/Flash.cpp index 87c9401..2604732 100644 --- a/firmware/stepper_nano_zero/Flash.cpp +++ b/firmware/stepper_nano_zero/Flash.cpp @@ -1,19 +1,33 @@ /********************************************************************** - * Author: tstern - * - Copyright (C) 2018 MisfitTech, All rights reserved. + Copyright (C) 2018 MisfitTech LLC, All rights reserved. - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License. + MisfitTech uses a dual license model that allows the software to be used under + a standard GPL open source license, or a commercial license. The standard GPL + license requires that all software statically linked with MisfitTec Code is + also distributed under the same GPL V2 license terms. Details of both license + options follow: - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. + - Open source licensing - + MisfitTech is a free download and may be used, modified, evaluated and + distributed without charge provided the user adheres to version two of the GNU + General Public License (GPL) and does not remove the copyright notice or this + text. The GPL V2 text is available on the gnu.org web site + + - Commercial licensing - + Businesses and individuals that for commercial or other reasons cannot comply + with the terms of the GPL V2 license must obtain a low cost commercial license + before incorporating MisfitTech code into proprietary software for distribution in + any form. Commercial licenses can be purchased from www.misfittech.net + and do not require any source files to be changed. + + + This code is distributed in the hope that it will be useful. You cannot + use MisfitTech's code unless you agree that you use the software 'as is'. + MisfitTech's code is provided WITHOUT ANY WARRANTY; without even the implied + warranties of NON-INFRINGEMENT, MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. MisfitTech LLC disclaims all conditions and terms, be they + implied, expressed, or statutory. - You should have received a copy of the GNU General Public License - along with this program. If not, see . Written by Trampas Stern for MisfitTech. @@ -83,7 +97,7 @@ void flashWrite(const volatile void *flash_ptr,const void *data, uint32_t size) destPtr=(uint8_t *)flash_ptr; srcPtr=(uint8_t *)data; - LOG("flash write called"); + //LOG("flash write called"); while(size>0) { uint32_t i,j; @@ -92,11 +106,11 @@ void flashWrite(const volatile void *flash_ptr,const void *data, uint32_t size) offset=((uint32_t)destPtr)%(FLASH_ROW_SIZE); //offset into page bytesInBlock=FLASH_ROW_SIZE-offset; //this is how many bytes we need to overwrite in this page - LOG("offset %d, bytesInBlock %d size %d", offset, bytesInBlock,size); + //LOG("offset %d, bytesInBlock %d size %d", offset, bytesInBlock,size); //get pointer to start of page ptrPage=(uint32_t *) ((((uint32_t)destPtr)/(FLASH_ROW_SIZE)) * FLASH_ROW_SIZE); - LOG("pointer to page %d(0x%08x) %d",(uint32_t)ptrPage,(uint32_t)ptrPage,destPtr); + //LOG("pointer to page %d(0x%08x) %d",(uint32_t)ptrPage,(uint32_t)ptrPage,destPtr); //fill page buffer with data from flash memcpy(buffer,ptrPage,FLASH_ROW_SIZE); @@ -107,7 +121,7 @@ void flashWrite(const volatile void *flash_ptr,const void *data, uint32_t size) { i=size; } - LOG("changing %d bytes",i); + //LOG("changing %d bytes",i); memcpy(&buffer[offset],srcPtr,i); //erase page diff --git a/firmware/stepper_nano_zero/Flash.h b/firmware/stepper_nano_zero/Flash.h index e48782b..c95d700 100644 --- a/firmware/stepper_nano_zero/Flash.h +++ b/firmware/stepper_nano_zero/Flash.h @@ -1,19 +1,33 @@ /********************************************************************** - * Author: tstern - * - Copyright (C) 2018 MisfitTech, All rights reserved. + Copyright (C) 2018 MisfitTech LLC, All rights reserved. + + MisfitTech uses a dual license model that allows the software to be used under + a standard GPL open source license, or a commercial license. The standard GPL + license requires that all software statically linked with MisfitTec Code is + also distributed under the same GPL V2 license terms. Details of both license + options follow: + + - Open source licensing - + MisfitTech is a free download and may be used, modified, evaluated and + distributed without charge provided the user adheres to version two of the GNU + General Public License (GPL) and does not remove the copyright notice or this + text. The GPL V2 text is available on the gnu.org web site + + - Commercial licensing - + Businesses and individuals that for commercial or other reasons cannot comply + with the terms of the GPL V2 license must obtain a low cost commercial license + before incorporating MisfitTech code into proprietary software for distribution in + any form. Commercial licenses can be purchased from www.misfittech.net + and do not require any source files to be changed. + + + This code is distributed in the hope that it will be useful. You cannot + use MisfitTech's code unless you agree that you use the software 'as is'. + MisfitTech's code is provided WITHOUT ANY WARRANTY; without even the implied + warranties of NON-INFRINGEMENT, MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. MisfitTech LLC disclaims all conditions and terms, be they + implied, expressed, or statutory. - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . Written by Trampas Stern for MisfitTech. diff --git a/firmware/stepper_nano_zero/angle.h b/firmware/stepper_nano_zero/angle.h index ff1b5f0..34e0226 100644 --- a/firmware/stepper_nano_zero/angle.h +++ b/firmware/stepper_nano_zero/angle.h @@ -1,24 +1,39 @@ -/* - * angle.h - * - * Created on: Sep 1, 2016 - * Author: TStern - * - Copyright (C) 2018 MisfitTech, All rights reserved. - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . +/********************************************************************** + Copyright (C) 2018 MisfitTech LLC, All rights reserved. + + MisfitTech uses a dual license model that allows the software to be used under + a standard GPL open source license, or a commercial license. The standard GPL + license requires that all software statically linked with MisfitTec Code is + also distributed under the same GPL V2 license terms. Details of both license + options follow: + + - Open source licensing - + MisfitTech is a free download and may be used, modified, evaluated and + distributed without charge provided the user adheres to version two of the GNU + General Public License (GPL) and does not remove the copyright notice or this + text. The GPL V2 text is available on the gnu.org web site + + - Commercial licensing - + Businesses and individuals that for commercial or other reasons cannot comply + with the terms of the GPL V2 license must obtain a low cost commercial license + before incorporating MisfitTech code into proprietary software for distribution in + any form. Commercial licenses can be purchased from www.misfittech.net + and do not require any source files to be changed. + + + This code is distributed in the hope that it will be useful. You cannot + use MisfitTech's code unless you agree that you use the software 'as is'. + MisfitTech's code is provided WITHOUT ANY WARRANTY; without even the implied + warranties of NON-INFRINGEMENT, MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. MisfitTech LLC disclaims all conditions and terms, be they + implied, expressed, or statutory. + Written by Trampas Stern for MisfitTech. + + Misfit Tech invests time and resources providing this open source code, + please support MisfitTech and open-source hardware by purchasing + products from MisfitTech, www.misifittech.net! *********************************************************************/ #ifndef ANGLE_H_ diff --git a/firmware/stepper_nano_zero/as5047d.cpp b/firmware/stepper_nano_zero/as5047d.cpp index 8182ac5..0812c36 100644 --- a/firmware/stepper_nano_zero/as5047d.cpp +++ b/firmware/stepper_nano_zero/as5047d.cpp @@ -1,25 +1,39 @@ /********************************************************************** - * Author: tstern - Copyright (C) 2018 MisfitTech, All rights reserved. + Copyright (C) 2018 MisfitTech LLC, All rights reserved. - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License. + MisfitTech uses a dual license model that allows the software to be used under + a standard GPL open source license, or a commercial license. The standard GPL + license requires that all software statically linked with MisfitTec Code is + also distributed under the same GPL V2 license terms. Details of both license + options follow: - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. + - Open source licensing - + MisfitTech is a free download and may be used, modified, evaluated and + distributed without charge provided the user adheres to version two of the GNU + General Public License (GPL) and does not remove the copyright notice or this + text. The GPL V2 text is available on the gnu.org web site + + - Commercial licensing - + Businesses and individuals that for commercial or other reasons cannot comply + with the terms of the GPL V2 license must obtain a low cost commercial license + before incorporating MisfitTech code into proprietary software for distribution in + any form. Commercial licenses can be purchased from www.misfittech.net + and do not require any source files to be changed. + + + This code is distributed in the hope that it will be useful. You cannot + use MisfitTech's code unless you agree that you use the software 'as is'. + MisfitTech's code is provided WITHOUT ANY WARRANTY; without even the implied + warranties of NON-INFRINGEMENT, MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. MisfitTech LLC disclaims all conditions and terms, be they + implied, expressed, or statutory. - You should have received a copy of the GNU General Public License - along with this program. If not, see . Written by Trampas Stern for MisfitTech. Misfit Tech invests time and resources providing this open source code, please support MisfitTech and open-source hardware by purchasing products from MisfitTech, www.misifittech.net! - *********************************************************************/ #include #include "syslog.h" diff --git a/firmware/stepper_nano_zero/as5047d.h b/firmware/stepper_nano_zero/as5047d.h index e92407d..8252c93 100644 --- a/firmware/stepper_nano_zero/as5047d.h +++ b/firmware/stepper_nano_zero/as5047d.h @@ -1,19 +1,33 @@ /********************************************************************** - * Author: tstern - * - Copyright (C) 2018 MisfitTech, All rights reserved. + Copyright (C) 2019 MisfitTech LLC, All rights reserved. + + MisfitTech uses a dual license model that allows the software to be used under + a standard GPL open source license, or a commercial license. The standard GPL + license requires that all software statically linked with MisfitTec Code is + also distributed under the same GPL V2 license terms. Details of both license + options follow: + + - Open source licensing - + MisfitTech is a free download and may be used, modified, evaluated and + distributed without charge provided the user adheres to version two of the GNU + General Public License (GPL) and does not remove the copyright notice or this + text. The GPL V2 text is available on the gnu.org web site + + - Commercial licensing - + Businesses and individuals that for commercial or other reasons cannot comply + with the terms of the GPL V2 license must obtain a low cost commercial license + before incorporating MisfitTech code into proprietary software for distribution in + any form. Commercial licenses can be purchased from www.misfittech.net + and do not require any source files to be changed. + + + This code is distributed in the hope that it will be useful. You cannot + use MisfitTech's code unless you agree that you use the software 'as is'. + MisfitTech's code is provided WITHOUT ANY WARRANTY; without even the implied + warranties of NON-INFRINGEMENT, MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. MisfitTech LLC disclaims all conditions and terms, be they + implied, expressed, or statutory. - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . Written by Trampas Stern for MisfitTech. diff --git a/firmware/stepper_nano_zero/board.h b/firmware/stepper_nano_zero/board.h index b69ac21..fd754f7 100644 --- a/firmware/stepper_nano_zero/board.h +++ b/firmware/stepper_nano_zero/board.h @@ -1,19 +1,33 @@ /********************************************************************** - * Author: tstern - * - Copyright (C) 2018 MisfitTech, All rights reserved. + Copyright (C) 2018 MisfitTech LLC, All rights reserved. + + MisfitTech uses a dual license model that allows the software to be used under + a standard GPL open source license, or a commercial license. The standard GPL + license requires that all software statically linked with MisfitTec Code is + also distributed under the same GPL V2 license terms. Details of both license + options follow: + + - Open source licensing - + MisfitTech is a free download and may be used, modified, evaluated and + distributed without charge provided the user adheres to version two of the GNU + General Public License (GPL) and does not remove the copyright notice or this + text. The GPL V2 text is available on the gnu.org web site - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License. + - Commercial licensing - + Businesses and individuals that for commercial or other reasons cannot comply + with the terms of the GPL V2 license must obtain a low cost commercial license + before incorporating MisfitTech code into proprietary software for distribution in + any form. Commercial licenses can be purchased from www.misfittech.net + and do not require any source files to be changed. - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - You should have received a copy of the GNU General Public License - along with this program. If not, see . + This code is distributed in the hope that it will be useful. You cannot + use MisfitTech's code unless you agree that you use the software 'as is'. + MisfitTech's code is provided WITHOUT ANY WARRANTY; without even the implied + warranties of NON-INFRINGEMENT, MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. MisfitTech LLC disclaims all conditions and terms, be they + implied, expressed, or statutory. + Written by Trampas Stern for MisfitTech. @@ -42,6 +56,10 @@ // comment out this next line if using the older hardware #define NEMA17_SMART_STEPPER_3_21_2017 +//The MKS Servo42 uses the A1333_Encoder +// Please uncomment this line and make sure the NEMA17_SMART_STEPPER_3_21_2017 is +// uncommented for the Servo42 +//#define A1333_ENCODER #ifdef A5995_DRIVER #ifdef NEMA17_SMART_STEPPER_3_21_2017 @@ -64,7 +82,7 @@ //#define ENABLE_PHASE_PREDICTION //this enables prediction of phase at high velocity to increase motor speed //as of FW0.11 it is considered development only -#define VERSION "FW: 0.38" //this is what prints on LCD during splash screen +#define VERSION "FW: 0.39" //this is what prints on LCD during splash screen //Define this to allow command out serial port, else hardware serial is debug log //#define CMD_SERIAL_PORT @@ -168,6 +186,8 @@ * 0.36 - eeprom set location math was wrong. * 0.37 - fixed bug where the motor would pause periodically do the the TC4 counter. * 0.38 - fixed bug in the velocity feedback mode. + * 0.39 - changed step count to TCC2, improved the dir pin setup/hold times + * - added support for the MKS Servo42 (A1333 encoder) */ @@ -201,9 +221,9 @@ typedef enum { // ******** TIMER USAGE A4954 versions ************ //TCC1 is used for DAC PWM to the A4954 //TCC0 can be used as PWM for the input pins on the A4954 +//TCC2 is used for the step count //D0 step input could use TCC1 or TCC0 if not used //TC3 is used for planner tick -//TC4 is used for step count //TC5 is use for timing the control loop // ******** TIMER USAGE NEMA23 10A versions ************ @@ -223,6 +243,9 @@ typedef enum { #define SerialUSB Serial #endif +#define PIN_TXD (30) +#define PIN_RXD (31) + #define PIN_STEP_INPUT (0) #define PIN_DIR_INPUT (1) @@ -240,7 +263,13 @@ typedef enum { #ifdef NEMA17_SMART_STEPPER_3_21_2017 #define PIN_SW1 (19)//analogInputToDigitalPin(PIN_A5)) #define PIN_SW3 (14)//analogInputToDigitalPin(PIN_A0)) + +#ifdef A1333_ENCODER //the MKS Servo42 uses A1 for this switch +#define PIN_SW4 (15)//analogInputToDigitalPin(PIN_A1)) +#else #define PIN_SW4 (2)//D2 +#endif + #define PIN_ENABLE (10) #define PIN_ERROR (3) @@ -297,6 +326,7 @@ typedef enum { #define PIN_A5995_VREF2 (9) //PA07 #define PIN_A5995_SLEEPn (25) //RXLED + #ifndef MECHADUINO_HARDWARE #define PIN_YELLOW_LED (8) #endif diff --git a/firmware/stepper_nano_zero/calibration.cpp b/firmware/stepper_nano_zero/calibration.cpp index 8c96cb1..e9ae16c 100644 --- a/firmware/stepper_nano_zero/calibration.cpp +++ b/firmware/stepper_nano_zero/calibration.cpp @@ -1,19 +1,33 @@ /********************************************************************** - * Author: tstern - * - Copyright (C) 2018 MisfitTech, All rights reserved. + Copyright (C) 2018 MisfitTech LLC, All rights reserved. + + MisfitTech uses a dual license model that allows the software to be used under + a standard GPL open source license, or a commercial license. The standard GPL + license requires that all software statically linked with MisfitTec Code is + also distributed under the same GPL V2 license terms. Details of both license + options follow: + + - Open source licensing - + MisfitTech is a free download and may be used, modified, evaluated and + distributed without charge provided the user adheres to version two of the GNU + General Public License (GPL) and does not remove the copyright notice or this + text. The GPL V2 text is available on the gnu.org web site + + - Commercial licensing - + Businesses and individuals that for commercial or other reasons cannot comply + with the terms of the GPL V2 license must obtain a low cost commercial license + before incorporating MisfitTech code into proprietary software for distribution in + any form. Commercial licenses can be purchased from www.misfittech.net + and do not require any source files to be changed. + + + This code is distributed in the hope that it will be useful. You cannot + use MisfitTech's code unless you agree that you use the software 'as is'. + MisfitTech's code is provided WITHOUT ANY WARRANTY; without even the implied + warranties of NON-INFRINGEMENT, MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. MisfitTech LLC disclaims all conditions and terms, be they + implied, expressed, or statutory. - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . Written by Trampas Stern for MisfitTech. diff --git a/firmware/stepper_nano_zero/calibration.h b/firmware/stepper_nano_zero/calibration.h index 42ff4df..eaba5a6 100644 --- a/firmware/stepper_nano_zero/calibration.h +++ b/firmware/stepper_nano_zero/calibration.h @@ -1,19 +1,33 @@ /********************************************************************** - * Author: tstern - * - Copyright (C) 2018 MisfitTech, All rights reserved. + Copyright (C) 2018 MisfitTech LLC, All rights reserved. + + MisfitTech uses a dual license model that allows the software to be used under + a standard GPL open source license, or a commercial license. The standard GPL + license requires that all software statically linked with MisfitTec Code is + also distributed under the same GPL V2 license terms. Details of both license + options follow: + + - Open source licensing - + MisfitTech is a free download and may be used, modified, evaluated and + distributed without charge provided the user adheres to version two of the GNU + General Public License (GPL) and does not remove the copyright notice or this + text. The GPL V2 text is available on the gnu.org web site + + - Commercial licensing - + Businesses and individuals that for commercial or other reasons cannot comply + with the terms of the GPL V2 license must obtain a low cost commercial license + before incorporating MisfitTech code into proprietary software for distribution in + any form. Commercial licenses can be purchased from www.misfittech.net + and do not require any source files to be changed. + + + This code is distributed in the hope that it will be useful. You cannot + use MisfitTech's code unless you agree that you use the software 'as is'. + MisfitTech's code is provided WITHOUT ANY WARRANTY; without even the implied + warranties of NON-INFRINGEMENT, MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. MisfitTech LLC disclaims all conditions and terms, be they + implied, expressed, or statutory. - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . Written by Trampas Stern for MisfitTech. diff --git a/firmware/stepper_nano_zero/command.cpp b/firmware/stepper_nano_zero/command.cpp index b9bdbef..bc6412a 100644 --- a/firmware/stepper_nano_zero/command.cpp +++ b/firmware/stepper_nano_zero/command.cpp @@ -1,26 +1,40 @@ -/* -Copyright (C) Trampas Stern name of author +/********************************************************************** + Copyright (C) 2018 MisfitTech LLC, All rights reserved. - Copyright (C) 2018 MisfitTech, All rights reserved. + MisfitTech uses a dual license model that allows the software to be used under + a standard GPL open source license, or a commercial license. The standard GPL + license requires that all software statically linked with MisfitTec Code is + also distributed under the same GPL V2 license terms. Details of both license + options follow: - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License. + - Open source licensing - + MisfitTech is a free download and may be used, modified, evaluated and + distributed without charge provided the user adheres to version two of the GNU + General Public License (GPL) and does not remove the copyright notice or this + text. The GPL V2 text is available on the gnu.org web site - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. + - Commercial licensing - + Businesses and individuals that for commercial or other reasons cannot comply + with the terms of the GPL V2 license must obtain a low cost commercial license + before incorporating MisfitTech code into proprietary software for distribution in + any form. Commercial licenses can be purchased from www.misfittech.net + and do not require any source files to be changed. + + + This code is distributed in the hope that it will be useful. You cannot + use MisfitTech's code unless you agree that you use the software 'as is'. + MisfitTech's code is provided WITHOUT ANY WARRANTY; without even the implied + warranties of NON-INFRINGEMENT, MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. MisfitTech LLC disclaims all conditions and terms, be they + implied, expressed, or statutory. - You should have received a copy of the GNU General Public License - along with this program. If not, see . Written by Trampas Stern for MisfitTech. Misfit Tech invests time and resources providing this open source code, please support MisfitTech and open-source hardware by purchasing products from MisfitTech, www.misifittech.net! -*/ + *********************************************************************/ #include "command.h" #include diff --git a/firmware/stepper_nano_zero/command.h b/firmware/stepper_nano_zero/command.h index f4b662d..3af3df2 100644 --- a/firmware/stepper_nano_zero/command.h +++ b/firmware/stepper_nano_zero/command.h @@ -1,24 +1,40 @@ -/* - * Copyright (C) 2018 MisfitTech, All rights reserved. +/********************************************************************** + Copyright (C) 2018 MisfitTech LLC, All rights reserved. + + MisfitTech uses a dual license model that allows the software to be used under + a standard GPL open source license, or a commercial license. The standard GPL + license requires that all software statically linked with MisfitTec Code is + also distributed under the same GPL V2 license terms. Details of both license + options follow: + + - Open source licensing - + MisfitTech is a free download and may be used, modified, evaluated and + distributed without charge provided the user adheres to version two of the GNU + General Public License (GPL) and does not remove the copyright notice or this + text. The GPL V2 text is available on the gnu.org web site - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License. + - Commercial licensing - + Businesses and individuals that for commercial or other reasons cannot comply + with the terms of the GPL V2 license must obtain a low cost commercial license + before incorporating MisfitTech code into proprietary software for distribution in + any form. Commercial licenses can be purchased from www.misfittech.net + and do not require any source files to be changed. - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - You should have received a copy of the GNU General Public License - along with this program. If not, see . + This code is distributed in the hope that it will be useful. You cannot + use MisfitTech's code unless you agree that you use the software 'as is'. + MisfitTech's code is provided WITHOUT ANY WARRANTY; without even the implied + warranties of NON-INFRINGEMENT, MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. MisfitTech LLC disclaims all conditions and terms, be they + implied, expressed, or statutory. + Written by Trampas Stern for MisfitTech. Misfit Tech invests time and resources providing this open source code, please support MisfitTech and open-source hardware by purchasing products from MisfitTech, www.misifittech.net! - */ + *********************************************************************/ #ifndef __COMMAND_H #define __COMMAND_H diff --git a/firmware/stepper_nano_zero/commands.cpp b/firmware/stepper_nano_zero/commands.cpp index c9be853..e9807b0 100644 --- a/firmware/stepper_nano_zero/commands.cpp +++ b/firmware/stepper_nano_zero/commands.cpp @@ -1,24 +1,40 @@ -/* - * Copyright (C) 2018 MisfitTech, All rights reserved. +/********************************************************************** + Copyright (C) 2018 MisfitTech LLC, All rights reserved. + + MisfitTech uses a dual license model that allows the software to be used under + a standard GPL open source license, or a commercial license. The standard GPL + license requires that all software statically linked with MisfitTec Code is + also distributed under the same GPL V2 license terms. Details of both license + options follow: + + - Open source licensing - + MisfitTech is a free download and may be used, modified, evaluated and + distributed without charge provided the user adheres to version two of the GNU + General Public License (GPL) and does not remove the copyright notice or this + text. The GPL V2 text is available on the gnu.org web site - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License. + - Commercial licensing - + Businesses and individuals that for commercial or other reasons cannot comply + with the terms of the GPL V2 license must obtain a low cost commercial license + before incorporating MisfitTech code into proprietary software for distribution in + any form. Commercial licenses can be purchased from www.misfittech.net + and do not require any source files to be changed. - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - You should have received a copy of the GNU General Public License - along with this program. If not, see . + This code is distributed in the hope that it will be useful. You cannot + use MisfitTech's code unless you agree that you use the software 'as is'. + MisfitTech's code is provided WITHOUT ANY WARRANTY; without even the implied + warranties of NON-INFRINGEMENT, MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. MisfitTech LLC disclaims all conditions and terms, be they + implied, expressed, or statutory. + Written by Trampas Stern for MisfitTech. Misfit Tech invests time and resources providing this open source code, please support MisfitTech and open-source hardware by purchasing products from MisfitTech, www.misifittech.net! - */ + *********************************************************************/ #include "commands.h" #include "command.h" #include "calibration.h" diff --git a/firmware/stepper_nano_zero/commands.h b/firmware/stepper_nano_zero/commands.h index ef306fd..b21d615 100644 --- a/firmware/stepper_nano_zero/commands.h +++ b/firmware/stepper_nano_zero/commands.h @@ -1,24 +1,40 @@ -/* - * Copyright (C) 2018 MisfitTech, All rights reserved. +/********************************************************************** + Copyright (C) 2018 MisfitTech LLC, All rights reserved. - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License. + MisfitTech uses a dual license model that allows the software to be used under + a standard GPL open source license, or a commercial license. The standard GPL + license requires that all software statically linked with MisfitTec Code is + also distributed under the same GPL V2 license terms. Details of both license + options follow: - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. + - Open source licensing - + MisfitTech is a free download and may be used, modified, evaluated and + distributed without charge provided the user adheres to version two of the GNU + General Public License (GPL) and does not remove the copyright notice or this + text. The GPL V2 text is available on the gnu.org web site + + - Commercial licensing - + Businesses and individuals that for commercial or other reasons cannot comply + with the terms of the GPL V2 license must obtain a low cost commercial license + before incorporating MisfitTech code into proprietary software for distribution in + any form. Commercial licenses can be purchased from www.misfittech.net + and do not require any source files to be changed. + + + This code is distributed in the hope that it will be useful. You cannot + use MisfitTech's code unless you agree that you use the software 'as is'. + MisfitTech's code is provided WITHOUT ANY WARRANTY; without even the implied + warranties of NON-INFRINGEMENT, MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. MisfitTech LLC disclaims all conditions and terms, be they + implied, expressed, or statutory. - You should have received a copy of the GNU General Public License - along with this program. If not, see . Written by Trampas Stern for MisfitTech. Misfit Tech invests time and resources providing this open source code, please support MisfitTech and open-source hardware by purchasing products from MisfitTech, www.misifittech.net! - */ + *********************************************************************/ #ifndef __COMMANDS_H__ #define __COMMANDS_H__ #include diff --git a/firmware/stepper_nano_zero/eeprom.cpp b/firmware/stepper_nano_zero/eeprom.cpp index bc04e9f..0a98a73 100644 --- a/firmware/stepper_nano_zero/eeprom.cpp +++ b/firmware/stepper_nano_zero/eeprom.cpp @@ -1,28 +1,40 @@ -/* - * eeprom.cpp - * - * Created on: May 30, 2017 - * Author: tstern - * Copyright (C) 2018 MisfitTech, All rights reserved. +/********************************************************************** + Copyright (C) 2018 MisfitTech LLC, All rights reserved. - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License. + MisfitTech uses a dual license model that allows the software to be used under + a standard GPL open source license, or a commercial license. The standard GPL + license requires that all software statically linked with MisfitTec Code is + also distributed under the same GPL V2 license terms. Details of both license + options follow: - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. + - Open source licensing - + MisfitTech is a free download and may be used, modified, evaluated and + distributed without charge provided the user adheres to version two of the GNU + General Public License (GPL) and does not remove the copyright notice or this + text. The GPL V2 text is available on the gnu.org web site + + - Commercial licensing - + Businesses and individuals that for commercial or other reasons cannot comply + with the terms of the GPL V2 license must obtain a low cost commercial license + before incorporating MisfitTech code into proprietary software for distribution in + any form. Commercial licenses can be purchased from www.misfittech.net + and do not require any source files to be changed. + + + This code is distributed in the hope that it will be useful. You cannot + use MisfitTech's code unless you agree that you use the software 'as is'. + MisfitTech's code is provided WITHOUT ANY WARRANTY; without even the implied + warranties of NON-INFRINGEMENT, MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. MisfitTech LLC disclaims all conditions and terms, be they + implied, expressed, or statutory. - You should have received a copy of the GNU General Public License - along with this program. If not, see . Written by Trampas Stern for MisfitTech. Misfit Tech invests time and resources providing this open source code, please support MisfitTech and open-source hardware by purchasing products from MisfitTech, www.misifittech.net! - */ + *********************************************************************/ #include "eeprom.h" #include "calibration.h" #include "Flash.h" diff --git a/firmware/stepper_nano_zero/eeprom.h b/firmware/stepper_nano_zero/eeprom.h index 1cde37f..75154eb 100644 --- a/firmware/stepper_nano_zero/eeprom.h +++ b/firmware/stepper_nano_zero/eeprom.h @@ -1,29 +1,40 @@ -/* - * eeprom.h - * - * Created on: May 30, 2017 - * Author: tstern - * Copyright (C) 2018 MisfitTech, All rights reserved. +/********************************************************************** + Copyright (C) 2018 MisfitTech LLC, All rights reserved. + + MisfitTech uses a dual license model that allows the software to be used under + a standard GPL open source license, or a commercial license. The standard GPL + license requires that all software statically linked with MisfitTec Code is + also distributed under the same GPL V2 license terms. Details of both license + options follow: + + - Open source licensing - + MisfitTech is a free download and may be used, modified, evaluated and + distributed without charge provided the user adheres to version two of the GNU + General Public License (GPL) and does not remove the copyright notice or this + text. The GPL V2 text is available on the gnu.org web site - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License. + - Commercial licensing - + Businesses and individuals that for commercial or other reasons cannot comply + with the terms of the GPL V2 license must obtain a low cost commercial license + before incorporating MisfitTech code into proprietary software for distribution in + any form. Commercial licenses can be purchased from www.misfittech.net + and do not require any source files to be changed. - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - You should have received a copy of the GNU General Public License - along with this program. If not, see . + This code is distributed in the hope that it will be useful. You cannot + use MisfitTech's code unless you agree that you use the software 'as is'. + MisfitTech's code is provided WITHOUT ANY WARRANTY; without even the implied + warranties of NON-INFRINGEMENT, MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. MisfitTech LLC disclaims all conditions and terms, be they + implied, expressed, or statutory. + Written by Trampas Stern for MisfitTech. Misfit Tech invests time and resources providing this open source code, please support MisfitTech and open-source hardware by purchasing products from MisfitTech, www.misifittech.net! - */ - + *********************************************************************/ #ifndef EEPROM_H_ #define EEPROM_H_ #include "Flash.h" diff --git a/firmware/stepper_nano_zero/fet_driver.cpp b/firmware/stepper_nano_zero/fet_driver.cpp index 19f18dd..cfe9b4e 100644 --- a/firmware/stepper_nano_zero/fet_driver.cpp +++ b/firmware/stepper_nano_zero/fet_driver.cpp @@ -1,22 +1,33 @@ -/* - * fet_driver.cpp - * - * Created on: Dec 24, 2016 - * Author: tstern - * - Copyright (C) 2018 MisfitTech, All rights reserved. - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. +/********************************************************************** + Copyright (C) 2018 MisfitTech LLC, All rights reserved. + + MisfitTech uses a dual license model that allows the software to be used under + a standard GPL open source license, or a commercial license. The standard GPL + license requires that all software statically linked with MisfitTec Code is + also distributed under the same GPL V2 license terms. Details of both license + options follow: + + - Open source licensing - + MisfitTech is a free download and may be used, modified, evaluated and + distributed without charge provided the user adheres to version two of the GNU + General Public License (GPL) and does not remove the copyright notice or this + text. The GPL V2 text is available on the gnu.org web site + + - Commercial licensing - + Businesses and individuals that for commercial or other reasons cannot comply + with the terms of the GPL V2 license must obtain a low cost commercial license + before incorporating MisfitTech code into proprietary software for distribution in + any form. Commercial licenses can be purchased from www.misfittech.net + and do not require any source files to be changed. + + + This code is distributed in the hope that it will be useful. You cannot + use MisfitTech's code unless you agree that you use the software 'as is'. + MisfitTech's code is provided WITHOUT ANY WARRANTY; without even the implied + warranties of NON-INFRINGEMENT, MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. MisfitTech LLC disclaims all conditions and terms, be they + implied, expressed, or statutory. - You should have received a copy of the GNU General Public License - along with this program. If not, see . Written by Trampas Stern for MisfitTech. diff --git a/firmware/stepper_nano_zero/fet_driver.h b/firmware/stepper_nano_zero/fet_driver.h index 4f3a0ee..a056897 100644 --- a/firmware/stepper_nano_zero/fet_driver.h +++ b/firmware/stepper_nano_zero/fet_driver.h @@ -1,22 +1,33 @@ -/* - * fet_driver.h - * - * Created on: Dec 24, 2016 - * Author: tstern - * - Copyright (C) 2018 MisfitTech, All rights reserved. - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. +/********************************************************************** + Copyright (C) 2018 MisfitTech LLC, All rights reserved. + + MisfitTech uses a dual license model that allows the software to be used under + a standard GPL open source license, or a commercial license. The standard GPL + license requires that all software statically linked with MisfitTec Code is + also distributed under the same GPL V2 license terms. Details of both license + options follow: + + - Open source licensing - + MisfitTech is a free download and may be used, modified, evaluated and + distributed without charge provided the user adheres to version two of the GNU + General Public License (GPL) and does not remove the copyright notice or this + text. The GPL V2 text is available on the gnu.org web site + + - Commercial licensing - + Businesses and individuals that for commercial or other reasons cannot comply + with the terms of the GPL V2 license must obtain a low cost commercial license + before incorporating MisfitTech code into proprietary software for distribution in + any form. Commercial licenses can be purchased from www.misfittech.net + and do not require any source files to be changed. + + + This code is distributed in the hope that it will be useful. You cannot + use MisfitTech's code unless you agree that you use the software 'as is'. + MisfitTech's code is provided WITHOUT ANY WARRANTY; without even the implied + warranties of NON-INFRINGEMENT, MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. MisfitTech LLC disclaims all conditions and terms, be they + implied, expressed, or statutory. - You should have received a copy of the GNU General Public License - along with this program. If not, see . Written by Trampas Stern for MisfitTech. diff --git a/firmware/stepper_nano_zero/ftoa.cpp b/firmware/stepper_nano_zero/ftoa.cpp index bbc4404..8ff7f42 100644 --- a/firmware/stepper_nano_zero/ftoa.cpp +++ b/firmware/stepper_nano_zero/ftoa.cpp @@ -1,24 +1,40 @@ -/* - * Copyright (C) 2018 MisfitTech, All rights reserved. +/********************************************************************** + Copyright (C) 2018 MisfitTech LLC, All rights reserved. - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License. + MisfitTech uses a dual license model that allows the software to be used under + a standard GPL open source license, or a commercial license. The standard GPL + license requires that all software statically linked with MisfitTec Code is + also distributed under the same GPL V2 license terms. Details of both license + options follow: - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. + - Open source licensing - + MisfitTech is a free download and may be used, modified, evaluated and + distributed without charge provided the user adheres to version two of the GNU + General Public License (GPL) and does not remove the copyright notice or this + text. The GPL V2 text is available on the gnu.org web site + + - Commercial licensing - + Businesses and individuals that for commercial or other reasons cannot comply + with the terms of the GPL V2 license must obtain a low cost commercial license + before incorporating MisfitTech code into proprietary software for distribution in + any form. Commercial licenses can be purchased from www.misfittech.net + and do not require any source files to be changed. + + + This code is distributed in the hope that it will be useful. You cannot + use MisfitTech's code unless you agree that you use the software 'as is'. + MisfitTech's code is provided WITHOUT ANY WARRANTY; without even the implied + warranties of NON-INFRINGEMENT, MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. MisfitTech LLC disclaims all conditions and terms, be they + implied, expressed, or statutory. - You should have received a copy of the GNU General Public License - along with this program. If not, see . Written by Trampas Stern for MisfitTech. Misfit Tech invests time and resources providing this open source code, please support MisfitTech and open-source hardware by purchasing products from MisfitTech, www.misifittech.net! - */ + *********************************************************************/ #include "board.h" #include "ftoa.h" /******************************************************************* diff --git a/firmware/stepper_nano_zero/ftoa.h b/firmware/stepper_nano_zero/ftoa.h index ff6d073..55000ff 100644 --- a/firmware/stepper_nano_zero/ftoa.h +++ b/firmware/stepper_nano_zero/ftoa.h @@ -1,28 +1,40 @@ -/* - * ftoa.h - * - * Created on: Jan 6, 2017 - * Author: tstern - * Copyright (C) 2018 MisfitTech, All rights reserved. +/********************************************************************** + Copyright (C) 2018 MisfitTech LLC, All rights reserved. - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License. + MisfitTech uses a dual license model that allows the software to be used under + a standard GPL open source license, or a commercial license. The standard GPL + license requires that all software statically linked with MisfitTec Code is + also distributed under the same GPL V2 license terms. Details of both license + options follow: - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. + - Open source licensing - + MisfitTech is a free download and may be used, modified, evaluated and + distributed without charge provided the user adheres to version two of the GNU + General Public License (GPL) and does not remove the copyright notice or this + text. The GPL V2 text is available on the gnu.org web site + + - Commercial licensing - + Businesses and individuals that for commercial or other reasons cannot comply + with the terms of the GPL V2 license must obtain a low cost commercial license + before incorporating MisfitTech code into proprietary software for distribution in + any form. Commercial licenses can be purchased from www.misfittech.net + and do not require any source files to be changed. + + + This code is distributed in the hope that it will be useful. You cannot + use MisfitTech's code unless you agree that you use the software 'as is'. + MisfitTech's code is provided WITHOUT ANY WARRANTY; without even the implied + warranties of NON-INFRINGEMENT, MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. MisfitTech LLC disclaims all conditions and terms, be they + implied, expressed, or statutory. - You should have received a copy of the GNU General Public License - along with this program. If not, see . Written by Trampas Stern for MisfitTech. Misfit Tech invests time and resources providing this open source code, please support MisfitTech and open-source hardware by purchasing products from MisfitTech, www.misifittech.net! - */ + *********************************************************************/ #ifndef FTOA_H_ #define FTOA_H_ diff --git a/firmware/stepper_nano_zero/nonvolatile.cpp b/firmware/stepper_nano_zero/nonvolatile.cpp index f22fc0d..627e21e 100644 --- a/firmware/stepper_nano_zero/nonvolatile.cpp +++ b/firmware/stepper_nano_zero/nonvolatile.cpp @@ -1,19 +1,33 @@ /********************************************************************** - * Author: tstern - * - Copyright (C) 2018 MisfitTech, All rights reserved. + Copyright (C) 2018 MisfitTech LLC, All rights reserved. - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License. + MisfitTech uses a dual license model that allows the software to be used under + a standard GPL open source license, or a commercial license. The standard GPL + license requires that all software statically linked with MisfitTec Code is + also distributed under the same GPL V2 license terms. Details of both license + options follow: - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. + - Open source licensing - + MisfitTech is a free download and may be used, modified, evaluated and + distributed without charge provided the user adheres to version two of the GNU + General Public License (GPL) and does not remove the copyright notice or this + text. The GPL V2 text is available on the gnu.org web site + + - Commercial licensing - + Businesses and individuals that for commercial or other reasons cannot comply + with the terms of the GPL V2 license must obtain a low cost commercial license + before incorporating MisfitTech code into proprietary software for distribution in + any form. Commercial licenses can be purchased from www.misfittech.net + and do not require any source files to be changed. + + + This code is distributed in the hope that it will be useful. You cannot + use MisfitTech's code unless you agree that you use the software 'as is'. + MisfitTech's code is provided WITHOUT ANY WARRANTY; without even the implied + warranties of NON-INFRINGEMENT, MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. MisfitTech LLC disclaims all conditions and terms, be they + implied, expressed, or statutory. - You should have received a copy of the GNU General Public License - along with this program. If not, see . Written by Trampas Stern for MisfitTech. @@ -36,7 +50,7 @@ __attribute__((__aligned__(FLASH_ROW_SIZE))) const uint16_t NVM_flash[16767]={ #else __attribute__((__aligned__(FLASH_ROW_SIZE))) const uint16_t NVM_flash[256]={ //allocates 512 bytes #endif -//35791,36134,36471,36788,37122,37463,37801,38118,38451,38791,39127,39447,39778,40121,40457,40783,41114,41459,41797,42120,42455,42801,43140,43465,43803,44151,44493,44818,45156,45506,45851,46178,46519,46869,47215,47542,47886,48236,48582,48910,49252,49605,49947,50272,50615,50963,51303,51631,51968,52316,52652,52974,53313,53654,53989,54307,54642,54980,55314,55630,55959,56299,56633,56946,57273,57615,57948,58259,58585,58926,59261,59575,59901,60242,60574,60888,61217,61558,61892,62208,62538,62878,63213,63528,63855,64195,64526,64844,65169,65507,304,618,941,1278,1609,1918,2238,2574,2901,3208,3529,3860,4188,4491,4810,5143,5463,5770,6089,6415,6737,7044,7359,7688,8009,8313,8629,8955,9276,9583,9898,10223,10544,10849,11163,11485,11806,12108,12423,12746,13066,13368,13680,14005,14323,14621,14935,15259,15576,15876,16189,16513,16827,17133,17445,17771,18088,18393,18709,19031,19352,19656,19976,20304,20627,20933,21254,21585,21908,22219,22540,22873,23200,23510,23835,24172,24502,24813,25141,25479,25810,26125,26454,26797,27130,27447,27777,28122,28456,28777,29110,29456,29792,30114,30449,30790,31131,31453,31786,32131,32471,32793,33127,33472,33809,34129,34462,34806,35143,35464, +//59962,60291,60621,60949,61267,61596,61924,62252,62567,62897,63223,63548,63865,64192,64518,64842,65157,65482,274,600,917,1247,1573,1902,2225,2560,2892,3225,3550,3888,4226,4564,4893,5234,5575,5914,6246,6587,6930,7267,7596,7937,8275,8611,8936,9274,9606,9940,10262,10594,10925,11253,11572,11902,12228,12553,12870,13195,13518,13844,14159,14480,14801,15123,15435,15756,16078,16398,16708,17031,17350,17675,17988,18312,18640,18965,19282,19609,19943,20271,20593,20924,21257,21589,21914,22250,22586,22920,23241,23578,23912,24245,24570,24902,25236,25567,25887,26219,26549,26877,27196,27524,27851,28178,28496,28823,29145,29470,29788,30112,30436,30759,31074,31396,31720,32041,32355,32681,33003,33329,33644,33971,34297,34625,34947,35278,35610,35941,36271,36605,36944,37280,37609,37948,38287,38625,38960,39300,39640,39977,40308,40651,40988,41325,41653,41989,42326,42655,42982,43316,43646,43976,44294,44626,44951,45277,45598,45924,46250,46572,46888,47212,47536,47856,48167,48490,48813,49133,49447,49769,50091,50412,50726,51051,51377,51701,52022,52353,52681,53013,53334,53668,53999,54334,54661,54997,55331,55665,55991,56330,56664,57001,57326,57662,57994,58327,58650,58981,59313,59641, 0xFFFF }; diff --git a/firmware/stepper_nano_zero/nonvolatile.h b/firmware/stepper_nano_zero/nonvolatile.h index 07f7b71..3e29c03 100644 --- a/firmware/stepper_nano_zero/nonvolatile.h +++ b/firmware/stepper_nano_zero/nonvolatile.h @@ -1,19 +1,33 @@ /********************************************************************** - * Author: tstern - * - Copyright (C) 2018 MisfitTech, All rights reserved. + Copyright (C) 2018 MisfitTech LLC, All rights reserved. - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License. + MisfitTech uses a dual license model that allows the software to be used under + a standard GPL open source license, or a commercial license. The standard GPL + license requires that all software statically linked with MisfitTec Code is + also distributed under the same GPL V2 license terms. Details of both license + options follow: - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. + - Open source licensing - + MisfitTech is a free download and may be used, modified, evaluated and + distributed without charge provided the user adheres to version two of the GNU + General Public License (GPL) and does not remove the copyright notice or this + text. The GPL V2 text is available on the gnu.org web site + + - Commercial licensing - + Businesses and individuals that for commercial or other reasons cannot comply + with the terms of the GPL V2 license must obtain a low cost commercial license + before incorporating MisfitTech code into proprietary software for distribution in + any form. Commercial licenses can be purchased from www.misfittech.net + and do not require any source files to be changed. + + + This code is distributed in the hope that it will be useful. You cannot + use MisfitTech's code unless you agree that you use the software 'as is'. + MisfitTech's code is provided WITHOUT ANY WARRANTY; without even the implied + warranties of NON-INFRINGEMENT, MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. MisfitTech LLC disclaims all conditions and terms, be they + implied, expressed, or statutory. - You should have received a copy of the GNU General Public License - along with this program. If not, see . Written by Trampas Stern for MisfitTech. diff --git a/firmware/stepper_nano_zero/nzs.cpp b/firmware/stepper_nano_zero/nzs.cpp index 4c93924..400a449 100644 --- a/firmware/stepper_nano_zero/nzs.cpp +++ b/firmware/stepper_nano_zero/nzs.cpp @@ -31,6 +31,7 @@ #include "angle.h" #include "eeprom.h" #include "steppin.h" +#include "wiring_private.h" #pragma GCC push_options #pragma GCC optimize ("-Ofast") @@ -637,7 +638,9 @@ void NZS::begin(void) #ifndef CMD_SERIAL_PORT - SysLogInit(&Serial5,LOG_DEBUG); //use SWO for the sysloging + SysLogInit(&Serial5,LOG_DEBUG); + pinPeripheral(PIN_TXD, PIO_SERCOM_ALT); + pinPeripheral(PIN_RXD, PIO_SERCOM_ALT); #else SysLogInit(NULL, LOG_WARNING); #endif diff --git a/firmware/stepper_nano_zero/stepper_controller.cpp b/firmware/stepper_nano_zero/stepper_controller.cpp index 08cbbfc..4eb6ef5 100644 --- a/firmware/stepper_nano_zero/stepper_controller.cpp +++ b/firmware/stepper_nano_zero/stepper_controller.cpp @@ -37,8 +37,6 @@ volatile bool TC5_ISR_Enabled=false; void setupTCInterrupts() { - - // Enable GCLK for TC4 and TC5 (timer counter input clock) GCLK->CLKCTRL.reg = (uint16_t) (GCLK_CLKCTRL_CLKEN | GCLK_CLKCTRL_GEN_GCLK0 | GCLK_CLKCTRL_ID(GCM_TC4_TC5)); while (GCLK->STATUS.bit.SYNCBUSY); diff --git a/firmware/stepper_nano_zero/stepper_controller.h b/firmware/stepper_nano_zero/stepper_controller.h index 75a3c2b..620dc64 100644 --- a/firmware/stepper_nano_zero/stepper_controller.h +++ b/firmware/stepper_nano_zero/stepper_controller.h @@ -27,6 +27,7 @@ #include "syslog.h" #include "board.h" #include "as5047d.h" +#include "A1333.h" #include "calibration.h" #include "A4954.h" #include "A5995.h" @@ -52,7 +53,7 @@ typedef struct { } PID_t; - typedef __attribute__((packed, aligned(4))) struct { + typedef __attribute__((aligned(4))) struct { int32_t microSecs; int32_t desiredLoc; int32_t actualLoc; @@ -77,7 +78,13 @@ class StepperCtrl { private: volatile bool enableFeedback; //true if we are using PID control algorithm + +#ifdef A1333_ENCODER + A1333 encoder; +#else AS5047D encoder; +#endif + #ifdef NEMA_23_10A_HW FetDriver stepperDriver; #else diff --git a/firmware/stepper_nano_zero/steppin.cpp b/firmware/stepper_nano_zero/steppin.cpp index db3a21b..8eb5659 100644 --- a/firmware/stepper_nano_zero/steppin.cpp +++ b/firmware/stepper_nano_zero/steppin.cpp @@ -28,29 +28,41 @@ extern StepperCtrl stepperCtrl; volatile int32_t stepsChanged=0; volatile int64_t steps=0; -#define WAIT_TC32_REGS_SYNC(x) while(x->COUNT16.STATUS.bit.SYNCBUSY); + #if (PIN_STEP_INPUT != 0) #error "this code only works with step pin being D0 (PA11, EXTINT11)" #endif -void TC4_Handler() +#define WAIT_TCC2_SYNC() while(TCC2->SYNCBUSY.reg) + +void checkDir(void) { -// if (TC4->COUNT16.INTFLAG.bit.OVF == 1) -// { -// TC4->COUNT16.INTFLAG.bit.OVF = 1; // writing a one clears the flag ovf flag -// RED_LED(true); -// if (TC4->COUNT16.CTRLBSET.bit.DIR) -// { -// //we are counting up -// stepsHigh-=1ul<<16; -// } else -// { -// stepsHigh+=1ul<<16; -// } -// -// } + int dir=1; + static int lastDir=-1; + + + if (CW_ROTATION == NVM->SystemParams.dirPinRotation) + { + dir=0; //reverse the rotation + } + + if (lastDir != dir) + { + if (dir) + { + EIC->CONFIG[1].reg &= ~EIC_CONFIG_SENSE2_Msk; + EIC->CONFIG[1].reg |= EIC_CONFIG_SENSE2_HIGH; + + } else + { + EIC->CONFIG[1].reg &= ~EIC_CONFIG_SENSE2_Msk; + EIC->CONFIG[1].reg |= EIC_CONFIG_SENSE2_LOW; + } + lastDir=dir; + } + } //this function can not be called in interrupt context as the overflow interrupt for tC4 needs to run. @@ -65,9 +77,16 @@ int64_t getSteps(void) uint16_t y; static uint16_t lasty=0; - y=TC4->COUNT16.COUNT.reg; - steps += int16_t(y-lasty); + TCC2->CTRLBSET.reg=TCC_CTRLBSET_CMD_READSYNC; + WAIT_TCC2_SYNC(); + + + y=(uint16_t)(TCC2->COUNT.reg & 0x0FFFFul); //use only lowest 16bits + //LOG("count is %d",y); + steps += (int16_t)(y-lasty); lasty=y; + + checkDir(); return steps; #else @@ -78,6 +97,10 @@ int64_t getSteps(void) return x; #endif } + + + + //this function is called on the rising edge of a step from external device static void stepInput(void) { @@ -119,6 +142,9 @@ void enableEIC(void) } + + + void setupStepEvent(void) { //we will set up the EIC to generate an even on rising edge of step pin @@ -130,13 +156,22 @@ void setupStepEvent(void) // Step pin is PA11, EXTINT11 pinPeripheral(PIN_STEP_INPUT, PIO_EXTINT); + //set up the direction pin PA10 to trigger external interrupt + pinPeripheral(PIN_DIR_INPUT, PIO_EXTINT); //EXTINT10 + + //***** setup EIC ****** EIC->EVCTRL.bit.EXTINTEO11=1; //enable event for EXTINT11 + EIC->EVCTRL.bit.EXTINTEO10=1; //enable event for EXTINT10 //setup up external interurpt 11 to be rising edge triggered - EIC->CONFIG[1].reg |= EIC_CONFIG_SENSE3_RISE; + //setup up external interurpt 10 to be both edge triggered + EIC->CONFIG[1].reg |= EIC_CONFIG_SENSE3_RISE | EIC_CONFIG_SENSE2_HIGH; + + checkDir(); - //diable actually generating an interrupt, we only want event triggered + //disable actually generating an interrupt, we only want event triggered EIC->INTENCLR.reg = EIC_INTENCLR_EXTINT11; + EIC->INTENCLR.reg = EIC_INTENCLR_EXTINT10; //**** setup the event system *** // Enable GCLK for EVSYS channel 0 @@ -144,72 +179,116 @@ void setupStepEvent(void) GCLK->CLKCTRL.reg = (uint16_t) (GCLK_CLKCTRL_CLKEN | GCLK_CLKCTRL_GEN_GCLK0 | GCLK_CLKCTRL_ID(GCM_EVSYS_CHANNEL_0)); while (GCLK->STATUS.bit.SYNCBUSY); + GCLK->CLKCTRL.reg = (uint16_t) (GCLK_CLKCTRL_CLKEN | GCLK_CLKCTRL_GEN_GCLK0 | GCLK_CLKCTRL_ID(GCM_EVSYS_CHANNEL_1)); + while (GCLK->STATUS.bit.SYNCBUSY); + + //setup the step pin to trigger event 0 on the TCC2 (step) EVSYS->CHANNEL.reg=EVSYS_CHANNEL_CHANNEL(0) | EVSYS_CHANNEL_EDGSEL_RISING_EDGE | EVSYS_CHANNEL_EVGEN(EVSYS_ID_GEN_EIC_EXTINT_11) | EVSYS_CHANNEL_PATH_ASYNCHRONOUS; EVSYS->USER.reg = EVSYS_USER_CHANNEL(1) - | EVSYS_USER_USER(EVSYS_ID_USER_TC4_EVU); + | EVSYS_USER_USER(EVSYS_ID_USER_TCC2_EV_0); + + //setup the dir pin to trigger event 2 on the TCC2 (dir change) + EVSYS->CHANNEL.reg=EVSYS_CHANNEL_CHANNEL(1) + | EVSYS_CHANNEL_EDGSEL_BOTH_EDGES + | EVSYS_CHANNEL_EVGEN(EVSYS_ID_GEN_EIC_EXTINT_10) + | EVSYS_CHANNEL_PATH_ASYNCHRONOUS; + + EVSYS->USER.reg = EVSYS_USER_CHANNEL(2) + | EVSYS_USER_USER(EVSYS_ID_USER_TCC2_EV_1); //**** setup the Timer counter ****** - PM->APBCMASK.reg |= PM_APBCMASK_TC4; - // Enable GCLK for TC4 and TC5 (timer counter input clock) - GCLK->CLKCTRL.reg = (uint16_t) (GCLK_CLKCTRL_CLKEN | GCLK_CLKCTRL_GEN_GCLK0 | GCLK_CLKCTRL_ID(GCM_TC4_TC5)); + PM->APBCMASK.reg |= PM_APBCMASK_TCC2; + + // Enable GCLK for TCC2 (timer counter input clock) + GCLK->CLKCTRL.reg = (uint16_t) (GCLK_CLKCTRL_CLKEN | GCLK_CLKCTRL_GEN_GCLK0 | GCLK_CLKCTRL_ID(GCM_TCC2_TC3)); while (GCLK->STATUS.bit.SYNCBUSY); - TC4->COUNT16.CTRLA.reg = TC_CTRLA_SWRST; //reset TC4 - WAIT_TC32_REGS_SYNC(TC4) - TC4->COUNT16.CTRLA.reg = TC_CTRLA_MODE_COUNT16 // Set Timer counter Mode to 16 bits - | TC_CTRLA_WAVEGEN_NFRQ //normal counting mode (not using waveforms) - | TC_CTRLA_PRESCALER_DIV1; //count each pulse - WAIT_TC32_REGS_SYNC(TC4) - TC4->COUNT16.CTRLBCLR.reg=0xFF; //clear all values. - WAIT_TC32_REGS_SYNC(TC4) + TCC2->CTRLA.reg &= ~TCC_CTRLA_ENABLE; + WAIT_TCC2_SYNC(); + + TCC2->CTRLA.reg= TCC_CTRLA_SWRST; //reset TCC2 + WAIT_TCC2_SYNC(); + while(TCC2->CTRLA.bit.SWRST ==1); + + + //TCC2->WAVE.reg = TCC_WAVE_WAVEGEN_NFRQ; + //WAIT_TCC2_SYNC(); + + TCC2->EVCTRL.reg=TCC_EVCTRL_EVACT0_COUNTEV | TCC_EVCTRL_TCEI0 + | TCC_EVCTRL_EVACT1_DIR | TCC_EVCTRL_TCEI1; + WAIT_TCC2_SYNC(); + - TC4->COUNT16.EVCTRL.reg=TC_EVCTRL_TCEI | TC_EVCTRL_EVACT_COUNT; //enable event input and count - WAIT_TC32_REGS_SYNC(TC4) + TCC2->COUNT.reg=0; + WAIT_TCC2_SYNC(); - TC4->COUNT16.COUNT.reg=0; - WAIT_TC32_REGS_SYNC(TC4) + //TCC2->CTRLBSET.bit.CMD=TCC_CTRLBSET_CMD_RETRIGGER; + //checkDirPin(); + TCC2->CTRLBSET.bit.DIR=1; + + WAIT_TCC2_SYNC(); + TCC2->CTRLA.reg |=TCC_CTRLA_ENABLE; + WAIT_TCC2_SYNC(); + + + //checkDirPin(); + +// +// TC4->COUNT16.CTRLA.reg = TC_CTRLA_MODE_COUNT16 // Set Timer counter Mode to 16 bits +// | TC_CTRLA_WAVEGEN_NFRQ //normal counting mode (not using waveforms) +// | TC_CTRLA_PRESCALER_DIV1; //count each pulse +// WAIT_TC32_REGS_SYNC(TC4) +// +// TC4->COUNT16.CTRLBCLR.reg=0xFF; //clear all values. +// WAIT_TC32_REGS_SYNC(TC4) +// +// TC4->COUNT16.EVCTRL.reg=TC_EVCTRL_TCEI | TC_EVCTRL_EVACT_COUNT; //enable event input and count +// WAIT_TC32_REGS_SYNC(TC4) +// +// TC4->COUNT16.COUNT.reg=0; +// WAIT_TC32_REGS_SYNC(TC4) // // TC4->COUNT16.INTENSET.bit.OVF = 1; //enable over/under flow interrupt // //setup the TC overflow/underflow interrupt // NVIC_SetPriority(TC4_IRQn, 0); // // Enable InterruptVector // NVIC_EnableIRQ(TC4_IRQn); - - - // Enable TC - TC4->COUNT16.CTRLA.reg |= TC_CTRLA_ENABLE; - WAIT_TC32_REGS_SYNC(TC4) +// +// +// // Enable TC +// TC4->COUNT16.CTRLA.reg |= TC_CTRLA_ENABLE; +// WAIT_TC32_REGS_SYNC(TC4) } -static void dirChanged_ISR(void) -{ - int dir=0; - //read our direction pin - //dir = digitalRead(PIN_DIR_INPUT); - if ( (PORT->Group[g_APinDescription[PIN_DIR_INPUT].ulPort].IN.reg & (1ul << g_APinDescription[PIN_DIR_INPUT].ulPin)) != 0 ) - { - dir=1; - } - - - if (CW_ROTATION == NVM->SystemParams.dirPinRotation) - { - dir=!dir; //reverse the rotation - } - if (dir) - { - TC4->COUNT16.CTRLBSET.bit.DIR=1; - } else - { - TC4->COUNT16.CTRLBCLR.bit.DIR=1; - } -} +//static void dirChanged_ISR(void) +//{ +// int dir=0; +// //read our direction pin +// //dir = digitalRead(PIN_DIR_INPUT); +// if ( (PORT->Group[g_APinDescription[PIN_DIR_INPUT].ulPort].IN.reg & (1ul << g_APinDescription[PIN_DIR_INPUT].ulPin)) != 0 ) +// { +// dir=1; +// } +// +// +// if (CW_ROTATION == NVM->SystemParams.dirPinRotation) +// { +// dir=!dir; //reverse the rotation +// } +// if (dir) +// { +// TC4->COUNT16.CTRLBSET.bit.DIR=1; +// } else +// { +// TC4->COUNT16.CTRLBCLR.bit.DIR=1; +// } +//} void stepPinSetup(void) @@ -218,13 +297,13 @@ void stepPinSetup(void) #ifdef USE_TC_STEP - //setup the direction pin - dirChanged_ISR(); - - //attachInterrupt configures the EIC as highest priority interrupts. - attachInterrupt(digitalPinToInterrupt(PIN_DIR_INPUT), dirChanged_ISR, CHANGE); +// //setup the direction pin +// dirChanged_ISR(); +// +// //attachInterrupt configures the EIC as highest priority interrupts. +// attachInterrupt(digitalPinToInterrupt(PIN_DIR_INPUT), dirChanged_ISR, CHANGE); setupStepEvent(); - NVIC_SetPriority(EIC_IRQn, 1); //set port A interrupt as highest priority +// NVIC_SetPriority(EIC_IRQn, 1); //set port A interrupt as highest priority #else