Dynamical simulation of a nonlinear stepper motor system

Coupled electromechanical interactions obser-ved in a closed-loop control system actuated by a stepper motor are studied. Analysed system consists of a PID controller used to maintain constant vertical inclination of a single DOF pendulum. This pendulum serves as a tensioner for a string being pulled by a rotary motion of the electric stepper motor. The second end of the string is being fed to the motor with a variable speed. The mathematical model governing dynamics of the mentioned system consists of a non-linear system of four ordinary differential equations. In addition to the mathematical model, various ways of control of the electric stepper motor have been applied. In particular, the rotor control using the micro-stepping approach has been used to model the real dynamics of the motor controller. Comparison of the proposed theoretical considerations and modelling of the studied system ﬁts well with the experimental investigations.

configurations, allowing for simplification of the electrical design.
Naturally, there are some drawbacks of the open loop configurations. Specifically, positioning errors can occur, as such systems lack position feedback and therefore it cannot be verified if the rotor achieved desired position. Those errors are usually a result of the phenomena specific to stepper and synchronous motors such as stalling (i.e. losing synchronous speed) and loss of step. These events can occur as a consequence of a sudden peak of load torque or exceeding allowed maximum velocity.
To combat these undesired phenomena, one can chose a closed loop approach [2][3][4]. For instance, the motor driver can wait for confirmation signal from the optical encoder after issuing every step command. The realistic system described in this paper, however, uses a simpler method. Instead of checking the position continuously, it is only verified after each positioning sequence, which is more than enough to ensure sufficient reliability in this particular case.
The goal of the following research is to create a mathematical model that could be used to evaluate motor's performance in a variety of scenarios. In particular it has to allow investigations of the system behavior under varying load conditions and using different control methods.

Physical system
In the following considerations we analyze a physical system being a part of an industrial device dedicated to measuring and cutting PVC bead strings (e.g. used in window and door blinds). The beads are being fed to the device from an injection molding machine at a variable speed. This requires cutting device speed to be appropriately adjusted. More importantly, the strings must be kept tightened to allow for a smooth cut. Because of that, the device has been fitted with a rotational tensioning arm with an inclination sensor. Tensioner angular position is fed back to the PLC allowing to maintain constant position of the arm and consequently-constant tension.
The drive system consists of a low power hybrid stepper motor powered by an appropriate driver. Incremental optical encoder has been installed on motor's shaft to ensure correct position after each positioning sequence (i.e. before cutting the string). Motor angular velocity must be adjusted according to the string feeding rate, therefore feedback signal from the inclinometer is run through a PID controller and converted to a pulse signal which drives the stepper motor. The whole machine, including human-machine interface, PID and motor speed is controlled by the PLC. The outline of the mentioned closed loop system is presented in Fig. 1.
Position setpoint is provided by the machine operator, who chooses the optimal string tension experimentally. The deviation from the setpoint is converted to a clock signal applied to stepper motor controller. Then it is converted to an analogue voltage signal powering two phases of a hybrid stepper motor (V a and V b ). Inclinometer provides a digital feedback data, transferred back to the PLC via a RS-232 interface.

Stepper motor
The equations governing the dynamics of a hybrid stepper motor can be found in a number of publications [1,[5][6][7][8]. They have been cast into the following system of four non-linear ordinary differential equations: where: i a , i b , V a , V b are currents and voltages in phases A and B; R, L are winding's resistance and inductance, respec-tively; K m is the motor torque constant, B is viscous friction coefficient, N r is the number of rotor teeth, J is rotor's moment of inertia, τ l is the load torque, ω is the rotor speed and Θ is its angular position. First two of the above equations determine the current in motor's windings (phase A and B), while the two latter correspond to Newton's 2nd Law of motion.

Controller
Stepper motor controller is compelled to provide appropriate voltage on motor's connectors and change them as required by the demanded motion sequence. The most basic circuit that can be used as a controller is a dual H-bridge. It consists of four transistors that are switching power sequentially, allowing the rotor to move in the desired direction in consecutive steps. While this approach has a big advantage of simplicity and low cost, it doesn't allow for a very good drive performance. Because of that, for more demanding tasks, dedicated integrated circuits are commonly used.
Those more advanced circuits allow micro-stepping, which by applying the voltages to both phases simultaneously, enable the rotor to take positions between the full steps. The ratio of V a to V b constrains the exact position of the rotor. This method reduces the vibrations excited during motion and makes drive's operation more smooth. Those commercially available controllers also use the so called chopper circuits. They use supply voltage that is much higher than motor's nominal voltage and turn it off when the current in phase goes slightly above the nominal value. This method allows the windings to be energized much more rapidly (as for each step current rises much faster), which results in much better performance of the motor, namely higher maximum speed and higher torque.
To recreate above considerations in the computer model, voltages substituted in Eqs. (1) are obtained by the following rule: In a realistic device, the frequency of switching the voltage is limited by the circuit parameters. Waveform of the measured phase voltage is shown in Fig. 2. It is worth noting that in this particular case, the supply voltage was being switched at a rate of 42 kHz. The above frequency was taken into consideration when designing the computational model. If the system is controlled with micro-stepping approach, maximum allowed current Im for each subsequent micro-step is determined by motor's nominal current and the appropriate current ratio. It can be determined using following two equations: where I n is the nominal current, n is the present micro-step and d denotes the division factor (e.g. 2 for half-stepping, 4 for quarter-stepping, etc.). Please note that there are several other methods of determining desired current while microstepping, that may be more suitable to a particular motor controller model.

Tensioning mechanism
The tensioning mechanism is a subject of control in the system. It has been modeled as a single DOF pendulum. The position of the pendulum is at all times restricted by the length of the string currently present in the device (see Fig. 3). Length a, depends on the one hand on the feeding speed and on the other on motor's speed. Using geometric relations function a(ϕ) has been derived. The inverse function has been approximated by the following third order polynomial: where: a is string's length and ϕ is arm's position. The above equation is very close to actual relation in angle range the device operates in (between 45 • and 90 • ).

Computer simulation
The above mathematical constraints have been applied in a computer model created using scicos which is a part of numerical computation software scilab. All of the mentioned subsystems were recreated and connected together, as seen in the diagram (Fig. 4). Simulation parameters, namely motor's specification, according to the data sheet are given in Table 1. Computer model allows applying different kinds of loads to the motor. In particular, load from tensioning arm is approximated. Assuming that at angle ϕ = π/2, the tensioner is in vertical position and at ϕ = 0 in horizontal position respectively, the simulated load on the motor is assumed to be: Apart from the above, the external load can be set to zero or given as step function with a constant load starting from time t 0 . Motor's excitation frequency (CLK signal), can be set as a constant value, a polynomial function or a value determined by a PID controller. In the latter case, all of the PID term's constants can be set, which allows tuning the device using the computer simulation instead of testing it on site.

Results
The following plots were made using the computer model described above. Among the objects of interest are phase currents of the stepper motor, as well as rotor's mechanical position. To evaluate the behavior of the model, different load and excitation conditions were tested.
Additionally, to evaluate the simulation results, some simple measurements on the physical object were attempted (compare [9]). In particular, phase current was measured. This was achieved by adding a serial resistor into the phase circuitry. The resistance of it is several orders of magnitude lower than the winding's resistance, so that motor performance is not affected by its presence. By connecting an oscilloscope to both ends of the resistor, one can easily measure voltage drop on the shunt resistor, which is an indirect way of measuring phase current in the circuit, as those two physical quantities are proportional. The downside of this simple method, however, is that the recorded waveforms contain a lot of noise and are not very accurate. This is because of the fact that the measured voltage drop is very low (less than 100 mV).  Investigations shown in Fig. 5 confirm that mathematical model's simulation results are compliant with the physical object. However subtle differences can be observed, such as the amplitude of the phase current. That is likely to be associated with the fact that the amplifier and chopper are not yet accurately modeled. Figure 6 shows current oscillations when the motor is advancing to the next step. As micro-stepping is used in the considered scenario, those oscillation's amplitude is proportional to maximum allowed current in a given micro step, as can be seen in Eqs. (3) and (4).
Discussed computational model is able to recreate some of the phenomena mentioned in Sect. 1. Figure 7 shows the rotor travel while accelerating. The profile of the motion is such that the excitation frequency is linearly increasing for 5 s from 0 Hz to 20 kHz. Instead of a constant acceleration, we observe loss of steps after about 3.5 s with motor never actually exceeding 10 kHz. This, of course, qualitatively fits with real device observations, even though small deviations from an actual maximum speed can be observed.
Although simulation results allow to reconstruct motor's behavior, because of the noise, measurement's accuracy is limited. Operation of the system as a whole is presented in Fig. 8. In this particular example, excitation frequency is regulated by a PID controller with non-zero "P" and "I" terms. Observe that it accurately resembles behavior of the actual physical device.

Concluding remarks
The qualitative results obtained during simulations fit well with the expected behavior of an electric stepper motor. In particular, the proposed solutions to simulating real stepper motor controllers, allow for realistic simulation conditions,  resembling commercially available devices. This can lead to a better understanding of pros and cons of certain control methods as well as allowing to a broader usage of electric stepper motors in environments, where their features are desirable, offer more performance or lower cost than their DC or asynchronous counterparts. The mathematical model of a stepper motor system allows for investigating and avoiding some of the phenomena that can hinder system's performance. Among those are electromechanical resonances that result in increased vibrations, stalling, losing steps, noisy operation and decreased performance and reliability.
It is worth noting that the proposed computational model is relatively complex. That means that the simulations with integration times over 5 s take a significant time to complete. Isolating most resource heavy parts and optimizing them may be crucial to continue the above analysis.
In further research, more physical object measurements will be made, which will open possibilities for fine-tuning the computer model. In particular, precise phase current measurements need to be done to verify the simulation results. This will require building a circuit that allows amplifying the measured signal as well as filtering out the background noise and interferences. Moreover, physical properties of the motor and the whole system should be verified as they can deviate slightly from the values provided in the data sheets.