Hello, I am using tmc 2209 in conjunction with ESP 32 (arduino) and TMC 2209 library (github). Movement at a given speed is carried out using the command stepper_driver.moveAtVelocity(speed); which corresponds to the VACTUAL register (see driver instructions). The tmc 2209 instruction says that you can get ripples from the INDEX output (at the driver) with each new step. Please tell me with the help of which register or what command can this be done, what needs to be written? I connected the wire from the index pin to the GPIO pin 34 (ESP 32), each time the signal code changes from 1 to 0, the COUNTER variable increases. Now it remains to understand how to use this output, by default, ripples do not come to it (COUNTER is always equal to 0).
#include <Arduino.h>
#include "mString.h"
#include <TMC2209.h>
#define PIN_POT_1 34
#include "GyverStepper2.h"
GStepper2< STEPPER2WIRE> stepper(200, 2, 4 , 0);
HardwareSerial & serial_stream = Serial2;
const int DELAY = 100;
//const uint8_t RUN_CURRENT_PERCENT = 150;
const int32_t VELOCITY = 20000;
//const uint8_t STALL_GUARD_THRESHOLD = 140;
int lastState = HIGH;
int currentState;
long int speed1;
int run_cur = 0;
int rc = 0;
int t = 0;
int th = 0;
uint32_t ttm = 0;
int low_value = 500;
volatile int counter = 0; // переменная-счётчик
char sym = 0;
//Instantiate TMC2209
TMC2209 stepper_driver;
void IRAM_ATTR index_pulses() {
counter++;
}
void setup()
{
pinMode(PIN_POT_1, INPUT);
Serial.begin(115200);
Serial.setTimeout(50);
attachInterrupt(PIN_POT_1, index_pulses, FALLING);
byte message_3[] = {0xAA, 0x00,0xA2,0x40, 0x01,0x00,0x00,0x3e};
Serial.write (message_3, sizeof(message_3));
stepper_driver.setup(serial_stream);
stepper_driver.moveAtVelocity(2000);
stepper_driver.writeStoredGlobalConfig();
if (stepper_driver.isSetupAndCommunicating())
{
Serial.println("Stepper driver setup and communicating!");
Serial.println("");
}
else
{
Serial.println("Stepper driver not setup and communicating!");
return;
}
stepper_driver.enable();
}
void loop() {
Serial.println(counter);
//uint16_t stall_guard_result = stepper_driver.getStallGuardResult();
//Serial.println(stall_guard_result);
if (Serial.available() > 0) {
sym = Serial.read();
if (sym == 's') {
String ch = Serial.readString();
String n = ch.substring(1);
int g = n.toInt();
speed1 = g;
stepper_driver.moveAtVelocity(speed1);
stepper_driver.setRunCurrent(400);
}
}
if (not stepper_driver.isSetupAndCommunicating())
{
Serial.println("Stepper driver not setup and communicating!");
return;
}
delay(DELAY);
}
The output of the index pin is what you use to count the number of steps you have moved when not commanding the motor to move with the step pin. Otherwise, the motor will just keep spinning and spinning. The whole point of using a stepper is to have more precise control of the movement than you would with a DC motor. If you're just going to spin in one direction forever, use a DC motor. It's simpler.
Yes, I want to use the output index to count steps, but I can’t do it (I know that there are libraries for counting steps using step and sir, but this is not my case, I set the speed using the moveAtvelocity command of the tmc 2209 library in it this is the VACTUAL register). How can I get pulses on the INDEX output? Sorry for the long messages, I need to resolve this issue.
What do you mean how do you "get" the pulses from the Index pin? You connect the index pin to one of the pins of your ESP32 that is set for INPUT. Then, every time that pin goes high, you have moved one step. The way I am handling it is by using an interrupt to count the pulses and then comparing that to the number of steps that I was intending to move. Steppers are always based on the number of steps that you want to move, whether you are moving it a step at a time with the step pin or counting the number of steps that the driver is moving the motor on it's own.
In setup:
Yes, I did everything exactly like this (see post #122). But my counter variable doesn't change, RISING, FALLING... Doesn't matter, I don't get pulses. The oscilloscope also shows nothing. As I said, in the library, the speed is set by the moveAtVelocity command, which corresponds to the VACTUAL register in the file of this library. In the datasheet there is a mention of the INDEX output, as I understand it, it should receive pulses by default, correct me if I'm wrong. Perhaps this function needs to be activated separately, but I did not find how, I would be grateful if someone throws off the activation code (what I need to send).
And you have the index pin on your TMC2209 connected to pin 34 on your ESP32? (I would use a different pin BTW. The high 30 pins can cause issues.). The index pin might be any of A, B or C of this drawing:
depending on your particular breakout board. For example, mine from BigTreeTech use pin B but Fysetc ones use pin A.
Yeah, I wouldn't assume that A is the INDEX pin. Try soldering in a pin into the middle pin. That is most likely the INDEX pin because in a 3d printer they are using the STEP/DIR interface so they have no need for the INDEX pin. Your pinout could be: