Initial commit

This commit is contained in:
Mario Voigt 2020-07-20 22:21:36 +02:00
commit ec6085f726
89 changed files with 59574 additions and 0 deletions

BIN
abc_measurements.xlsx Normal file

Binary file not shown.

View File

@ -0,0 +1,122 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?fileVersion 4.0.0?><cproject storage_type_id="org.eclipse.cdt.core.XmlProjectDescriptionStorage">
<storageModule moduleId="org.eclipse.cdt.core.settings">
<cconfiguration id="cdt.managedbuild.toolchain.gnu.cross.base.1504376676">
<storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="cdt.managedbuild.toolchain.gnu.cross.base.1504376676" moduleId="org.eclipse.cdt.core.settings" name="Default">
<externalSettings>
<externalSetting>
<entry flags="RESOLVED" kind="includePath" name="C:\Users\tstern\AppData\Local\Arduino15\packages\misfittech\hardware\samd\1.0.0\variants\nano_zero"/>
<entry flags="RESOLVED" kind="includePath" name="C:\Users\tstern\AppData\Local\Arduino15\packages\misfittech\hardware\samd\1.0.0\cores\arduino"/>
</externalSetting>
</externalSettings>
<extensions>
<extension id="org.eclipse.cdt.core.ELF" point="org.eclipse.cdt.core.BinaryParser"/>
<extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.CWDLocator" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
</extensions>
</storageModule>
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
<configuration artifactName="${ProjName}" buildProperties="" description="" id="cdt.managedbuild.toolchain.gnu.cross.base.1504376676" name="Default" parent="org.eclipse.cdt.build.core.emptycfg">
<folderInfo id="cdt.managedbuild.toolchain.gnu.cross.base.1504376676.350447049" name="/" resourcePath="">
<toolChain id="cdt.managedbuild.toolchain.gnu.cross.base.515513271" name="Cross GCC" superClass="cdt.managedbuild.toolchain.gnu.cross.base">
<option id="cdt.managedbuild.option.gnu.cross.prefix.582370251" name="Prefix" superClass="cdt.managedbuild.option.gnu.cross.prefix"/>
<option id="cdt.managedbuild.option.gnu.cross.path.231717393" name="Path" superClass="cdt.managedbuild.option.gnu.cross.path"/>
<targetPlatform archList="all" binaryParser="org.eclipse.cdt.core.ELF" id="cdt.managedbuild.targetPlatform.gnu.cross.1339435354" isAbstract="false" osList="all" superClass="cdt.managedbuild.targetPlatform.gnu.cross"/>
<builder id="cdt.managedbuild.builder.gnu.cross.241627781" keepEnvironmentInBuildfile="false" managedBuildOn="false" name="Gnu Make Builder" superClass="cdt.managedbuild.builder.gnu.cross">
<outputEntries/>
</builder>
<tool id="cdt.managedbuild.tool.gnu.cross.c.compiler.1805317535" name="Cross GCC Compiler" superClass="cdt.managedbuild.tool.gnu.cross.c.compiler">
<option id="gnu.c.compiler.option.include.paths.1641555759" name="Include paths (-I)" superClass="gnu.c.compiler.option.include.paths" useByScannerDiscovery="false" valueType="includePath">
<listOptionValue builtIn="false" value="&quot;C:\Users\tstern\AppData\Local\Arduino15\packages\misfittech\hardware\samd\1.0.0\variants\nano_zero&quot;"/>
<listOptionValue builtIn="false" value="&quot;C:\Users\tstern\Documents\Arduino\libraries\Adafruit_SSD1306-master&quot;"/>
<listOptionValue builtIn="false" value="&quot;C:\Users\tstern\Documents\Arduino\libraries\Adafruit-GFX-Library-master&quot;"/>
<listOptionValue builtIn="false" value="&quot;C:\Users\tstern\AppData\Local\Arduino15\packages\arduino\tools\CMSIS\4.0.0-atmel\Device\ATMEL\samd21\include&quot;"/>
<listOptionValue builtIn="false" value="&quot;C:\Users\tstern\AppData\Local\Arduino15\packages\arduino\tools\CMSIS\4.0.0-atmel\Device\ATMEL\samd21\include\pio&quot;"/>
<listOptionValue builtIn="false" value="&quot;C:\Users\tstern\AppData\Local\Arduino15\packages\arduino\tools\CMSIS\4.0.0-atmel\Device\ATMEL\samd21\include\instance&quot;"/>
<listOptionValue builtIn="false" value="&quot;C:\Users\tstern\AppData\Local\Arduino15\packages\arduino\tools\CMSIS\4.0.0-atmel\Device\ATMEL\samd21\include\component&quot;"/>
<listOptionValue builtIn="false" value="&quot;C:\Users\tstern\AppData\Local\Arduino15\packages\misfittech\hardware\samd\1.0.0\cores\arduino&quot;"/>
<listOptionValue builtIn="false" value="&quot;C:\Users\tstern\AppData\Local\Arduino15\packages\arduino\tools\CMSIS\4.0.0-atmel\Device\ATMEL&quot;"/>
<listOptionValue builtIn="false" value="&quot;C:\Users\TSTERN\AppData\Local\Arduino15\packages\arduino\hardware\samd\1.6.6\libraries\SPI&quot;"/>
<listOptionValue builtIn="false" value="&quot;C:\Users\tstern\AppData\Local\Arduino15\packages\arduino\tools\CMSIS\4.0.0-atmel\CMSIS\include&quot;"/>
</option>
<option id="gnu.c.compiler.option.preprocessor.def.symbols.77778103" name="Defined symbols (-D)" superClass="gnu.c.compiler.option.preprocessor.def.symbols" useByScannerDiscovery="false" valueType="definedSymbols">
<listOptionValue builtIn="false" value="ARDUINO_SAMD_ZERO"/>
<listOptionValue builtIn="false" value="__SAMD21G18A__"/>
</option>
<inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.1328245026" superClass="cdt.managedbuild.tool.gnu.c.compiler.input"/>
</tool>
<tool id="cdt.managedbuild.tool.gnu.cross.cpp.compiler.1543385682" name="Cross G++ Compiler" superClass="cdt.managedbuild.tool.gnu.cross.cpp.compiler">
<option id="gnu.cpp.compiler.option.include.paths.784350866" name="Include paths (-I)" superClass="gnu.cpp.compiler.option.include.paths" useByScannerDiscovery="false" valueType="includePath">
<listOptionValue builtIn="false" value="&quot;C:\Users\tstern\AppData\Local\Arduino15\packages\misfittech\hardware\samd\1.0.0\cores\arduino&quot;"/>
<listOptionValue builtIn="false" value="&quot;C:\Users\tstern\AppData\Local\Arduino15\packages\misfittech\hardware\samd\1.0.0\variants\nano_zero&quot;"/>
<listOptionValue builtIn="false" value="&quot;C:\Users\tstern\Documents\Arduino\libraries\Adafruit_SSD1306-master&quot;"/>
<listOptionValue builtIn="false" value="&quot;C:\Users\tstern\Documents\Arduino\libraries\Adafruit-GFX-Library-master&quot;"/>
<listOptionValue builtIn="false" value="&quot;C:\Users\tstern\AppData\Local\Arduino15\packages\arduino\tools\CMSIS\4.0.0-atmel\Device\ATMEL\samd21\include&quot;"/>
<listOptionValue builtIn="false" value="&quot;C:\Users\tstern\AppData\Local\Arduino15\packages\arduino\tools\CMSIS\4.0.0-atmel\Device\ATMEL\samd21\include\pio&quot;"/>
<listOptionValue builtIn="false" value="&quot;C:\Users\tstern\AppData\Local\Arduino15\packages\arduino\tools\CMSIS\4.0.0-atmel\Device\ATMEL\samd21\include\instance&quot;"/>
<listOptionValue builtIn="false" value="&quot;C:\Users\tstern\AppData\Local\Arduino15\packages\arduino\tools\CMSIS\4.0.0-atmel\Device\ATMEL\samd21\include\component&quot;"/>
<listOptionValue builtIn="false" value="&quot;C:\Users\tstern\AppData\Local\Arduino15\packages\arduino\tools\CMSIS\4.0.0-atmel\Device\ATMEL&quot;"/>
<listOptionValue builtIn="false" value="&quot;C:\Users\TSTERN\AppData\Local\Arduino15\packages\arduino\hardware\samd\1.6.6\libraries\SPI&quot;"/>
<listOptionValue builtIn="false" value="&quot;C:\Users\tstern\AppData\Local\Arduino15\packages\arduino\tools\CMSIS\4.0.0-atmel\CMSIS\include&quot;"/>
</option>
<option id="gnu.cpp.compiler.option.preprocessor.def.215333140" name="Defined symbols (-D)" superClass="gnu.cpp.compiler.option.preprocessor.def" useByScannerDiscovery="false" valueType="definedSymbols">
<listOptionValue builtIn="false" value="__SAMD21G18A__"/>
<listOptionValue builtIn="false" value="ARDUINO_SAMD_ZERO"/>
</option>
<inputType id="cdt.managedbuild.tool.gnu.cpp.compiler.input.1198492994" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.input"/>
</tool>
<tool id="cdt.managedbuild.tool.gnu.cross.c.linker.1644022969" name="Cross GCC Linker" superClass="cdt.managedbuild.tool.gnu.cross.c.linker"/>
<tool id="cdt.managedbuild.tool.gnu.cross.cpp.linker.1373326859" name="Cross G++ Linker" superClass="cdt.managedbuild.tool.gnu.cross.cpp.linker">
<option id="gnu.cpp.link.option.paths.1624146493" name="Library search path (-L)" superClass="gnu.cpp.link.option.paths"/>
<inputType id="cdt.managedbuild.tool.gnu.cpp.linker.input.1257879712" superClass="cdt.managedbuild.tool.gnu.cpp.linker.input">
<additionalInput kind="additionalinputdependency" paths="$(USER_OBJS)"/>
<additionalInput kind="additionalinput" paths="$(LIBS)"/>
</inputType>
</tool>
<tool id="cdt.managedbuild.tool.gnu.cross.archiver.722380566" name="Cross GCC Archiver" superClass="cdt.managedbuild.tool.gnu.cross.archiver"/>
<tool id="cdt.managedbuild.tool.gnu.cross.assembler.7579640" name="Cross GCC Assembler" superClass="cdt.managedbuild.tool.gnu.cross.assembler">
<option id="gnu.both.asm.option.include.paths.2128933212" name="Include paths (-I)" superClass="gnu.both.asm.option.include.paths" valueType="includePath">
<listOptionValue builtIn="false" value="&quot;C:\Users\tstern\AppData\Local\Arduino15\packages\misfittech\hardware\samd\1.0.0\variants\nano_zero&quot;"/>
<listOptionValue builtIn="false" value="&quot;C:\Users\tstern\Documents\Arduino\libraries\Adafruit_SSD1306-master&quot;"/>
<listOptionValue builtIn="false" value="&quot;C:\Users\tstern\Documents\Arduino\libraries\Adafruit-GFX-Library-master&quot;"/>
<listOptionValue builtIn="false" value="&quot;C:\Users\tstern\AppData\Local\Arduino15\packages\arduino\tools\CMSIS\4.0.0-atmel\Device\ATMEL\samd21\include&quot;"/>
<listOptionValue builtIn="false" value="&quot;C:\Users\tstern\AppData\Local\Arduino15\packages\arduino\tools\CMSIS\4.0.0-atmel\Device\ATMEL\samd21\include\pio&quot;"/>
<listOptionValue builtIn="false" value="&quot;C:\Users\tstern\AppData\Local\Arduino15\packages\arduino\tools\CMSIS\4.0.0-atmel\Device\ATMEL\samd21\include\instance&quot;"/>
<listOptionValue builtIn="false" value="&quot;C:\Users\tstern\AppData\Local\Arduino15\packages\arduino\tools\CMSIS\4.0.0-atmel\Device\ATMEL\samd21\include\component&quot;"/>
<listOptionValue builtIn="false" value="&quot;C:\Users\tstern\AppData\Local\Arduino15\packages\misfittech\hardware\samd\1.0.0\cores\arduino&quot;"/>
<listOptionValue builtIn="false" value="&quot;C:\Users\tstern\AppData\Local\Arduino15\packages\arduino\tools\CMSIS\4.0.0-atmel\Device\ATMEL&quot;"/>
<listOptionValue builtIn="false" value="&quot;C:\Users\TSTERN\AppData\Local\Arduino15\packages\arduino\hardware\samd\1.6.6\libraries\SPI&quot;"/>
<listOptionValue builtIn="false" value="&quot;C:\Users\tstern\AppData\Local\Arduino15\packages\arduino\tools\CMSIS\4.0.0-atmel\CMSIS\Include&quot;"/>
</option>
<inputType id="cdt.managedbuild.tool.gnu.assembler.input.474088881" superClass="cdt.managedbuild.tool.gnu.assembler.input"/>
</tool>
</toolChain>
</folderInfo>
<sourceEntries>
<entry excluding="Adafruit-GFX-Library-master|Adafruit_SSD1306-master" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name=""/>
</sourceEntries>
</configuration>
</storageModule>
<storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
<storageModule moduleId="ilg.gnuarmeclipse.managedbuild.packs"/>
</cconfiguration>
</storageModule>
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
<project id="NZS.null.440051529" name="NZS"/>
</storageModule>
<storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/>
<storageModule moduleId="scannerConfiguration">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
<scannerConfigBuildInfo instanceId="cdt.managedbuild.toolchain.gnu.cross.base.1504376676;cdt.managedbuild.toolchain.gnu.cross.base.1504376676.350447049;cdt.managedbuild.tool.gnu.cross.c.compiler.1805317535;cdt.managedbuild.tool.gnu.c.compiler.input.1328245026">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
</scannerConfigBuildInfo>
<scannerConfigBuildInfo instanceId="cdt.managedbuild.toolchain.gnu.cross.base.1504376676;cdt.managedbuild.toolchain.gnu.cross.base.1504376676.350447049;cdt.managedbuild.tool.gnu.cross.cpp.compiler.1543385682;cdt.managedbuild.tool.gnu.cpp.compiler.input.1198492994">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
</scannerConfigBuildInfo>
</storageModule>
<storageModule moduleId="refreshScope"/>
<storageModule moduleId="org.eclipse.cdt.make.core.buildtargets"/>
</cproject>

View File

@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>NZS</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
<triggers>clean,full,incremental,</triggers>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name>
<triggers>full,incremental,</triggers>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.cdt.core.cnature</nature>
<nature>org.eclipse.cdt.core.ccnature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
</natures>
<linkedResources>
<link>
<name>arduino</name>
<type>2</type>
<location>C:/Users/tramp_000/AppData/Local/Arduino15/packages/arduino/hardware/samd/1.6.8/cores/arduino</location>
</link>
</linkedResources>
</projectDescription>

View File

@ -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 <Arduino.h>
#include "syslog.h"
#include "A1333.h"
#include "SPI.h"
#include <stdio.h>
#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;
}

View File

@ -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 <Arduino.h>
#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_ */

View File

@ -0,0 +1,412 @@
/**********************************************************************
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!
*********************************************************************/
#include "A4954.h"
#include "wiring_private.h"
#include "syslog.h"
#include "angle.h"
#include "Arduino.h"
#include "sine.h"
static uint8_t pinState=0;
#pragma GCC push_options
#pragma GCC optimize ("-Ofast")
#define DAC_MAX (0x01FFL)
// Wait for synchronization of registers between the clock domains
static __inline__ void syncTCC(Tcc* TCCx) __attribute__((always_inline, unused));
static void syncTCC(Tcc* TCCx) {
//int32_t t0=1000;
while (TCCx->SYNCBUSY.reg & TCC_SYNCBUSY_MASK)
{
// t0--;
// if (t0==0)
// {
// break;
// }
// delay(1);
}
}
static inline void bridge1(int state)
{
if (state==0)
{
PORT->Group[g_APinDescription[PIN_A4954_IN1].ulPort].PINCFG[g_APinDescription[PIN_A4954_IN1].ulPin].bit.PMUXEN = 0;
GPIO_OUTPUT(PIN_A4954_IN1);//pinMode(PIN_A4954_IN1,OUTPUT);
GPIO_OUTPUT(PIN_A4954_IN2);//pinMode(PIN_A4954_IN2,OUTPUT);
GPIO_HIGH(PIN_A4954_IN1);// digitalWrite(PIN_A4954_IN1, HIGH);
GPIO_LOW(PIN_A4954_IN2);//digitalWrite(PIN_A4954_IN2, LOW);
//pinPeripheral(PIN_A4954_IN2, PIO_TIMER_ALT);
pinState=(pinState & 0x0C) | 0x1;
}
if (state==1)
{
PORT->Group[g_APinDescription[PIN_A4954_IN2].ulPort].PINCFG[g_APinDescription[PIN_A4954_IN2].ulPin].bit.PMUXEN = 0;
GPIO_OUTPUT(PIN_A4954_IN2);//pinMode(PIN_A4954_IN2,OUTPUT);
GPIO_OUTPUT(PIN_A4954_IN1);pinMode(PIN_A4954_IN1,OUTPUT);
GPIO_LOW(PIN_A4954_IN1);//digitalWrite(PIN_A4954_IN1, LOW);
GPIO_HIGH(PIN_A4954_IN2);//digitalWrite(PIN_A4954_IN2, HIGH);
//pinPeripheral(PIN_A4954_IN1, PIO_TIMER);
pinState=(pinState & 0x0C) | 0x2;
}
if (state==3)
{
GPIO_LOW(PIN_A4954_IN1);
GPIO_LOW(PIN_A4954_IN2);
//digitalWrite(PIN_A4954_IN1, LOW);
//digitalWrite(PIN_A4954_IN2, LOW);
}
}
static inline void bridge2(int state)
{
if (state==0)
{
PORT->Group[g_APinDescription[PIN_A4954_IN3].ulPort].PINCFG[g_APinDescription[PIN_A4954_IN3].ulPin].bit.PMUXEN = 0;
GPIO_OUTPUT(PIN_A4954_IN3); //pinMode(PIN_A4954_IN3,OUTPUT);
GPIO_OUTPUT(PIN_A4954_IN4);//pinMode(PIN_A4954_IN4,OUTPUT);
GPIO_HIGH(PIN_A4954_IN3);//digitalWrite(PIN_A4954_IN3, HIGH);
GPIO_LOW(PIN_A4954_IN4);//digitalWrite(PIN_A4954_IN4, LOW);
//pinPeripheral(PIN_A4954_IN4, PIO_TIMER_ALT);
pinState=(pinState & 0x03) | 0x4;
}
if (state==1)
{
PORT->Group[g_APinDescription[PIN_A4954_IN4].ulPort].PINCFG[g_APinDescription[PIN_A4954_IN4].ulPin].bit.PMUXEN = 0;
GPIO_OUTPUT(PIN_A4954_IN4);//pinMode(PIN_A4954_IN4,OUTPUT);
GPIO_OUTPUT(PIN_A4954_IN3);//pinMode(PIN_A4954_IN3,OUTPUT);
GPIO_LOW(PIN_A4954_IN3);//digitalWrite(PIN_A4954_IN3, LOW);
GPIO_HIGH(PIN_A4954_IN4);//digitalWrite(PIN_A4954_IN4, HIGH);
//pinPeripheral(PIN_A4954_IN3, PIO_TIMER_ALT);
pinState=(pinState & 0x03) | 0x8;
}
if (state==3)
{
GPIO_LOW(PIN_A4954_IN3);
GPIO_LOW(PIN_A4954_IN4);
//digitalWrite(PIN_A4954_IN3, LOW);
//digitalWrite(PIN_A4954_IN4, LOW);
}
}
static void enableTCC0(uint8_t percent)
{
#ifdef MECHADUINO_HARDWARE
return;
#else
Tcc* TCCx = TCC0 ;
uint32_t ulValue=((uint32_t)(100-percent)*480)/100;
//ERROR("Enable TCC0");
GCLK->CLKCTRL.reg = (uint16_t) (GCLK_CLKCTRL_CLKEN | GCLK_CLKCTRL_GEN_GCLK0 | GCLK_CLKCTRL_ID( GCM_TCC0_TCC1 )) ;
while ( GCLK->STATUS.bit.SYNCBUSY == 1 ) ;
//ERROR("Setting TCC %d %d",ulValue,ulPin);
TCCx->CTRLA.reg &= ~TCC_CTRLA_ENABLE;
syncTCC(TCCx);
// Set TCx as normal PWM
TCCx->WAVE.reg |= TCC_WAVE_WAVEGEN_NPWM;
syncTCC(TCCx);
// Set TCx in waveform mode Normal PWM
TCCx->CC[1].reg = (uint32_t)ulValue; //ch5 //IN3
syncTCC(TCCx);
TCCx->CC[2].reg = (uint32_t)ulValue; //ch6 //IN4
syncTCC(TCCx);
TCCx->CC[3].reg = (uint32_t)ulValue; //ch7 //IN2
syncTCC(TCCx);
TCCx->CC[1].reg = (uint32_t)ulValue; //ch1 == ch5 //IN1
syncTCC(TCCx);
// Set PER to maximum counter value (resolution : 0xFF)
TCCx->PER.reg = DAC_MAX;
syncTCC(TCCx);
// Enable TCCx
TCCx->CTRLA.reg |= TCC_CTRLA_ENABLE ;
syncTCC(TCCx);
//ERROR("Enable TCC0 DONE");
#endif
}
static void setDAC(uint32_t DAC1, uint32_t DAC2)
{
TCC1->CC[1].reg = (uint32_t)DAC1; //D9 PA07 - VREF12
syncTCC(TCC1);
TCC1->CC[0].reg = (uint32_t)DAC2; //D4 - VREF34
syncTCC(TCC1);
}
static void setupDAC(void)
{
Tcc* TCCx = TCC1 ;
pinPeripheral(PIN_A4954_VREF34, PIO_TIMER_ALT);
pinPeripheral(PIN_A4954_VREF12, PIO_TIMER);
GCLK->CLKCTRL.reg = (uint16_t) (GCLK_CLKCTRL_CLKEN | GCLK_CLKCTRL_GEN_GCLK0 | GCLK_CLKCTRL_ID( GCM_TCC0_TCC1 )) ;
while ( GCLK->STATUS.bit.SYNCBUSY == 1 ) ;
//ERROR("Setting TCC %d %d",ulValue,ulPin);
TCCx->CTRLA.reg &= ~TCC_CTRLA_ENABLE;
syncTCC(TCCx);
// Set TCx as normal PWM
TCCx->WAVE.reg |= TCC_WAVE_WAVEGEN_NPWM;
syncTCC(TCCx);
// Set TCx in waveform mode Normal PWM
TCCx->CC[1].reg = (uint32_t)0;
syncTCC(TCCx);
TCCx->CC[0].reg = (uint32_t)0;
syncTCC(TCCx);
// Set PER to maximum counter value (resolution : 0xFFF = 12 bits)
// =48e6/2^12=11kHz frequency
TCCx->PER.reg = DAC_MAX;
syncTCC(TCCx);
// Enable TCCx
TCCx->CTRLA.reg |= TCC_CTRLA_ENABLE ;
syncTCC(TCCx);
}
void A4954::begin()
{
//setup the A4954 pins
digitalWrite(PIN_A4954_IN3,LOW);
pinMode(PIN_A4954_IN3,OUTPUT);
digitalWrite(PIN_A4954_IN4,LOW);
pinMode(PIN_A4954_IN4,OUTPUT);
digitalWrite(PIN_A4954_IN2,LOW);
pinMode(PIN_A4954_IN2,OUTPUT);
digitalWrite(PIN_A4954_IN1,LOW);
pinMode(PIN_A4954_IN1,OUTPUT);
//setup the PWM for current on the A4954, set for low current
digitalWrite(PIN_A4954_VREF12,LOW);
digitalWrite(PIN_A4954_VREF34,LOW);
pinMode(PIN_A4954_VREF34, OUTPUT);
pinMode(PIN_A4954_VREF12, OUTPUT);
enabled=true;
lastStepMicros=0;
forwardRotation=true;
enableTCC0(90);
setupDAC();
//
// int i=0;
// bridge1(0);
// bridge2(0);
//while (1)
// {
// int32_t x;
// WARNING("MA %d",i);
// x=(int32_t)((int64_t)i*(DAC_MAX))/3300;
// setDAC(x,x);
// delay(1000);
// i=i+10;
// if (i>1000)
// {
// i=0;
// }
//
// }
//
// WARNING("Setting DAC for 500mA output");
// setDAC((int32_t)((int64_t)1000*(DAC_MAX))/3300,(int32_t)((int64_t)1000*(DAC_MAX))/3300);
// bridge1(0);
// bridge2(0);
// while(1)
// {
//
// }
return;
}
void A4954::limitCurrent(uint8_t percent)
{
#ifdef MECHADUINO_HARDWARE
return;
#else
//WARNING("current limit %d",percent);
enableTCC0(percent);
if (pinState & 0x01)
{
pinPeripheral(PIN_A4954_IN2, PIO_TIMER_ALT); //TCC0 WO[7]
}
if (pinState & 0x02)
{
pinPeripheral(PIN_A4954_IN1, PIO_TIMER); //TCC0 WO[1]
}
if (pinState & 0x04)
{
pinPeripheral(PIN_A4954_IN4, PIO_TIMER_ALT);
}
if (pinState & 0x08)
{
pinPeripheral(PIN_A4954_IN3, PIO_TIMER_ALT);
}
#endif
}
void A4954::enable(bool enable)
{
enabled=enable;
if (enabled == false)
{
WARNING("A4954 disabled");
setDAC(0,0); //turn current off
bridge1(3); //tri state bridge outputs
bridge2(3); //tri state bridge outputs
}
}
//this is precise move and modulo of A4954_NUM_MICROSTEPS is a full step.
// stepAngle is in A4954_NUM_MICROSTEPS units..
// The A4954 has no idea where the motor is, so the calling function has to
// to tell the A4954 what phase to drive motor coils.
// A4954_NUM_MICROSTEPS is 256 by default so stepAngle of 1024 is 360 degrees
// Note you can only move up to +/-A4954_NUM_MICROSTEPS from where you
// currently are.
int32_t A4954::move(int32_t stepAngle, uint32_t mA)
{
uint16_t angle;
int32_t cos,sin;
int32_t dacSin,dacCos;
//static int i=0;
if (enabled == false)
{
//WARNING("A4954 disabled");
setDAC(0,0); //turn current off
bridge1(3); //tri state bridge outputs
bridge2(3); //tri state bridge outputs
return stepAngle;
}
//WARNING("move %d %d",stepAngle,mA);
//handle roll overs, could do with modulo operator
stepAngle=stepAngle%SINE_STEPS;
//figure out our sine Angle
// note our SINE_STEPS is 4x of microsteps for a reason
//angle=(stepAngle+(SINE_STEPS/8)) % SINE_STEPS;
angle=(stepAngle);
//calculate the sine and cosine of our angle
sin=sine(angle);
cos=cosine(angle);
//if we are reverse swap the sign of one of the angels
if (false == forwardRotation)
{
cos=-cos;
}
//scale sine result by current(mA)
dacSin=((int32_t)mA*(int64_t)abs(sin))/SINE_MAX;
//scale cosine result by current(mA)
dacCos=((int32_t)mA*(int64_t)abs(cos))/SINE_MAX;
// if (i==0)
// {
// WARNING("dacs are %d %d",dacSin,dacCos);
// }
//convert value into DAC scaled to 3300mA max
dacCos=(int32_t)((int64_t)dacCos*(DAC_MAX))/3300;
//convert value into DAC scaled to 3300mA max
dacSin=(int32_t)((int64_t)dacSin*(DAC_MAX))/3300;
//WARNING("dacs are %d %d ",dacSin,dacCos);
setDAC(dacSin,dacCos);
if (sin>0)
{
bridge1(1);
}else
{
bridge1(0);
}
if (cos>0)
{
bridge2(1);
}else
{
bridge2(0);
}
// if (i++>3000)
// {
// i=0;
// }
// YELLOW_LED(led);
// led=(led+1) & 0x01;
lastStepMicros=micros();
return stepAngle;
}
#pragma GCC pop_options

View File

@ -0,0 +1,90 @@
/**********************************************************************
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 __A4954__H__
#define __A4954__H__
#include <Arduino.h>
#include "board.h"
#include "angle.h"
#include "sine.h"
#define A4954_NUM_MICROSTEPS (256)
#define A4954_MIN_TIME_BETWEEN_STEPS_MICROS (1000)
//prevent someone for making a mistake with the code
#if ((A4954_NUM_MICROSTEPS*4) != SINE_STEPS)
#error "SINE_STEPS must be 4x of Micro steps for the move function"
#endif
/*
* When it comes to the stepper driver if we use angles
* we will always have a rounding error. For example
* a 0-65536(360) angle for 1.8 degree step is 327.68 so
* if you increment 200 of these as 327 you have a 13.6 error
* after one rotation.
* If you use floating point the effect is the same but takes longer.
*
* The only error-less accumulation system is to use native units, ie full
* steps and microsteps.
*
*/
class A4954
{
private:
uint32_t lastStepMicros; // time in microseconds that last step happened
bool forwardRotation=true;
volatile bool enabled=true;
public:
void begin(void);
//moves motor where the modulo of A4954_NUM_MICROSTEPS is a full step.
int32_t move(int32_t stepAngle, uint32_t mA);
uint32_t microsSinceStep(void) {return micros()-lastStepMicros;};
void setRotationDirection(bool forward) {forwardRotation=forward;};
void enable(bool enable);
void limitCurrent(uint8_t percent); //higher more current
};
#endif //__A4954__H__

View File

@ -0,0 +1,337 @@
/**********************************************************************
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!
*********************************************************************/
#include "A5995.h"
#include "wiring_private.h"
#include "syslog.h"
#include "angle.h"
#include "Arduino.h"
#include "sine.h"
static uint8_t pinState=0;
#pragma GCC push_options
#pragma GCC optimize ("-Ofast")
#define DAC_MAX (0x01FFL)
// Wait for synchronization of registers between the clock domains
static __inline__ void syncTCC(Tcc* TCCx) __attribute__((always_inline, unused));
static void syncTCC(Tcc* TCCx) {
//int32_t t0=1000;
while (TCCx->SYNCBUSY.reg & TCC_SYNCBUSY_MASK)
{
// t0--;
// if (t0==0)
// {
// break;
// }
// delay(1);
}
}
static void setDAC(uint32_t DAC1, uint32_t DAC2)
{
TCC1->CC[1].reg = (uint32_t)DAC1; //D9 PA07 - VREF2
syncTCC(TCC1);
TCC1->CC[0].reg = (uint32_t)DAC2; //D4 - VREF1
syncTCC(TCC1);
}
static void setupDAC(void)
{
Tcc* TCCx = TCC1 ;
pinPeripheral(PIN_A5995_VREF1, PIO_TIMER_ALT);
pinPeripheral(PIN_A5995_VREF2, PIO_TIMER);
GCLK->CLKCTRL.reg = (uint16_t) (GCLK_CLKCTRL_CLKEN | GCLK_CLKCTRL_GEN_GCLK0 | GCLK_CLKCTRL_ID( GCM_TCC0_TCC1 )) ;
while ( GCLK->STATUS.bit.SYNCBUSY == 1 ) ;
//ERROR("Setting TCC %d %d",ulValue,ulPin);
TCCx->CTRLA.reg &= ~TCC_CTRLA_ENABLE;
syncTCC(TCCx);
// Set TCx as normal PWM
TCCx->WAVE.reg |= TCC_WAVE_WAVEGEN_NPWM;
syncTCC(TCCx);
// Set TCx in waveform mode Normal PWM
TCCx->CC[1].reg = (uint32_t)0;
syncTCC(TCCx);
TCCx->CC[0].reg = (uint32_t)0;
syncTCC(TCCx);
// Set PER to maximum counter value (resolution : 0xFFF = 12 bits)
// =48e6/2^12=11kHz frequency
TCCx->PER.reg = DAC_MAX;
syncTCC(TCCx);
// Enable TCCx
TCCx->CTRLA.reg |= TCC_CTRLA_ENABLE ;
syncTCC(TCCx);
}
void A5995::begin()
{
//setup the A5995 pins
digitalWrite(PIN_A5995_ENABLE1,LOW);
pinMode(PIN_A5995_ENABLE1,OUTPUT);
digitalWrite(PIN_A5995_ENABLE2,LOW);
pinMode(PIN_A5995_ENABLE2,OUTPUT);
digitalWrite(PIN_A5995_MODE1,LOW);
pinMode(PIN_A5995_MODE1,OUTPUT);
digitalWrite(PIN_A5995_MODE2,LOW);
pinMode(PIN_A5995_MODE2,OUTPUT);
digitalWrite(PIN_A5995_PHASE1,LOW);
pinMode(PIN_A5995_PHASE1,OUTPUT);
digitalWrite(PIN_A5995_PHASE2,LOW);
pinMode(PIN_A5995_PHASE2,OUTPUT);
digitalWrite(PIN_A5995_SLEEPn,HIGH);
pinMode(PIN_A5995_SLEEPn,OUTPUT);
//setup the PWM for current on the A4954, set for low current
digitalWrite(PIN_A5995_VREF1,LOW);
digitalWrite(PIN_A5995_VREF2,LOW);
pinMode(PIN_A5995_VREF1, OUTPUT);
pinMode(PIN_A5995_VREF2, OUTPUT);
enabled=true;
lastStepMicros=0;
forwardRotation=true;
setupDAC();
//
// GPIO_HIGH(PIN_A5995_ENABLE1);
// GPIO_HIGH(PIN_A5995_ENABLE2);
// GPIO_LOW(PIN_A5995_MODE1);
// GPIO_LOW(PIN_A5995_MODE2);
// GPIO_HIGH(PIN_A5995_PHASE1);
// GPIO_HIGH(PIN_A5995_PHASE2);
// int i=0;;
// while (1)
// {
// int32_t x;
// WARNING("MA %d",i);
// x=(int32_t)((int64_t)i*(DAC_MAX))/3300;
// setDAC(x,x);
// delay(1000);
// i=i+10;
// if (i>1000)
// {
// i=0;
// }
//
// }
return;
}
void A5995::enable(bool enable)
{
enabled=enable;
if (enabled == false)
{
WARNING("A4954 disabled");
setDAC(0,0); //turn current off
GPIO_LOW(PIN_A5995_ENABLE1);
GPIO_LOW(PIN_A5995_ENABLE2);
GPIO_LOW(PIN_A5995_MODE1);
GPIO_LOW(PIN_A5995_MODE2);
GPIO_LOW(PIN_A5995_PHASE1);
GPIO_LOW(PIN_A5995_PHASE2);
}
}
//this is precise move and modulo of A4954_NUM_MICROSTEPS is a full step.
// stepAngle is in A4954_NUM_MICROSTEPS units..
// The A4954 has no idea where the motor is, so the calling function has to
// to tell the A4954 what phase to drive motor coils.
// A4954_NUM_MICROSTEPS is 256 by default so stepAngle of 1024 is 360 degrees
// Note you can only move up to +/-A4954_NUM_MICROSTEPS from where you
// currently are.
int32_t A5995::move(int32_t stepAngle, uint32_t mA)
{
uint16_t angle;
int32_t cos,sin;
int32_t dacSin,dacCos;
static int32_t lastSin=0,lastCos=0;
static int i=1;
if (enabled == false)
{
WARNING("A4954 disabled");
setDAC(0,0); //turn current off
GPIO_LOW(PIN_A5995_ENABLE1);
GPIO_LOW(PIN_A5995_ENABLE2);
GPIO_LOW(PIN_A5995_MODE1);
GPIO_LOW(PIN_A5995_MODE2);
GPIO_LOW(PIN_A5995_PHASE1);
GPIO_LOW(PIN_A5995_PHASE2);
return stepAngle;
}
//WARNING("move %d %d",stepAngle,mA);
stepAngle=(stepAngle) % SINE_STEPS;
//figure out our sine Angle
// note our SINE_STEPS is 4x of microsteps for a reason
//angle=(stepAngle+(SINE_STEPS/8)) % SINE_STEPS;
angle=stepAngle;
if (i==0)
{
WARNING("angle %d ",angle);
}
//calculate the sine and cosine of our angle
sin=sine(angle);
cos=cosine(angle);
//if we are reverse swap the sign of one of the angels
if (false == forwardRotation)
{
cos=-cos;
}
//scale sine result by current(mA)
dacSin=((int32_t)mA*(int64_t)(sin))/SINE_MAX;
if (i==0)
{
WARNING("dacsine %d ",dacSin);
}
// if ((lastSin-dacSin)>100) //decreasing current
// {
// GPIO_LOW(PIN_A5995_MODE2); //fast decay
// } else
// {
// GPIO_HIGH(PIN_A5995_MODE2); //slow decay
// }
lastSin=dacSin;
//convert value into DAC scaled to 3300mA max
dacSin=(int32_t)((int64_t)abs(dacSin)*(DAC_MAX))/3300;
//scale cosine result by current(mA)
dacCos=((int32_t)mA*(int64_t)(cos))/SINE_MAX;
if (i==0)
{
WARNING("daccos %d ",dacCos);
}
// if ((lastCos-dacCos)>100) //decreasing current
// {
// GPIO_LOW(PIN_A5995_MODE1); //fast decay
// } else
// {
// GPIO_HIGH(PIN_A5995_MODE1); //slow decay
// }
lastCos=dacCos;
//convert value into DAC scaled to 3300mA max
dacCos=(int32_t)((int64_t)abs(dacCos)*(DAC_MAX))/3300;
if (i==0)
{
WARNING("dacs are %d %d",dacSin,dacCos);
}
setDAC(dacSin,dacCos);
GPIO_HIGH(PIN_A5995_ENABLE1);
GPIO_HIGH(PIN_A5995_ENABLE2);
GPIO_LOW(PIN_A5995_MODE1);
GPIO_LOW(PIN_A5995_MODE2);
if (i==0)
{
WARNING("sins are %d %d",sin,cos);
}
if (sin>0)
{
GPIO_HIGH(PIN_A5995_PHASE2);
}else
{
GPIO_LOW(PIN_A5995_PHASE2);
}
if (cos>0)
{
GPIO_HIGH(PIN_A5995_PHASE1);
}else
{
GPIO_LOW(PIN_A5995_PHASE1);
}
// i++;
// if (i>3000) i=0;
// YELLOW_LED(led);
// led=(led+1) & 0x01;
lastStepMicros=micros();
return stepAngle;
}
#pragma GCC pop_options

View File

@ -0,0 +1,92 @@
/**********************************************************************
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 A5995_H_
#define A5995_H_
#include <Arduino.h>
#include "board.h"
#include "angle.h"
#include "sine.h"
#define A5995_NUM_MICROSTEPS (256)
//prevent someone for making a mistake with the code
#if ((A5995_NUM_MICROSTEPS*4) != SINE_STEPS)
#error "SINE_STEPS must be 4x of Micro steps for the move function"
#endif
/*
* When it comes to the stepper driver if we use angles
* we will always have a rounding error. For example
* a 0-65536(360) angle for 1.8 degree step is 327.68 so
* if you increment 200 of these as 327 you have a 13.6 error
* after one rotation.
* If you use floating point the effect is the same but takes longer.
*
* The only error-less accumulation system is to use native units, ie full
* steps and microsteps.
*
*/
class A5995
{
private:
uint32_t lastStepMicros; // time in microseconds that last step happened
bool forwardRotation=true;
volatile bool enabled=true;
public:
void begin(void);
//moves motor where the modulo of A4954_NUM_MICROSTEPS is a full step.
int32_t move(int32_t stepAngle, uint32_t mA);
uint32_t microsSinceStep(void) {return micros()-lastStepMicros;};
void setRotationDirection(bool forward) {forwardRotation=forward;};
void enable(bool enable);
void limitCurrent(uint8_t percent) {return;}; //Not used
};
#endif /* A5995_H_ */

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,155 @@
#ifndef _ADAFRUIT_GFX_H
#define _ADAFRUIT_GFX_H
#if ARDUINO >= 100
#include "Arduino.h"
#include "Print.h"
#else
#include "WProgram.h"
#endif
#include "gfxfont.h"
class Adafruit_GFX : public Print {
public:
Adafruit_GFX(int16_t w, int16_t h); // Constructor
// This MUST be defined by the subclass:
virtual void drawPixel(int16_t x, int16_t y, uint16_t color) = 0;
// These MAY be overridden by the subclass to provide device-specific
// optimized code. Otherwise 'generic' versions are used.
virtual void
drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color),
drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color),
drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color),
drawRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color),
fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color),
fillScreen(uint16_t color),
invertDisplay(boolean i);
// These exist only with Adafruit_GFX (no subclass overrides)
void
drawCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color),
drawCircleHelper(int16_t x0, int16_t y0, int16_t r, uint8_t cornername,
uint16_t color),
fillCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color),
fillCircleHelper(int16_t x0, int16_t y0, int16_t r, uint8_t cornername,
int16_t delta, uint16_t color),
drawTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1,
int16_t x2, int16_t y2, uint16_t color),
fillTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1,
int16_t x2, int16_t y2, uint16_t color),
drawRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h,
int16_t radius, uint16_t color),
fillRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h,
int16_t radius, uint16_t color),
drawBitmap(int16_t x, int16_t y, const uint8_t *bitmap,
int16_t w, int16_t h, uint16_t color),
drawBitmap(int16_t x, int16_t y, const uint8_t *bitmap,
int16_t w, int16_t h, uint16_t color, uint16_t bg),
drawBitmap(int16_t x, int16_t y, uint8_t *bitmap,
int16_t w, int16_t h, uint16_t color),
drawBitmap(int16_t x, int16_t y, uint8_t *bitmap,
int16_t w, int16_t h, uint16_t color, uint16_t bg),
drawXBitmap(int16_t x, int16_t y, const uint8_t *bitmap,
int16_t w, int16_t h, uint16_t color),
drawChar(int16_t x, int16_t y, unsigned char c, uint16_t color,
uint16_t bg, uint8_t size),
setCursor(int16_t x, int16_t y),
setTextColor(uint16_t c),
setTextColor(uint16_t c, uint16_t bg),
setTextSize(uint8_t s),
setTextWrap(boolean w),
setRotation(uint8_t r),
cp437(boolean x=true),
setFont(const GFXfont *f = NULL),
getTextBounds(char *string, int16_t x, int16_t y,
int16_t *x1, int16_t *y1, uint16_t *w, uint16_t *h),
getTextBounds(const __FlashStringHelper *s, int16_t x, int16_t y,
int16_t *x1, int16_t *y1, uint16_t *w, uint16_t *h);
#if ARDUINO >= 100
virtual size_t write(uint8_t);
#else
virtual void write(uint8_t);
#endif
int16_t height(void) const;
int16_t width(void) const;
uint8_t getRotation(void) const;
// get current cursor position (get rotation safe maximum values, using: width() for x, height() for y)
int16_t getCursorX(void) const;
int16_t getCursorY(void) const;
protected:
const int16_t
WIDTH, HEIGHT; // This is the 'raw' display w/h - never changes
int16_t
_width, _height, // Display w/h as modified by current rotation
cursor_x, cursor_y;
uint16_t
textcolor, textbgcolor;
uint8_t
textsize,
rotation;
boolean
wrap, // If set, 'wrap' text at right edge of display
_cp437; // If set, use correct CP437 charset (default is off)
GFXfont
*gfxFont;
};
class Adafruit_GFX_Button {
public:
Adafruit_GFX_Button(void);
void initButton(Adafruit_GFX *gfx, int16_t x, int16_t y,
uint8_t w, uint8_t h, uint16_t outline, uint16_t fill,
uint16_t textcolor, char *label, uint8_t textsize);
void drawButton(boolean inverted = false);
boolean contains(int16_t x, int16_t y);
void press(boolean p);
boolean isPressed();
boolean justPressed();
boolean justReleased();
private:
Adafruit_GFX *_gfx;
int16_t _x, _y;
uint16_t _w, _h;
uint8_t _textsize;
uint16_t _outlinecolor, _fillcolor, _textcolor;
char _label[10];
boolean currstate, laststate;
};
class GFXcanvas1 : public Adafruit_GFX {
public:
GFXcanvas1(uint16_t w, uint16_t h);
~GFXcanvas1(void);
void drawPixel(int16_t x, int16_t y, uint16_t color),
fillScreen(uint16_t color);
uint8_t *getBuffer(void);
private:
uint8_t *buffer;
};
class GFXcanvas16 : public Adafruit_GFX {
GFXcanvas16(uint16_t w, uint16_t h);
~GFXcanvas16(void);
void drawPixel(int16_t x, int16_t y, uint16_t color),
fillScreen(uint16_t color);
uint16_t *getBuffer(void);
private:
uint16_t *buffer;
};
#endif // _ADAFRUIT_GFX_H

View File

@ -0,0 +1,750 @@
/*********************************************************************
This is a library for our Monochrome OLEDs based on SSD1306 drivers
Pick one up today in the adafruit shop!
------> http://www.adafruit.com/category/63_98
These displays use SPI to communicate, 4 or 5 pins are required to
interface
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
Written by Limor Fried/Ladyada for Adafruit Industries.
BSD license, check license.txt for more information
All text above, and the splash screen below must be included in any redistribution