Motion Control and Motor Drives

cancel
Showing results for 
Search instead for 
Did you mean: 

Feedback loop (PID) for driving a stepper motor

Hi,

I am using a stepper motor to control a valve in order to actively regulate the pressure of my system to acheive a specific setpoint. I have been using the PCI 6229 card to control the stepper motor with a digital output for the direction and a TTL (also generated via a digital output) to drive the motor. I have developed a variation of  Write Digital Chan -Ext Clk.vi to send the pulse train to my device through a digital output because I have no spare counters to use for this application. I would like to use the output of my pressure monitor (an analog voltage) as the input to labVIEW for a feedback loop where the output is a pulse train with a varying number of pulses depending on how close I am to the desired pressure.

 

This seems like a common application, but I couldn't find an previous posts that suggest how you can use labVIEW to develop a PID or other feedback loop with an analog input and a pulse-train of varying length for the output. I would appreciate any suggestions, even links to previous posts that may be relevant.

 

If there is an obvious solution, I might be able to free up a counter for this purpose, but I didn't see any PID examples that included counter outputs either ....

 

Thanks!

0 Kudos
Message 1 of 10
(21,524 Views)

The reason why you can't find PID examples with pulse train outputs is the fact, that this is everything else but a typical usecase. Unlike servo motors, the discrete positions of a stepper motor are not well suited for closed loop control. In fact most motion control systems that offer closed loop stepper modes don't run PID loops. Instead they compare the motor's position with the commanded position at the end of the move and compensate the difference by pull-in moves. Stable PID control of a stepper motor is hard to obtain and it's not recommended.

 

With this said here are some tips that might help you:

 

  •  Any closed loop system requires real-time behavior (low jitter, stable loop timing) for stable behavior. This is at least as important as a proper tuning of the PID parameters. Windows doesn't provide stable real-time behavior. For LabVIEW real-time options please refer to this link.
  • Instead of using the digital outputs or a counter you might want to use an analog output as the control signal with an external voltage to frequency converter. As long as you limit the slew rate of the analog output to a reasonable value that doesn't exceed the torque limits (acceleration) of the motor, this could make things much easier. Still the discrete behavior of the motor will make the tuning process a tedious task.


Kind regards,

Jochen Klier

National Instruments

0 Kudos
Message 2 of 10
(21,518 Views)

For some reasons we sometimes use a stepper instead of a servo motor and we have successfully developped several applications using a PID. Our setup is quite different to yours and the value to control is the torque :

 

  • NI motion controller (eg PCI-7332) with one of our power drivers to control the stepper
  • NI DAQ board (eg PCI-6221) to measure the analog output of the torquemeter
  • software PID (NI's PID toolkit)
  • use of Load Velocity Override.flx to modify the speed of the stepper (NI FlexMotion library)

 

There are some important limitations with this solution (software PID, override percentage is "only" 0 to 150 of the programmed velocity...) but it works quite well in our applications.

Message 3 of 10
(21,436 Views)
Thanks for your insight. Both of these suggestions have given us some good ideas. We are very aware that real-time stability may be a problem, but we have a relatively large tolerance for our pressure and can deal with relatively large time delays to allow the system to come to equilibrium before making further changes. Thanks for providing the solution you use with the stepper-motor. Even though your application is somewhat different, it seems like the a very similar set of parameters!
0 Kudos
Message 4 of 10
(21,431 Views)

Here's a screenshot from the PID loop. I add some comments that should help you to understand the code :

 

  • The motor is started and stopped outside the PID loop (other cases of a state machine)
  • AI Couple : measurement of the torque (AI of the DAQ board) --> Ist --> process variable
  • Soll : torque setpoint, computed in a parallel loop.
  • The range of the velocity override is limited from 50 to 150% (100 +-50)

Message Edité par JB le 05-11-2009 03:41 PM
Message 5 of 10
(21,429 Views)

JB,

 

I really like the idea of using the velocity overide function for a closed loop control of a stepper motor. Thus you don't have to take care of the step generation and there is not such a risk of a step loss compared to direct step generation from a software control loop.

It's always great to learn something new!

 

Kind regards,

Jochen

0 Kudos
Message 6 of 10
(21,403 Views)

Jochen,

 

It's really a great honor for me if you, the uncontested Motion specialist (I don't like the word Guru), could learn something from me !

 

Kind regards

Message Edité par JB le 05-12-2009 11:52 AM
0 Kudos
Message 7 of 10
(21,400 Views)
I wanted to jump in here and offer some ideas, but I don't have all the answers.  With your setup, I would feed the analog signal to the Labview PID.  Set up the PID for -100% to +100% output.  Convert the %output to a frequency for the step output, in other words velocity.  Any negative output just toggles the direction bit.  You could also buy a stepper drive that takes in an analog signal for velocity control.  This is usually called joystick control.
0 Kudos
Message 8 of 10
(21,367 Views)

Hi,

 

I am trying out something similar, but with a servomotor and need torque feedback. I have an existing piece of code written using event generation logic which works well (Toggling motor direction between upper and lower limits for a fixed # of cycles), but need to improvise the same functionality using state machine architecture, This is giving me the problem. I believe my transition of states is messed up. I am attaching both my codes, can anyone take a look at them and let me know where I am going wrong? 

 

Thanks

 

Sasi.

Download All
0 Kudos
Message 9 of 10
(21,300 Views)

Hi Sasidhar,

 

You should try running your code using Highlight Execution. You can select the light bulb at the top of the block diagram to do this.  You can watch your code execute with Highlight Execution and see where the transition mistake is happening.  I use it all the time to figure out how my code flows.  Don't forget to turn it off once you fix the problem though!  Thanks.

Stephen Meserve
National Instruments
0 Kudos
Message 10 of 10
(21,263 Views)