## 4 Experimental Design of the Control System
### Algorithm of Velocity and the Phase Difference  
A method for calculating the velocity of the master motor and the phase difference between ERs will be presented in this section to match control targets. Because of the vibration performance, the velocity of a vibration motor in one period varies from moment to moment, which causes the difficulty of calculating velocity. The conventional M/T method cannot calculate the exact value of velocity for a vibration motor. For this problem, the approach of measuring multiple rotational periods of the motor is chosen to obtain a more accurate value of velocity. However, too long periods will result in the loss of real-time control. Considering the experimental velocity near 1500 r/min of the motor in this work, the calculating period of the velocity is set at four rotational periods of the motor. Since the limit of the QEP component of TMS320F28335, the phase difference cannot be calculated directly, which requires a data conversion process. To prevent the accumulation of measuring errors, the Z signal of an encoder is used to clear zero for the calculator function of QEP. Due to the calculator is affected by a clear process, it is not correct to subtract the pulse number of two encoders directly. Next, the data conversion process will be described in detail. Because there is a master-slave control in this paper, we take two motors as an example to introduce the data conversion process. As shown in Table 2, if the phases of two ERs are either in the 1 st and 4 th quadrant or in the 2 nd and 3 rd quadrant, the phase difference between the two ERs is less than \(\pi\) no matter what changes. However, there will be two results when the phases of two ERs are, respectively, in the 1 st and 4 th quadrant or the 2 nd and 3 rd quadrant. After recording the previous and current pulse numbers, it is necessary to determine whether there is a process of clearing zero. As shown in Table 3, the determining algorithm can be formalized through the truth table of the phase difference. To cooperate with Table 3, the sampling period must ensure that more records are carried out in one rotational period of the motor. In other words, the pulse difference between the previous record and the current record must less than the total number of pulses in one rotational period of the motor. Taking motor 1 as the master motor and motor 2 as the slave one, the calculation flow chart of velocity and the phase difference is shown in Figure 5. Step 1, pulses of two encoders are recorded. NewInpluse_MotorX denotes the value of the encoder in present control period. (int 16)EQepXRegs.QPOSCNT represents the storage unit in hardware system. Step 2, whether there is a clearing process is estimated using Tables 2 and 3. OldInpluse_MotorX denotes the value of the encoder in previous control period. Inpluse_MotorX denotes the phase change of motorX. Step 3, the phase difference is calculated. Phase_num denotes the phase difference between motor 1 and motor 2. Step 4, the phase leading motor is determined. Encodernum denotes the total number of pulses in a full rotation of the motor. Step 5, the values of previous and present pulse numbers are \begin{table}
\begin{tabular}{c c c} \hline \hline
**Case** & **ER 2 in 1 st and 4 th Quadrants** & **ER 2 in 2 nd and 3 rd Quadrants** \\ \hline ER 1 in 1 st and 4 th quadrants & Phase difference \(<\pi\) & a. Phase difference \(>\pi\) \\ ER 1 in 2 nd and 3 rd quadrants & a. Phase difference \(>\pi\) & b. Phase difference \(<\pi\) \\ \hline \hline \end{tabular}
\end{table} 
Table 2: Change domain of the phase difference. \begin{table}
\begin{tabular}{c c c} \hline \hline
**Case** & **Reading of 1 st with Reset** & **Reading of 1 st without Reset** \\ \hline Reading of 2 nd with reset & Inexistence & Needing to complement \\ Reading of 2 nd without reset & Normal subtraction & Normal subtraction \\ \hline \hline \end{tabular}
\end{table} 
Table 3: The actual value of the phase difference.