Stepper motor is steping futher than intended - Page 1
Forum section: electronics / beginners

author: yashrk
author_rank: Frequent Contributor
timestamp: February 08, 2023, 07:51:14 am
content: Hey everyone!I am using DRV8825 based module to control the a stepper motor. I send 200 pulses i.e. 1 rotation to the motor driver every time a push button is pressed.Please check wiring diagram attached below.As this is battery power application I used the Sleep pin to power down the motor when not in use. Motor is currently not attached to anything.The algorithm look like this:Get device out of sleepdelaySet directionLoop for 200 times:step pin highdelaystep pin lowdelayPut device to sleepThe issue I am facing is if I signal motor to do one rotation the motor will do just slightly more than 200 steps over time I can visually see that start position of the motor is shifting froward.Things I have tried:-> Checked the code to see if I am stepping 200 and not more-> Varied delay after putting the device to sleep and varied the delay between steps too-> Increased current going to the motor using potentiometer on the moduleI have narrowed it down the issue to the sleep if I stop the motor driver from sleeping after every rotation i.e. keeping it permanently on, this solves the issue.But I am not sure what is happening and would love your inputs on the same.Regards,Yash

author: Brianf
author_rank: Regular Contributor
timestamp: February 08, 2023, 08:33:56 am
content: When your micro sleeps what does it do with the IO lines? Maybe you need some resistors to make sure that the signals to the DRV do not float and pick up noise.

author: eblc1388
author_rank: Frequent Contributor
timestamp: February 08, 2023, 08:52:04 am
content: Quote from: yashrk on February 08, 2023, 07:51:14 amMake sure you wait for 1,700us in the above delay before setting the direction. Or you can set the direction immediately but wait 1,700us before generating the stepping pulses.

author: Nominal Animal
author_rank: Super Contributor
timestamp: February 08, 2023, 09:30:20 pm
content: TheTI DRV8825 datasheetdescribes the STEP pin as "Rising edge causes the indexer to move one step. Internal pulldown."This means you want the STEP pin to idle low, with each step occurring on a rising edge. Edges on the STEP and DIR pins must be at least 1.9 µs apart (datasheet chapter 7.6 Timing requirements), but otherwise the duration of the high pulse does not matter. This assumes you use a typical module that does not invert the STEP and DIR signals (as for example optoisolators might).So, I would suggest the following logic:Set STEP low (0).Set DIR.Pull SLP high, waking up DRV8825.Wait at least 1.7 ms = 1700 µs.For each step:Set STEP high.Wait 2 µs.Set STEP low.Wait (pulse interval - 2µs).End loopWait a sufficient duration for the DRV8825 to complete the step and the stepper motor to move to the new state; I suggest several milliseconds, maybe longer.(When in sleep mode, DRV8825 does not drive the motor; if it has sufficient inertia, it could even freewheel forwards one or more steps.)Pull SLP low, putting the driver to sleep.Pulse interval is inverse of the step rate. The maximum step rate is 250 kHz = 250 000 s⁻¹, so the minimum pulse interval is 1/250000 s = 0.000004 s = 4 µs. The microstepping you use, and the particular stepper motor you use, determines what the maximum actual step rate achievable is; if you try too high step rate (too short intervals), the stepper will usually just "buzz" and heat up.

author: jmelson
author_rank: Super Contributor
timestamp: February 09, 2023, 02:47:39 am
content: When the driver is powered, the coil current holds the rotor at an exact position. When you shut off the current, the motor can "relax" to a different position. Then, when you turn the current on again, the motor can jump to a different position than when it was shut off, rather than jmping back to the original position. If the driver has a reduced current feature, use that rather than turning off all current.Jon

author: yashrk
author_rank: Frequent Contributor
timestamp: February 09, 2023, 01:44:25 pm
content: Quote from: Brianf on February 08, 2023, 08:33:56 amThat's an interesting take. It has pull up / pull down internal resistors. And it wasn't the issue because it worked if sleep pin is always high.Quote from: eblc1388 on February 08, 2023, 08:52:04 amI had the same instinct and like I mentioned in the main post I also played around with the delay but that didn't help.Quote from: jmelson on February 09, 2023, 02:47:39 amNo the shifting is significant enough that it can be more than 4-5 steps.The way I solved it was to basically give 2ms delay after getting the module out of sleep. Then giving almost 1ms delay between the step high and step low. Finally putting the device to sleep immediately after.Yes 1ms delay between the step high and step low if I want low current draw. And I tried 0.5ms with higher current draw. As speed wasn't an issue I didn't try even faster rotation speeds.Quote from: Nominal Animal on February 08, 2023, 09:30:20 pmI am intrigued by your though process Nominal Animal, I will try it out and keep you updated. I will be comparing the current consumption as well.

author: TomKatt
author_rank: Frequent Contributor
timestamp: February 09, 2023, 01:48:38 pm
content: I doubt this plays a role since you are talking full complete revolutions, but I'd also look into what happens during sleep if you are using fractional stepping instead of full steps. The stepper will likely move to the nearest full cog step if power is removed while it's in a fractional position between full steps.

author: yashrk
author_rank: Frequent Contributor
timestamp: February 18, 2023, 06:20:45 pm
content: Quote from: Nominal Animal on February 08, 2023, 09:30:20 pmAfter implementing the code according to the mentioned algorithm, following are the observation:Starting from 2uS delay in between steps and low to maximum current limit. There was basically no movement till 300uS. Motor started moving with delay of 350uS with noise and vibration but the current consumption was 560mA. And after doing current limiting minimum current required was 210mA - 270mA.Anyway I was not able to reproduce the issue which I was getting on the original hardware.But with this test I wanted to check what would be the maximum speed I can run the motor and how much current it will consume. Answer to that is 428 RPM at 210mA.