Stepper motor PWM - A4988

Hi,

I am working on an autonomous vehicle for uni. The vehicle is based on the Arduino Mega and needs to process sensor inputs, and drive two motors accordingly (at varying speeds to steer the vehicle). I have purchased a dual A4988 carrier board to drive the motors. I have attached the specs of the motor. In the wiki of the stepper motor (below) it has some sample code at the bottom. I ran this code on my Arduino and the motor spun! However, when I removed the shield from the Arduino and probed the pin that corresponded to STEP with an oscilloscope I got a PWM-like signal, however, it wasn't what I expected. The signal had a very high duty cycle and the frequency was odd (it had a long period of high followed by a short period of low followed by a short period of high followed by a short period of low repeated).

Now, the code they provided used delays and thus I wouldn't have been able to simultaneously process sensor input and run the PWM signal. So, I turned to the Timer1 and Timer3 libraries in the hope of gaining this functionality. I was hoping to set a 50% duty cycle on the STEP pin and vary the frequency to adjust how quickly the motor stepped, however, when I rigged it all up I got NOTHING! I checked with the scope and my PWM signal was perfect. I am really not sure why this didn't work. I was/am under the impression that every time you pull the STEP pin high the motor steps, so I thought that PWM would be perfect.

Any suggestions? If I forgot to provide some information please let me know. Any stepper libraries that are non-blocking that you can recommend? I really don't want to have to learn about the intricacies of ISR's and interrupts - I would really like a library that would take care of it all for me and allow me to "set and forget" the frequency that STEP is pulled high until I want to change it.

Thanks.

Dual A4988 carrier board: Stepper_Motor_Shield_For_Arduino__SKU_DRI0023_-DFRobot

I just noticed that the motor specs that I posted aren't particularly helpful. I will post something better tomorrow morning, but until then the keys specs are:
1.7 Amps
1.2 phase resistance
1.8 phase inductance
Please also note that I have the a4988 vref configured to 0.5 volts which should correspond to (current/0.7 = vref * 2.5, (1/0.7)/2.5 = vref = 0.57) a current of less than one - well within soec of motor and driver. This is all assuming that the dfrobot a4988 uses the same sense resistor values as the pololu boards. I could not find this information about the dfrobot board anywhere on the Internet.

Cheers!

The step input responds only to the rising edge, the duty cycle is irrelevant.
The direction pin is sensed on the step rising edge too, so it can be any value
at other times and not matter.

Normal industrial practice is to use 10us positive going pulses on stepper
controllers, 10us being long enough for slow opto-couplers to respond so I'm
suprized you're seeing negative going pulses, but as I said it doesn't matter.

A4988 has a datasheet, it explains more.

You may find something useful in stepper motor basics and this simple stepper code might be useful for exploring.

...R

Thanks for your response MarkT. I understand that the duty cycle should be irrelevant. I have had a look at the data sheet but I see no reason for the stepper to not respond to being pulled high and low by the PWM that was verified by my scope.

Also, thank you Robin2. The code that you provided uses delays to generate PWM. This won't work for my application as I need to be able to process data while the motors spin.

Thanks,
Jack.

The code that you provided uses delays to generate PWM.

The second code entry in Robin2's "simple stepper code" link does not use delays. Take another look.