Unfortunately I cannot find anywhere how can I turn the motor to +/- 1°
Once I have a pulse, I don’t understand how to tell the motor and the driver to move 142µsteps
After you set the correct microstepping mode on our High-Power Stepper Motor Driver 36v4 (in addition to the other required configuration procedures, like setting the current limit) all you need to do is send as many pulses to the STEP pin as the number of microsteps you want the motor to move. For example, if you want your stepper motor to move 142 microsteps in 1/256 microstepping mode, you need to configure the driver to operate in that mode then pulse the STEP pin 142 times.
I have a working program on Arduino but I can’t make the stepper motor moving of 1° at each impuls.
When I do a full 360° rotation of my coding weel, the motor make a 1/4 turn (if i set the microsteps to 1, the motor make a 1/2 turn but miss some steps)
How could I change that?
Could you please help me on that one?
here is the code:
// Deux moteurs pas à pas + deux manivelles
//Pilotage moteurs pas à pas avec driver pololu & comminication SPI
#include <SPI.h>
#include <HighPowerStepperDriver.h>
#include <Arduino.h>
#define RCod_Dr_B 2
#define RCod_Dr_A 3
float compteur_Dr = 0;
const uint8_t CSPin_Dr = 53;
// This period is the length of the delay between steps, which controls the
// stepper motor's speed. You can increase the delay to make the stepper motor
// go slower. If you decrease the delay, the stepper motor will go faster, but
// there is a limit to how fast it can go before it starts missing steps.
const uint16_t StepPeriodUs = 100;
HighPowerStepperDriver sd;
//---------------------VOID IRQ CODEUR MESURE DE VITESSE Droite----
void Isr_Dr() {
if (digitalRead(RCod_Dr_A)) {
compteur_Dr = compteur_Dr - 1;
} else {
compteur_Dr = compteur_Dr + 1;
}
if (compteur_Dr > 0) {
sd.setDirection(0);
sd.step();
delayMicroseconds(StepPeriodUs);
compteur_Dr = compteur_Dr - 1;
} else {
sd.setDirection(1);
sd.step();
delayMicroseconds(StepPeriodUs);
compteur_Dr = compteur_Dr + 1;
}
}
void setup()
{
// Moteurs Pas à Pas
Serial.begin(9600);
pinMode(RCod_Dr_B, INPUT);
pinMode(RCod_Dr_A, INPUT);
attachInterrupt(digitalPinToInterrupt(RCod_Dr_B), Isr_Dr, RISING );
SPI.begin();
sd.setChipSelectPin(CSPin_Dr);
// Give the driver some time to power up.
delay(1);
// Reset the driver to its default settings and clear latched status
// conditions.
sd.resetSettings();
sd.clearStatus();
// Select auto mixed decay. TI's DRV8711 documentation recommends this mode
// for most applications, and we find that it usually works well.
sd.setDecayMode(HPSDDecayMode::AutoMixed);
// Set the current limit. You should change the number here to an appropriate
// value for your particular system.
sd.setCurrentMilliamps36v4(1500);
// Set the number of microsteps that correspond to one full step.
sd.setStepMode(HPSDStepMode::MicroStep2);
// Enable the motor outputs.
sd.enableDriver();
}
void loop()
{
// ................next of the program.....................
delay(10000);
}
I am not sure what your “coding wheel” is, but it sounds like whatever counts or measurements you are getting from that just are not lining up with the commands you need to send your driver to get the desired behavior. It looks like you are equating each coding wheel count to one step, but unless the counts per revolution of your coding wheel happens to equal the microsteps per revolution of your stepper motor, the conversion is probably going to be more complicated than that. I recommend just making a program that reports counts from your coding wheel so you can get a better idea of what it is doing.
Also, it looks like you are sending SPI commands in your interrupt routine, which could be problematic. In general, it is best to keep interrupt routines as simple as possible, so it would probably be better if you set up your program to send step commands and set the rotation direction outside of that routine.