logo xon
Phone: +39 011 901.66.10
Fax: +39 011 901.66.26
info@xonelectronics.it

bandiera-italiana  Lingua italiana



About us
Products
Services
Downloads
Technical support
     EZ-Red
           EZ-Red + stepper motor
     Ministep


More info on:

EZ-Red drives a stepper motor
An experiment started for fun, shows some EZ-Red features:

Commercial informations:
commerciale@xonelectronics.it

Technical informations:
tecnico@xonelectronics.it

Webmaster:
web@xonelectronics.it

This site uses only technical cookies which, for italian laws, do not need explicit user acceptance (GU 126 3 june 2014)


(C) XON Electronics
Copying material from this site is forbidden.

Foto

To make a stepper motor turn, power and precise waves are required... EZ-Red has them all, why not to give it a try?

So went, for fun, I made a few connections and wrote a simple PLC cycle.

Warning: this is an experiment with NO REAL APPLICATION: stepper motors need constant current driving - EZ-Red does not have a suitable circuitry.

Look at the video of this experiment

Connections

A stepper motor normally requires that each coil gets powered in "direct" and "reverse" mode. As EZ-Red has fixed polarity on its outputs, I took a unipolar motor which, for each coil, has 3 wires: by using the middle one as common return, it is possible to reverse the polarity when needed (losing some power, but this is just an experiment). The connection scheme I used is the following:


Power supply and resistors must be chosen depending on the motor: as a starting point, 16 volts and 200 ohms / 2 watts are safe values.

PLC Cycle

The cycle is designed around the idea that the correct sequence for energizing the coils is like: ...and this sequence repeats forever. After every new output configuration, some delay is needed - this time determines the angular speed of the rotor. The motor used in this case has 200 steps per turn, so a delay of 5 ms per step (200 steps a second) generates a full rotation every second. These concepts expressed in EZ-Red language lead to a simple task like this:
task2:
  ybyte=0b0001
  wait stpdelay
	; stpdelay is the variable that
	; contains the delay in ms

  ybyte=0b0100
  wait stpdelay

  ybyte=0b0010
  wait stpdelay

  ybyte=0b1000
  wait stpdelay
	

To rotate the motor in the opposite direction, simply use this sequence, but reversed. If, after each step, a variable "posmot" is incremented (or decremented), it is possible to know (and hence, control) completely the motor. So, the PLC cycle contains two tasks (clockwise and counter-clockwise) to make the motor turn: by starting (and stopping) one of the two tasks, and monitoring the rotor position, we can completely control the motor. By writing the STPDELAY variable, even the speed is controlled. The main task reads the potentiometer and decides whether to change the rotor position and, if yes, in which direction. The difference between the potentiometer position and the motor position is also examined in order to choose the motor speed.

The full program listing (which is not a perfect one) is the following:

define stpdelay dt1
define posmot dt5
stpdelay=5

task1:
  if posmot>260 then posmot=1
  if posmot>ain1 then
    if posmot-ain1 > 10 then stpdelay = 5 else stpdelay=20
    suspend 2
    wakeup 3
  end
  if posmot<ain1 then
    if ain1-posmot > 10 then stpdelay = 5 else stpdelay=20
    suspend 3
    wakeup 2
  end
  if posmot=ain1 then
    suspend 2
    suspend 3
    ybyte=0
  end

task2:
  ; outs: RRLL
  ybyte=0b0001
  posmot=posmot+1
  wait stpdelay

  ybyte=0b0100
  posmot=posmot+1
  wait stpdelay

  ybyte=0b0010
  posmot=posmot+1
  wait stpdelay

  ybyte=0b1000
  posmot=posmot+1
  wait stpdelay

task3:
  ; outs: RRLL
  ybyte=0b0001
  posmot=posmot-1
  wait stpdelay

  ybyte=0b1000
  posmot=posmot-1
  wait stpdelay

  ybyte=0b0010
  posmot=posmot-1
  wait stpdelay

  ybyte=0b0100
  posmot=posmot-1
  wait stpdelay

	

XON Electronics Srl - P.Iva I-02828930046 - PEC xonelectronics@pec.xonelectronics.it