EEVblog Electronics Community Forum

Electronics => Beginners => Topic started by: Archades on November 06, 2020, 06:22:55 pm

Title: Count stepper motor steps.
Post by: Archades on November 06, 2020, 06:22:55 pm
Hi, I was wondering what equipment I need to count pulses of a stepper motor, to make sure my cnc router is operating perfectly. So I can run G-code to do say 1000 steps, I want to test that the motor is stepping 1,000 times.

Not sure if oscillosopes have a function for this, I have a Siglent SDS1104X-E. Is there a function on the scope to do this? Or do I need a Universal counter? If so are there any best bang for buck ones, or can an arduino be setup to count pulses to an LCD. 

Thanks
Title: Re: Count stepper motor steps.
Post by: Ian.M on November 06, 2020, 07:27:18 pm
That probably won't help.  If its loosing steps, the problem is rarely due the drive waveforms.  Usually its due to the motor being too heavily loaded for the commanded acceleration rate so there isn't enough torque for the rotor to be able to follow the magnetic field.  To monitor steps lost due to overloading, you'd need an encoder monitoring the axis in question driving a digital readout.
Title: Re: Count stepper motor steps.
Post by: Archades on November 06, 2020, 07:37:09 pm
Ah ok. As for counting the steps, what would be useful? More just for my own learning and ability to do for ever the time arises, I like to see it working. Also want to be able to calibrate flow meters and other pulsed devices.
Would the VC3165 Frequency counter be alright?
Title: Re: Count stepper motor steps.
Post by: Domagoj T on November 06, 2020, 07:43:18 pm
If you don't need closed loop control, and just want to verify that you're not losing steps, put a dial indicator near the ends of travel and move the axis back and forth at incrementally increasing acceleration and speed. If you get different results at different speeds, it means you're losing steps.
Title: Re: Count stepper motor steps.
Post by: Archades on November 06, 2020, 07:47:15 pm
That's a good idea on the dial indicator.

Probably won't catch many errors but if I was really keen I could measure 20-30 pulses and manually count them on the scope?
Title: Re: Count stepper motor steps.
Post by: wizard69 on November 06, 2020, 08:09:31 pm
Ah ok. As for counting the steps, what would be useful? More just for my own learning and ability to do for ever the time arises, I like to see it working. Also want to be able to calibrate flow meters and other pulsed devices.
Would the VC3165 Frequency counter be alright?

Well you could put a counter on the STEP signal.    This would only be useful in verifying code.    Counting steps by monitoring the signals going to the stepper motor coils would be a lot harder to almost impossible.    This is mainly due to current regulation, the voltage to the coils could be switched many times, resulting in a complex signal to try to trigger on.    For some of your other concerns a multi function counter sounds like the right solution.

As for the  VC3165, I can't say based on the Amazon listing.    MY guess would be probably not as it looks like its primary purpose is to be a frequency meter.    Hopefully somebody that actually has one of these can chime in.    At least for some of your needs I would imagine you will need a totalize function, a second trigger input wouldn't hurt either.   Consider something like the B&K Precision 1823A which at least has good on line documentation.    In any event you can't really expect to get a properly specced model suggestion online, you need to fit the meter to as many uses you have as is possible.    Only you really know what those uses are.
Title: Re: Count stepper motor steps.
Post by: Domagoj T on November 06, 2020, 08:21:24 pm
Another thing that crossed my mind - contact microphone.
Audacity should be fine for later counting and analysis.
Title: Re: Count stepper motor steps.
Post by: rstofer on November 06, 2020, 10:36:09 pm
You can't find missing steps by looking at the electrical.  By definition, the steps energized the coils.  If the motor missed the step it is because it couldn't keep up due to either mechanical load or RPM.  If you count the electrical steps, it tells you nothing about the mechanical steps.  A dial indicator is the tool of choice.

Another thing:  Whether the motor misses a step or not is pretty much dependent on the mechanical load.  If your feed rate is too fast or your cut depth is too deep, the motor will jump out of synch and you will 'miss a step'.  It had nothing to do with the electrical pulses, the motor just wasn't powerful enough for the feed rate/cut depth.  Every motion from that point on is incorrect in absolute terms even though it may be correct in relative terms.  Steppers are a problem as they have no independent position feedback.
Title: Re: Count stepper motor steps.
Post by: perieanuo on November 07, 2020, 09:00:22 am
Hi, I was wondering what equipment I need to count pulses of a stepper motor, to make sure my cnc router is operating perfectly. So I can run G-code to do say 1000 steps, I want to test that the motor is stepping 1,000 times.

Not sure if oscillosopes have a function for this, I have a Siglent SDS1104X-E. Is there a function on the scope to do this? Or do I need a Universal counter? If so are there any best bang for buck ones, or can an arduino be setup to count pulses to an LCD. 

Thanks
hi, you have only one way called encoder.
you can count whatever you like on power stage output, this count doesn't guarantee the motor executed that step you just count, excepting putting an encoder monitoring the shaft
and that technique is expensive, by a lot. so stick with controlling the mechanical chain, put correct limiters on ends and make a clean wiring and a good pcb, that's all
monitoring stepper motor steps is done only on high level/demanding app automation stuff
Title: Re: Count stepper motor steps.
Post by: Doctorandus_P on November 07, 2020, 12:36:21 pm
Sigrok / Pulseview is logic analyser software that has a decoder for steppermotor pulses.
And you only need <EUR10 of hardware to start with it.

https://sigrok.org/ (https://sigrok.org/)
Title: Re: Count stepper motor steps.
Post by: Ian.M on November 07, 2020, 02:36:34 pm
Its also got a decoder 'Gray code' that can handle rotary and linear quadrature encoders.   Get a cheap Cypress FX2 based 8 channel logic analyser (i.e a Salae Logic 8 clone), and you can log steps + direction to your stepper driver and an encoder on the same axis and still have four channels free, e.g. to monitor limit and home switches or another axis. 

For a dirt-cheap linear encoder, strip down a dead inkjet or dot matrix printer.  There is often a plastic optical grating strip the width of the platten (+ some over-travel for head parking)  running through a quadrature optosensor (usually an IR LED and two phototransistors behind narrow slits) that's part of the head assembly.  The optical grating is printed, so don't try to clean it with anything harsher than water, and when you disassemble it, keep its tensioner spring!
Title: Re: Count stepper motor steps.
Post by: wizard69 on November 07, 2020, 04:45:35 pm
Quote
Hi, I was wondering what equipment I need to count pulses of a stepper motor, to make sure my cnc router is operating perfectly.

After reading some of the replies here I have to wonder what you are actually trying to accomplish as I was left with the impression you want to verify your CNC controllers code.   As others have indicated if your goal is to mechanically verify operation you will need to do so with mechanical tools.   Depending upon how far you want to go this would mean a collection of dial indicators, squares and straight edges.

I bring this up because getting a machine to run to mechanical spec is hard work and is never "perfect".   Contrast this with software that needs to be as perfect as possible, software that loses counts or has off by one errors, is not acceptable.    I say this as the result of working several years with a machine tool rebuilding mechanic, nothing is perfect but your work has to meet specs for that machine.

With home built machines, the builder is often limited by the tools he has available.    For example if you don't have a good quality machinists squares you will have a hard time squaring up the machine.   If the machine is too far out of square you will have a hard time getting your ratios right for linear movements, not to mention that everything will be slightly off as far as squareness goes.

So what I'm saying here is that you don't even worry about the CNC controls until you get the machine mechanically right.   It will save you a lot of grief blaming the CNC controller when you have mechanical issues as the root problem.

Now on the flip side I can relate an instant when running a lathe in a loop helped us trace down an issue with a CNC controller loosing steps.   In this case the controller was developing an error someplace in its code that resulted in a sub micron error in position that we could actually see after running the machine through many cycles.   The thing here is that we would never had been able to measure that error on a sloppy axis in a reasonable time.   Eventually we found that a relay inside a packaged spindle drive was causing a glitch that threw off the CNC controller a tiny bit each time the spindle was cycled.   I say tiny because I don't actually know what was happening inside the controller, just that we had to run numerous cycles to even measure it with a dial indicator reading 2 microns per division.    What you can take from this is that an error in the CNC controller was determined by making precise measurements on a well tuned mechanical axis.   The issue was further narrowed down by running the same code with the spindle cycling eliminated.   Note that at no time was there any counter used, in fact due to resolver feed back and servo drive it would have been hard to find a place to slap a counter.

So why the long reply?   Simple to relate that your machine isn't perfect, there never has been such a mechanical contraption.   The first limitation is your ability to measure and align.   CNC controller code is an entirely different matter and there you need to rely upon the person coding the software.
Title: Re: Count stepper motor steps.
Post by: Kjelt on November 07, 2020, 07:01:22 pm
Just to comment on this:
So I can run G-code to do say 1000 steps, I want to test that the motor is stepping 1,000 times.
G-code does not know about #steps.
The G-code is defined in mm if in metric, something 1/1000 of an inch related if empirical.
This means that the translation has to be entered as a parameter in your cnc control software being Mach3 or EdingCNC or whatever.
There you enter an amount of steps per mm.
The amount of steps per mm is depending on your motordriver and the number of microsteps it is configured AND the mechanical translation from rotation to linear movement being a spindle with ballscrew or belt how much linear mm results per one full rotation.

So what you do is use a mechanical clock run it to a fixed piece of metal, zero the clock and the axis (workpiece coordinate not machine coordinate) and execute for instance for the X axis a G0 X1 to move 1mm to the right or G0 X-1 for 1mm to the left whatever is appropriate and then the cnc software dhould say X1 or -1 and your clock says for instance 2mm. Then you know you have to half the amount of steps per mm in the setup of your cnc control software
Title: Re: Count stepper motor steps.
Post by: Doctorandus_P on November 08, 2020, 07:21:34 am
The most common problems with stepper motors are:

* Some mechanical problem that overloads the stepper motors and causes it to loose steps.
* Miss-adjusted stepper motor driver that does not drive enough current though the coils and causes it to loose steps.
* Too low voltage for the stepper motor driver, which makes the motor loose torque at higher speeds.
* Running the motor at too high speed, where it looses torque.
* Running the motor at too high acceleration, which temporarily overloads the motor.

If a problem is caused by this, you will not see it with Sigrok / Pulseview.
An indication for faults like this is that the motor is always losing a (multiple of) 4 complete steps (for a 2-phase motor).
You can get some idea of safety margins by adding loading. For example add some cord and pull on it to increase loading, or add a pulley and a weight. All directions should be checked.

Another common problem is loose wires or bad connectors with intermittent contact, which can best be diagnosed by jiggling the wires a bit while the machine is moving. The copper core of wires that go to moving parts can also break by fatigue without damage to the plastic mantle.

Yet another problem that sometimes sticks up it's head is timing problems between the step pulses and the change of direction. Especially with bigger motor drives that have opto couplers. The direction often has a slower optocoupler then the step signal. The best way to verify timing is with an oscilloscope and compare it to the datasheet.

The easiest way to verify that all these and other factors work is tog let the CNC machine go through some moves and then return to the start position and measure any deviations.  For example with calipers, a dial indicator or with a camera in a fixed position.

If you have some specific problem then explain here.
Title: Re: Count stepper motor steps.
Post by: viperidae on November 11, 2020, 06:04:47 am
Some stepper motor drivers have missed so detection. Trinamic have some with that feature I believe. Some 3d printers use it instead of end stops and to warn about failed prints.
Title: Re: Count stepper motor steps.
Post by: cncjerry on November 13, 2020, 04:37:32 am
a couple posts back someone mentioned encoders.  Yes, that is the only way to do it.  But they aren't expensive at all.  I use them on my servo mills and with servos you need them, of course.  You can put them on stepper systems and make it closed loop.  Some stepper drivers have encoder input so you don't have to feed the signal back to the PC controller.  If not, then you can most likely feed it back through your breakout board  and if you are using LinuxCNC  then I think there are preconfigured modules for that config.

But that has always been the issue with stepper systems, lost or extra pulses from noise.  One was to reduce the problem, if at all, is just to run the motors slower with increased torque.

Jerry
Title: Re: Count stepper motor steps.
Post by: PixieDust on April 04, 2021, 02:35:07 am
Isn't it also possible to lose steps due to un-shielded cables?
Title: Re: Count stepper motor steps.
Post by: Nominal Animal on April 04, 2021, 01:34:20 pm
Hi, I was wondering what equipment I need to count pulses of a stepper motor, to make sure my cnc router is operating perfectly. So I can run G-code to do say 1000 steps, I want to test that the motor is stepping 1,000 times.
Get an optical incremental rotary encoder, couple it to the drive shaft, and count the pulses using a microcontroller.  If you have a belt drive, you can attach a driven pulley to the rotary encoder axis instead of a drive shaft.  Use two freewheeling pulleys to make sure the belt does a half turn around the driven pulley.

Because of typical stepper motor properties, I'd use an encoder with 200 pulses per revolution.  It looks like these cost about $10 USD on eBay etc.  Add a Pro Micro clone to read the pulses at 5V, and a small OLED display or 8-digit MAX7219 LED display to display the count as a number, maybe with a tactile button or two for reset, and the entire thing sets you back about $15-$20.  Power it from an USB powerbank, to avoid ground loops.
Title: Re: Count stepper motor steps.
Post by: Kjelt on April 04, 2021, 02:41:15 pm
Isn't it also possible to lose steps due to un-shielded cables?
I would say that due to severe interference you can get "ghost" steps faster then lost pulses.
Title: Re: Count stepper motor steps.
Post by: PixieDust on April 09, 2021, 04:32:12 pm
What are ghost steps?
Title: Re: Count stepper motor steps.
Post by: ogden on April 09, 2021, 04:57:03 pm
Use/put disk with mark on the shaft, let ir work for enough *exact* 360-degree revolutions in *one* direction and see - mark is shifted against initial position or not.
Title: Re: Count stepper motor steps.
Post by: Pack34 on April 12, 2021, 06:37:13 pm
If you want to watch and quantify the signals being sent to the stepper motor then I'd throw a Saleae at it. You can record an event and their software can calculate the amount of pulses and timing for you.

https://www.saleae.com/ (https://www.saleae.com/)
Title: Re: Count stepper motor steps.
Post by: perieanuo on April 13, 2021, 01:20:48 pm
hi,
any quadrature encoder with the correct resolution will do, in ideal world for a complete revolution ( 360 deg rotation) the encoder should count multiple (including x1) of motor step number per one complete rotation. if you're microstepping the stepping motor, no of microsteps for one rotation gives you the encoder needed.
if correctly made, some machine woldn't 'loose' steps, but in real world it happens so encoder might be necessary in specific apps
the next level is to close the loop between motor stepping driver and encoder reading
that's the theory, but few apps need encoder on step motors (we were manufacturing step motors with open/close loop for medical security devices for example, but that was medical area!!)
Title: Re: Count stepper motor steps.
Post by: Doctorandus_P on May 10, 2021, 04:36:46 pm
Another important way which can cause stepper motors to misbehave is during a direction change. Usually you need some setup time when switching direction of a stepper motor, and when this time is violated, the steppermotor will take a step in the wrong direction.

This is particularly important with the bigger stepper motor drives with built-in opto couplers.
It is particularly easy to spot on the TB6600 bare PCB's with the toshiba chip and heatsink on the back.
These have three different opto couplers:

EL6N137 =  8-pin device for the Step signal. (Speed is important here)
EL4N35  = 6-pin device for the direction signal. (Bit slower, so give it some time when changing direction)
EL814  = 4-pin device for the disable signal, (speed is not important here, just get some signal through).

Direction of stepper motors can't be changed at high speeds, so a slower opto coupler is OK for the diretion, but you have to verify, and possibly correct in software to get this right.
Title: Re: Count stepper motor steps.
Post by: Kjelt on May 13, 2021, 07:45:39 am
What are ghost steps?
Outside Interference that causes spikes on the "step" line which causes an undesired extra step in the motor.
One of the reasons you should use shielded cables, optocouplers always connect with their own return channel line (so always two lines per opto) or differential drivers to the opto.