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
ConnectionsA 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 CycleThe cycle is designed around the idea that the correct sequence for energizing the coils is like:
- Coil 1 direct
- Coil 2 direct
- Coil 1 inverse
- Coil 2 inverse
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
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