1 Introduction

Nowadays, stepper motors are widely used in both industry and consumer devices, such as scanners, ink-jet printers or digital cameras. Their properties are advantageous in many mechatronic devices, especially where there is a need of a cost effective positioning system [1]. Such synchronous electric motors are characterized by a good performance in open loop 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 [24]. 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.

2 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.

Fig. 1
figure 1

Control system with feedback

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.

3 Mathematical model

3.1 Stepper motor

The equations governing the dynamics of a hybrid stepper motor can be found in a number of publications [1, 58]. They have been cast into the following system of four non-linear ordinary differential equations:

$$\begin{aligned} \begin{aligned}&\frac{di_A}{dt} = \frac{1}{L} \left[ V_A - Ri_A + K_m \omega \sin (N_r \varTheta ) \right] , \\&\frac{di_B}{dt} = \frac{1}{L} \left[ V_B - Ri_B + K_m \omega \cos (N_r \varTheta ) \right] , \\&\frac{d\omega }{dt} = \frac{1}{J} \left[ -K_m i_A \sin (N_r\varTheta ) + K_m i_B \cos (N_r\varTheta ) - B\omega - \tau _l \right] , \\&\frac{d\varTheta }{dt} = \omega , \end{aligned} \end{aligned}$$
(1)

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, respectively; \(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, \(\tau _l\) is the load torque, \(\omega \) is the rotor speed and \(\varTheta \) 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.

3.2 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:

$$\begin{aligned} V= {\left\{ \begin{array}{ll} V_{cc} &{} \text{ if } i < I_m \\ 0 &{} \text{ if } i \ge I_m. \end{array}\right. } \end{aligned}$$
(2)

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.

Fig. 2
figure 2

Voltage measurement on phase A using a digital oscilloscope

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:

$$\begin{aligned} I_{ma}&= I_n \sin \left( \frac{n}{2d} \pi \right) \quad \text{ for } n \in \{ 1, 2, \dots , 4d\}, \end{aligned}$$
(3)
$$\begin{aligned} I_{mb}&= I_n \cos \left( \frac{n}{2d} \pi \right) \quad \text{ for } n \in \{ 1, 2, \dots , 4d\}, \end{aligned}$$
(4)

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 micro-stepping, that may be more suitable to a particular motor controller model.

3.3 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(\varphi )\) has been derived. The inverse function has been approximated by the following third order polynomial:

$$\begin{aligned} \varphi (a) = 1072{,}9 a^3 - 3864{,}7 a^2 + 4812{,}7 a - 2002, \end{aligned}$$
(5)

where: \(a\) is string’s length and \(\varphi \) is arm’s position. The above equation is very close to actual relation in angle range the device operates in (between \(45^{\circ }\) and \(90^{\circ }\)).

Fig. 3
figure 3

Tensioning mechanism

4 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.

Fig. 4
figure 4

Computer model in scicos

Table 1 Stepper motor properties

Computer model allows applying different kinds of loads to the motor. In particular, load from tensioning arm is approximated. Assuming that at angle \(\varphi =\pi /2\), the tensioner is in vertical position and at \(\varphi =0\) in horizontal position respectively, the simulated load on the motor is assumed to be:

$$\begin{aligned} \tau _l= \tau _{max}\cos (\varphi ). \end{aligned}$$
(6)

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.

5 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.

Fig. 5
figure 5

Current in phase A during a test run with excitation frequency f \(=\) 100 Hz and micro stepping 1/16

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).

Fig. 6
figure 6

Current in phase A during a test run with excitation frequency f \(=\) 4 Hz and micro stepping 1/16

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.

Fig. 7
figure 7

Motor exceeding its maximum speed

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.

Fig. 8
figure 8

Arm position during PID control (P \(=\) 15, I \(=\) 5, D \(=\) 0)

6 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.