LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

controlling speed of bipolar stepper motor with micro stepping driver

Hi 

I want to control speed of bipolar stepper motor with micro stepping driver and arduino board,

I have already written a code for it in just one speed,I need 3 pulse , first one is true pulse for enabling driver , second one is for direction and third one is pwm pulse ( but duty cycle isn't important)  as I realized for changing the speed of this stepper I only need to change the pwm frequency (frequency of pulse) , what should I do to change the frequency?? do I need to change arduino board frequency?

is there any other way to change the frequency without changing board freqcuency??

note that my code is working well without error I wanna improve it .
I will attach my code 

tnx.

0 Kudos
Message 1 of 8
(6,375 Views)

I've done this sort of thing with LabVIEW, arduino and a stepper motor.

 

I would recommend that instead of using PWM to control the frequency, you just use a digital output pin (like you are doing for the "Dir") and then:

 

  1. set pin value to HIGH
  2. wait n milliseconds.
  3. set pin value to LOW
  4. wait n milliseconds.

The frequency of the pulse cycle will be approximately 1000/(2n).  You can then set the value of n using a control or a calculation.

 

The attached snippet shows how I would do this in the 'clockwise' case. Ideally, I would break this out so that clockwise and counterclockwise use the same code to do the step High, step Low, and differ only in the direction bit.... but since your code is working, I don't want to disrupt it too much.

 Stepper Motor Frequency.png

 

 

 

0 Kudos
Message 2 of 8
(6,274 Views)

Just for fun, I took a stab at rewriting the whole thing. 

 

I removed the redundant code and the local variables. I hope this looks simpler.

 

Stepper Motor.png

 

 If it were me, I'd also take out the sequence structure because it just takes up space and the wires between Set Direction and Step High, Step Low ensure that these will operate in the correct order. I left it in because I thought it makes it a little more readable to separate these two.

Message 3 of 8
(6,265 Views)

@LandJBelenky wrote:

Just for fun, I took a stab at rewriting the whole thing. 

 

I removed the redundant code and the local variables. I hope this looks simpler.

 

Stepper Motor.png

 

 If it were me, I'd also take out the sequence structure because it just takes up space and the wires between Set Direction and Step High, Step Low ensure that these will operate in the correct order. I left it in because I thought it makes it a little more readable to separate these two.


Thank you for your reply, I really appreciate it.
I have solved my problem and controlled the speed of stepper.

as you mentioned we need to set high and low with some frequency , for this purpose I have used "Digital write square wave" block and its working correctly. this block produce square wave with 50% duty cycle , and we can set frequency as input, so we can change speed of stepper as well.
digital write square wave address: makerhub>>Linx>>Peripherals>>Digital>> digital write square wave.

 

0 Kudos
Message 4 of 8
(6,242 Views)

From a programming point of view, I think your solution makes a lot of sense because it involves less activity in LabView and just lets the arduino do all the work of managing the pulse HIGH, pulse LOW repetition. The solution I suggested would require that the LabVIEW program keep running to generate those pulses one at a time.

 

The one thing I worried about is what would happen if the LabView program stops before it sends a DISABLE or turns off the square wave. Or, if the connection between the computer and the arduino is lost. The arduino might keep pulsing, and the motor would keep moving, with no easy way to regain control. Depending on your application, that could be bad, or even dangerous. 

 

 

0 Kudos
Message 5 of 8
(6,229 Views)

Hello guys,

 

Sorry to reply to this post after a long time.

I am currently working on a project controlling linear actuators powered by stepper motors.

 

Even though I can control the direction and speed of the motor I cannot control the steps it will do.

I remember on LIFA there was StepsToMove function? 

How can I specify the exact steps? Which block should I use?

The duration should be an answer to that. (calculating frequency x time to get distance) but it does not work. The motor continues after the specified time.??

0 Kudos
Message 6 of 8
(5,298 Views)

Hi,

Could you please send me the vi file? tnx in advance 


@Alirezap30 wrote:

@LandJBelenky wrote:

Just for fun, I took a stab at rewriting the whole thing. 

 

I removed the redundant code and the local variables. I hope this looks simpler.

 

Stepper Motor.png

 

 If it were me, I'd also take out the sequence structure because it just takes up space and the wires between Set Direction and Step High, Step Low ensure that these will operate in the correct order. I left it in because I thought it makes it a little more readable to separate these two.


Thank you for your reply, I really appreciate it.
I have solved my problem and controlled the speed of stepper.

as you mentioned we need to set high and low with some frequency , for this purpose I have used "Digital write square wave" block and its working correctly. this block produce square wave with 50% duty cycle , and we can set frequency as input, so we can change speed of stepper as well.
digital write square wave address: makerhub>>Linx>>Peripherals>>Digital>> digital write square wave.

 


 

0 Kudos
Message 7 of 8
(4,192 Views)

@asatarsh wrote:

Hi,

Could you please send me the vi file? tnx in advance 

 


The above image is a LabVIEW snippet, and is for all practical purpose very close to the VI (except for VI options, connector pane assignments, etc.). See if that works for you.

0 Kudos
Message 8 of 8
(4,177 Views)