Spra 605
Spra 605
Spra 605
ABSTRACT
This application report presents a TMS320F240 DSP solution for obtaining the angular
position and speed of a resolver.
A resolver is an absolute mechanical position sensor used, for example, in servo
applications. It is basically a rotating transformer. The sinusoidal input reference is amplitude
modulated with the sine and cosine of the mechanical angle, respectively. These two output
signals have to be decoded to obtain the angular position.
For decoding the resolver output signals, a basic method is introduced. It utilizes
undersampling and an inverse tangent function. To achieve a higher angular resolution an
improved method, which adds oversampling techniques is used. Due to an integral invariant
filter, which is a combination of an IIR and FIR filter, the digitized angular position does not
suffer any velocity lag.
Thanks to its peripherals, the Texas Instruments TI TMS320F240 DSP can be ideally used
for decoding the two resolver output signals as well as for generating the input reference
frequency. The hardware interfacing of the resolver to the TMS320F240 is shown and the
software realization of the improved method on the TMS320F240 is documented. All
software routines are C-compatible. The angular resolution achievable with the
TMS320F240 is up to 14 bits, at a CPU loading of 13%.
Thus, the TMS320F240 will eliminate the cost for the external resolver-to-digital conversion
IC, since the algorithm runs in addition to the motor control task.
Contents
1
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
5
5
6
6
6
7
7
8
SPRA605
6
7
Introduction
Digital signal processors are going to become more common in digital motor control
applications. They permit sophisticated real-time control applications to be implemented, which
improve dynamic response, precision and efficiency. In addition, they enable sensorless control,
which reduces total system operating by eliminating mechanical sensors.
TMS320F240 DSP Solution for Obtaining Resolver Angular Position and Speed
SPRA605
TMS320F240 DSP Solution for Obtaining Resolver Angular Position and Speed
SPRA605
U2
U0
U1
U2
U0
U1
45
90
u 0( t ) u^ 0 sin reft
The two orthogonal stator coils are wound, so that when the rotor shaft turns, the amplitude of
the output signals is modulated with the sine and cosine of the shaft angle , relative to some
zero, according to:
u1,2(f)
freffB
fref
freq
fref+fB
f B 1 d
2 dt
4
MAX
TMS320F240 DSP Solution for Obtaining Resolver Angular Position and Speed
SPRA605
3.1
n+1
u1
ADC
u2
ADC
sin
N bit
cos
N bit
angle D
N + bit
uu nn
( )
, if u 2(n ) 0
( )
2
1
arctan
uu nn
( )
, if u 2(n ) 0
( )
1
2
To be accurate, both signals, u1 and u2, have to be sampled simultaneously, at, or close to their
maximum positive value, synchronized to the reference frequency according to:
To avoid aliasing, the Nyquist criteria must be met. It requires the sample rate fS to be at least
twice the bandwidth fB of the interesting signal. To meet that, an analog anti-alias filter has to
remove any frequency components outside the band-of-interest fref fB. Referring to Figure 2, it
is obvious that any DC offset has to be removed prior to sampling. Otherwise, it would be added
to the demodulated sine and cosine signals and decrease accuracy.
For an N-bit ADC, the angular accuracy achievable is N+1-bit. With the dual 10-bit ADCs
integrated on the TMS320F240, the angular accuracy achievable is 10 arc minutes. A higher
resolution and better noise rejection are achievable by oversampling and averaging techniques,
which are discussed in the following section.
TMS320F240 DSP Solution for Obtaining Resolver Angular Position and Speed
SPRA605
3.2
3.2.1
Overview
The total algorithm, utilizing oversampling, is depicted in Figure 4. The high-resolution digital
angle _m is the output of the position-tracking closed-loop.
dither
3.2.3.
Decimation
U1
+
ADC
sin
BP
FIR Bandpass
3.2.4.
_ m(n1)
Gain
()
dither
ADC
cos
BP
2K:1
FIR Bandpass
(n)
arctan
Decimation
U2
3.3.5.
2K:1
Gain
Position
& Speed
Tracking
Angle: _ m(n)
@N+4 bit
Nbit @ K .2Fref
3.2.2
TMS320F240 DSP Solution for Obtaining Resolver Angular Position and Speed
SPRA605
This ensures that the quantization error is not correlated with the input signal. Note that this
does not increase the total quantization error.
3.2.3
Frequency
fref
fref 2
fref + (fref/2)
3.2.4
u 1,FIR(n )
, u 2,FIR(n ) 0
u 2,FIR(n )
arctan
u 2,FIR(n )
, u 2,FIR(n ) 0
u 1,FIR(n )
Compared to the basic method, shown in section 3.1, the digitized angle now has got a higher
resolution, due to the averaging FIR filter. However, as depicted in Figure 6, the digitized angle
shows a velocity lag, due the group delay of the FIR filter. The error of the digitized angle is
proportional to the rotational speed.
TMS320F240 DSP Solution for Obtaining Resolver Angular Position and Speed
SPRA605
angle [rad]
resolver angle []
angular error
angular error
t
t_delay (FIR)
t_delay (FIR)
Figure 6. Angular Error as Function of the Rotational Speed After the FIR Filter
A closed-loop position and speed interpolator will be used to compensate for the angular error
and to further improve the angular resolution.
3.2.5
Improve the accuracy of the angular position _m. The accuracy depends on bandwidth
selected.
Compensate the delay of the FIR filter, so that _m suffers no velocity lag
The result will be a higher accuracy of the interpolated angular position _m. Additionally _m
does not suffer a velocity lag.
This is achieved by the following. The output signal _m is delayed with the same time as the
FIR filters group delay. Hence the delayed output signal _m(n1) is also compared with the
delayed FIR filtered angle _FIR. The closed-loop forces both delayed angles to be identical. For
constant speeds, the output _m of the closed-loop is then identical with the real resolver shaft
angle.
Z1
_m
_m
Integrator
_FIR
+
IIR
PI controller
TMS320F240 DSP Solution for Obtaining Resolver Angular Position and Speed
SPRA605
4.1
Overview
The TMS320F240 DSP controller incorporates two 10-bit A/D converters, which sample both
analog inputs simultaneously. The A/D sampling point can be triggered by any timer event,
hence synchronously to the on-chip PWM. One PWM channel (part of the event manager) is
used to generate the sinusoidal reference frequency.
(20 MIPS)
WD
SCI
SPI
PLL
10bit A/D
10bit A/D
C2xx
DSP
U2
16KW
FLASH
28 bit I/O
EVENT
MGR
TMS320F240
U0
U1
H/W interface
Resolver
Synchronizes the sampling point to the sinusoidal frequency [ADC, Event Manager]
TMS320F240 DSP Solution for Obtaining Resolver Angular Position and Speed
SPRA605
4.2
+ U0
4k7
10k
PWM8
0.22n
4n7
+ 15 V
1n
+ 15 V
5 V si n(t+ )
THS4001
3k3
GND
3k3
+
THS4001
U0
shield
15 V
PWM7
4k7
1n2
GND
+
10k
33k
0.22n
15 V
GND
GND
SallenKey Lowpass, 10 kHz, optional
11k
330p
2.25sin()sin(t) + 2.5V
ADCIN5
U1
U1
+
47p
47k
VCCA
10k
1/2 TLV2772
11k 330p
47p
+U1
+ U1
47k
1/2 TLV2772
10k
2.5V
1/2 TLV2772
0.10
shield
11k
U2
2.5 V
VCCA
2k
4n7
U2
+
47p
47k
VCCA
47p
47k
+ U2
10k
2.5 V
1/2 TLV2772
VCCA
1/2 TLV2772
VCCA
1
0.1u
0.1u
shield
R E SO L V E R
10u
Tantalum
1
10k VREFH
10u
Tantalum
0.1u
VREFH
VREFH
TL2425
2.5 V
ADCIN13
2.5V
+U2
2k
4n7
10k
1/2 TLV2772
11k 330p
VCCA
2.25cos()sin(t) + 2.5V
330p
0.1u
AGND
AGND
AGND
GND
GND
T M S3 2 0 F 2 4 0
10
TMS320F240 DSP Solution for Obtaining Resolver Angular Position and Speed
SPRA605
Note that the values of the components are valid for a 5-kHz reference with a 10 VPP
peak-to-peak voltage and a resolver with a transformation ratio of 2:1. Thus, the maximum
peak-to-peak voltage of the two modulated resolver output signals is 5 VPP.
The circuit performs the following:
Signal conditioning of the PWM output to drive the resolver with a sinusoidal reference
frequency u0.
The PWM channels PWM7 and PWM8 (differential signals) are used to generate the
sinusoidal reference frequency. The first op amp THS4001 is used to filter out the PWM
carrier signal, to do the level shifting and amplification to get a sine wave at 10Vpp output
voltage swing. The second op amp performs a Sallen-Key lowpass filter and further reduces
harmonic distortion.
Signal conditioning and level shifting of both resolver output signals, u1, u2 to drive the
TMS320F240 A/D converters.
The differential output signals of the resolver are fed into non-inverting buffers TLV2772 and
referenced to the virtual ground. The following differential amplifier TLV2772 suppresses
common mode noise and performs the level shifting to meet the 5-V A/D input range. The
TL2772 are single supply, rail-to-rail output CMOS op amps. The RC network performs the
anti-alias filter. The capacitor is chosen to drive the A/D module switch capacitor input, rather
than the op amp. Therefore the capacitor should be as close as possible to the analog input
pins ADCIN5 and ADCIN13, respectively.
The TL2425 provides the 2.5V virtual ground, to operate with single 5V supply only.
11 k
U 1 (U 2)
33 0p
10 u
T antal um
t) + 2 .5V
2 .2 5cos( ) si n( t) + 2 .5V
2.25si n( )si n(
10 k
V CCA
V R EFL
+ U 1(U 2)
2 .5V
11 k
+ U 1 ( U 2)
shi el d
10 k
A D C I N 5 (A D C I N 1 3)
1 /2 T L V 27 72
2k
4n7
100 p
4.3
4.3.1
Program Structure
The software is mainly written in ANSI C language to achieve a modular and readable software
structure. Only time critical functions, like the FIR filter, arc tangent, etc., are written in run-time
optimized assembler, but provide a C-compatible interface. Hence these functions can also be
called from any C program.
TMS320F240 DSP Solution for Obtaining Resolver Angular Position and Speed
11
SPRA605
The software integrates all modules required to obtain the resolvers angular position and speed.
It can be easily integrated, for example, in a standard field-oriented control. The source files and
a short functional description are given in Table 1.
The software is basically structured into three main functional blocks. Each functional block is
realized as a C function, which might call other functions. The following three sections give a
detailed description on these functions.
Table 1. Source Modules and Functional Description
Source Module
C Callable Functions
Functional Description
MAIN.C
main()
Main program
INIT.C
Resolver_Init()
F240 initialization
T3_INT.C
timer3_int()
CONTROL.C
control()
FIR_DEC8.ASM
CL.C
Resolver_ClosedLoop()
ATAN_DIV.ASM
4.3.2
Timer 3 period interrupt is the main time base. The cycle time is 25us, hence the reference
frequency period is 200us, or 5 kHz.
The simple compare units are used to generate the sinusoidal reference frequency and
noise, respectively. Timer2 is selected as the PWM time base. The timer2 period is set to
of the timer 3 period. This will give a PWM period of 6.25us. The reason for that is to reduce
the ripple on the sine wave. This relaxes the requirements to the analog reconstruction filter.
The resolver output signals, connected to ADCIN5, ADCIN13 are automatically sampled on
a timer3 compare event. This guarantees that the sampling points are synchronized to the
PWM unit, which generates the reference frequency. Triggering the conversion by a timer3
compare event allows optimizing the phase at which the signal is sampled. The timer3
compare value is initially set to 12.5us. This means that the signals are sampled 12.5us
before the interrupt occurs. Any modification of the timer3 compare value shifts the sampling
point and hence the phase at which the resolver signals are sampled within +/22.5 degrees.
However, the conversion time of 6us, prior to the timer3 period interrupt must still be met.
Note: The corresponding header file INIT.H contains the values for the reference frequency and
the gain error of the two input channels at the analog inputs ADCIN5 and ADCIN13.
12
TMS320F240 DSP Solution for Obtaining Resolver Angular Position and Speed
SPRA605
4.3.3
timer 3_int
(timer3_int_count++)%32
read ADCIN5, ADCIN13
write ADCIN5,13 to delay line
resolver_buffer [ ] [ ]
lookup sine value
generate random noise
update PWM7/8(sine), 9(noise)
timer3_int_count%8=0?
no
yes
call CONTROL
RETI
4 x oversampling of the sine and cosine modulated resolver signals u1, connected to
ADCIN5 and u2, connected to ADCIN13
The ADC sample rate is synchronized with the sinusoidal reference frequency, which is
generated by the TMS320F240 on-chip simple compare unit.
The ADC sampling point is triggered automatically by a timer3 compare event. This allows
compensating a phase shift of up to 22.5 between the reference frequency u0 and the
modulated resolver output signals u1 and u2. Thus, a modification of the timer3 compare
value shifts the phase at which the signals are sampled. Note, that the timer3 compare event
must occur no later than 6us before the timer3 period interrupt, to meet the ADC conversion
time of 6us.
The data of ADC1 FIFO (result of channel 5) and ADC2 FIFO (result of channel 13) is
divided by two to get a headroom of 6dB. An offset is added to convert to a 2s complement
TMS320F240 DSP Solution for Obtaining Resolver Angular Position and Speed
13
SPRA605
or Q15 fractional number. These Q15 numbers are stored into the delay line
resolver_buffer[][]. The variable timer3_int_count is used to point to the latest position in
the delay buffer according to:
resolver_buffer[0][timer3_int_count] = ADCFIFO1/2 + 32768
resolver_buffer[1][timer3_int_count] = ADCFIFO2/2 + 32768
The lower array resolver_buffer [0] [] always stores the latest 32 sine modulated samples
in Q15 notation with a 6dB headroom. The upper array resolver_buffer[1][] stores the latest
32-cosine modulated samples, respectively.
Resolver reference frequency generation via the simple compare PWM unit
The simple compare PWM unit, used to generated the sinusoidal reference frequency, is
updated in this interrupt every 25 s. This is equivalent to 8 updates during one period of
the sine wave. Therefore a sine wave lookup table is used, which stores the corresponding 8
PWM duty cycles. The elements are accessed according to:
PWM = sine_table [(timer3_int_count + sine_phase_lag) % 8]
The variable sine_phase_lag is used as an offset to the pointer timer_int_count and is
initialized, so that the output of the FIR filter is at a maximum.
To reduce harmonics the simple compare PWM period is 6.25 s, which is of timer3
period. This reduces the amount of analog filtering and leads to a sine wave with lower
harmonic distortion.
Random noise generation and update via the simple compare PWM9 unit
The noise generator is a random number generator, which calculates a new random number
each timer 3 interrupt. The new random number is stored to the compare register of PWM9.
4.3.4
epsilon_m =
omega_m =
angular speed
14
TMS320F240 DSP Solution for Obtaining Resolver Angular Position and Speed
SPRA605
/**/
/* 17tap FIR decimation bandpass */
/**/
index = &resolver_buffer[0][timer3_int_count]; /* Ptr to latest */
/* element in delay line */
r_sin = FIRBandpass_17A_Dec8(index);
r_cos = FIRBandpass_17A_Dec8(index+BUFFER_SIZE);
/**/
/* Gain compensation (optional) */
/**/
r_sin = (int) ((long)R_SIN_GAIN_Q15 * (long)r_sin >> 15);
r_cos = (int) ((long)R_COS_GAIN_Q15 * (long)r_cos >> 15);
/**/
/* Angle determination utilizing arc tangent function
*/
/**/
epsilon = atan_div(r_sin,r_cos);
/* 200us delayed angle */
/**/
/* closedloop angle and speed interpolation
*/
/**/
/* epsilon_m = actual position WITHOUT velocity lag
*/
/* omega_m
= actual scaled speed
*/
/**/
Resolver_ClosedLoop();
}
Note: The function control() could be used to include a PI current controller. If a faster current
controller cycle time is required, control() might be called on every 4th timer 3 interrupt and the
resolver-to-digital algorithm is skipped every one, respectively.
Function: int FIR_Bandpass_17A_Dec8 (* int)
This function performs the bandpass filtering and decimation by 8, since it is called only every
8th input sample. The variable sine_phase_lag is used as an offset to the pointer
timer_int_count. It is initialized so, that the FIR filter takes always the window of 17 samples,
which leads to the maximum output amplitude.
The argument passed to the filter is the pointer to the latest sample (start of the window) in the
delay line. The return value is the filtered signal.
The filter coefficients are designed with the Digital Filter Design Package [7]. It is a symmetrical
FIR bandpass filter with 17 taps and a 5-kHz center frequency. The magnitude response is
shown below.
TMS320F240 DSP Solution for Obtaining Resolver Angular Position and Speed
15
SPRA605
Return:
Error:
< 3 LSB
epsilon_m
omega_m
(high-resolution speed)
Figure 13 shows the block diagram of the closed loop. The settings of the parameters, which
define the bandwidth, are shown in the next section.
16
TMS320F240 DSP Solution for Obtaining Resolver Angular Position and Speed
SPRA605
PI controller
IIR lowpass
z 1
b1
kp
ki + kp
epsilon(n)
+
y(k)
x
u(n)
+
z 1
e(n)
1 x
z 1
epsilon_m(n1)
epsilon_m(n)
z 1
a0
a1
omega_m(n)
Integrator
TMS320F240 DSP Solution for Obtaining Resolver Angular Position and Speed
17
SPRA605
4.4
4.4.1
Changing Parameters
Reference Frequency
The resolver reference frequency and the gain compensation of the input signals at ADCIN5 and
ADCIN13 can be changed in the header file INIT.H
/*==============================================================*/
/* RESOLVER CONSTANTS
*/
/*==============================================================*/
#define R_SIN_GAIN
0.976
/* [0 .. +1.0] */
#define R_COS_GAIN
0.976
/* [0 .. +1.0] */
/* Reference frequency period in [us]*/
#define REF_FREQ_PERIOD
200
/* [us] */
/* Note: only 4[us] steps allowed */
4.4.2
Bandwidth
KI (Q15)
KP [Q15]
13 bit
600 Hz
0.026
0.3
13.5 bit
300 Hz
0.005
0.1
14 bit
150 Hz
0.001
0.05
Results
5.1
Processor Utilization
The R/D conversion algorithm can be subdivided into four functions. Table 3 gives an overview
on the total CPU cycles for each subfunction.
Table 3. TMS320F240 CPU Loading
Function
18
CPU cycles
timer3_int()
76
atan_div()
103
Resolver_ClosedLoop()
56
FIRBandpass_17A_Dec8()
36
TMS320F240 DSP Solution for Obtaining Resolver Angular Position and Speed
SPRA605
All functions, except timer3_int(), are called every 200us, for a 5-kHz reference frequency. The
interrupt routine is called 2-times the selected oversampling rate K. Thus, the total CPU loading
depends mainly on the oversampling rate K.
The CPU loading, for the algorithm utilizing 4-times oversampling and a 5-kHz reference
frequency is approximately 13%. The CPU loading for two times oversampling will be
approximately 8%.
5.2
Figure 15. Measured Normalized Step Response for a 1 Angular Step (1 ~ 180).
The achievable angular accuracy and the settling time are shown in Table 4 for a 1 angular
step.
Table 4. Angular Accuracy and Settling Time Versus Bandwidth
Bandwidth
Settle Time
Resolution
600Hz
8 ms
13-bit
300Hz
18 ms
13.5-bit
150Hz
40 ms
14-bit
In order to test the dynamic error and accuracy of the R/D converter implementation on the
TMS320F240, the two output signals of a resolver where generated with a [LeCroy] signal
generator.
The function realized was an angular speed reversal from 180 rpm to +180 rpm, as shown in
Figure 16.
TMS320F240 DSP Solution for Obtaining Resolver Angular Position and Speed
19
SPRA605
180 rpm
Figure 17. Angular Position Error for a Speed Reversal From 180 rpm to +180 rpm
20
TMS320F240 DSP Solution for Obtaining Resolver Angular Position and Speed
SPRA605
Conclusion
The resolver-to-digital converter has been successfully implemented on the TMS320F240 DSP
controller.
The angular accuracy achievable is up 14 bits. Thanks to the integral invariant filter, realized as
a combination of FIR and IIR filter, the digitized angle does not suffer any velocity lag. The
angular accuracy is comparable with application specific ICs. The digital filter realization allows
changing the bandwidth by software, allowing the user to determine a suitable tradeoff time
between bandwidth and resolution. Adaptive bandwidth as a function of the rotation speed is
possible.
The CPU loading is approximately 13%. Hence, the DSP has got enough power to perform the
R/D conversion in parallel to sophisticated digital control algorithms, like the field-oriented
control. Typical applications are numerical control and robotics in noisy environment, using a
synchronous motor (PMSM) with a resolver as absolute position sensor.
For these applications this TMS320F240 DSP solution reduces total system cost, due to the
elimination of an external R/D converter. The TMS320F240 solution even does not require an
external oscillator.
TMS320F240 DSP Solution for Obtaining Resolver Angular Position and Speed
21
SPRA605
References
1. TMS320C24x DSP Controllers Reference Set: Vol.1 and 2, SPRU160 and SPRU161
Texas Instruments Inc., 1998.
2. TMS320F240 Data Sheet, SPRS063 and SPRS064, Texas Instruments Inc., 1998.
3. TMS320C2x/C2xx/C5x Optimizing C Compiler Users Guide, SPRU024
Texas Instruments Inc., 1995.
4. TLV2772 Advanced LinCMOS Rail-to-Rail Dual Op Amp, Data Sheet, SL0S209
Texas Instruments Inc.,1998.
5. Goepel, W.: Sensors A Comprehensive Survey, VCH, Weinheim, 1989.
6. Jonacha,H.: Integralinvariantes Antialiasing-filter fuer inertiale Messysteme, Technisches
Messen 59 (1992), 7/8, Oldenburg Verlag.
7. TMS320 ASPI Digital Filter Design Package for PC,
Atlanta Signal Processors Inc., 1990
22
TMS320F240 DSP Solution for Obtaining Resolver Angular Position and Speed
IMPORTANT NOTICE
Texas Instruments and its subsidiaries (TI) reserve the right to make changes to their products or to discontinue
any product or service without notice, and advise customers to obtain the latest version of relevant information
to verify, before placing orders, that information being relied on is current and complete. All products are sold
subject to the terms and conditions of sale supplied at the time of order acknowledgment, including those
pertaining to warranty, patent infringement, and limitation of liability.
TI warrants performance of its semiconductor products to the specifications applicable at the time of sale in
accordance with TIs standard warranty. Testing and other quality control techniques are utilized to the extent
TI deems necessary to support this warranty. Specific testing of all parameters of each device is not necessarily
performed, except those mandated by government requirements.
Customers are responsible for their applications using TI components.
In order to minimize risks associated with the customers applications, adequate design and operating
safeguards must be provided by the customer to minimize inherent or procedural hazards.
TI assumes no liability for applications assistance or customer product design. TI does not warrant or represent
that any license, either express or implied, is granted under any patent right, copyright, mask work right, or other
intellectual property right of TI covering or relating to any combination, machine, or process in which such
semiconductor products or services might be or are used. TIs publication of information regarding any third
partys products or services does not constitute TIs approval, warranty or endorsement thereof.