Macromodel of Precise Signal-Phase Meter

This paper presents a precise macromodel of a signal-phase meter, which allows continuous phase measurement during simulation. It has been developed as a support tool during the design process of a signal-conditioning circuit for incremental position encoders. The development of a signal conditioning circuit requires precise measurements of small signal phases, amplitudes and offsets using the analog/digital circuit simulator. The phase measurement cannot be performed directly with a simulator, therefore an appropriate macro-model is needed for a circuit simulator. The structure of the signal-phase meter is based on the conventional signal-phase measuring method and is intended for the measuring of a cosine-signal phase with a known frequency. It recommends that the time variations of an input signal’s parameters (amplitude, phase, frequency, and offset voltage) are slow and small as possible. Rapid change of a signal’s parameters decreases the simulation result’s accuracy. A macro-model’s precision mainly depends on the chosen parameters for the macro-model and for the simulation. We show that with the proposed meter’s model, the phase angle can be measured with an accuracy of more than ±0,02%.


Introduction
Position encoders are sensors that convert their linear or rotary displacements into appropriate electrical signals and are widely used in many computer-controlled machines. Position signals can be generated by magnetic, capacitive, or optical means, and represent displacement information in absolute or incremental forms [1,2].
Ideally, the linear optical incremental position encoders produce two 90 • shifted analog signals, which enable us to detect the position of an encoder's head. However, due to encoder's and optical grating's mechanical limitations, these signals have unideal sine/cosine shapes, variable amplitudes, offset voltages, and additional phase shifts. The influences of such various unwanted effects are reduced and corrected by a signal-conditioning circuit, which is usually an encoder's integral part, realized as an integrated circuit. Thus, the signal-conditioning circuit is an analog/digital circuit, generally developed using an analog/digital circuit simulator. The development of such circuit, always requires very precise signal-phase measurements, which cannot be performed directly by a simulator. This paper deals with the SPICE macromodel of signalphase meter, which enables a precise phase measurement whilst simulation is running. It is based on well-known practically implemented conventional phase-measurement techniques, as described in [3][4][5][6][7]. Although structures, similar to our model, can be found in [8], to our knowledge, this type of model has never been developed. This paper is organized as follows. Section 2 briefly describes the conventional signal-phase measurement techniques. A detailed description of the proposed macromodel is given in Section 3. Section 4 comprises examples of signalphase measurement using the proposed model and the SPICE simulator. This model's accuracy and other properties are also described. The conclusions are given in Section 4. or between the pulse centers [4][5][6][7]. Due to certain disadvantages of conventional phase measurement methods, especially in cases of harmonically distorted signals, many authors suggest signal digitalization and further digital signal processing. The author in [6] presents a theory of highprecision phase measurement and a practical algorithm for phase calculation between two signals. The possibility for its implementation is described in [7]. Similarly, improved ways of phase measuring can also be found in [4,9,10].

Macromodel Description
The proposed phase meter macromodel consists of basic components (resistors, capacitors, etc.) and analog behavioral functions (differentiators, multipliers, etc.). Their real circuit implementation would be difficult, but usage within a simulator is simple. It is intended for the phasemeasurements of cosine signals with known frequencies and excludes measurement of the sine-signal phase. It could however, also be generalized for such cases.
A generalized expression of macromodel's input cosine signal v c (t) can be written using the equation: where A c (t): amplitude time waveform, f (t): frequency time waveform, V c (t): offset voltage time waveform, and ϕ(t): signal phase time waveform. Figure 1 shows a block diagram of the phase meter macromodel. The input signals are the voltage signals v c (t) and f (t). The signal f (t) in volts is proportional to the input-signal frequency in hertz. The output signal ϕ(t) in volts quantifies a measured phase in degrees. The phase is measured between the input v c (t) and internally generated cosine signal (the latter is not shown in this figure).
The model does not measure the frequency f (t). It is presumed that f (t) is known in advance. This simplifies the model's structure. It also requires a quantification of the following expected maximal input signal parameters: the frequency f max , the amplitude A max , and the phase ϕ max .
The macromodel was developed modularly with appropriate sub models: (i) peak-detector, (ii) offset voltage corrector and amplitude corrector, (iii) signal-phase calculator.
The peak detector generates both the maximal (v c max ) and minimal (v c min ) input-signal time values. They are required for input signal amplitude normalization performed using the offset voltage corrector and the amplitude corrector. The normalized signal v c norm (t) drives the phase calculator, where the phase difference is calculated between the input signal and the internally generated ideal cosine signal. The ideal cosine signal has the amplitude 1 V and the same frequency as the input-signal v c (t).
The entire signal-phase meter macromodel was constructed in the ICAP (ICAP/4 for Windows 8.1.11) SpiceNet as detailed in the following subsections. The usage of the Peak detector Offset/amplitude Signal phase calculator macromodel requires a schematic form ( * .dng file) conversion to the text netlist form ( * .cir file) and its inclusion to the SPICE library file ( * .lib file) as shown in Figure 2.
3.1. Peak Detector. The main task of the peak detector is the detection and holding back of those extreme values from input signal v c (t). The current peak value is kept constant until the next peak-value occurs.
The peak detector sub-model works as an analog memory of peak values. Therefore, it could also be used in the other cases [11], where the analog peak values should be temporarily stored. Figure 3 presents the structure of peak detector submodel. It has two inputs (in, Vfreq) and two outputs (peak, npeak). in is driven by cosine signal v c (t), from which the minimal v c min (t) and maximal v c max (t) time values are generated. Since the concept of the macromodel requires knowledge of the frequency, there is a second voltage driven input Vfreq. The Vfreq input voltage in volts must be proportional to the input signal frequency in hertz. Other than Vfreq, additional parameters (dv, Amax, maxfreq) are required for the peak detector to operate. They are further described in this sub section.
Capacitor C1 is needed for temporal storage of the input signals' local minimum values, whilst capacitor C2 stores its local maximum values. Appropriate control of switches X1 and X2 ensures, that both capacitors are timely charged to the input-voltages' local extremes. The charging period is followed by a hold-back period, when the capacitors' voltages are kept constant. Capacitors C1 and C2 are connected to outputs npeak and peak.
The input-voltages' extreme values occur during the time instants when the first derivative of the input signal is equal to zero. A second derivative sign is required in order to distinguish between the local minimum and maximum.
Although the input signal parameters could be time variable values, it was assumed that they are constant, in Parameters: order to simplify the model. In this case, the first derivative of the input signal v c (t) can be written using the equation: Switches X1 and X2 are controlled by input-signal derivative values which have been previously normalized. According to (3), the derivative of the input signal can be normalized using constant (2·π·A max · f ), where A max stands for the expected maximal input-signal amplitude. The first and second derivatives' normalizations are performed using the voltage-controlled sources B4 and B5, respectively. Both sources B4 and B5 are linked to sources B1 and B2, which generate the control voltages for switches X1 and X2. X1, X2 are switched "ON" at a positively control voltage, otherwise they are switched "OFF".
The "ON" resistances (R ON ) of switches X1 and X2 are inversely-proportional to the values of their control voltages. By choosing a value for the control voltage equal to 1/R ON and R ON equal to 1 Ω, the "ON" time constant τ ON = R ON ·C, only depends on capacitance C. X1 is "ON" when the values of the second and first derivatives are correspondingly positive and negative. Simultaneously, the value of the first derivative must be greater than the negative reference voltage V ON . Vice versa applies for switch X2. X2 is "ON" if the second derivative is negative and the first derivative is positive. Simultaneously, the value of the first derivative must be smaller than the reference voltage V ON , generated by source B3.
The reference voltage V ON is the threshold value of the first derivative, when the switches X1 and X2 must be toggled "ON" to ensure adequate charging time Δt for capacitors C1 and C2. In Δt the capacitors are charged to input voltage extreme values with Δv tolerance.
Since the capacitor's charging-time is substantially shorter than the input signal period, it can be presume that during the charging periods, the input signal voltage is constant. In the worst-case scenario, at maximal frequency f max and maximal amplitude A max , capacitor C is charging from 0 V to A max . At the permitted tolerance Δv, the capacitor will be charged to the value (A max − Δv) within the time interval: Since, within the time Δt, the cosine signal will reach the value: the capacitor's charging time can be written as Equalizing (4) and (6), the capacitances C1 and C2 are Choosing R ON equal to 1 Ω, the capacitances depend solely on the permitted tolerance Δv, and the expected f max and A max . C1 and C2 start to charge at the time instant: For example, for the time Δt before extreme-value occurrence. According to (6), (8), and the normalized (3), the reference voltage V ON can be calculated using After the charging period Δt, the switches X1 and X2 disconnect the connections between the input and capacitors C1 and C2, correspondingly. Whilst the switches are "OFF", the capacitors remain charged to the input signals' extreme values. Since switches X1 and X2 are "OFF", the resistances are very high (e.g., R OFF = 1 GΩ), during the "OFF" period the voltages on the capacitors will not change significantly.
Using the sub-model requires setting the parameters: Δv, f max , and A max , which are labeled in Figure 3 as dv, maxfreq, and Amax, consecutively. These parameters enable the calculation of reference voltage V ON according to (9), and the capacitances C1 and C2 according to (7).

Offset/Amplitude
Corrector. The offset voltage corrector removes the offset voltage V DC from the input cosine signal v c (t). Assuming a constant offset voltage, it can be written as where V c min stands for the minimal and V c max stands for the maximal input cosine signal amplitudes. The cosine-time waveform without offset voltage can thus be expressed as The absolute minimal and maximal peak values are equal and are The signal v AC (t) is normalized with A c0 , thus providing a constant equalizer output amplitude of value 1 V. The normalized signal waveform describes (13): The offset voltage corrector and amplitude corrector submodel is shown in Figure 4. The inputs' peak and npeak are connected to the peak detector. The output signal v c norm (t) is the normalized cosine signal with a constant amplitude value of 1 V and a frequency f.
The offset voltage and amplitude correction are performed by controlled voltage source B17, which generates voltage according to (13). B17 additionally limits the output signal's amplitude within the range [−1 V, 1 V]. Limitation is performed for the cases of variable input-signal amplitude, which will be described later. Should the output voltage exceed the permitted range [−1 V, 1 V], the signal phase calculation would not be feasible. The process of amplitude limitation does not affect the signal phase measurements, since they are always performed at zero crossing instant.

Signal-Phase
Calculator. The signal phase calculator calculates the phase difference ϕ(t) between the normalized cosine signal v c norm (t) and the internally generated cosine signal of amplitude 1 V. The signals frequencies are equal and known in advance. The ideal cosine signal is generated using a voltage-controlled oscillator modeled with Laplace transformation and a voltage-controlled source, as proposed in [12]. Figure 5 shows the signal phase calculator submodel.
The calculation of phase difference is periodic within the period T = 1/f, according to the following: It is performed using the controlled voltage source B9. When the switch X3 is switched ON, the capacitor C3 charges to a voltage value proportional to the phase difference measured over the previous period. When the switch X3 is switched OFF, the precharged value is held constant at the Vphase output. X3 is controlled by the source B7. It ensures that the switch is turned on once per period. This event occurs when a second derivative of input signal v c (t) is negative and the value of the normalized signal v c norm (t) is within the range: 0 < v c norm (t) < V ON1 . Here, V ON1 stands for the reference voltage, provided by the source B11, according to (9). When the signal v c norm (t) reaches zero value, X3 switches OFF. The voltage of C3 remains constant. Its value in volts is proportional to the phase-difference value ϕ(t) in degrees. For the same reason described for the peak-detector submodel, the X3 switch "OFF" resistance has to be high (acos(V(vinnorm))−acos(cos(v(wt))))·180/pi <−1·{fimax} ? −1·{fimax}: (acos(V(vinnorm))−acos(cos(v(wt))))·180/pi enough. This ensures that the voltage on C3 will not change significantly until the next toggle of the switch X3. The capacitance of C3 is calculated using an equation similar to (7) where A max is replaced with the predicted maximum value of the input-signal phase fimax. In the worst case scenario, C3 must be charged to the voltage value proportionally to the fimax value in degrees, with the permissible phase-tolerance dϕ. The same values of the permissible tolerances were used for the phase calculator and the peak detector in order to reduce the number of model parameters.

Macromodel
Parameters. An entire macromodel of the precise signal-phase meter, suitable for SPICE simulators consists of all previous described sub-models. It performs precise cosine signal phase measurements at any frequency, amplitude, and offset voltage on condition that the input signal-frequency time waveform is known in advance. The model's operation is based on the assumption that the inputsignal parameters are constant. However, its usefulness in situations of time variable parameters was also examined. The signal phase measurement, whilst the signal's frequency, amplitude, and offset voltage are time-variable, is a very problematic task [13] and in general it has not been fully explored as yet.
Using the macromodel of the signal-phase meter requires knowledge of the four model parameters that have an influence on its accuracy and precision. These parameters are (i) Amax: expected maximum input-signal amplitude; (ii) maxfreq: expected maximum input-signal frequency; (iii) fimax: expected maximum input-signal phase; (iv) dv: admissible tolerance of input signal peak values (equal to the admissible tolerance for the measured signal phase).
The accuracies of signal-phase measurements depend on the macromodel's accuracy, and on the simulation parameter values. They are transient (.TRAN) analysis parameters: (i) tstart: time to start recording data; (ii) tstop: total analysis time; (iii) tstep: data-step time; (iv) tmax: maximum time-step.
The most influential simulation parameter is tmax. It must be lower or equal to the capacitors' C1-C3 chargingtimes. Using (6), the recommended maximum time step can be calculated as where A stands for the smallest values: Any increase of model's accuracy can be achieved with a decrease in the parameters dv or dϕ. According to (15), this decreases tmax which reduces the integration step time. Therefore, more accurate results prolong the simulation duration.

Phase-Measurement Simulation Results
The following section presents the phase measurement simulation results using the proposed macromodel for the

Phase Measurements of the Input Signal with Constant
Parameters. This example focused on the phase measurement of a cosine signal with constant parameters, which were A c (t) = 1 V, f (t) = 1 kHz, ϕ(t) = 0.1 • , and V c (t) = 1 mV. Using these parameters the following macromodel parameters were defined: Amax = 1 V, maxfreq = 1 kHz, and fimax = 0.1 • . Simulations were performed at three different tolerances dv of values: 10 −4 V, 10 −5 V, and 10 −6 V. Using (15) and (7), the simulation parameters tmax: 2.25 μs, 712 ns and 225 ns, were calculated. The rest of simulation parameters were tstart = 5 ms, tstop = 100 ms, and tstep = 10 μs. Figure 6 shows the simulation results at three different permissible tolerances dv. Δϕ(t) is the phase error between measured and the actual phase of the input signal.
Despite the constant input signal parameters, Δϕ is time variable. Its time variability is the consequence of the simulator's internal integration time step, which varies whilst the transient analysis is running. The integration time-step automatically adapts to the time changes of circuit signals. Therefore, Δϕ(t) are not constant-time waveforms. Table 1 shows the worst case results for all three examples. From Figure 6 and Table 1, it can be concluded that reducing the parameter dv decreases the phase error Δϕ.

Phase Measurements of Input Signal with Time-Variable
Parameters. At the macromodel development stage, it was assumed that the input signal parameters are not time variable. Nevertheless, its suitability for cases of time variable parameters has also been verified.
The chosen intervals of the time-variable input signal parameters were as follows: Figure 7 shows the parameters' time waveforms used in our example.
According to the intervals of the input-signal parameters, the following macromodel parameters were set: maxfreq = 10 kHz, Amax = 1.1 V, and fimax = 5 • . The value of the permissible tolerance dv was chosen as dv = 10 −4 V. According to (15) the maximum time step was calculated as tmax = 101 ns. The transient analysis results are shown in Figure 8.
Δϕ(t) waveform shows the phase error between the actual ϕ(t) and measured ϕ i (t) signal phases. Noticeable, the phase error is a result of an assumption that the inputsignal parameters are constant. Consequently, the derivatives in (2) are equal to zero which, in our case, is untrue. Rapid changes in input-signal parameters increase the phase-error. This clearly illustrates the time waveform 4 within the timerange from 20 ms to 80 ms, when simultaneous changes in amplitude, frequency, phase, and offset voltage occur. In continuation, the time variations of the parameters were moderate and the phase error Δϕ was significantly reduced. Therefore, the highest precision signal phase can only be measured under stationary conditions, when the smallest possible phase error can be expected.

Conclusion
The objective of this paper was to present a new macromodel of a precise signal-phase meter, as required for the development of integrated circuits, implemented within linear position encoders. The macromodel is suitable for precise phase measurements whilst transient analysis is running. Namely the reduction of various unwanted effects of an encoder's head requires very accurate signal-phase measurements during the encoder development stage.
In order to simplify the concept of a macromodel, it was assumed that signal parameters are not time-variable values. As shown in Section 4, as such a signal phase was measured within an accuracy of more than ±0.02%. Simulations also showed a substantial decrease in the results' accuracies due to the rapid-time change of the signal parameters. The signal-phase measurement under such conditions is a very problematic task [13] and has not yet been fully explored. Therefore any improvement in the presented macromodel in this direction would not be meaningful. However, this macromodel concept represents an idea for real-world implementation of a precise signal-phase meter.