-
-
Notifications
You must be signed in to change notification settings - Fork 531
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dynamically changing the mode of I2S #547
Conversation
The use of I2S as an expander requires a definition. #define USE_I2S_OUT The use of I2S as a stepper requires additional definitions. #define USE_I2S_STEPS If you want to always use I2S static, you need an additional define. (Optional.) #define DEFAULT_STEPPER ST_I2S_STATIC This is the machine file for my test environment: #pragma once
// clang-format off
/*
i2s_out_xyzabc_trinamic_test.h
Part of Grbl_ESP32
Pin assignments for the ESP32 SPI 6-axis board
2018 - Bart Dring
2020 - Mitch Bradley
2020 - Michiyasu Odaki
Grbl_ESP32 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, or
(at your option) any later version.
Grbl 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 Grbl_ESP32. If not, see <http://www.gnu.org/licenses/>.
*/
#define MACHINE_NAME "ESP32 SPI 6 Axis Driver Board Trinamic Test"
#ifdef N_AXIS
#undef N_AXIS
#endif
#define N_AXIS 6
// === Special Features
// I2S (steppers & other output-only pins)
#define USE_I2S_OUT
#define USE_I2S_STEPS
//#define DEFAULT_STEPPER ST_I2S_STATIC
#define I2S_OUT_BCK GPIO_NUM_22
#define I2S_OUT_WS GPIO_NUM_17
#define I2S_OUT_DATA GPIO_NUM_21
#define TRINAMIC_RUN_MODE TRINAMIC_MODE_COOLSTEP
#define TRINAMIC_HOMING_MODE TRINAMIC_MODE_COOLSTEP
#define X_TRINAMIC_DRIVER 2130
#define X_DISABLE_PIN I2SO(0)
#define X_DIRECTION_PIN I2SO(1)
#define X_STEP_PIN I2SO(2)
#define X_CS_PIN I2SO(3)
#define X_RSENSE TMC2130_RSENSE_DEFAULT
#define Y_TRINAMIC_DRIVER 2130
#define Y_DIRECTION_PIN I2SO(4)
#define Y_STEP_PIN I2SO(5)
#define Y_DISABLE_PIN I2SO(7)
#define Y_CS_PIN I2SO(6)
#define Y_RSENSE X_RSENSE
#define Z_TRINAMIC_DRIVER 2130
#define Z_DISABLE_PIN I2SO(8)
#define Z_DIRECTION_PIN I2SO(9)
#define Z_STEP_PIN I2SO(10)
#define Z_CS_PIN I2SO(11)
#define Z_RSENSE X_RSENSE
#define A_TRINAMIC_DRIVER 2130
#define A_DIRECTION_PIN I2SO(12)
#define A_STEP_PIN I2SO(13)
#define A_DISABLE_PIN I2SO(15)
#define A_CS_PIN I2SO(14)
#define A_RSENSE X_RSENSE
#define B_TRINAMIC_DRIVER 2130
#define B_DISABLE_PIN I2SO(16)
#define B_DIRECTION_PIN I2SO(17)
#define B_STEP_PIN I2SO(18)
#define B_CS_PIN I2SO(19)
#define B_RSENSE X_RSENSE
#define C_TRINAMIC_DRIVER 2130
#define C_DIRECTION_PIN I2SO(20)
#define C_STEP_PIN I2SO(21)
#define C_DISABLE_PIN I2SO(23)
#define C_CS_PIN I2SO(22)
#define C_RSENSE X_RSENSE
/*
#define SPINDLE_TYPE SPINDLE_TYPE_PWM // only one spindle at a time
#define SPINDLE_OUTPUT_PIN GPIO_NUM_26
#define SPINDLE_ENABLE_PIN GPIO_NUM_4
#define SPINDLE_DIR_PIN GPIO_NUM_16
*/
#define X_LIMIT_PIN GPIO_NUM_33
#define Y_LIMIT_PIN GPIO_NUM_32
#define Z_LIMIT_PIN GPIO_NUM_35
#define A_LIMIT_PIN GPIO_NUM_34
#define B_LIMIT_PIN GPIO_NUM_39
#define C_LIMIT_PIN GPIO_NUM_36
#define SPINDLE_TYPE SPINDLE_TYPE_RELAY
#define SPINDLE_OUTPUT_PIN GPIO_NUM_26
#define PROBE_PIN GPIO_NUM_25
#define COOLANT_MIST_PIN GPIO_NUM_2
// === Default settings
#define DEFAULT_STEP_PULSE_MICROSECONDS I2S_OUT_USEC_PER_PULSE
// redefine some stuff from config.h
#ifdef HOMING_CYCLE_0
#undef HOMING_CYCLE_0
#endif
#define HOMING_CYCLE_0 bit(X_AXIS) // this 'bot only homes the X axis
#ifdef HOMING_CYCLE_1
#undef HOMING_CYCLE_1
#endif
#ifdef HOMING_CYCLE_2
#undef HOMING_CYCLE_2
#endif
#define DEFAULT_STEPPING_INVERT_MASK 0 // uint8_t
#define DEFAULT_DIRECTION_INVERT_MASK 2 // uint8_t
#define DEFAULT_INVERT_ST_ENABLE 0 // boolean
#define DEFAULT_INVERT_LIMIT_PINS 1 // boolean
#define DEFAULT_INVERT_PROBE_PIN 1 // boolean
#define DEFAULT_HOMING_ENABLE 1
#define DEFAULT_HOMING_DIR_MASK 0 // move positive dir Z, negative X,Y
#define DEFAULT_HOMING_FEED_RATE 200.0 // mm/min
#define DEFAULT_HOMING_SEEK_RATE 1000.0 // mm/min
#define DEFAULT_HOMING_DEBOUNCE_DELAY 250 // msec (0-65k)
#define DEFAULT_HOMING_PULLOFF 3.0 // mm
#define DEFAULT_X_STEPS_PER_MM 88.889
#define DEFAULT_Y_STEPS_PER_MM 77.037
#define DEFAULT_Z_STEPS_PER_MM 100.0 // This is percent in servo mode
#define DEFAULT_X_MAX_RATE 5000.0 // mm/min
#define DEFAULT_Y_MAX_RATE 15000.0 // mm/min
#define DEFAULT_Z_MAX_RATE 3000.0 // mm/min
#define DEFAULT_X_ACCELERATION 200.0 // mm/sec^2. 200 mm/sec^2 = 720000 mm/min^2
#define DEFAULT_Y_ACCELERATION 200.0 // mm/sec^2
#define DEFAULT_Z_ACCELERATION 50.0 // mm/sec^2
#define DEFAULT_X_MAX_TRAVEL 50.0 // mm NOTE: Must be a positive value.
#define DEFAULT_Y_MAX_TRAVEL 300.0 // mm NOTE: Must be a positive value.
#define DEFAULT_Z_MAX_TRAVEL 100.0 // This is percent in servo mode |
Here's a video recording of the $HX test. |
I'm experimenting with the limitations of I2S static. I2S stream I2S static |
Test results: Video Log
|
The current pulse interval of the I2S stream is adjusted using the adhoc value so that the timing is similar to that of a normal interrupt processing stepper. Settings:
G-Code: |
Homing and Probing test results. It appears to be normal. I2S stream (dynamic switching)
I2S static (always static):
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the long term, we should move to a class structure so we do not need enumerations of stepper types and name lists. But that can wait for another day.
A bug found. |
* Dynamically changing the mode of I2S * Fix invalid step pulse width in I2S static * More accurate I2S stream stepping Co-authored-by: bdring <barton.dring@gmail.com>
The I2S stepper has two modes.
Short (4-8 μsec) delay, little jitter
Long (10-12 millisec) delay, no jitter
This PR is a proposed change that takes advantage of the strengths of each mode of I2S and uses them to their advantage.
In homing and probing, synchronization of sensor input and motor movement is important. So be sure to use the I2S static mode.
Normal motor movement can generate perfectly precalculated steps in normal motor movement, so use the I2S stream mode for accurate movement.
However, it is now possible to fix it to I2S static mode in the machine configuration.
#define DEFAULT_STEPPER ST_I2S_STATIC
In my environment, it appears to be working as intended.
Please confirm.