diff --git a/firmware/osape-smoothieroll-drop-stepper/src/drivers/indicators.h b/firmware/osape-smoothieroll-drop-stepper/src/drivers/indicators.h deleted file mode 100644 index 2dcb3ac7823931c3a60fdd534ab9cf10f10f176a..0000000000000000000000000000000000000000 --- a/firmware/osape-smoothieroll-drop-stepper/src/drivers/indicators.h +++ /dev/null @@ -1,52 +0,0 @@ -// for the new one! with the DIP switch! -#define CLKLIGHT_PIN 27 -#define CLKLIGHT_PORT PORT->Group[0] -#define ERRLIGHT_PIN 8 -#define ERRLIGHT_PORT PORT->Group[1] - -#define DEBUG1PIN_PIN 13 -#define DEBUG1PIN_PORT PORT->Group[1] -#define DEBUG2PIN_PIN 12 -#define DEBUG2PIN_PORT PORT->Group[1] -#define DEBUG3PIN_PIN 13 -#define DEBUG3PIN_PORT PORT->Group[1] -#define DEBUG4PIN_PIN 14 -#define DEBUG4PIN_PORT PORT->Group[1] - -// PA27 -#define CLKLIGHT_BM (uint32_t)(1 << CLKLIGHT_PIN) -#define CLKLIGHT_ON CLKLIGHT_PORT.OUTCLR.reg = CLKLIGHT_BM -#define CLKLIGHT_OFF CLKLIGHT_PORT.OUTSET.reg = CLKLIGHT_BM -#define CLKLIGHT_TOGGLE CLKLIGHT_PORT.OUTTGL.reg = CLKLIGHT_BM -#define CLKLIGHT_SETUP CLKLIGHT_PORT.DIRSET.reg = CLKLIGHT_BM; CLKLIGHT_OFF - -// PB08 -#define ERRLIGHT_BM (uint32_t)(1 << ERRLIGHT_PIN) -#define ERRLIGHT_ON ERRLIGHT_PORT.OUTCLR.reg = ERRLIGHT_BM -#define ERRLIGHT_OFF ERRLIGHT_PORT.OUTSET.reg = ERRLIGHT_BM -#define ERRLIGHT_TOGGLE ERRLIGHT_PORT.OUTTGL.reg = ERRLIGHT_BM -#define ERRLIGHT_SETUP ERRLIGHT_PORT.DIRSET.reg = ERRLIGHT_BM; ERRLIGHT_OFF - -#define DEBUG1PIN_BM (uint32_t)(1 << DEBUG1PIN_PIN) -#define DEBUG1PIN_ON DEBUG1PIN_PORT.OUTSET.reg = DEBUG1PIN_BM -#define DEBUG1PIN_OFF DEBUG1PIN_PORT.OUTCLR.reg = DEBUG1PIN_BM -#define DEBUG1PIN_TOGGLE DEBUG1PIN_PORT.OUTTGL.reg = DEBUG1PIN_BM -#define DEBUG1PIN_SETUP DEBUG1PIN_PORT.DIRSET.reg = DEBUG1PIN_BM; DEBUG1PIN_OFF - -#define DEBUG2PIN_BM (uint32_t)(1 << DEBUG2PIN_PIN) -#define DEBUG2PIN_ON DEBUG2PIN_PORT.OUTSET.reg = DEBUG2PIN_BM -#define DEBUG2PIN_OFF DEBUG2PIN_PORT.OUTCLR.reg = DEBUG2PIN_BM -#define DEBUG2PIN_TOGGLE DEBUG2PIN_PORT.OUTTGL.reg = DEBUG2PIN_BM -#define DEBUG2PIN_SETUP DEBUG2PIN_PORT.DIRSET.reg = DEBUG2PIN_BM; DEBUG2PIN_OFF - -#define DEBUG3PIN_BM (uint32_t)(1 << DEBUG3PIN_PIN) -#define DEBUG3PIN_ON DEBUG3PIN_PORT.OUTSET.reg = DEBUG3PIN_BM -#define DEBUG3PIN_OFF DEBUG3PIN_PORT.OUTCLR.reg = DEBUG3PIN_BM -#define DEBUG3PIN_TOGGLE DEBUG3PIN_PORT.OUTTGL.reg = DEBUG3PIN_BM -#define DEBUG3PIN_SETUP DEBUG3PIN_PORT.DIRSET.reg = DEBUG3PIN_BM; DEBUG3PIN_OFF - -#define DEBUG4PIN_BM (uint32_t)(1 << DEBUG4PIN_PIN) -#define DEBUG4PIN_ON DEBUG4PIN_PORT.OUTSET.reg = DEBUG4PIN_BM -#define DEBUG4PIN_OFF DEBUG4PIN_PORT.OUTCLR.reg = DEBUG4PIN_BM -#define DEBUG4PIN_TOGGLE DEBUG4PIN_PORT.OUTTGL.reg = DEBUG4PIN_BM -#define DEBUG4PIN_SETUP DEBUG4PIN_PORT.DIRSET.reg = DEBUG4PIN_BM; DEBUG4PIN_OFF \ No newline at end of file diff --git a/firmware/osape-smoothieroll-drop-stepper/src/drivers/step_a4950.cpp b/firmware/osape-smoothieroll-drop-stepper/src/drivers/step_a4950.cpp index 6638cce631f82286924567c8bb7dc8f7c87e2045..440e5a8678dd941ce5280e5a8104661e94c09d7b 100644 --- a/firmware/osape-smoothieroll-drop-stepper/src/drivers/step_a4950.cpp +++ b/firmware/osape-smoothieroll-drop-stepper/src/drivers/step_a4950.cpp @@ -117,22 +117,22 @@ void STEP_A4950::init(boolean invert, float cscale){ // A: ^ ^ ^ x v v v x // B: ^ x v v v x ^ ^ void STEP_A4950::step(void){ - // increment: wrapping comes for free with uint8_t + // increment: wrapping comes for free with uint8_t, bless if(_dir){ if(_dir_invert){ - _aStep -= MICROSTEP_COUNT; - _bStep -= MICROSTEP_COUNT; + _aStep -= _microstep_count; + _bStep -= _microstep_count; } else { - _aStep += MICROSTEP_COUNT; - _bStep += MICROSTEP_COUNT; + _aStep += _microstep_count; + _bStep += _microstep_count; } } else { if(_dir_invert){ - _aStep += MICROSTEP_COUNT; - _bStep += MICROSTEP_COUNT; + _aStep += _microstep_count; + _bStep += _microstep_count; } else { - _aStep -= MICROSTEP_COUNT; - _bStep -= MICROSTEP_COUNT; + _aStep -= _microstep_count; + _bStep -= _microstep_count; } } // a phase, @@ -166,6 +166,32 @@ boolean STEP_A4950::getDir(void){ return _dir; } +void STEP_A4950::setMicrostep(uint8_t microstep){ + switch(microstep){ + case 64: + _microstep_count = MICROSTEP_64_COUNT; + break; + case 32: + _microstep_count = MICROSTEP_32_COUNT; + break; + case 16: + _microstep_count = MICROSTEP_16_COUNT; + break; + case 8: + _microstep_count = MICROSTEP_8_COUNT; + break; + case 4: + _microstep_count = MICROSTEP_4_COUNT; + break; + case 1: + _microstep_count = MICROSTEP_1_COUNT; + break; + default: + _microstep_count = MICROSTEP_1_COUNT; + break; + } +} + void STEP_A4950::setCurrent(float cscale){ if(cscale > 1){ _cscale = 1; diff --git a/firmware/osape-smoothieroll-drop-stepper/src/drivers/step_a4950.h b/firmware/osape-smoothieroll-drop-stepper/src/drivers/step_a4950.h index 15825e310d0bf629ce92f8451325048c8b457311..fc435d3ba208ca92e42264a4e682722db21aa934 100644 --- a/firmware/osape-smoothieroll-drop-stepper/src/drivers/step_a4950.h +++ b/firmware/osape-smoothieroll-drop-stepper/src/drivers/step_a4950.h @@ -15,7 +15,7 @@ is; no warranty is provided, and users accept all liability. #ifndef STEP_A4950_H_ #define STEP_A4950_H_ -#include <arduino.h> +#include <Arduino.h> #include "dacs.h" #include "indicators.h" @@ -36,6 +36,13 @@ is; no warranty is provided, and users accept all liability. // 32: full steps #define MICROSTEP_COUNT 1 +#define MICROSTEP_64_COUNT 1 +#define MICROSTEP_32_COUNT 2 +#define MICROSTEP_16_COUNT 4 +#define MICROSTEP_8_COUNT 8 +#define MICROSTEP_4_COUNT 16 +#define MICROSTEP_1_COUNT 32 + // AIN1 PB06 // AIN2 PA04 // BIN1 PA07 @@ -80,8 +87,9 @@ class STEP_A4950 { volatile uint8_t _bStep = 63; // of the same table, startup 90' out of phase volatile boolean _dir = false; boolean _dir_invert = false; + uint8_t _microstep_count = 1; // try single scalar - float _cscale = 0.25; + float _cscale = 0.1; public: STEP_A4950(); @@ -91,6 +99,8 @@ class STEP_A4950 { void step(void); void dir(boolean val); boolean getDir(void); + // microstep setting + void setMicrostep(uint8_t microstep); // current settings void setCurrent(float cscale); void setInversion(boolean inv); diff --git a/firmware/osape-smoothieroll-drop-stepper/src/main.cpp b/firmware/osape-smoothieroll-drop-stepper/src/main.cpp index 590a1e2426a1726eb881e06b3ca05b5790758620..9a27f9f2a5baff9f64b618881b7aa25b82100dd1 100644 --- a/firmware/osape-smoothieroll-drop-stepper/src/main.cpp +++ b/firmware/osape-smoothieroll-drop-stepper/src/main.cpp @@ -1,6 +1,6 @@ #include <Arduino.h> -#include "drivers/indicators.h" +#include "indicators.h" #include "drivers/step_a4950.h" #include "osape-d51/osape/osap/osap.h" #include "osape-d51/vertices/vt_usbSerial.h" @@ -42,6 +42,15 @@ boolean onAxisInvertData(uint8_t* data, uint16_t len){ vertex_t* axisInvertEp = osapBuildEndpoint("axisInvert", onAxisInvertData, nullptr); +// -------------------------------------------------------- MICROSTEP EP + +boolean onMicrostepData(uint8_t* data, uint16_t len){ + stepper_hw->setMicrostep(data[0]); + return true; +} + +vertex_t* microstepEp = osapBuildEndpoint("microstep", onMicrostepData, nullptr); + // -------------------------------------------------------- SPU EP boolean onSPUData(uint8_t* data, uint16_t len){ @@ -113,6 +122,7 @@ vertex_t* homeStateEp = osapBuildEndpoint("HomeState", nullptr, beforeHomeStateQ boolean beforeHomeStateQuery(void){ homeStateEp->ep->data[0] = homing; homeStateEp->ep->dataLen = 1; + return true; } // -------------------------------------------------------- LIMIT SETUP @@ -153,13 +163,15 @@ void setup() { osapAddVertex(axisPickEp); // 2 // axis invert osapAddVertex(axisInvertEp); // 3 + // microstep + osapAddVertex(microstepEp); // 4 // SPU - osapAddVertex(spuEp); // 4 + osapAddVertex(spuEp); // 5 // cscale - osapAddVertex(cScaleEp); // 5 + osapAddVertex(cScaleEp); // 6 // homing - osapAddVertex(homeEp); // 6 - osapAddVertex(homeStateEp); // 7 + osapAddVertex(homeEp); // 7 + osapAddVertex(homeStateEp); // 8 // stepper init stepper_hw->init(false, c_scale); } diff --git a/firmware/osape-smoothieroll-drop-stepper/src/osape-d51 b/firmware/osape-smoothieroll-drop-stepper/src/osape-d51 index 4b8fbfdf4ae987c291b24be77ac4ddab157a545a..ee77dd8eda08bde0e2fed2ff62a418f7864b0ce3 160000 --- a/firmware/osape-smoothieroll-drop-stepper/src/osape-d51 +++ b/firmware/osape-smoothieroll-drop-stepper/src/osape-d51 @@ -1 +1 @@ -Subproject commit 4b8fbfdf4ae987c291b24be77ac4ddab157a545a +Subproject commit ee77dd8eda08bde0e2fed2ff62a418f7864b0ce3