Author Topic: (STP/DIR) Manually driving the stepper motors using Raspberry Pi  (Read 265 times)

0 Members and 1 Guest are viewing this topic.

Offline DiscoDan78

  • Active Member
  • Posts: 6
    • View Profile
(STP/DIR) Manually driving the stepper motors using Raspberry Pi
« on: November 22, 2018, 03:14:52 PM »
I have CNC router along with its driver unit. I dont want to use it as a router, i'm hacking it to move manually using 2 joysticks. One joystick is a 4-way and controls the X and Y axis. The other joystick is a 2-way and controls the Z-axis.

I want to keep my work to a minimum, so i plan to drive the CNC from the parallel port that would usually get signals from the PC (i.e. Mach3). It would appear there are only 3 wires from the parallel port to each of the stepper motor drivers. I assume these are: STEP, DIR & GND?

My question is this:
Assuming that is the only signals I need, what type of waveforms do they need?
From what i've read, DIR is just a standard logic signal (5V or 0V). Is that correct?
It would appear the STEP signal requires a pulsed input? That would make sense.
So assuming it needs a pulsed input, what is the frequency (25kHz)?
Also, what would a typical pulse train look like in order to get the motor moving?
I know the Pi is 3.3V, i have a driver converting them all to 5V.

Any help much appreciated. I'll try post some pics and vids later.

10-4 Rubber Ducky

Offline joeaverage

  • Active Member
  • Posts: 4,532
    • View Profile
Re: (STP/DIR) Manually driving the stepper motors using Raspberry Pi
« Reply #1 on: November 22, 2018, 03:55:03 PM »
Hi,
you are correct most stepper drivers are 5V TTL input. More recent designs will accommodate 3.3V TTL as well, you may not need
that converter.

To start with assume that the stepper drivers have no microstepping activated. Thus every time a pulse is delivered to the step terminal the motor will
advance one full step, with a two phase stepper that is 1.80. So with 200 pulses the motor would rotate  one turn.
If you want your stepper to rotate at 100 rpm then you will need 100 X 200 =20,000 pulses per minute or 333.33 pulses per second.

If you suddenly turned on the PI and it were producing 333 pulse per second the motor would stall. The motor cannot go from zero speed to
100 rpm instantly.....you have to build up to it slowly, or ramp up, as they say. If you apply a pulse stream too rapidly the motor can't keep up
and it stalls making a squealing noise. The only way to overcome that is to remove the pulse stream and then reapply it but 'ramp' it up.

A device like the PI or an Arduino can do this easily. It will take a lot of programming. Mach3 or Mach4 has already got all that 'ramp up and ramp down'
stuff built in amongst many other features including joystick jogging at variable rate and modes.

Craig
My wife left with my best friend...
     and I miss him!

Offline DiscoDan78

  • Active Member
  • Posts: 6
    • View Profile
Re: (STP/DIR) Manually driving the stepper motors using Raspberry Pi
« Reply #2 on: November 22, 2018, 04:27:55 PM »
Hi Craig

Thanks for the reply, ramping up makes perfect sense, otherwise the magnetic field inside the motor will be moving faster than the motor can go from a standing start.

I cant use Mach 3 because it needs to be idiot proof. I want to use it as a soldering machine and there's limited space, so i want to keep it as compact as possible. The pi fits inside the little control box with 2 little joysticks and a button that turns the heat on and off. Its actually a resistance solder process so it heats up instantly. Probably going off topic now.

So to summarise:
I just need to control the motor using a square wave, there's no PWM required?
The frequency of the waveform controls the speed of the motor?
Start the frequency slow and ramp it up.

Thanks again.

Offline joeaverage

  • Active Member
  • Posts: 4,532
    • View Profile
Re: (STP/DIR) Manually driving the stepper motors using Raspberry Pi
« Reply #3 on: November 22, 2018, 04:52:21 PM »
Hi,

Quote
Thanks for the reply, ramping up makes perfect sense, otherwise the magnetic field inside the motor will be moving faster than the motor can go from a standing start

That is a perfect description of a stepper motor stall. The rate at which a stepper can accelerate is determined by the rotational inertia
of the rotor and associated ballscrew. The mass of the load in effect increases the rotational inertia of the armature. It is for this reason that
servos and steppers have detailed specifications about torque and rotational inertia....because they set the possible angular acceleration.

Quote
I just need to control the motor using a square wave, there's no PWM required?

That is correct. Most stepper drivers will have some specification about minimum pulse width, commonly 5 us. That still allows for a very fast
pulse train, faster than you will ever require.

A absolutely vital piece of stepper motor physics is that the torque reduces as speed increases. Much is made of the inductance of the windings,
the smaller the inductance the faster the motor will go with acceptable torque. As a rule the torque available from a stepper is about 1/2 of its
maximum rated torque at 500 rpm. If you want good performance with rotational speeds in excess of 500 rpm you are going to have to do some
homework OR use servos.

Your stepper drivers probably have microstepping. It is a means of causing the motor to rotate 'in between' the 1.80 full step positions.
While it sounds a seductive means to increase the resolution of a stepper due to physics it is not as effective as you might like to believe. What
microstepping does do however is make the motion smoother and can greatly reduce mid-band resonance which plagues steppers. Thus you would have
some microstepping, usually set by switches in the dirives. A micro step of 8 is a good compromise. It increases resolution over full step by a factor of
2 reliably and gives smooth motion without your controller having to deliver accurate pulse streams in the high tens of kHz.

If you had microstepping set to 8 then it will require 8 x 200 =1600 pulse /er rev. Remember the 200 comes from 3600/1.80=200.

Craig
My wife left with my best friend...
     and I miss him!

Offline DiscoDan78

  • Active Member
  • Posts: 6
    • View Profile
Re: (STP/DIR) Manually driving the stepper motors using Raspberry Pi
« Reply #4 on: November 22, 2018, 05:09:33 PM »
Hi Craig

The drivers do indeed have dip switches on them, so there will be some microstepping.
I'm gonna gave a bash at this over the next couple days.
Thanks again for clearing all that up so concisely.

Cheers
Dan

Offline joeaverage

  • Active Member
  • Posts: 4,532
    • View Profile
Re: (STP/DIR) Manually driving the stepper motors using Raspberry Pi
« Reply #5 on: November 22, 2018, 07:10:39 PM »
Hi,
I'm guessing that you are going to have to program things like limit switches and/or home switches plus the motion control.
That is a major undertaking.

I understand that you wish to keep the installation compact and certainly the PI is that.

The only alternative to writing all that code is:

https://www.dfrobot.com/product-1585.html

$209 gets you a Windows 10 PC with Windows 10 Enterprise installed with 4/64G memory....not bad. If you wanted to run Mach (3 or 4)
you would require a motion control board like a SmoothStepper or a UC300. A 64 bit machine like the LattePanda 4/64 CANNOT run a parallel
port. Thus your budget would need to include the cost of an external controller. I use an Ethernet SmoothStepper (ESS) by Warp9 TD (don't get ripped
by the bulls*********t Chinese knockoffs) for $185.00. You would also want a breakout board (BoB), a ubiquitous C10 for $23.00
The LattaPanda, the ESS and BoB would fit into a 120mm cube or thereabouts.

May I suggest downloading Mach, either or both 3 or 4, and try them as demo at no cost. It might interest you to see how the motor tuning is set up.
Likewise it may give you an appreciation of all the features including jogging etc. I would recommend Mach4, it is superior when it comes to customization
which you'll want for a standalone machine.

There is already a 'Shuttle Pro' plugin which maybe adaptable to your requirements. If the Shuttle Pro plugin is not suitable then the Xbox plugin will.
It is written by users and so you can download it and tweak it to your satisfaction. Note these plugins are only for Mach4 to my knowledge.

Yet another alternative is LinuxCNC. The same LattePanda board without Windows 10 is $149.00. You can install LinuxCNC for free and it will
run a parallel port. Its not the norm to recommend what amounts to a competeing software product on the Mach forum but I feel honour bound
to point out that it could be a perfect solution for you. Indeed LinuxCNC could be installed on a PI as well, even cheaper again!.

Craig
My wife left with my best friend...
     and I miss him!

Offline DiscoDan78

  • Active Member
  • Posts: 6
    • View Profile
Re: (STP/DIR) Manually driving the stepper motors using Raspberry Pi
« Reply #6 on: November 23, 2018, 08:14:27 AM »
Hi Craig

Wow, that's excellent info, i had no idea there was so many options.
Looking at them all now, think I'll definitely use one of those.
Thanks for adding all that extra detail - really helpful.

Cheers
Dan

Offline DiscoDan78

  • Active Member
  • Posts: 6
    • View Profile
Re: (STP/DIR) Manually driving the stepper motors using Raspberry Pi
« Reply #7 on: November 24, 2018, 08:37:44 AM »
Hi Craig

I'm looking to get the 4/64GB lattepanda but it says there's none in stock on the dfrobot site.
I checked elsewhere and Amazon have them but its expensive at £425 (GBP).
They have a 2/32GB for something like £115 (GBP), would still work?

Cheers
Dan


Offline DiscoDan78

  • Active Member
  • Posts: 6
    • View Profile
Re: (STP/DIR) Manually driving the stepper motors using Raspberry Pi
« Reply #8 on: November 24, 2018, 08:44:49 AM »
Sack that last post, found one.
Im gonna trial using the setup you suggested.
Might be back in touch later if i get stuck.

Cherrs