A4988 doesn't microstep properly

Oh, I have “planning” code that when I tell it “do one step” it will issue an accelleration, and steps value that results in (almost (*)) exactly one microstep.

For the video I had a shell script on my raspberry pi issue a “please advance one position” every second:

while true; do
   echo p 1 > /dev/ttyAMA0
   sleep 1
done

and on the logic analyser that shows up as a single microstepping pulse every second. In fact behind the scenes, there is an accelleration and deceleration that results in 16 million (2^24) nano-steps. Lets call them that. :slight_smile: The whole operation will take a bunch of miliseconds, and I don’t know where in those miliseconds the “carry” to the “integer position” happens with the actual microstep command being issued. But in “realtime” it happens pretty much the moment I issue the “please advance 1 microstep” command.

Hmm. I think I still have the code to “issue x pulses” in there somewhere. No interrupts, just a “send pulse, wait” loop.

What do you guys recommend I do with “sleep” and “reset”? I’ve tied them together and nowhere else, as suggested on the product page.

Sometimes when I touch my A4988 motor driver PCB (to check the chip’s temperature), the motors sometimes start whining. I haven’t been able to find out what I need to touch for this to happen.

I think I’m going to put ms1 ms2 and ms3 under microcontroller control. And the “reset”. The STM32F4 discovery board has some 80 GPIOs, but it’s a hassle to find out which ones are free. I picked PD3 and PD4 at “random” because they looked nice. Then for the second motor I picked PD5 and PD6. Wrong! there is a led and something else on PD5, so I had to move to PD1, PD2. I’ll have to do the gruntwork to figure out a few free pins. (On these ARM chips you can’t just start using a GPIO pin like on the AVR. You have to make sure hte GPIO port has a clock signal and things like that before it starts to work. That’s why I’m sticking to GPIOD for now, no need to take that hurdle again… ).

(*) The position after time t with accelleration a is 0.5 . a . t . t, However in the discrete case like here there is a t-1 in there somewhere. This means that I sometimes end up a few nanosteps short. The difference is well short of a microstep (I’ve seen 0x1000 = about 4000), so in theory when I tell it to microstep every second, it might skip the microstep say 4000 in every 16 million steps. i.e. once every 4000 seconds. Nothing to worry about in my current 20 second experiments.