FPGA-Based Architecture for Sensing Power Consumption on Parabolic and Trapezoidal Motion Proﬁles

: The objective of this work is to design and implement a scalable Field-Programmable Gate Array (FPGA)-based motion control system for DC servo motors using a parabolic velocity proﬁle for industrial applications. The implementation in this device allows the obtaining of a fast, ﬂexible and low-cost system. The system is divided into control, communication and closed-loop coupling. The work also addresses a comparative analysis of the most used proﬁles, the trapezoidal and parabolic. The comparison is made considering the energy consumption of both proﬁles. As a consequence of the comparison made, the velocity proﬁle can be selected to reduce production costs by saving energy and reducing wear on machinery. The discrete models of the velocity proﬁles are obtained through numerical methods that permit the control blocks to be implemented in an FPGA. To reduce maintenance costs and energy consumption in servo mechanisms, the derivation of the acceleration or jerk of the motor is shown. A Graphic User Interface (GUI) is presented, which allows monitoring the position, velocity and angular acceleration of the motor shaft. In addition, the developed interface supports modiﬁcation of parameters of the ﬁnal position and maximum velocity in the motor. The delivered current is compared, evaluating its decrease using a parabolic velocity proﬁle. Finally, the experimental results are illustrated.


Introduction
Motors are used in a wide variety of applications, from washing machine [1] in homes to electric vehicles [2] in the transport sector. Modern control systems generally require more efficient techniques to execute the instructions at high velocity and get more accurate results. According to [3], the best way to achieve high performance in servo control is to remove the servo control loop implemented in a Digital Signal Processor (DSP) or in a microcontroller and transfer it to a high-velocity control loop in an Field-Programmable Gate Array (FPGA). The statement takes into account the advantages selection of its parameters [31]. For this reason, the aforementioned profiles constitute the focus of this investigation. Table 1 shows a brief comparison of the main characteristics of the velocity profiles treated at work. Although the S profile is not addressed in the present investigation, its inclusion in the previous table was considered important. Furthermore, Table 2 presents a summary of similar works. Table 1. General comparison of the velocity profiles.

Trapezoidal Velocity Profile Parabolic Velocity Profile S Velocity Profile
Advantage This profile can be executed in shorter periods of time when using point-to-point movement Parabolic profile reduces mechanical jerks The profile makes the jerk constant for several periods of time, avoiding that the jerk goes to the infinite.

Limiting
Trapezoidal profile can produce undesirable mechanical jerks Requires a longer cycle time S profile is slower than the trapezoidal and parabolic profile. Table 2. Summary of the state of the art.

Ref./Year Implementation Contributions
[16]/2017 Raspberry Pi 3 and FPGA ZYBO The paper presents a comparison between the trapezoidal and s-curve velocity profile used in robotics and CNC machinery.
[25]/2019 TMS320C28346 microcontroller A trapezoidal profile generator based on a cascaded P-PI position controller is proposed.
[32]/2008 MDi MC4000 Pro controller card The model of polynomial s-curve motion profiles is generalized in a recursive form.
[33]/2013 TMS320F28335 controller The position reference in consideration of jerk is generated in the control system of permanent magnet synchronous motor.
[34]/2019 PCI-7345 Tuning parameters are adjusted to place the zeros of the motion profile at a vibrating pole in the system to minimize vibration.
[35]/2007 PMDi MC4000 Pro controller card Experimental results show the effectiveness and promising application ability of the algorithms in s-curve motion profiling.
It is important to mention that greater efficiency in production chains is not the only justification for the development of this research. In addition, a correct modulation must be made in the maximum velocity of the actuators, since it allows the prevention of collisions or overheating in moving parts. The regulation of energy consumption directly affects production costs and it is precisely this characteristic that highlights the parabolic profile versus the trapezoidal profile, reducing the rate of change in acceleration with respect to time. The objective of the work is the practical FPGA-based implementation of a control for servo motors for industrial use, in addition to establishing a comparative analysis that results in the selection of the most suitable profile for the application. For this, a separate implementation of each module is carried out. The paper is structured as follows. Section 2 presents the analytical model of velocity profiles. In Section 3, the development and implementation of the modules that make up the motion control system is documented. The experimental results and the comparative analysis of the trapezoidal and parabolic profiles are presented in Section 4. A list of the acronyms used in this paper is presented at the end of the document and in the Table A3 is shown the main signals used in the diagrams.

Analytical Model of Velocity Profiles
The trajectories are expressed as parametric functions of time and their analysis begins with the proposal of different velocity curves. First, the behavior of a parabolic velocity profile is analyzed, given by a function of the second degree and concludes with the study of the trapezoidal profile consisting of a sectioned function of the first degree.

Parabolic Velocity Profile
A parabolic trajectory belongs to a quadratic function and in turn, the derivative of said function is a line of first grade, as shown in Figure 1a. The equation that describes the acceleration line is defined in Equation (1).
where: T is the sample time, a is the acceleration value and t is the time.
The angular velocity shown in Equation (2) and illustrated in Figure 1b is obtained by integrating Equation (1) from 0 to T.
Equation (3) is obtained by solving the integral. The maximum value is presented at the point where the acceleration line intersects the abscissa axis. For this reason, to evaluate this function in T 2 the maximum velocity is obtained as Equation (4). Finally, the angular position function is calculated as in Equation (5). Figure 1c shows the result of evaluating the previously calculated position function from 0 to T. The final position is obtained by evaluating θ(t) in T: For application purposes it is convenient to define Equation (7) in terms of the maximum velocity: The development of these equations allows the conclusion that the desired position and the maximum acceleration depend solely on the end position assigned by the user and the maximum velocity of the motor. In the implementation of the parabolic profile (in its digital form), the values T, a and m = −2a T are used as coefficients to iteratively calculate the different positions for each instant of time through of numerical integration.

Trapezoidal Velocity Profile
The trapezoidal velocity profile is described as a sectioned function in two straight lines that have a slope and a line parallel to the X axis. The function that represents the acceleration of this profile is also given by a sectioned function in constant values as shown in Figure 2a, but they could be modified and experimented with different geometries of the trapezoid.
The functions that describe the velocity and position of the trapezoidal profile require integration by parts in the time interval established in the acceleration function. Table 3 summarizes the results obtained from angular velocity after solving each integral. The maximum velocity of the motor is represented by Equation (11), which results from evaluating the first result in T 3 . Figure 2b presents the velocity graph obtained.

Interval α(t)
Function ω(t) Obtaining the angular position function requires the same part integration procedure used for the velocity function. Table 4 summarizes the results of evaluating the integral for each of the time intervals. From the values presented, Figure 2c is presented.
The final position is obtained by evaluating θ(t) in T in Equation (12) and Equation (13) is obtained.
It is convenient to factor the Expression (14) into the product of aT 3 by 2T 3 in order to substitute with Equation (11) and describe the final position in terms of maximum velocity and time period.
From the previous equation can be solved T and taking into account Equation (15), the acceleration constant is solved in Equation (16).
Similar to the parabolic profile, the coefficients obtained as a function of the maximum velocity and the final position indicated by the user will serve for the iterative calculation in the discrete system of the following section.

Design and Implementation of Modules
According to [36], modeling a physical system consists of obtaining and solving equations that describe the behavior through its variables. The components of the system are modeled separately and finally connected according to their configuration and the laws of nature that govern them. However, one of the main advantages of using velocity profiles is that it is not required to obtain the motor model to carry out its motion control. Figures 3 and 4 show the system proposed and the general hardware architecture for this work, respectively. The Artix-7 FPGA family is used, which optimized for low power applications requiring serial transceivers and high DSP and logic throughput. Provides the lowest total bill of materials cost for high-throughput, cost-sensitive applications. Also, this FPGA family offers high-end performance at the lowest cost and achievable power. The main characteristics of the device used are presented in Table 5. The selection of the sampling period was made after carrying out some experiments with higher values. It was also decided to establish a sampling period of 1 ms to simplify the calculations in the internal blocks since it avoids the use of extra blocks (multiplication blocks) when working with the value of 1. Furthermore, in previous investigations the use of this value has been formally justified [37,38].
Block programming is done using VHDL. The blocks are implemented in a flexible and modular way to enable easy customization. It was decided to take advantage of this language advantage due to its magnitude. In this way, if any correction is necessary for any of the blocks, it is not necessary to modify the entire system.   The control flow begins with the user interface, where the type of profile, the maximum velocity and the desired position are selected. Then, the coefficient generator sends the values to the FPGA through a UART transmission-reception module. The profile generator calculates for each instant of time a portion of the final position according to the selected profile. The difference between the profile generator position and the current motor position is sent to the profile tracker; this block induces a current in the motor. The direction of the current is determined by a bit in the received frame and it depends on the sign of the error. The current motor position is measured with the motor encoder and processed with a quadrature module described in the FPGA. The result is used in three ways in the system: as feedback to the profile tracker, as a decimal value displayed on a seven-segment display and as a vector of data transmitted to the interface to graph the motor path.
A Finite State Machine allows control of the two signals given by the encoder. The main clock of the system feeds this component in order to generate a count that could be decremental or incremental, depending on the direction of the shaft of the motor. The two signals from the encoder could reach some MHz, in this sense, when a multi-axe system is requires, the FPGA is a good choice.
The implementation of the profile tracker is done after obtaining a discrete model to add it to the design in the FPGA. As in the velocity profiles, the sampling time T s is 1 ms. The difference (θ d − θ) can be expressed as the error e(t) and rewrite the equation as: u(t) = e(t). The block input is the difference between the encoder reading and the desired position. With this circuit, the necessary operations are performed, thus tracing the position requested by the velocity profile generator. The output of the circuit is saturated to couple the result to a 4-bit control action for the motor driver.

Implementation of the Parabolic Profile
The calculation of the velocity profiles develops by integrating the acceleration curve once to obtain the velocity and twice to obtain the position. The implementation in the digital system occurs under the same logic, but instead of solving through an analytical integration, numerical integration is used to approximate the desired value at each instant of time. The discrete acceleration equation is obtained by substituting in Equation (1) the value of t for kT s , where k is an integer value that increases by 1 for each instant of time and T s is the sampling period. To simplify operations, it is convenient to select a unit sampling period, in this case 1 ms. The discrete equations are expressed as: The circuit implemented in the FPGA is described in Figure 5.

Implementation of the Trapezoidal Profile
The implementation of the trapezoidal profile is carried out in a similar way to Section 3.1 and is shown in Figure 6. The component inputs are acceleration and time period coefficients, a CLK, a ST and an RST. With this circuit it is possible to carry out the rectangular integration that allows us to obtain the angular position of the profile starting from its acceleration. The circuit components are: The behavior of the state machine of the trapezoidal and parabolic profiles is described in Figures A1 and A2. The flow of states determines the activation and deactivation of the registers that store the velocity and position values. The only difference between both machines is that for the trapezoidal profile, there is no acceleration register that must be activated and consequently, it consists of only seven states.

Implementation of the Servo Amplifier
The coupling of the DC motor with the digital controller is achieved through the LMD18245 driver. According to the reference datasheet of the manufacturer, a four-bit digital-to-analog converter (DAC) provides a digital path for controlling the motor current, and, by extension, simplifies implementation of full, half and microstep stepper motor drives. For higher resolution applications, an external DAC can be used. However, the accuracy that is achieved with 4 bits is sufficient for the application developed. The main function of the driver is to control the current supply that the DC motor receives at each instant of time, which modifies its velocity. The main characteristics of the DC motor and driver used for the experiments in this work are mentioned in Table 6. The current that the driver supplies to the servo motor varies in correspondence to the reference voltage VREF. This voltage is proportionally limited by the decimal value of the 4-bit word formed by pins M4 to M1, where M4 is the most significant bit. This reference is sensed and amplified by the CS OUT pin in combination with the Rs resistor.
The current required to overcome the motor resistance and cause movement is 75 mA. When it reaches the nominal velocity (without load), 150 mA is consumed, and the reference voltage may be less than 5 V. The voltage is adjusted to 1.8 V to take full advantage of the 4-bit resolution that the DAC provides for more precise velocity changes. In the event that a load is added to the motor or replaced by a motor that requires more current, it is only necessary to readjust the reference voltage to increase the range of current supplied.

Experimental Results
The FPGA assembled on the built PCB is illustrated in Figure 7. Some surface mount components were used to compact the component distribution and increase its wear resistance. The control system interface presented in Figure A5 allow the user to simulate 4 different velocity profiles where they can modify: the maximum motor velocity (given by its specifications), the final angular position and the sampling time. The GUI has been introduced as follows. The GUI helps to the user to set values of the system such as PID gains. Moreover, it permits plotting in real time or offline of the power consumption, and the behavior of the position, among other graphs. It is used the transmitter and receiver virtual serial port from the PC and connected to the FPGA by using three wires.
The precision of a numerical method depends on the iterations that are carried out, the experiment is performed with 15 turns of the parabolic profile and compared with the position obtained through Equation (5). The rectangular numerical method is the one used for the iterations. Before analyzing the results achieved through hardware, studying the error that exists when calculating the angular position with a numerical method is convenient. The results are shown in Figure 8, where the analytical and numerical method is compared with different sampling times by simulation. It is important to note that even with a sampling period 10 times slower than the one used at work (1 ms), the average error remains less than 1%. In a range of 100 ms up to 1 s, the error becomes more significant. The processing velocity in this system is of utmost importance to achieve the results closest to the desired values.  Each test shown in Figure 9 delivers a vector of monitored angular positions in a millisecond. Therefore, it is necessary to adjust the velocity of the RS232 protocol to the maximum supported by the MATLAB IDE: 115200 bps. The interface is not able to graph the received data in real time due to the high-reception velocity. It is important to note that the expected times to reach each angular position are the same for both profiles. Within the tests carried out on the system, the profile tracker is monitored when velocity profiles are used at its input and when the user directly assigns the position. Maximum engine velocity is a factor that path planning takes into account when calculating the position vector. For this experiment, the velocity is set to 10 per ms, equivalent to 71.4286 rpm, in order not to push the motor operation to the limit. The path followed by the profile tracker without the profile will use the 80 rpm of the engine. The experiments performed are presented in Figure 10.
The results obtained show that the implemented control reaches the established setpoint. Comparisons between the parabolic profile, the trapezoidal profile and a non-profile response are also presented. It can be seen that the parabolic profile reaches the desired position through a smoother curve in an average time of 5 s. It is important to mention that with the implemented control, it is not necessary to use an additional control loop to decrease the steady-state error. The error under standard system operation is less than 1%.  Figure 11 show the current measurement made with the Analog Discovery oscilloscope and MAX471 sensor to measure the power consumption of 10 turns. It should be noted that the function described by the voltages of both experiments is very similar to the velocity curve of each profile. Table 7 presents a comparison of the values of current, voltage and average power for both profiles. Finally, the percentage of use of FPGA resources is shown in Figure 8. It is observed that the consumption of FPGA resources is not excessive, even if improvements are required, they can be carried out without exceeding half the available resources. The results in the table above show a saving in power consumption of 0.85 W between the trapezoidal profile and the system without a profile. Similarly, 1.38 W is saved using the parabolic profile compared to the system without a profile. For its part, the parabolic profile represents an energy saving of 0.53 W compared to the use of the trapezoidal profile. Consumption in the FPGA can be reduced by applying different techniques. From a programming standpoint, techniques such as one-hot encoding for state machines and protected evaluation can be implemented while ensuring that logical loops that oscillate are not created. In addition, I/O standards must be chosen appropriately to avoid excessive use of static energy. Finally, an important technique to prevent excessive power usage in the FPGA is to suspend the part of the FPGA that is not in use.
It is important to note that the system responds satisfactorily to tracking the trajectory proposed by both profiles. The average error of the experiments ranges from 2.24% to 4.9%. Although the average error might seem considerable, it is interesting to note that the average error is very high at motor start because the theoretical value vector starts with very small decimal values less than 1 and the encoder gives counts per unit, not per fraction. Therefore, the errors at the beginning of the trajectory are up to almost 100%. However, after approximately the first sixth of the journey, the error is below 1%. The experiment was carried out for three different distances (5, 10 and 15 turns) to verify that the system remains stable at small or long distances and does not increase the value of the error. Regarding energy consumption, it can be seen that as shown in theory, it was significantly lower in the parabolic profile case than the trapezoidal one.
It can be seen that the voltage in both cases (parabolic and trapezoidal profile) was practically the same. However, the significant difference came from the current consumption, being considerably less in the parabolic profile. It can be concluded that the energy consumption in the parabolic profile was 17.3% less than the trapezoidal one. On the other hand, the behavior of energy consumption without a speed profile is considerably higher. Table 8 shows the consumption of FPGA resources. Furthermore, Table 9 shows a comparison of resources used by the FPGA for similar work. It can be seen that the developed design notably reduces the use of FPGA resources by using multipliers. This aspect enables the implementation of the proposed project in a wide range of similar devices and does not limit its use to devices with high performance. Latency in clock cycles of the implementation 11 Table 9. Comparison of resources consumed in similar works.

Conclusions
In the paper, a motion control system based on the parabolic velocity profile is developed and implemented and a comparative analysis with the trapezoidal profile is performed. In the selection of the parabolic profile, the behavior of a planned trajectory is observed. The theoretical estimates that address the characteristics of each profile, such as the velocity of response and energy consumption, were verified through experimentation. The difference between the forecast of the mathematical model and the practical example was very low. Among the advantages of the work presented, its modularity stands out. This prototype can be replicated for motors with a consumption of up to 3 A and only requires minor modifications in case of using motors with higher consumption.
Due to the versatility offered by the implementations in digital logic, it was possible to reconfigure the system to observe the behavior with and without the assistance of velocity profiles. The previous approach is verified when the theoretical curve of the profile is very similar to that of the experiment for different angular positions. The main reason for this behavior was the sampling time at 1 ms, which allowed the profiles to show changes of position so small that they did not represent a complication for the profile tracker.
A comparison of the characteristics between the parabolic and trapezoidal profile with a special focus on response time and energy consumption was carried out. Finally, one of the greatest advantages of the parabolic profile compared to the trapezoidal one was demonstrated: a lower energy consumption necessary to complete the desired path. It is important to note that the response time for both profiles was the same and consequently, saving energy did not represent a loss in velocity. With this conclusion, the importance of planning trajectories based on mathematical models that contemplate the focus on variables that significantly impact different mobility applications can be highlighted, in this case: the reduction of costs due to energy savings.
States description: • S0: The system is waiting for the ST start signal, once received, the calculation of the acceleration, velocity and position values begins. • S1: The STT start signal is sent to the time base to count 0.9992 ms and finally set the TS signal too high to start loading the registers. • S2: The first register is enabled by means of the LDA signal, this register stores the value of acceleration at that instant of time given by the sum of Q0 and Q3. • S3, S5, S7 and S9: The signals that enable registers are set to low to avoid sequenced registers active at the same time. • S4 and S6: The register that captures the angular velocity for that instant of time is enabled. • S8: The register that captures the last angular position is enabled. • S9: All signals are set to low level and in case the CRDY input signal is low, the cycle is repeated from state S1. Otherwise it returns to state S0. The CRDY signal will be high once the programmable counter detects that the acceleration, velocity and position values have already been calculated for all time instants from 0 to T.
States description: • S0: The system is waiting for the ST start signal, once received, the calculation of the velocity and position values begins. • S1: The STT start signal is sent to the time base to count 1 ms and finally set the TS signal too high to start loading the registers. • S2: The first register is enabled by means of the LDV signal, this register stores the value of velocity V1 at that instant of time given by the sum of A2 and V2. • S3 and S5: The signals that enable registers are set to low to avoid sequenced registers active at the same time. • S4 and S6: The registers that captures the angular positions P1 and P2 for respective instants of time are enabled. • S7: All signals are set to low level and in case the CRDY input signal is low, the cycle is repeated from state S1. Otherwise it returns to state S0. The CRDY signal will be high once the programmable counter detects that the velocity and position values have already been calculated for all time instants from 0 to T.
Timing simulation is shown in Figures A3 and A4 to have a general overview of the FPGA's behavior when computes numerical values.