# stepper motors

#### Driver72

Jan 10, 2024
13
Let me preface that I'm not an expert on stepper motors, but here's my 2 cents from what I can deduce from the manual and from your description:

The DM542T seems to be controlled by these signals:
• pulse - stepper pulses from the controller (Raspbery Pi) to the Stepper driver
• dir - direction signal from teh controller to the driver. Note that the dir signal needs to lead the pulse signal by 5 µs (table on page 3) which means that after changing dir you need to wait 5 µs before issuing the next pulse by the controller.
• ena - enable 5 V inputs instead of 24 V inputs. This signal can be fixed to active (my understanding of the manual)
These are differential signals, meaning that you apply a positive voltage to the "+" pin and GND to the '-' pin. This alow easy control of the driver bei either high-active outputs or low-active outputs, see manual, figure 4 and 5, respectively.

That said let's assume the pins are wired correctly.

Next step would be to set the cintrol signal voltage to 5 V as the factory setting is 24 V (see table on page 3 and figure 2 and read slo chapter 4 of the manual). The Raspberry can't handle 24 V signals, only 5 V signals.
Let's assume this has been done.

Now to the code. I will use pseudo code as I don't know how you are programming this (probably Python?), but pseudo code should be good enough to get you on track:
Code:
# Declaration of pins

mot1_dir = pin??
mot1_step = pin??
mot2_dir = pin??
mot2_step = pin??

# Declaration of constants for better readability.
# Needs to be matched to your actual setup

LEFT = 1
RIGHT = 0

# Subroutine to move either motor by numsteps in the given direction
def move_motor(motor, direction, numsteps):
if (motor==1):
mot1_dir = direction
wait(5µs)
for i in range(numsteps): #create pulses
mot1_step=1
wait(5µs) #for max. speed of 200 kHz pulse frequency. Increase the value for slower speed.
mot1_step=0
wait(5µs) #for max. speed of 200 kHz pulse frequency. Increase the value for slower speed.
if (motor==2):
mot2_dir = direction
wait(5µs)
for i in range(numsteps): #create pulses
mot2_step=1
wait(5µs) #for max. speed of 200 kHz pulse frequency. Increase the value for slower speed.
mot2_step=0
wait(5µs) #for max. speed of 200 kHz pulse frequency. Increase the value for slower speed.

# Here comes your main routine to control the movement of the motors with a sample sequence.
# This sequence needs to be matched to your requirements.
# You also may want to incorporate some kind of control like e.g. reading a button to initiate or stop the sequence etc.
move_motor(1,LEFT, 100) # This will move motor 1 only, motor 2 is at rest.
move_motor(2, RIGHT, 200) # This in turn moves motor 2 whiel motor 1 is at rest
move_motor(1,RIGHT, 100)
move_motor(2, LEFT, 200) # after this step all motors should be in the initial position
Actually moving only one motor a a time, as you requestwed, is the easy part. Moving 2 motors synchronously will be more challenging as you have to output pulses to both motors simultaneously.

Note that this code is very rudimentary. You may want to add lots of features like for example:
• moving the motors to a defined position when you turn on the machine. This may require additional sensors (end switches) to detect the end position of the motors/mechanics)
• adding an emergency button to immediately stop the motors
• adding code to evaluate the alarm signals from the DM542T
• etc.
Here is an example of a tutorial how to drive a stepper motor by a Raspberry Pi.

By the way: If this is the only job for the Raspberry Pi, this computer is pure overkill. A comaparatively cheap Arduino (clone) can do this for way less money.
Yes this is exactly what i'm trying to do. I will be going at it again today and will be using this info hopefully getting better results. I'll be getting back to you and let you know how i'm doing.
Thanks again for all your help

#### Minder

Apr 24, 2015
3,478
I don't see why they would require that the DIR signal is pulsed, if you are moving in a specific direction it can remain HI or LOW, at least on the systems I have implemented they can do this.
Stepper motors can handle constant rated current, with the correct drive that maintains the plate rated current at all times.
It is often done in applications that require a certain holding force.
That said, remove power if the feature is not needed.

#### Driver72

Jan 10, 2024
13
I don't see why they would require that the DIR signal is pulsed, if you are moving in a specific direction it can remain HI or LOW, at least on the systems I have implemented they can do this.
Stepper motors can handle constant rated current, with the correct drive that maintains the plate rated current at all times.
It is often done in applications that require a certain holding force.
That said, remove power if the feature is not needed.
I think that is correct. From the program I'm trying to work with it uses only the pulse_pin,gpio.HIGH or LOW for direction if I'm correct.

#### Harald Kapp

##### Moderator
Moderator
Nov 17, 2011
13,720
I don't see why they would require that the DIR signal is pulsed,
It is not required.
What the manual states is that the DIR signal needs at least 5 µs setuop time befor a stepper pulse is issued.

Replies
2
Views
316
Replies
21
Views
8K
Replies
5
Views
2K
Replies
2
Views
917
Replies
3
Views
2K