Simple Torque Control Method for Hybrid Stepper Motors Implemented in FPGA

Stepper motors are employed in a wide range of consumer and industrial applications. Their use is simple: a digital device generates pulse-bursts and a direction bit towards a power driver that produces the 2-phase currents feeding the motor windings. Despite its simplicity, this open-loop approach fails if the torque load exceeds the motor capacity, so the motor and driver should be oversized at the expense of efficiency and cost. Field-Oriented closed-loop Control (FOC) solves the problem, and the recent availability of low cost electronics devices like Digital Signal Processors, Field Programmable Gate Arrays (FPGA), or even Microcontrollers with dedicated peripherals, fostered the investigation and implementation of several variants of the FOC method. In this paper, a simple and economic FOC torque control method for hybrid stepper motors is presented. The load angle is corrected accordingly to the actual shaft position through pulse-bursts and direction commands issued towards a commercial stepper driver, which manages the 2-phase winding currents. Thanks to the FPGA implementation, the control loop updates the electrical position every 50 μs only, thus allowing a load angle accuracy of −1/100 rad for a rotor velocity up to 750 rev/min, as shown in the reported experiments.


Introduction
The stepper motor [1] is widely used nowadays in a large range of applications such as 3D printers, industrial manufacturing tools, robotic arms, etc.Part of its success is certainly due to its capability of moving in a sequence of accurate and discreet locations (steps).A microcontroller connected to one of the several power drivers available on the market through a "step" clock and a "direction" command is often sufficient for the motor control [2]: For every "step" pulse, the driver modifies the 2-phase currents that feed the motor so that the shaft rotates by a "step" (typically 1.8 • ) or a fraction of it (µ-step) [3].
Unfortunately, the performance of the stepper motor heavily depends on the load condition.Therefore, if the load accidentally increases over the motor capacity, the control misses the actual shaft position and the application fails.To prevent this catastrophic event, stepper motors (and their drivers) are typically selected with a torque capacity that abundantly exceeds the nominal requirement.This results in oversized motors, and waste of power and heat [4].Closed-loop motor control with the Field Oriented Control (FOC) method [5,6] solves this problem.The typical FOC implementation is based on Direct-Quadrature (DQ) coordinate transformations [6,7] that, in the past, required a considerable calculation effort and correspondingly complex hardware, which was not compatible with economic consumer applications.In recent years, however, the availability of microcontrollers with dedicated peripherals and/or economic Field Programmable Gate Arrays (FPGAs) has supported the development and implementation of new closed-loop approaches.In particular, FPGA represents a standard device for industrial applications [8,9], including motor control.For example, a Proportional-Integral-Derivative (PID) controller [10] with velocity feed-forward was proposed in [11]; in [12] a closed-loop control system based on motor parameter identification was presented; in [13] and [14], motor controllers based on Neural Networks are proposed.
In this paper a closed-loop torque control method for hybrid stepper motors is presented with its FPGA implementation.The method is based on a simple control loop that, thanks to the FPGA's performance, executes every few 10 s of µs.Every loop iteration, the motor shaft position is monitored through an incremental encoder, and the stator magnetic field position is updated so that the relative phase between the positions of the stator and the rotor generates the desired load angle.While this quick loop maintains accurate control of the load angle, the magnitude of the phase currents is adjusted to obtain the programmed torque.
The output of the control loop consists of the number of µ-steps and the direction bit the rotor should move to maintain the desired load angle.These data perfectly fit with the "step/direction" interface present in several commercial power devices which are typically employed for open-loop µ-step motor control.In other words, this method does not need custom power electronics for the generation and control of the motor phase currents, which can be delivered by one of the monolithic devices already available in the market.
The proposed control is implemented in a FPGA from the MAX10 family (Intel/Altera, San Jose, CA, USA), connected to the PowerStep01 stepper driver (STMicroelectronics, Geneva, Switzerland).The paper presents the basics of the applied method in the next section; the employed electronics system and the FPGA implementation are described in Section 3; finally, several experiments are reported in Section 4.

Torque Generation and Step Movement
In a hybrid 2-phase stepper motor, the torque is generated by the interaction of the field produced by the rotor fixed magnet, and the field dynamically generated by the stator windings.The torque is composed by 3 components: the cogging, the reluctance, and the electrodynamic component [15,16]; however, in this work, the electrodynamic component, being predominant, is the only one considered.With reference to Figure 1, if I a and I b are the currents flowing in the 2 windings, the magnitude and angle of the resulting current is I = I 2 a + I 2 b and θ I = tan −1 I b I a .The motor torque Γ E is generated by I combined to the load angle θ L , i.e., the phase angle between the rotor position θ R and the current position θ I [15]: where K t is the torque constant.The torque is null when θ L = 0 independently from the current magnitude, and it is maximum when θ L = π/2.A sinusoidal current excitation produces a continuous rotation of the current vector of amplitude I and a corresponding movement of the equilibrium position of the rotor.However, the typical commercial stepper driver produces only a limited set of quantized values of the phase currents.If N M is the number of the different current levels the driver produces, 4N M equilibrium positions are generated around the electrical circle of Figure 1 in In a stepper motor the torque is related to the load angle   , present between the rotor magnet,   , and the current field,   .The target load angle   is obtained by advancing of   the current field   .

Torque Modulation
According to (1), the torque can be modulated by controlling the load angle,   , and/or the current, .The typical FOC application regulates the motor windings currents to generate a load angle of   = ±π/2, and the current magnitude  modulates the torque.This is the most efficient approach, since the minimum current is used for a given torque.However, in some situations, maintaining  fixed and modulating the torque through   can be convenient.Let's consider, for example, a 10A motor driver that, at a particular moment, is required to produce a low torque of 1/100 of the nominal value.By controlling the load angle to 90°, the windings' current magnitude should be reduced to 10/100 = 0.1A.It is feasible that the driver, which typically employs chopper amplifiers designed for high currents, suffers reduced accuracy in this low current range [17].Thus, imposing a current magnitude of, for example,  = 1A, and reducing the load angle at sin(  ) = 1/10, can help to make the driver produce the desired torque while working in its preferred current range.
In order to show that the proposed method is able to modulate the torque by changing both  and   , in the proposed implementation we chose a double control approach, as summarized in Table 1.Which of the 2 control approaches is applied depends on the instantaneous required torque ratio   ⁄  , where   =   •   is the nominal torque of the motor, produced at the nominal current   with the maximum load angle.For high torque values, i.e.,   ⁄  >10% (see first row of Table 1), the same approach as in the FOC is used: the load angle is fixed to ±π/2, and, from (1), the torque is   = ±   , which is modulated by controlling  (the sign depends on the direction of rotation).On the other hand, when a torque lower than   ⁄  =10% is required (bottom row in the table), the current is fixed to  =0.

Torque Modulation
According to (1), the torque can be modulated by controlling the load angle, θ L , and/or the current, I.The typical FOC application regulates the motor windings currents to generate a load angle of θ L = ±π/2, and the current magnitude I modulates the torque.This is the most efficient approach, since the minimum current is used for a given torque.However, in some situations, maintaining I fixed and modulating the torque through θ L can be convenient.Let's consider, for example, a 10 A motor driver that, at a particular moment, is required to produce a low torque of 1/100 of the nominal value.By controlling the load angle to 90 • , the windings' current magnitude should be reduced to 10/100 = 0.1 A. It is feasible that the driver, which typically employs chopper amplifiers designed for high currents, suffers reduced accuracy in this low current range [17].Thus, imposing a current magnitude of, for example, I = 1 A, and reducing the load angle at sin(θ L ) = 1/10, can help to make the driver produce the desired torque while working in its preferred current range.
In order to show that the proposed method is able to modulate the torque by changing both I and θ L , in the proposed implementation we chose a double control approach, as summarized in Table 1.Which of the 2 control approaches is applied depends on the instantaneous required torque ratio Γ E /Γ M , where Γ M = K t •I M is the nominal torque of the motor, produced at the nominal current I M with the maximum load angle.For high torque values, i.e., Γ E /Γ M > 10% (see first row of Table 1), the same approach as in the FOC is used: the load angle is fixed to ±π/2, and, from (1), the torque is Γ E = ±K t I, which is modulated by controlling I (the sign depends on the direction of rotation).On the other hand, when a torque lower than Γ E /Γ M = 10% is required (bottom row in the table), the current is fixed to I = 0.1•I M .From (1), the torque is Γ E = K t I M 10 sin(θ L ), which is modulated by changing θ L .
The Torque column of Table 1 describes the achieved torque when the current magnitude and the load angle are known.To control the motor we need the opposite, i.e., given a desired torque Γ E , we need to know the load angle, θ L , and the current, I, which produce such a torque.This result is obtained by solving the torque equations present in the Torque column of Table 1 with respect to the current I and the angle θ L (first row and second row of Table 2): Table 2 should be read as follow: given the desired torque Γ E , the load angle and current to be used with the the motor to generate such a torque are those reported in Angle and Current columns, at the row selected by the Condition column.
It is now convenient to distinguish the actual current I and load angle θ L , from the target current I t and load angle θ Lt , respectively.With reference to Figure 1, the first are the values currently present in the motor, while the others are the values that the motor control should achieve for generating the imposed torque.According to the aforementioned strategy, the electronics control, during the rotor movement, should drive the 2-phase currents so that I has the desired amplitude (I = I t ) and is dynamically positioned to maintain the target load angle (θ L = θ Lt ).Thus, if θ R and θ I are the actual rotor and current positions, (see Figure 1), the current position should be incremented/decremented by an angle of: For practical reasons, since we are going to use a µ-step driver where the current position can be incremented/decremented in discrete steps of amplitude 2π/4/N M rad, it is convenient to rewrite (4) as: where ST i , LA T , RP, CP, correspond to θ In , θ Lt , θ R , θ I , respectively, now expressed in µ-step unit.
For a better understanding of the proposed method, Figure 2 summarizes the control procedure.The instantaneous desired torque, expressed as torque ratio Γ E Γ M , the present current position, CP, and rotor position, RP, are inputs to the procedure.The calculation is divided into 2 steps.In the first step (Figure 2, top), the torque ratio is compared to the 0.1 threshold.If higher (Y-branch of the graph in Figure 2), the load angle is fixed to the maximum, i.e., θ Lt = π 2 , corresponding to LA T = N M µ-steps, and the current magnitude is calculated according to (3a).On the other hand, if the torque ratio is lower than the threshold (N-branch of the graph in Figure 2), the current module is set to its minimum I t = 0.1•I M , and the torque is modulated through the load angle, as calculated by (3b).In the second step (Figure 2, bottom), the target load angle   and the actual current and rotor positions are used in (5) to obtain the number of μ-steps   necessary to update the  position so that the load angle changes from   to the target load angle   .The output values   and   are finally sent to the motor drive.Please note that when the border value of   = 0.1•  is used in both the branches of the procedure, it produces the same current module   = 0.1 •   and target load angle   =   .This confirms that the decision above the threshold does not produce discontinuities in the generated currents and target angles.
The 2 nd step of the descripted procedure represents the quick and simple control loop mentioned in Sec.I.It should loop at a high rate, so that CP tracks RP accurately with the correct phase during the motion of the shaft, which can rotate at several rev/s.On the other hand, the 1 st step is more relaxed, since the torque changes are affected by the relatively slow dynamics of the motor mechanics.For example, let us consider a motor running at a constant velocity of 1000 rpm and loaded by a constant resistant torque.In case of a 200-step/turn motor controlled with 16 μ-step per step, the shaft runs a μ-step every 20 μs.To maintain the load angle, the control loop should correct the CP position with comparable timing, while no change is made to   and   .

The Electronics
The proposed method was implemented in an electronics system based on 3 boards (see Figure 3).The DECA MAX10 (Arrow Electronics, Centennial, CO) includes an FPGA from the low-cost MAX10 family produced by Altera (San Jose, CA).It is connected to a homemade interface board that includes the basic electronics to read the quadrature signals from incremental encoders, and to connect to the evaluation boards of the PowerSTEP01 motor control device.The board and the device are both produced by STMicroelectronics (Geneva, Switzerland).PowerSTEP01 is able to drive a stepper motor with up to 80V and 10A currents in an open loop.In this work, the device was set for   =16 (1/16 μ-step mode), and used in "Step-clock" mode, where it rotates the current position, , by a single µ -step every rise-edge generated on the step-clock signal.The direction of the rotation and the current are set by specific commands sent through a SPI channel.In the second step (Figure 2, bottom), the target load angle LA T and the actual current and rotor positions are used in (5) to obtain the number of µ-steps ST i necessary to update the CP position so that the load angle changes from θ L to the target load angle θ Lt .The output values I t and ST i are finally sent to the motor drive.Please note that when the border value of Γ E = 0.1•Γ M is used in both the branches of the procedure, it produces the same current module I t = 0.1•I M and target load angle LA T = N M .This confirms that the decision above the threshold does not produce discontinuities in the generated currents and target angles.
The 2nd step of the descripted procedure represents the quick and simple control loop mentioned in Section 1.It should loop at a high rate, so that CP tracks RP accurately with the correct phase during the motion of the shaft, which can rotate at several rev/s.On the other hand, the 1st step is more relaxed, since the torque changes are affected by the relatively slow dynamics of the motor mechanics.For example, let us consider a motor running at a constant velocity of 1000 rpm and loaded by a constant resistant torque.In case of a 200-step/turn motor controlled with 16 µ-step per step, the shaft runs a µ-step every 20 µs.To maintain the load angle, the control loop should correct the CP position with comparable timing, while no change is made to I t and θ Lt .

The Electronics
The proposed method was implemented in an electronics system based on 3 boards (see Figure 3).The DECA MAX10 (Arrow Electronics, Centennial, CO) includes an FPGA from the low-cost MAX10 family produced by Altera (San Jose, CA).It is connected to a homemade interface board that includes the basic electronics to read the quadrature signals from incremental encoders, and to connect to the evaluation boards of the PowerSTEP01 motor control device.The board and the device are both produced by STMicroelectronics (Geneva, Switzerland).PowerSTEP01 is able to drive a stepper motor with up to 80 V and 10 A currents in an open loop.In this work, the device was set for N M = 16 (1/16 µ-step mode), and used in "Step-clock" mode, where it rotates the current position, CP, by a single µ-step every rise-edge generated on the step-clock signal.The direction of the rotation and the current are set by specific commands sent through a SPI channel.

FPGA Implementation
The proposed method is implemented in the FPGA of the DECA MAX10 board, and is sketched in Figure 4.This implementation refers to a stepper driver set for   =16 and a 10k pulse-per-turn encoder; however, it can easily be adapted to different settings.The time-critical calculations, like the control loop (5), are implemented in the FPGA fabric and coded directly in VHDL, while parts of the remaining tasks are coded in the C language and run in a NiosII® soft processor included in the FPGA.This approach allowed low execution time for the control loop (5) and a faster and easier code development for the other tasks.The sections coded in the soft-processor include a conventional Proportional-Integral (PI) controller [10] and a simple trajectory generator, which are ancillary blocks that are necessary to allow the experimental test of the torque control method.
With reference to Figure 4, the soft processor includes the simple trajectory loop, that according to a programmed trajectory, calculates the target position PT every 1 ms.PT feeds the PI controller [10] that compares PT to the actual position PA and outputs the target torque   .The torque is then processed in the Torque block, which applies the first step of the control procedure detailed in Figure 2, and generates the required current   and the target load angle   .  is delivered to the LoadAngle block, while   is directly programmed to the driver through the SPI.Both the PI and the load angle calculation run every 200 μs.
The FPGA fabrics include several interacting blocks.The EncCnt counter (Figure 4  In the Mapper block, the physical position of the rotor PA is converted from encoder to μ-step units [18] (8/25 factor for 10k pulse/turn encoder and   =16).The least-significant 5 bits of this value maps the rotor position in the electrical circle of Figure 1, RP, expressed in μ-step unit, which is delivered to the LoadAngle block.
The current position CP is tracked in the StepMan block (see Figure 4).The number of μ-steps   demanded to the driver in every control cycle are accumulated in the "step counter" with a sign that depends on the direction of rotation.The counter works with a 4  module: for   =16 a 5-bit counter is used.

FPGA Implementation
The proposed method is implemented in the FPGA of the DECA MAX10 board, and is sketched in Figure 4.This implementation refers to a stepper driver set for N M = 16 and a 10 k pulse-per-turn encoder; however, it can easily be adapted to different settings.The time-critical calculations, like the control loop (5), are implemented in the FPGA fabric and coded directly in VHDL, while parts of the remaining tasks are coded in the C language and run in a NiosII®soft processor included in the FPGA.This approach allowed low execution time for the control loop (5) and a faster and easier code development for the other tasks.The sections coded in the soft-processor include a conventional Proportional-Integral (PI) controller [10] and a simple trajectory generator, which are ancillary blocks that are necessary to allow the experimental test of the torque control method.
With reference to Figure 4, the soft processor includes the simple trajectory loop, that according to a programmed trajectory, calculates the target position P T every 1 ms.P T feeds the PI controller [10] that compares P T to the actual position PA and outputs the target torque Γ E .The torque is then processed in the Torque block, which applies the first step of the control procedure detailed in Figure 2, and generates the required current I t and the target load angle LA T .LA T is delivered to the LoadAngle block, while I t is directly programmed to the driver through the SPI.Both the PI and the load angle calculation run every 200 µs.
The FPGA fabrics include several interacting blocks.The EncCnt counter (Figure 4  In the Mapper block, the physical position of the rotor PA is converted from encoder to µ-step units [18] (8/25 factor for 10 k pulse/turn encoder and N M = 16).The least-significant 5 bits of this value maps the rotor position in the electrical circle of Figure 1, RP, expressed in µ-step unit, which is delivered to the LoadAngle block.
The current position CP is tracked in the StepMan block (see Figure 4).The number of µ-steps ST i demanded to the driver in every control cycle are accumulated in the "step counter" with a sign that depends on the direction of rotation.The counter works with a 4N M module: for N M = 16 a 5-bit counter is used.
The LoadAngle block (see Figure 4) finally calculates the µ-steps required to maintain the desired load angle, ST i , by applying the second step of the control procedure described in Figure 2 to the inputs provided from the blocks previously described.Every 50 µs, ST i is delivered to the StepMan block that issues to the powerSTEP01 driver the direction command followed by a burst of ST i electrical pulses of 1 µs each.
Electronics 2018, 7, x FOR PEER REVIEW 7 of 16 The LoadAngle block (see Figure 4) finally calculates the μ-steps required to maintain the desired load angle,   , by applying the second step of the control procedure described in Figure 2 to the inputs provided from the blocks previously described.Every 50 µ s,   is delivered to the StepMan block that issues to the powerSTEP01 driver the direction command followed by a burst of   electrical pulses of 1 µ s each.

Debug Memory
The FPGA includes a debug memory (see Figure 4 bottom, right), where PA,   ,   , CP, RP, and   parameters are simultaneously saved with a sampling rate set by the user from 1 μs to 100 ms.Up to 4096 values of each parameter can be saved without interfering with the algorithm.The memory can be downloaded to a host PC when the motor is stopped.Although this feature has no impact on the algorithm, it is essential for debugging and performance analysis.

Timings and Resources
The trajectory controller updates the target position, PT, every 1 ms, and executes in 1.0 μs on a Nios processor clocked at 100 MHz.The PI controller and the torque control run every 200 μs, and execute the calculations in 1.5 μs only.This result is obtained using a look-up table for the sin inversion necessary in control step 1 (see Table 2, second row) for low torque condition.The remaining tasks, performed in FPGA fabric, are simple mathematical calculations or logic operations

Debug Memory
The FPGA includes a debug memory (see Figure 4 bottom, right), where P A , LA T , I t , CP, RP, and ST i parameters are simultaneously saved with a sampling rate set by the user from 1 µs to 100 ms.Up to 4096 values of each parameter can be saved without interfering with the algorithm.The memory can be downloaded to a host PC when the motor is stopped.Although this feature has no impact on the algorithm, it is essential for debugging and performance analysis.

Timings and Resources
The trajectory controller updates the target position, P T , every 1 ms, and executes in 1.0 µs on a Nios processor clocked at 100 MHz.The PI controller and the torque control run every 200 µs, and execute the calculations in 1.5 µs only.This result is obtained using a look-up table for the sin inversion necessary in control step 1 (see Table 2, second row) for low torque condition.The remaining tasks, performed in FPGA fabric, are simple mathematical calculations or logic operations that take a few clock cycles at most to execute.The LoadAngle block (step 2 in Figure 2) is evaluated every 50 µs.In this period, the StepMan block issues a SPI command and a step-clock burst to the driver (see Figure 5).The SPI transmission, 1 byte at 4 MHz, takes about 3 µs.PowerSTEP01 driver requires a step-clock period of 1 µs, so the maximum length of the burst is of 32 µs (every position in a 64 µ-steps electrical circle can be reached by, at maximum, 32 µ-steps towards the shorter path).The minimum temporal length of a torque control loop is thus 3 + 32 = 35 µs, which fits well in the 50 µs period used here.
Electronics 2018, 7, x FOR PEER REVIEW 8 of 16 that take a few clock cycles at most to execute.The LoadAngle block (step 2 in Figure 2) is evaluated every 50 μs.In this period, the StepMan block issues a SPI command and a step-clock burst to the driver (see Figure 5).The SPI transmission, 1 byte at 4 MHz, takes about 3 μs.PowerSTEP01 driver requires a step-clock period of 1 μs, so the maximum length of the burst is of 32 μs (every position in a 64 μ-steps electrical circle can be reached by, at maximum, 32 μ-steps towards the shorter path ).
The minimum temporal length of a torque control loop is thus 3 + 32 = 35 μs, which fits well in the 50μs period used here.The resources employed in the FPGA are reported in Table 3.As expected, most of the resources are used by the Nios® soft processor, while the other control blocks need relatively few logic cells and registers, and no memory nor mathematical processors (DSPs).

Experimental Set-Ups
The control method was implemented in the electronics system reported in Sec.3.1, which was connected to the set-ups shown in Figure 6.The set-up is composed by the M1233041 stepper motor (Lam Technologies, Florence, Italy) connected to the REV621 (Elap, Milan, Italy) encoder through a flexible mechanical coupling.Table 4 reports the main features of the employed motor and encoder.The resources employed in the FPGA are reported in Table 3.As expected, most of the resources are used by the Nios®soft processor, while the other control blocks need relatively few logic cells and registers, and no memory nor mathematical processors (DSPs).

Experimental Set-Ups
The control method was implemented in the electronics system reported in Section 3.1, which was connected to the set-ups shown in Figure 6.The set-up is composed by the M1233041 stepper motor (Lam Technologies, Florence, Italy) connected to the REV621 (Elap, Milan, Italy) encoder through a flexible mechanical coupling.Table 4 reports the main features of the employed motor and encoder.

Control Procedure Test
In this test, the trajectory and PI control loops implemented in the Nios II® were bypassed.The soft processor was programmed to set a fixed torque ratio     ⁄ = 0.5.Being the ratio higher than the 0.1 threshold, the control sets a fixed current   = 0.5 •   = 2.1A and a 90° load angle, i.e.   =   = 16 µ -steps.The debug memory in FPGA was programmed to acquire a complete set of parameters every 1 µ s.The motor was enabled for 1s, and when the rotor reached a stable velocity the initial acceleration, the debug memory was downloaded and processed in Matlab (The Mathworks, Natick, MA, USA).The parameters trend is reported in Figure 7 for a period of about 1.6 ms.The rotor electrical position (RP, Figure 7 first row) completes an electrical revolution (i.e.64 μ-steps) in 0.68 ms.An electrical revolution corresponds to 4 steps [3]; thus, since the employed motor features 200 step/rev, the shaft performs a complete physical turn in 200/4•0.68 = 34 ms.The current electrical position, CP, is reported in the 2nd row of Figure 7.As expected, it has a step-like behavior, with each step being 50 μs, i.e. the loop period.Similarly to RP, CP performs an electrical revolution (0-64 μ-steps) in 34 ms.7).In this experiment,   is in the range 5 ± 1 μ-steps, but most of the time is exactly 5 μ-steps.The calculated

Control Procedure Test
In this test, the trajectory and PI control loops implemented in the Nios II®were bypassed.The soft processor was programmed to set a fixed torque ratio Γ E Γ M = 0.5.Being the ratio higher than the 0.1 threshold, the control sets a fixed current I t = 0.5•I M = 2.1 A and a 90 • load angle, i.e., LA T = N M = 16 µ-steps.The debug memory in FPGA was programmed to acquire a complete set of parameters every 1 µs.The motor was enabled for 1 s, and when the rotor reached a stable velocity after the initial acceleration, the debug memory was downloaded and processed in Matlab (The Mathworks, Natick, MA, USA).The parameters trend is reported in Figure 7 for a period of about 1.6 ms.The rotor electrical position (RP, Figure 7 first row) completes an electrical revolution (i.e., 64 µ-steps) in 0.68 ms.An electrical revolution corresponds to 4 steps [3]; thus, since the employed motor features 200 step/rev, the shaft performs a complete physical turn in 200/4•0.68 = 34 ms.The current electrical position, CP, is reported in the 2nd row of Figure 7.As expected, it has a step-like behavior, with each step being 50 µs, i.e., the loop period.Similarly to RP, CP performs an electrical revolution (0-64 µ-steps) in 34 ms.Every 50 µs, the controller calculates ST i from RP and CP (see 3rd row of Figure 7).In this experiment, ST i is in the range 5 ± 1 µ-steps, but most of the time is exactly 5 µ-steps.The calculated value is then used to update CP in next control period.The measured load angle, calculated in Matlab®as LA M = CP − RP (see Figure 1) is reported in the last row of Figure 7, where it is compared to the target angle LA T represented by the horizontal dashed line at 16 µ-step.It features a rough triangular shape of 50 µs period.When the CP is updated by ST i µ-steps, LA M reaches LA T and the load angle error is zero.Then, in the following 50 µs, the shaft moves, RP rises, and LA M diminishes until the next control period zeroes the error again.
value is then used to update CP in next control period.The measured load angle, calculated in Matlab® as   = C − R (see Figure 1) is reported in the last row of Figure 7, where it is compared to the target angle   represented by the horizontal dashed line at 16 μ-step.It features a rough triangular shape of 50 μs period.When the CP is updated by   μ-steps,   reaches   and the load angle error is zero.Then, in the following 50 μs, the shaft moves, RP rises, and   diminishes until the next control period zeroes the error again.This experiment helps to clarify that the error between the measured and target angle depends on the motor velocity and the control period T. In fact, the higher the velocity, the wider the angle turned by RP in the control period.Quantitatively, the load angle peak error, in μ-steps can be expressed as: where ω is the motor velocity in rad/s and 3200 is the number of μ-steps per revolution.Since the error features a triangle-like shape (see last row of Figure 7), its mean value is half of the peak, i.e., Lerr/2.

Torque Load Disturbance Test
With the set-up used in previous experiment, the trajectory generator was disabled and the PI was enabled with its input fixed to PT = 0 (see Figure 4).The debug memory was programmed to save a parameter set every 200μs.In this test, the motor shaft was loaded with an external positive torque, which was released at time t = 0. Figure 8 reports the shaft position measured by the encoder, PA, the current ratio, It/IM, the target angle,   , calculated by the motor control, and the measured load angle,   , together with its error with respect to the target angle.
Before the torque was released (t < 0), the control system maintained the rotor at position PA = 0 by imposing the maximum load angle   = −16 μ-steps and a current of about 50% of the nominal value.After the external torque was released (t > 0), the control system reacted by reducing the current to its minimum of 10% in about 40 ms, then further reduced the torque by lowering the load 0 0.  This experiment helps to clarify that the error between the measured and target angle depends on the motor velocity and the control period T. In fact, the higher the velocity, the wider the angle turned by RP in the control period.Quantitatively, the load angle peak error, in µ-steps can be expressed as: where ω is the motor velocity in rad/s and 3200 is the number of µ-steps per revolution.Since the error features a triangle-like shape (see last row of Figure 7), its mean value is half of the peak, i.e., Lerr/2.

Torque Load Disturbance Test
With the set-up used in previous experiment, the trajectory generator was disabled and the PI was enabled with its input fixed to P T = 0 (see Figure 4).The debug memory was programmed to save a parameter set every 200 µs.In this test, the motor shaft was loaded with an external positive torque, which was released at time t = 0. Figure 8 reports the shaft position measured by the encoder, P A , the current ratio, It/I M , the target angle, LA T , calculated by the motor control, and the measured load angle, LA M , together with its error with respect to the target angle.
Before the torque was released (t < 0), the control system maintained the rotor at position P A = 0 by imposing the maximum load angle LA T = −16 µ-steps and a current of about 50% of the nominal value.After the external torque was released (t > 0), the control system reacted by reducing the current to its minimum of 10% in about 40 ms, then further reduced the torque by lowering the load angle towards 0. Meanwhile, due to the sudden load change, the shaft rotated of about −1.5 rad out of position, so the PI responded by imposing a slight positive load angle (t > 60 ms), while maintaining the current at its minimum level.The shaft recovered the target position in about 250 ms and the load angle decreased to 0. The error between the target and measured load angles, shown in last row, is within ±1 µ-step, except for few outliers.The load angle error is the same with (t < 0), and without (t > 0) the presence of load.The position error calculated as mean ± standard deviation of the errors measured before torque release (t < 0) is 0.05 ± 1.3 mrad, while after a stable condition was reached at t > 250 ms, is 0.09 ± 1.4 mrad.The test shows that the control reacts to a strong load change recovering the original position and controlling the load angle with a high level of accuracy.

Trajectory Test in Different Load Conditions
The trajectory generator of Figure 4 was programmed to produce a forward movement of 2π rad, with a constant acceleration/deceleration of 270 rad/s 2 and a maximum velocity of 16.4 rad/s.The experiment was repeated with the motor free, i.e., no load except the encoder, and with the motor connected to a load.The load was realized with a weight suspended by wire wrapped around the shaft.In the movement, the motor raised up the weight generating a torque that corresponds to about 20% of the full motor capacity. Figure 9 reports the parameters acquired in the FPGA every 300 µs.Left and right columns report the measurements obtained without and with the load, respectively.The errors are expressed as mean ± standard deviation calculated on the samples population of the corresponding measurement.
The measured position P A is reported on the 1st row of Figure 9.The movement lasted 0.83 s; it featured a typical "S" shape, which is barely visible because of the high acceleration used.The position error Perr is shown in the 2nd row.In the experiment with no load, the error peaks up to ±0.2 rad in the high acceleration/deceleration regions, but it is as low as 1 ± 2 mrad in the constant velocity region.The motor reacts to the acceleration in presence of load with an oscillation error of ±0.02 rad, which damps down in 200 ms.In the remaining part of the constant velocity region, the error is the same as in the no-load condition.With load, after the movement, the controller recovers the right steady position a bit more slowly with respect to no-load condition.The measured velocity shows the expected trapezoidal shape with some oscillations.The velocity is reported on the 3rd row of Figure 9, where it is compared to the target value, i.e., 16.4 rad/s, highlighted by the red horizontal segment.The velocity error was 0.01 ± 0.58 rad/s with no load, and 0.02 ± 0.85 rad/s with the load.
Without load, as expected, the current was set to its 10% minimum (4th row, left) and the torque was modulated by the load angle (  5th row, left), which, during the movement, was about 10 μ-steps and reduced in the steady region.The error on the load angle (Lerr, 6th row, left) was 0.03 ± 0.7 μ-step.With load, during the movement, the load angle was fixed to its maximum, i.e. 16 μ-step corresponding to 90° (  5th row, right), and the torque was modulated by the current (4 th row, right), which was about 20% of the nominal value.At the end of the movement, when the torque required reduced, the current went down to 10% and the torque was again modulated by the angle.In this case, the error on the load angle was −0.4 ± 0.5 μ-step.The measured velocity shows the expected trapezoidal shape with some oscillations.The velocity is reported on the 3rd row of Figure 9, where it is compared to the target value, i.e., 16.4 rad/s, highlighted by the red horizontal segment.The velocity error was 0.01 ± 0.58 rad/s with no load, and 0.02 ± 0.85 rad/s with the load.
Without load, as expected, the current was set to its 10% minimum (4th row, left) and the torque was modulated by the load angle (LA T 5th row, left), which, during the movement, was about 10 µ-steps and reduced in the steady region.The error on the load angle (Lerr, 6th row, left) was 0.03 ± 0.7 µ-step.With load, during the movement, the load angle was fixed to its maximum, i.e., 16 µ-step corresponding to 90 • (LA T 5th row, right), and the torque was modulated by the current (4th row, right), which was about 20% of the nominal value.At the end of the movement, when the torque required reduced, the current went down to 10% and the torque was again modulated by the angle.In this case, the error on the load angle was −0.4 ± 0.5 µ-step.

Discussion and Conclusions
Stepper motors are pervasive in modern applications; however, their use of open loops has several drawbacks.This work aims at a simple closed-loop method for overcoming such disadvantages.The method is fully compatible with the commercial monolithic devices typically used for open-loop drive of stepper motors, so that the generation and control of phase currents can be achieved on such devices.

Discussion and Conclusions
Stepper motors are pervasive in modern applications; however, their use of open loops has several drawbacks.This work aims at a simple closed-loop method for overcoming such disadvantages.The method is fully compatible with the commercial monolithic devices typically used for open-loop drive of stepper motors, so that the generation and control of phase currents can be achieved on such devices.
The heart of the method is represented by the loop control (5).It comprises a few simple operations that are executed at a high rate.In fact, the ripple on the load angle error depends on the loop execution period T, according to (6).In this implementation, we used T = 50 µs, which, for example, allowed us to reduce the load angle error to less than −5 µ-step (about 1/100 rad) for a rotor velocity up to 750 rev/min.The proposed method achieves a very low static error both in load (0.05 ± 1.3 mrad) and no-load (0.09 ± 1.4 mrad) conditions, as measured in the experiment reported in Section 4.4).This error can be compared, for example, to those obtained by similar closed loop controllers described in [19] and [20], where static errors of 0.5 • (~8 mrad) and 0.2 • (3.5 mrad) are reported, respectively.The position error present during constant velocity movement (see experiment 4.4) is similar or lower to that shown in Figure 5 of [11], where a different FOC closed loop controller for stepper motors is presented.The controller presented in [11], among other differences, is based on a microcontroller where the control loop runs at T = 350 µs, with respect to T = 50 µs proposed here.
The high execution rate used in this work would be critical-if not unfeasible-in full microprocess implementation; hence, the use of an FPGA, as proposed here.On the other hand, the remaining tasks, e.g., current calculation, are more time-relaxed, and a C-like microprocessor approach makes the development and the debug easier.The use of the FPGA fabric and the soft processor answers to both requirements with a single electronics device.However, in cases where FPGA resources must be saved, a full VHDL controller implementation is feasible.
Several improvements can be made to the proposed method, like the damping of the motor resonances [21], the use of optimal load angle [22], the sensor-less angle measurement [23,24], ripple reduction [25], and others.
The proposed method represents a simple and economic implementation of closed-loop control, which yields significant improvement in stepper motor performance with respect to the typical open-loop approach.

Figure 2 .
Figure 2. Procedure of the proposed control method.

Figure 2 .
Figure 2. Procedure of the proposed control method.

Figure 3 .
Figure 3.The electronics system is composed of the DECA Max10 and the EVLPOWERStep01 developing boards connected through a homemade interface board.A second drive board can be connected to simultaneously drive 2 motors.
top, right) tracks the actual rotor position PA by integrating the quadrature signals produced by the encoder.PA is then used by the PI and the Mapper block in the FPGA fabric.

Figure 3 .
Figure 3.The electronics system is composed of the DECA Max10 and the EVLPOWERStep01 developing boards connected through a homemade interface board.A second drive board can be connected to simultaneously drive 2 motors.
top, right) tracks the actual rotor position PA by integrating the quadrature signals produced by the encoder.PA is then used by the PI and the Mapper block in the FPGA fabric.

Figure 4 .
Figure 4. FPGA implementation of the proposed method.Control step 1 and Control step 2 refer to the calculations reported in the corresponding steps of Figure 2.

2 PCFigure 4 .
Figure 4. FPGA implementation of the proposed method.Control step 1 and Control step 2 refer to the calculations reported in the corresponding steps of Figure 2.

Figure 5 .
Figure 5. Timing of the commands sent to the power driver.

Figure 5 .
Figure 5. Timing of the commands sent to the power driver.

Figure 6 .
Figure 6.Experimental set-up with the stepper motor (left) connected to the encoder (right) through a flexible mechanical coupling (center).

Figure 6 .
Figure 6.Experimental set-up with the stepper motor (left) connected to the encoder (right) through a flexible mechanical coupling (center).

Figure 7 .
Figure 7. Rotor (RP) and Current (CP) Positions, Step Increment (ST i ), and measured Load Angle (LA M ) with fixed 2.5 A phase currents and 16 µ-steps target load angle (LA T ).

Figure 8 .
Figure 8.The rotor position is controlled at position 0.An external positive torque is applied and released at t = 0 (vertical dashed line).From top to bottom, physical Rotor position PA, motor current ratio (It/IM), target (LAT) and measured (LAM) load angles, and load angle error (Err), are reported.

Figure 8 .
Figure8.The rotor position is controlled at position 0.An external positive torque is applied and released at t = 0 (vertical dashed line).From top to bottom, physical Rotor position P A , motor current ratio (I t /I M ), target (LA T ) and measured (LA M ) load angles, and load angle error (Err), are reported.

Figure 9 .
Figure 9. Movement of 2π rad with acceleration of 270 rad/s 2 and maximum velocity of 16.4 rad/s, performed with motor free (left column) and with a load of 20% motor capacity (right column).From top to bottom, Shaft position (PA), Position error (Perr), Velocity (Vel), motor current ratio (It/IM), target load angle (LAT), and load angle error (Lerr), are reported.

Figure 9 .
Figure 9. Movement of 2π rad with acceleration of 270 rad/s 2 and maximum velocity of 16.4 rad/s, performed with motor free (left column) and with a load of 20% motor capacity (right column).From top to bottom, Shaft position (P A ), Position error (Perr), Velocity (Vel), motor current ratio (I t /I M ), target load angle (LA T ), and load angle error (Lerr), are reported.
Figure 1.In a stepper motor the torque is related to the load angle θ L , present between the rotor magnet, θ R , and the current field, θ I .The target load angle θ Lt is obtained by advancing of θ In the current field θ i .

Table 3 .
FPGA Resources employed by the control system.

Table 3 .
FPGA Resources employed by the control system.

Table 4 .
Features of the Motor and the Encoder used in the experimental set-up.Every 50 μs, the controller calculates   from RP and CP (see 3rd row of Figure

Table 4 .
Features of the Motor and the Encoder used in the experimental set-up.