From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Control a stepper motor using a4988 driver board and a myRio?

Hi I am wondering whether it is possible to control a stepper motor using an A4988 driver board and a myRio and what Labview code you would need to make this work?

 

Thanks!

0 Kudos
Message 1 of 13
(3,470 Views)

Hey Rory,

 

I see no reason why you couldn't - from the spec sheet of the driver board you mention it wants a minimum pulse duration of around 200 nanoseconds, and the minimum pulse width on a digital output from a myRIO-1950 is around 20 nanoseconds.

 

If you are able to provide which myRIO you are using that would let the search be more specific.

 

For that sort of timing you would need to be using an FPGA, not the real time OS on the myRIO. I would take a look at this page for more info on FPGA coding:

 

http://www.ni.com/tutorial/14532/en/

 

Hopefully this helps!

 

Mitch

0 Kudos
Message 2 of 13
(3,423 Views)

Hi Mitch,

 

I'm using a myRio-1900. I haven't tried writing the code yet but I'm hoping it's not going to be too complex. Is it just a PWM signal that I will need to send to the board do you think? I didn't realise I would have to use FPGA, I'll have a look into that cheers. Does FPGA make things a bit more complex?

 

Rory

0 Kudos
Message 3 of 13
(3,419 Views)

Hi Rory,

 

You may not need to use the FPGA if the pulse widths are fairly long - I jumped to that as it would be the most reliable and would allow for the smallest pulse width the controller can use.

 

The myRIO 1900 has the same minimum pulse duration on the digital lines, so should more than do the job.

 

This express VI should be easy to set up as an initial test:

 

http://zone.ni.com/reference/en-XX/help/373925C-01/myrioreference/myrioref_exp_pwm/

 

Mitch

Message 4 of 13
(3,416 Views)

Stepper motor drive boards like this will usually trigger the next step on the rising edge of the "step" input.

In cases like this PWM will not help, since PWM varies the duty cycle and not the frequency. The rising edge will occur at the same time regardless of the PWM duty cycle setting.

 

In order to control the motor's speed, you will need to control the frequency of the pulse train you are generating.

 

0xDEAD

 

Edit:

 

I just noticed that this express VI includes an option to modify the PWM frequency at run time, so it should work for you! Set the duty cycle to 0.5 and modify frequency to control the motor's speed.

 

Specifies the frequency settings for the PWM signal. If you specify a frequency that is invalid, this Express VI coerces the specified value to the nearest valid value when you click the Validate button. Frequencycontains the following options:

  • Set using input to Express VI—Specifies to set the frequency by using the Frequency [Hz] block diagram input. This option allows you to set the frequency at run time
Message 5 of 13
(3,402 Views)

Hey guys,

 

Thanks so much for your help! 

I've wired everything up now and written some code which I thought would work but no luck! 

 

I have tried using the express VI like you have suggested (see bottom right of attached picture) but I'm not getting any movement. When I switch on the power supply the motor makes a very high pitch noise and is held in place (as in you can't manually turn it any more) so it seems as if the coils are being powered up. But when I try running the code nothing is happening...

 

Do you have any suggestions, am I doing something wrong? 

 

(ive also attached a couple of pictures of the wiring, not sure this will help with anything though!)

0 Kudos
Message 6 of 13
(3,386 Views)

Do you have the datasheet for that board (the motor driver) that you can share?

 

0 Kudos
Message 7 of 13
(3,381 Views)

Hi guys, I've managed to sort it now the express PWM signal works great! 

 

I was being stupid! I thought the output that I had connected to was a/DIO3 but it was c/DIO3 so no wonder it wasnt working!

 

Now the only issue is its quite jumpy at lower speeds (frequency). Do you have any idea how to smooth this out or is that just the nature of stepper motors? 

 

Thanks for all your help!

0 Kudos
Message 8 of 13
(3,374 Views)

Does the board have an option to set microstepping?

0 Kudos
Message 9 of 13
(3,370 Views)

I think it might actually. Would that help? I'll have a look tomorrow 

 

Thanks,

Rory

 

0 Kudos
Message 10 of 13
(3,364 Views)