setMinPulseWidth question

1,070 views
Skip to first unread message

Luke Lawcock

unread,
Nov 18, 2016, 4:34:59 PM11/18/16
to accelstepper
Hi all,

I am having much success with this library but I now have one more question regarding setMinPulseWidth. The pulsewidth is in Microseconds, of which there are 1,000,000 per second, if I input setMinPulseWidth(20); does this give me a maximum of 50,000 steps per second or 25.000? During my project I have found that the higher the pulsewidth is set, the more torque I achieve from my stepper. If I can clarify this point, I can add this to my data for future reference.

Kind Regards

Luke

gregor

unread,
Nov 23, 2016, 1:30:30 PM11/23/16
to accelstepper
Hi, 

from AccelStepper.cpp:
// 1 pin step function (ie for stepper drivers)
// This is passed the current step number (0 to 7)
// Subclasses can override
void AccelStepper::step1(long step)
{
    // _pin[0] is step, _pin[1] is direction
    setOutputPins(_direction ? 0b10 : 0b00); // Set direction first else get rogue pulses
    setOutputPins(_direction ? 0b11 : 0b01); // step HIGH
    // Caution 200ns setup time 
    // Delay the minimum allowed pulse width
    delayMicroseconds(_minPulseWidth);
    setOutputPins(_direction ? 0b10 : 0b00); // step LOW
}

there is only one call to delayMicroseconds() in the step function, but since the other things need time you will not be able to achieve 50k steps / second when setting min pulse width to 20µs.

Luke Lawcock

unread,
Nov 23, 2016, 5:23:17 PM11/23/16
to accelstepper
Hi gregor,

Thanks for the reply. I'm not trying to achieve 50,000 steps, far from it. What I am trying to understand is that if i set a pulsewidth of say 100 microseconds, there are 1,000,000 microseconds to a second, therefore the max amount of steps would be 10,000, or is it? Is it step HIGH for 100 microseconds then step LOW for 100 microseconds, therefore only 5,000 steps achievable? The latter would make more sense to as what I have encountered during testing but i'm yet to buy an oscilloscope and to be honest I'm pretty new to this. Is there a way to calculate it, for example if you set 10,000 as max speed, the pulsewidth can only be xyz etc

Best Regards

Luke

Mike McCauley

unread,
Nov 23, 2016, 6:32:58 PM11/23/16
to accels...@googlegroups.com
Hello,

On Wednesday, November 23, 2016 02:23:17 PM Luke Lawcock wrote:
> Hi gregor,
>
> Thanks for the reply. I'm not trying to achieve 50,000 steps, far from it.
> What I am trying to understand is that if i set a pulsewidth of say 100
> microseconds, there are 1,000,000 microseconds to a second, therefore the
> max amount of steps would be 10,000, or is it? Is it step HIGH for 100
> microseconds then step LOW for 100 microseconds, therefore only 5,000 steps
> achievable? The latter would make more sense to as what I have encountered
> during testing but i'm yet to buy an oscilloscope and to be honest I'm
> pretty new to this. Is there a way to calculate it, for example if you set
> 10,000 as max speed, the pulsewidth can only be xyz etc

AccelStepper blocks for the period of the pulsewidth, son long pulse withdts
limits the amount of processing time for other thins.

at 100us pulsewidth you will not acieve even nearly 10000 steps, since cpu
time is needed for many other things too.

Use the minimum possible pulse width you can.

Cheers.

>
> Best Regards
>
> Luke
>
> On Friday, 18 November 2016 21:34:59 UTC, Luke Lawcock wrote:
> > Hi all,
> >
> > I am having much success with this library but I now have one more
> > question regarding setMinPulseWidth. The pulsewidth is in Microseconds, of
> > which there are 1,000,000 per second, if I input setMinPulseWidth(20);
> > does
> > this give me a maximum of 50,000 steps per second or 25.000? During my
> > project I have found that the higher the pulsewidth is set, the more
> > torque
> > I achieve from my stepper. If I can clarify this point, I can add this to
> > my data for future reference.
> >
> > Kind Regards
> >
> > Luke

--
Mike McCauley VK4AMM mi...@airspayce.com
Airspayce Pty Ltd 9 Bulbul Place Currumbin Waters QLD 4223 Australia
http://www.airspayce.com
Phone +61 7 5598-7474

Luke Lawcock

unread,
Nov 23, 2016, 7:25:50 PM11/23/16
to accelstepper
Hi mike,
Thanks for the reply, I'm still very much a novice in regards to accelstepper and arduino for that matter.
I think I understand your reply, however, using the minimum pulsewidth possible is a lot of trial and error, I was hoping to have a more calculated method of deciding the figure.
For example, originally I had set the pulsewidth to 20us as I had read in the docs that would be around the minimum. At 12500 steps on an arduino due, 20us pulsewidth resulted in almost zero torque where as 40us pulsewidth gave me a reasonable amount of torque. I appreciate each motor, driver, controller and application will be different but for me, having that available figure made the difference between a failed project and a successful project.

Best regards

Luke

Brian Schmalz

unread,
Nov 23, 2016, 7:57:21 PM11/23/16
to accels...@googlegroups.com
Luke,

The pulse width sent to a step and direction driver won't have any affect on the torque. As long as he pulse width is long enough to trigger the step, it's going to take a step, and the torque won't be different if the pulse width is longer than that minimum.

So I think there is something else going on in your system that is affecting torque. 

What you really need is a nice logic analyzer. Take a close look at the pulses coming out of your micro. Run at fixed step speeds - say 1K steps/s, 2K steps/sec, 3K, etc. and look at the pulses coming out. If you're using one of the normal Arduinos (16MHz AVR) after about 4K steps/sec you will start to see strange aliasing in the step rates, and it won't look like you expect. Give it a try - see at exactly what speed your torque drops off, and I'll bet that's the speed you start to see strange pulses come out of the micro.

*Brian


--
You received this message because you are subscribed to the Google Groups "accelstepper" group.
To unsubscribe from this group and stop receiving emails from it, send an email to accelstepper+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Luke Lawcock

unread,
Nov 24, 2016, 4:14:10 AM11/24/16
to accelstepper
Hi Brian,

Thanks for the reply. I don't have a logic analyser but I may invest in one as I wish to pursue the Arduino route as I've found the project very interesting.

What I currently have is an Arduino Due controlling an M542T driver which drives a NEMA23 wired Bipolar Parallel. This motor feeds into a 90:1 reduction gearbox rotary stage which has a 24 partition disc on. I rotate the disc 15 degrees using two sensors fed to a PLC which triggers a relay output, which the Arduino reads as a push-button. The first sensor starts the acceleration up to speed and the second sensor removes the output and my code brings it to a dead stop (no deceleration).
With the attached code, if i set the minPulseWidth to 20us, there isn't enough torque to even rotate the motor given the inertia required to drive the gearbox and its attached load. When I set the minPulseWidth to 35us there is enough torque to drive the motor and attached gearbox/load with additional load from the product entering into each partition. This is the reason for my initial enquiry into the pulsewidth. I will have to look deeper into this.

Thanks for all your help, any more information and insight is welcomed.

Best Regards

Luke
To unsubscribe from this group and stop receiving emails from it, send an email to accelstepper...@googlegroups.com.
IFL_Capper_FINALgg.ino

Mike McCauley

unread,
Nov 24, 2016, 4:42:12 AM11/24/16
to accels...@googlegroups.com
According to the data sheet for M542T the PUL pulse only needs to be more than
1.5 usec.

I suspect you dont have it wired up correctly.

Cheers.
> >> email to accelstepper...@googlegroups.com <javascript:>.
> >> For more options, visit https://groups.google.com/d/optout.

Luke Lawcock

unread,
Nov 24, 2016, 4:48:14 AM11/24/16
to accelstepper
I'm almost certain I have everything wired up correctly, the cables are screened etc. I have too read the datasheet for the M542T driver and have taken into account the listed PUL limitation which is far less that the 20us accelstepper has as a limitation. As said above, I'll have to buy a logic analyser and learn more.

BR 

Luke

Brian Schmalz

unread,
Nov 24, 2016, 6:33:33 AM11/24/16
to accels...@googlegroups.com
Luke,

Agreed. Something doesn't smell right here. Your 20uS pulses aren't really 20uS maybe. Or maybe they're rounded off instead of nice and square (you'll need a scope to see that), etc.

Here's what I use on a daily basis, and it's just the best : https://www.saleae.com/
Get the best one you can afford - Saleae analyzers are wonderful and you won't regret it.

*Brian

To unsubscribe from this group and stop receiving emails from it, send an email to accelstepper+unsubscribe@googlegroups.com.

Luke Lawcock

unread,
Nov 24, 2016, 10:16:51 AM11/24/16
to accelstepper
Brian,

I might treat myself to one for Xmas, I have this http://uk.rs-online.com/web/p/digital-oscilloscopes/1176089/ saved in my bookmarks, I'll take a look at the ones you have linked me to also.

BR Luke
To unsubscribe from this group and stop receiving emails from it, send an email to accelstepper...@googlegroups.com.

Mike McCauley

unread,
Nov 24, 2016, 2:40:02 PM11/24/16
to accels...@googlegroups.com, Brian Schmalz
On Thursday, November 24, 2016 05:33:32 AM Brian Schmalz wrote:
> Luke,
>
> Agreed. Something doesn't smell right here. Your 20uS pulses aren't really
> 20uS maybe. Or maybe they're rounded off instead of nice and square (you'll
> need a scope to see that), etc.
>
> Here's what I use on a daily basis, and it's just the best :
> https://www.saleae.com/
> Get the best one you can afford - Saleae analyzers are wonderful and you
> won't regret it.

Agree that the Salae analyzers are great.
> > email to accelstepper...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages