Hello people.
I'm working with stepper motors NEMA 17 and 14, configuring TMCStepper library with ESP8266 UART1 TX.
My code for this motor is the following:
/**
* Author Teemu Mäntykallio
* Initializes the library and runs the stepper
* motor in alternating directions.
*/
#include <TMCStepper.h>
#define EN_PIN 38 // Enable
#define DIR_PIN 5 // Direction
#define STEP_PIN 16 // Step
#define micro_steps 4
#define R_SENSE 0.11f // Match to your driver
// SilentStepStick series use 0.11
// UltiMachine Einsy and Archim2 boards use 0.2
// Panucatt BSD2660 uses 0.1
// Watterott TMC5160 uses 0.075
TMC2208Stepper driver(&Serial1, R_SENSE); // Hardware Serial
int ang_meas = 180;
bool shaft = false;
bool stop = false;
void setup() {
/*Serial communication MATLAB */
Serial.begin(115200);
Serial.setTimeout(5000);
/* UART communication driver */
Serial1.begin(115200); // HW UART drivers
/* Configure output pins */
pinMode(EN_PIN, OUTPUT);
pinMode(STEP_PIN, OUTPUT);
digitalWrite(EN_PIN, LOW); // Enable driver in hardware
/* Configure driver */
driver.begin(); // SPI: Init CS pins and possible SW SPI pins
driver.pdn_disable(true); // Use PDN/UART pin for communication
driver.I_scale_analog(false); // Use internal voltage reference
driver.rms_current(230); // Set motor RMS current
driver.mstep_reg_select(1); // necessary for TMC2208 to set microstep register with UART
driver.microsteps(micro_steps); // Set microsteps
driver.toff(5); // Enables driver in software
// driver.en_pwm_mode(true); // Enable stealthChop
driver.pwm_autoscale(true); // Needed for stealthChop
delay(8000);
}
void loop() {
uint16_t max_steps = ang_meas/(1.8/micro_steps); // Calculate maximum steps
// Run 180 degree steps and return to position in software
while(stop == false){
for (uint16_t i = 0; i<=max_steps; i++) {
Serial.println(i); // Tell MATLAB to measure
//Advance 1 step
digitalWrite(STEP_PIN, HIGH);
delayMicroseconds(6000);
digitalWrite(STEP_PIN, LOW);
delay(300);
}
delay(5000);
shaft = !shaft;
driver.shaft(shaft);
for (uint16_t i = 0; i<=max_steps; i++) {
digitalWrite(STEP_PIN, HIGH);
delayMicroseconds(2000);
digitalWrite(STEP_PIN, LOW);
delayMicroseconds(2000);
}
stop=true;
}
}
My question is regarding current consumption. Because I want the motor to increment step by step, I do not know if it is better to use Vactual instead of STEP mode?
My current consumption when the motor rotates is all the time on the maximum, is it supposed?
When using NEMA 17 with 800mA rms current it happens also it also remains on maximum or near.
I use a bench power supply and check the current value there.
Edit: Because in my first tests with another driver (DRV) and without UART option. This meaning manually current adjust through potenciometer and microsreps configurations with STM32 and more delay between step level toggle. For that configuration the current was not at maximum, only if I apply more pressure it increases.
Thanksss