Variable Speed Control of Single-Phase AC Induction Motor, Texas Instruments, 2000.
Variable Speed Control of Single-Phase AC Induction Motor, Texas Instruments, 2000.
Variable Speed Control of Single-Phase AC Induction Motor, Texas Instruments, 2000.
SPRU442
September 2000
ACI1-1
Variable Speed Control of
Single-Phase AC Induction Motor
Topic Page
1 System Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
2 Hardware and Software Configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
3 Incremental System Build – Phase 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
4 Incremental System Build – Phase 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
5 Incremental System Build – Phase 3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
6 Incremental System Build – Phase 4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
SPRU442 ACI1-1 1
System Overview
1 System Overview
Figure 1 shows the complete system configuration for a single-phase ACI motor drive. A
full H-bridge is utilized to control two phase voltages of the motor. Four PWM channels
from the DSP control four power devices of the inverter. Two analog to digital channels are
utilized to measure DC bus voltages. One capture input is needed to measure the speed
of the drive.
x24xx
DSP
PWM1 +
PWM2
Line PWM1 PWM3 ACI
PWM3
Single phase
PWM4
Neutral
+
ADCINx
PWM2 PWM4
ADCINx
CAP1
CAP1
Tacho
ADCINx
ADCINx
BOX_CAR
CAP_EVENT_DRV
COMPWM
DATA_LOG
D_PID_REG
FC_PWM_O_DRV
ADC04U_DRV
RAMP_CNTL
SINCOSPH
SINTB360
SPEED_PRD
SYS_INIT
V_HZ_PROFILE
Note:
The C version of the software at this time excludes the modules COMPWM,
FC_PWM_O_DRV, and ADC04U_DRV. Instead, the module
FC_PWM_DRV has been used. Also, the incremental build level 4 is not im-
plemented for the C system.
2 SPRU442
System Overview
c_int0 INT2
interrupt
Background INT2
loop
SPRU442 ACI1-1 3
Hardware and Software Configuration
2.1 Hardware
Refer to the User’s Guides and or Manuals for configuration of the above items and their
connection to the system. Table 1, Table 2, and Table 3 list some of the other system level
choices that must be made.
JP1, JP2, JP3 Install all jumpers Use 3-Phase power inverter
configuration
4 SPRU442
Hardware and Software Configuration
JP1, JP2, JP3 Install all jumpers Use 3-Phase power inverter
configuration
The linker command file, ACI1_10.cmd, that defines memory map and specifies
memory allocation;
SPRU442 ACI1-1 5
Hardware and Software Configuration
It is also assumed that the emulator used is XDS510pp. Once the directory
“C:\TI\DCS\ACI1_1” contains all the necessary files (as mentioned above), the next step
is to provide the supply voltage(+5V DC) to the F243/LF2407 EVM and RESET the emula-
tor. Then start the Code Composer and open the project ACI1_10.mak. Now load the
workspace file aci1_10_phase1wks.
Loading the workspace will automatically open up the project file ACI1_10.mak and show
all the files relevant to the project. The following shows the expanded project view as part
of CC environment aci1_10_phase1 wks is loaded:
Note that the same project can be built from scratch easily if the workspace file,
aci1_10_phase1.1wks, can’t be loaded directly because of differences in CC setup and
or emulator used. Refer to CC tutorial for information on a building project.
The variables in the Watch Window can be added manually according to CC tutorial.
From the ‘PROGRAM LOAD OPTIONS’ in CC select ‘Load Program After Build’ for auto-
matic loading of the program to the target once the program is compiled.
2) Incremental Build Control: The build level is set in the header file, build.h in the C infra-
structure. This header file is in the aci11\aci11_010\include\ directory. The incremen-
tal build level 4 is not implemented for the C system.
To set the build level, define the symbol BUILDLEVEL to one of the available levels.
/*–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
Following is the list of the Build Level choices.
–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––*/
#define LEVEL1 1
#define LEVEL2 2
#define LEVEL3 3
#define LEVEL3 4 /* This LEVEL4 is not implemented yet */
/*–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
This line sets the BUILDLEVEL to one of the available choices.
–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––*/
#define BUILDLEVEL LEVEL3
6 SPRU442
Hardware and Software Configuration
3) The target processor selection is in the header file, target.h. This file is included in the
code composer project and can also be found in the directory
aci11\aci11_010\include\
To change the processor set the TARGET macro to the desired one.
/*–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
Following is the selection list of the target choices.
Note that the F241 is represented by the F243 and the
LF2407 represents the LF2406 and the LF2402.
–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––*/
#define F240 1
#define F243 2
#define F2407 4
#define UNKNOWN 8
/*–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
This line sets the target to one of the available choices.
–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––*/
#define TARGET F2407
4) The object VHZ11_TI is defined in the header file, vhz11_ti.h and it is implemented
as vhz in aci11.c. This has many sub-objects such as PID, SINCOSPH,
RMPCNTL, etc. To modify variables such as pid coefficients, etc. watch:
The entire object vhz, and observe/modify vhz.pid.K0.
An alternative is to watch vhz.pid and modify pid.K0.
Watching smaller objects in the watch window has the advantage of lowering the
amount of data that must be up-loaded to the debug tool.
SPRU442 ACI1-1 7
Incremental System Build – Phase 1
In the SYSTEM OPTIONS section of the code, select phase 1 incremental build option by
setting the constant phase1_commissioning to 1. Save the program, compile it and load
it to the target.
3.1 Phase 1
In this phase, two sine waves are generated based on the user speed input as shown
in Figure 3. Three software modules are utilized in this phase to generate two sine
wave forms.
phase1_commissioning .set 1
phase2_commissioning .set 0
phase3_commissioning .set 0
phase4_commissioning .set 0
The module SINCOSPH generates two sine waves. The phase angle between these
waves can be controlled by modifying the variable “phase_in”.
The generated wave forms can be watched using the software module “DATA_LOG”.
In order to watch the waveforms in real time initialize dlog_iptr1 = sine_a1 and
dlog_iptr2 = sine_a2.
8 SPRU442
Incremental System Build – Phase 1
rpm_scaler phase_in
sine_a1
speed_setpt
RAMP_CNTL x V_Hz_PROFILE SINCOSPH sine_a2
Graph Window1
DATA_LOG
Graph Window2
SPRU442 ACI1-1 9
Incremental System Build – Phase 1
10 SPRU442
Incremental System Build – Phase 2
In Phase 2 of incremental system build, a single phase AC induction motor will be operated
using DMC1000 board (www.spectrumdigital.com) and EVM board from TI. In Phase 2a
few software checks are made and then in Phase 2b an inverter and motor is used to oper-
ate a single phase ac induction motor with variable speed control.
phase1_commissioning .set 0
phase2_commissioning .set 1
phase3_commissioning .set 0
phase4_commissioning .set 0
The additional software modules added in this Phase 2a are FC_PWM_DRV and
SPEED_PRD.
FC_PWM_DRV configures PWM module of the DSP controller. It also provides the
required dead band through avoid shoot thorough faults. The third input, Mfunc_c3,
FC_PWM_DRV is set to zero. This is necessary because a single-phase AC induction
drive utilizes only four PWM channels.
SPEED_PRD calculates motor speed from the capture events. The capture module
of the device is configured at the very beginning by calling CAP_EVENT_DRV_INIT
module.
The variable “direction” can be set to “1” or “0” to change the direction of rotation of
the motor. When direction is equal to “1’, sine wave-1 will lead sine wave-2. If direction
is equal to “0” than the opposite will happen. The available graph display in CC can
be utilized to observe this. Put dlog_iptr1 = Mfunc_c1 and dlog_iptr2 = Mfunc_c2.
Figure 6 and Figure 7 shows how two sine waves lead or lag each other depending
on the value of “direction”.
SPRU442 ACI1-1 11
Incremental System Build – Phase 2
speed_setpt
X RAMP_CNTL V_Hz_PROFILE SINCOSPH
direction
CC GRAPH DISPLAY 1
CC GRAPH DISPLAY 1
PWM 1
PWM 2
FC_PWM_DRV
PWM 3
PWM 4
SPEED_PRD CAP_EVENT_DRV
12 SPRU442
Incremental System Build – Phase 2
Note: Motor rotational direction in Figure 7 will be opposite of rotational direction in Figure 6.
SPRU442 ACI1-1 13
Incremental System Build – Phase 2
JP19 on DMC1000 should be between 1 and 2 (disables power factor correction cir-
cuit).
Motor neutral point connects to P14 on DMC1000 (Figure 8 shows the motor connec-
tion with DMC1000).
Once the software is running, apply DC bus voltage by rotating the variac. At this time
the current probe should show sinusoidal phase current and after sufficient DC bus
voltage, the motor will start rotating.
The direction of rotation will depend on two variables – First the motor phase connec-
tions and second the value of the variable “direction”.
Changing the value of “direction” as mentioned in the previous section (Phase 2a) can
change the rotational direction.
14 SPRU442
Incremental System Build – Phase 2
Modifying the variable “speed_setpt” can vary the motor speed. The maximum speed
is fixed at 2500RPM. However, user can change that by modifying V_Hz_PROFILE
software module.
Figure 8. Hardware Connection Between a Single-Phase AC Induction Motor and DMC1000 Board
Q1 Q3
C1
NEUTRAL–P19–P20
Q2 Q4
C2
PHASE 1
PHASE 2
SPRU442 ACI1-1 15
Incremental System Build – Phase 3
phase1_commissioning .set 0
phase2_commissioning .set 0
phase3_commissioning .set 1
phase4_commissioning .set 0
The Hall effect speed sensor output is connected to P27 of DMC1000. P27 has
ground, power and capture input. The available ground and power from P27 can be
utilized as sensor ground and power. The voltage output at P27 can be set at various
level to match the sensor requirement.
After starting the software, the motor will start rotating as the DC bus voltage is applied
by rotating the variac from zero to higher voltages.
The measured speed can be watched by adding the variable “speed_rpm” in the
watch window.
16 SPRU442
Incremental System Build – Phase 4
phase1_commissioning .set 0
phase2_commissioning .set 0
phase3_commissioning .set 0
phase4_commissioning .set 1
Remove file PWMODRV.asm from the project and ADD COMPWM.asm to the project.
Initialize the reference DC bus voltages ADC_ref1 and ADC_ref2. ADC_ref1 is upper
capacitor voltage and ADC_ref2 is lower capacitor voltage. These numbers should be
provided in Q15 format (see the COMPWM sofware module documentation).
DMC1000 board is utilized to implement this phase. Two ADC channels are utilized
to measure DC bus voltages. ADC07 measures the complete DC bus voltage (soft-
ware variable is total_bus). ADC05 measures the lower capacitor voltage (software
variable is half_bus). From these two measurements, individual capacitor voltages
are calculated. For example, ADC1 is the voltage across the top capacitor and is equal
to the difference between total_bus and half_bus.
The software is initialized with the compensation turned off. In order to turn on the
compensation the variable DC_RIPPLE should be changed from 0 to 1.
SPRU442 ACI1-1 17
18
rpm_scaler
SPRU442
phase_in phase
SINCOSPH
setpt_value
speed_setpt target_value freq_in
freq sine_a1
RAMP_CNTL
sine_a2
V_Hz_
vhz_freq PROFILE v_out
gain_cs
SPRU442
rpm_scaler
phase_in phase
SINCOSPH
target_value setpt_value
speed_setpt freq_in
freq sine_a1
RAMP_CNTL
sine_a2
V_Hz_
vhz_freq PROFILE v_out
gain_cs
direction
sine_a1 PWM1
FC_PWM EV
sine_a2 mfunc_c1
DRV HW PWM2
Q0
mfunc_c2 PWM3
EV CAP_ PWM4
EVENT_ SPEED_
CAPn CAP1FIFO time_stamp PRD speed_prd
H/W DRV mfunc_c3
0
Q15
closed_loop_flag
SPRU442
rpm_scaler
setpt_value
target_value
RAMP_CNTL
EV CAP_
EVENT_ SPEED_ BOX_CAR
CAPn CAP1FIFO time_stamp PRD speed_prd BC_IN BC_OUT D_fb
H/W DRV
Q15
direction
phase_in phase
SINCOSPH
PWM1
freq_in mfunc_c3 FC_PWM EV
freq
DRV HW PWM2
sine_a1 Q0
V_Hz_ PWM3
vhz_freq PROFILE v_out mfunc_c1
gain_cs sine_a2
Q15 / Q15 PWM4
mfunc_c2
SPRU442
rpm_scaler
phase_in
direction
phase_in
phase
SINCOSPH freq
sine_a1
EV COMPWM
PWM1 gain_cs
HW mfunc_c1 sine_a2
PWM2
mfunc_c2
PWM3
PWM4
mfunc_c3
0
ADC channel connected to mea-
total_bus
VDC_ACTUAL ADC04D EV sure total DC bus voltage
RV HW
VDC_HOT half_bus
ADC channel connected to mea-
DC_RIPPLE ripple_on sure half of DC bus voltage
Description The software module “SINCOSPH” generates two sine waves with variable magnitude
(gain_cs), frequency (freq), and phase difference (phase). The two sine waves are
“sine_a1” and “sine_a2”. The maximum magnitude of these waves set by the variable
“gain_cs”. The frequency of the waves is set by “freq” and the phase difference is set
by the variable “phase”.
gain_cs sine_a1
freq
SINCOSPH
phase sine_a2
SINCOSPH 1
Direct ASM Interface
Variable Declaration:
In the system file include the following statements:
Memory map:
All variables are mapped to an uninitialized named section ‘sincos’
Example:
CALL SINCOSPH
2 SPRU
C/C–Callable ASM Interface
Object Definition The structure of the SINCOSPH object is defined in the header file, sincosph.h, as
seen in the following:
SINCOSPH_DEFAULTS
Initializer for the SINCOSPH object. This provides the initial values to the terminal vari-
ables, internal variables, as well as method pointers. This is initialized in the header
file, sincosph.h.
Initialization:
To instance a pre-initialized object:
sc1.calc(&sc1);
sc2.calc(&sc2);
SINCOSPH 3
C/C–Callable ASM Interface
Example:
Lets instance two SINCOSPH objects, otherwise identical, and run two sine-cosine
generators. The following example is the c source code for the system file.
main()
{
4 SPRU
Background Information
Background Information
The generation of the sine wave is performed using a look up table. To be able to con-
trol the frequency of sine waves, a method based on the modulo mathematical opera-
tion is used. For more information, see Digital Signal Processing applications with the
TMS320 Familt: Theory, Algorithms, and Implementations, Volume 1, (Literature Num-
ber SPRA012A).
A 16 bit software counter is used to determine the location of the next value of the sine
waves. A step value is added to the counter every time a new value from the sine table
is to be loaded. By changing the value of the step, one can accurately control the fre-
quency of the sine wave.
Although a 16 bit counter is used, the upper byte determines the location of the next
sine value to be used; thus, by changing how quickly values overflow from the lower
byte (i.e. manipulating the step value), the frequency of the sine wave can be changed.
The modulo mathematical operation is used when there is overflow in the accumulator
from the lower word to the upper word. When an overflow occurs, only the remainder
(lower word) is stored.
For example, the counter is set to 0000h and the step value is set to 40h. Every time
a value is to be looked up in the table, the value 40h is added to the counter; however,
since the upper byte is used as the pointer on the look up table, the first, second, and
third values will point to the same location. In the fourth step, which results in an over-
flow into the upper byte, the value that is loaded will change. Since the upper byte is
used as the pointer, the lookup table has 256 values, which is equivalent to the number
of possibilities for an 8-bit number – 0 to 255. Additionally, since the upper word of the
accumulator is disregarded, the pointer for the sine lookup table does not need to be
reset.
. . . .
. . . .
. . . .
The step size controls the frequency that is output; as a result, the larger the step, the
quicker the overflow into the upper byte, and the faster the pointer traverses through
the sine lookup table.
SINCOSPH 5
Background Information
1 00C0h 00h
Although the step size indicates how quickly the pointer moves through the look up
table, the step size does not provide much information about the approximate frequen-
cy that the sine wave will be modulating the PWM signal. To determine the frequency
of the sine wave, one needs to determine how often the value in the compare register
will be modified.
The frequency that the sine wave will be modulated at can be calculated from the fol-
lowing formula
step
f (step)
Ts 2n
Where,
f(step) = desired frequency
TS = the time period between each update (in this case, the PWM period)
n = the number of bits in the counter register
step = the step size used
The frequency that the PWM signal will be modulated is proportional to the step size
and inversely proportional to the size of the counter register and the period at which
the routine is accessed. Thus, to increase the resolution that one can increment or
decrement the frequency of the PWM modulation, one needs to have a larger counting
register or access the routine at a slower frequency by increasing the period.
The second sine wave is generated using the same method. However, for the second
wave a phase is also added with the counter before reading the value from the sine
table.
6 SPRU
COMPWM Compensated Full-Compare PWM Output Driver
Description The software module “COMPWM” compensates and/or modifies the PWM output
based on system inputs. Although this module is applied for a single phase AC induc-
tion motor drive, the same can be applied for a three phase AC induction motor drive.
Mfunc_c1
Mfunc_c2 PWM1
Mfunc_c3
limit PWM2
DC_RIPPLE
COMPWM EV
VDC_ACTUAL PWM3
VDC_HOT
VDC_TOP_REF PWM4
VDC_BOT_REF
Availability This module is available in the direct-mode assembly-only interface (Direct ASM).
xDAIS module No
COMPWM 1
Direct ASM Interface
Variable Declaration:
In the system file include the following statements:
2 SPRU
Direct ASM Interface
Memory map:
All variables are mapped to an uninitialized named section “compwm”
Example:
LDP #DC_RIPPLE
CALL COMPWM
COMPWM 3
Background Information
Background Information
This software module modifies a particular system variable based on other system
variable feedback. One obvious application of this module is to modify PWM output
based on DC bus voltage variation of the voltage source inverter. Ideally, the PWM duty
ratio is calculated assuming that the DC bus voltage is stiff with no variation. However,
in a practical system there is always DC bus voltage variation based on the load. If this
variation is not taken into account than the voltage output of the inverter will get dis-
torted and lower order harmonics will be introduced. The inverter voltage output can
be immune to the DC bus variation if the PWM duty ratio is modified according to the
bus voltage variation. The following equation shows the mathematical relationship be-
tween various variables –
At any PWM cycle the ideal voltage applied across Phase A is,
Va = (T1PER – compare_1)*VDC_TOP_REF – VDC_BOT_REF*compare_1 (1)
In an actual system, voltages across the capacitors will have ripple and the actual volt-
age applied across Phase A is,
Va_actual = (T1PER – Ta_new)*V1 – Ta_new*V2 (2)
Where,
V1 = measured voltage across the upper capacitor (VDC_ACTUAL – VDC_HOT)
V2 = measured voltage across the lower capacitor (VDC_HOT)
The compensated compare values for Phase A (Ta_new) can be calculated by solving
equations (1) and (2) and is given by,
Va = Va_actual
Ta_new = (T1PER*V1 – Va)/ (V1+V2) (3)
Similar, calculation can be performed for Phase B and the compensated compare val-
ue becomes,
Tb_new = (T1PER*V1 – Vb)/ (V1+V2) (4)
Where,
Vb = (T1PER – compare_2)*VDC_BOT_REF – VDC_TOP_REF*compare_2
It is clear from equations (3) and (4) that the compensation routine depends on accu-
rate measurement of DC bus voltages. Moreover, the user will have to provide protec-
tion so that the power devices do not stay ON for a long period to create a short circuit
in the motor phase.
4 SPRU
V_HZ_PROFILE Volts/Hertz Profile for AC Induction Motor
Description This module generates an output command voltage for a specific input command fre-
quency according to the specified volts/hertz profile. This is used for variable speed
implementation of AC induction motor drives.
V_Hz_PROFILE
vhz_freq v_out
V_HZ_PROFILE 1
Direct ASM Interface
Init / Config FL† Low frequency point on v/f profile. Q15 Application
dependent
Variable Declaration:
In the system file include the following statements:
Memory map:
All variables are mapped to an uninitialized named section ‘vhz_prof’
Example:
CALL V_Hz_PROFILE
2 SPRU446
C/C–Callable ASM Interface
Init / Config fl† Low frequency point on v/f profile. Q15 Application
dependent
DEFAULT_PROFILE
Initializer for the SVGENMF Object. This provides the initial values to the terminal vari-
ables, internal variables, as well as method pointers.
V_HZ_PROFILE 3
C/C–Callable ASM Interface
Initialization:
To instance a pre-initialized object
VHZPROFILE vhz1=DEFAULT_PROFILE;
vhz1.calc(&vhz1);
Example:
Lets instance two SVGENMF objects, otherwise identical, but running with different
freq values. These SVGENMF objects need the computed value of the envelope for
the SVGEN waveforms, and this is computed by the VHZPROFILE objects.
VHZPROFILE vhz1=DEFAULT_PROFILE;
VHZPROFILE vhz2=DEFAULT_PROFILE;
main()
{
sv1.freq=1200; /* Set properties for sv1 */
sv2.freq=1800; /* Set properties for sv2 */
}
sv2.gain=vhz2.gain;
/* Do something with the outputs. Something is probably modulate PWMs to drive motors with.
*/
4 SPRU446
Background Information
Background Information
If the voltage applied to a three phase AC Induction motor is sinusoidal, then by ne-
glecting the small voltage drop across the stator resistor, we have, at steady state,
^ ^
V j
i.e.,
V
^ ^
where V and are the phasor representations of stator voltage and stator flux,
and V and are their magnitude, respectively. Thus, we get
V 1 V
2 f
From the last equation, it follows that if the ratio V/f remains constant for any change
in f, then flux remains constant and the torque becomes independent of the supply fre-
quency. In actual implementation, the ratio of the magnitude to frequency is usually
based on the rated values of these parameters, i.e., the motor rated parameters. How-
ever, when the frequency, and hence the voltage, is low, the voltage drop across the
stator resistor cannot be neglected and must be compensated for. At frequencies high-
er than the rated value, maintaining constant V/Hz means exceeding rated stator volt-
age and thereby causing the possibility of insulation break down. To avoid this,
constant V/Hz principle is also violated at such frequencies. This principle is illustrated
in Figure 1.
Vrate
Voltage
f rate Frequency
Slip speed
V_HZ_PROFILE 5
Background Information
Both open and closed-loop control of the speed of an AC induction motor can be imple-
mented based on the constant V/Hz principle. Open-loop speed control is used when
accuracy in speed response is not a concern such as in HVAC (heating, ventilation and
air conditioning), fan or blower applications. In this case, the supply frequency is deter-
mined based on the desired speed and the assumption that the motor will roughly fol-
low its synchronous speed. The error in speed resulted from slip of the motor is consid-
ered acceptable.
Vrate
Voltage
Vmin
The command frequency is allowed to go below the minimum frequency, fmin, with the
output voltage saturating at a minimum value, Vmin . Also, when the command frequen-
cy is higher than the maximum frequency, fmax, the output voltage is saturated at a
maximum value, Vmax.
6 SPRU446
FC_PWM_O_DRV Full-Compare PWM Driver with Over-modulation
Description The module implements over-modulation technique to increase DC bus voltage utiliza-
tion for a voltage source inverter. The input limit sets the extent of over-modulation. For
example, limit = 0 means no over-modulation and limit = (timer period)/2 means maxi-
mum over-modulation.
mfunc_c1
PWM1
mfunc_c2 PWM2
FC_PWM_ PWM3
mfunc_c3 EV
O_DRV PWM4
HW
mfunc_p Q0 PWM5
limit PWM6
Availability This module is available in the direct-mode assembly-only interface (Direct ASM).
xDAIS module No
FC_PWM_O_DRV 1
Direct ASM Interface
Variable Declaration:
In the system file include the following statements:
.ref FC_PWM_O_DRV
.ref FC_PWM_O_DRV_INIT ;function call
.ref Mfunc_c1, Mfunc_c2, Mfunc_c3, Mfunc_p ;Inputs
Memory map:
All variables are mapped to an uninitialized named section “pwmodrv”
Example:
CALL FC_PWM_O_DRV
2 SPRU449
Background Information
Background Information
For high performance motor drive systems, full utilization of the dc bus voltage is an
important factor to achieve maximum output torque under any operating conditions,
and to extend the field weakening range of the motor. However, for a pulse-width mod-
ulated voltage source inverter (PWM–VSI), the maximum voltage is 78% of the six-
step waveform value. Therefore, in general, a standard motor supplied from an inverter
can not utilize the full DC bus voltage capability. To obtain higher DC bus voltage utiliza-
tion, operating the inverter in over-modulation region is required.
This software module implements a simple but effective over-modulation scheme for
PWM inverters. This module can be applied both for three phase drive (using Space
Vector PWM or regular Sine PWM strategies) as well as single phase drive.
FC_PWM_O_DRV 3
Background Information
(a)
(b)
(c)
4 SPRU449
CAP_EVENT_DRV Capture Input Event Driver
Description This module provides the instantaneous value of the selected time base (GP Timer)
captured on the occurrence of an event. Such events can be any specified transition
of a signal applied at the event manager (EV) capture input pins of 24x/24xx devices.
CAP_EVENT_
CAPn_FIFO EV CAPn
DRV
HW
Q15
CAP_EVENT_DRV 1
Direct ASM Interface
Variable Declaration:
In the system file include the following statements:
Memory map:
Not required.
Example:
CALL CAP_EVENT_DRV_INIT
ldp #CLK_prescaler_bits
splk #7, CLK_prescaler_bits ;To specify a prescaler of 128
CALL CAP_EVENT_DRV_CLKPS_INIT
2 SPRU450
C/C–Callable ASM Interface
Object Definition The structure of the CAPTURE object is defined by the following struct
/*––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
Define the structure of the Capture Driver Object
––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––*/
typedef struct { int time_stamp;
int (*init)(); /*Pointer to the init function */
int (*read)(); /*Pointer to the init function */
} CAPTURE;
CAPTURE_DEFAULTS
Initializer for the CAPTURE Object. This provides the initial values to the terminal vari-
ables as well as method pointers.
CAPTURE_handle
This is typedef’ed to CAPTURE *.
int read(CAPTURE_handle)
Reads a time stamp value from the timer associated with the capture unit. Note that
the time stamp is placed in the capture object. The return value of the function is either
0 or 1. If the function read a value from the hardware, i.e. if a capture event has oc-
curred, then the function returns 0. Otherwise the return value is 1.
Initialization:
To instance a pre-initialized object
CAPTURE cap1=CAP1_DEFAULTS;
CAP_EVENT_DRV 3
C/C–Callable ASM Interface
cap1.read(&cap1);
Example:
Lets instance one CAPTURE object, init it and invoke the read function to fetch a time
stamp.
main()
{
cap1.init(&cap1);
}
void interrupt periodic_interrupt_isr()
{
int status;
int time_of_event;
status=cap1.read(&cap1);
if(status==0)
{
time_of_event=cap1.time_stamp;
}
}
4 SPRU450
ADC04U_DRV General Purpose 4 Conversion ADC Driver (unipolar)
Description This module performs 4-channel AD conversion on unipolar signals. The channels are
specified by A4_ch_sel .
ADCINw C1_out
ADCINx C2_out
ADC ADC04U_DRV
ADCINy HW C3_out
ADCINz C4_out
ADC04U_DRV 1
Running Title—Attribute Reference
H/W Inputs ADCINw/x/y/z ADC pins in 24x/24xx device. w,x,y,z N/A N/A
correspond to the channel numbers
selected by A4_ch_sel
Init / Config A4_ch_sel ADC channel select variable. Use this Q0 N/A
to specify appropriate ADC channels.
Input format = C4C3C2C1, for
example, A4_ch_sel = FC83 implies
selected channels are, Ch3 as C1,
Ch8 as C2, Ch12 as C3 and Ch15 as
C4.
Cn_gain Gain control for channel Q13 0–7FFF
(n=1,2,3,4) corresponding to Cn. Use this to
adjust gain for each channel for
appropriately scaled signals.
Variable Declaration:
In the system file include the following instructions:
Memory map:
All variables are mapped to an uninitialized named section ‘adc4udrv’
Example:
During system initialization specify the inputs as follows:
Then in the interrupt service routine call the module and read results as follows:
CALL ADC04U_DRV
2 SPRU462
Running Title—Attribute Reference
Object Definition The structure of the ADCVALS Interface Object is defined by the following structure
definition
typedef struct {
int c1_gain; /* Gain control for channel 1[Q13] */
int c2_gain; /* Gain control for channel 2[Q13] */
int c3_gain; /* Gain control for channel 3[Q13] */
int c4_gain; /* Gain control for channel 4[Q13] */
H/W Inputs ADCINw/x/y/z ADC pins in 24x/24xx device. w,x,y,z N/A N/A
correspond to the channel numbers
selected by A4_ch_sel
Init / Config A4_ch_sel ADC channel select variable. Use this Q0 N/A
to specify appropriate ADC channels.
Input format = C4C3C2C1, for
example, A4_ch_sel = FC83 implies
selected channels are, Ch3 as C1,
Ch8 as C2, Ch12 as C3 and Ch15 as
C4.
ADCVALS_DEFAULTS
Initializer for the ADCVALS Object. This provides the initial values to the terminal vari-
ables as well as method pointers.
ADCVALS_handle
Typedef’ed to ADCVALS *
ADC04U_DRV 3
Running Title—Attribute Reference
F243_ADC_DEFAULTS
Constant initializer for the F243ADC Interface.
F2407_ADC_DEFAULTS
Constant initializer for the F2407 ADC Interface
void update(ADCVALS_handle)
Updates the ADC Driver hardware with the data from the ADCVALS Structure.
ADCVALS adc;
Initialization:
To instance a pre-initialized object
Hardware Initialization:
adc.init(&adc);
adc.update(&adc);
Example:
Lets instance one ADCVALS object
main()
{
adc.a4_ch_sel = 0x5432 ; /* Initialize */
adc.c1_gain = 0x1FFF;
adc.c2_gain = 0x1FFF;
adc.c3_gain = 0x1FFF;
adc.c4_gain = 0x1FFF;
4 SPRU462
SPEED_PRD Speed Calculator Based on Period Measurement
Description This module calculates the motor speed based on a signal’s period measurement.
Such a signal, for which the period is measured, can be the periodic output pulses from
a motor speed sensor.
speed_prd
time_stamp SPEED_PRD
Q0/Q15
speed_rpm
SPEED_PRD 1
Direct ASM Interface
Memory map: All variables are mapped to an uninitialized named section ‘speedprd’
Example:
2 SPRU451
C/C–Callable ASM Interface
Object Definition The structure of the SPEED_MEAS object is defined by the following structure defini-
tion
typedef struct {
int time_stamp_new; /*Variable: New ‘Timestamp’ corresponding to a capture event*/
int time_stamp_old; /*Variable: Old ‘Timestamp’ corresponding to a capture event*/
int time_stamp; /*Input: Current ‘Timestamp’ corresponding to a capture event*/
int shift; /*Parameter: For maximum accuracy of 32bit/16bit division*/
int speed_scaler; /*Parameter: Scaler converting 1/N cycles to a Q15 speed*/
int speed_prd; /*Output: speed in per–unit
int rpm_max; /*Parameter: Scaler converting Q15 speed to rpm (Q0) speed*/
int speed_rpm; /*Output: speed in r.p.m.
int (*calc) (); /*Pointer to the calculation function*/
} SPEED_MEAS; /*Data type created*/
SPEED_MEAS
The module definition itself is created as a data type. This makes it convenient to
instance a Space Vector Generation module. To create multiple instances of the mod-
ule simply declare variables of type SVGENMF.
SPEED_PRD 3
C/C–Callable ASM Interface
SPEED_PR_MEAS_DEFAULTS
Initializer for the SVGENMF Object. This provides the initial values to the terminal vari-
ables, internal variables, as well as method pointers.
SPEED_MEAS shaftSpeed;
Initialization:
To instance a pre-initialized object
SPEED_MEAS shaftSpeed=SPEED_PR_MEAS_DEFAULTS;
shaftSpeed.calc(&shaftSpeed);
Example:
/*––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
Pre initialized declaration for the speed measurement object.
––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––*/
SPEED_MEAS shaftSpeed=SPEED_PR_MEAS_DEFAULTS;
/*––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
Declaration for the capture driver. For more details see the CAP_DRV
document.
––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––*/
CAPTURE cap=CAPTURE_DEFAULTS;
main()
{
/*––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
Initialize the capture interface
––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––*/
cap.init(&cap);
void periodic_interrupt_isr()
{
/*–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
Call the capture driver read function. Note, that this func returns
the status, as the return value, NOT the time_stamp. The time_stamp
is returned directly into the CAPTURE object structure.
––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––*/
if((cap.read(&cap))==0) /* Call the capture read function */
{
shaftSpeed.time_stamp=cap.time_stamp; /* Read out new time stamp */
shaftSpeed.calc(&shaftSpeed); /* Call the speed calulator */
}
4 SPRU451
Background Information
Background Information
A low cost shaft sprocket with n teeth and a Hall effect gear tooth sensor is used to mea-
sure the motor speed. Figure 5 shows the physical details associated with the sprock-
et. The Hall effect sensor outputs a square wave pulse every time a tooth rotates within
its proximity. The resultant pulse rate is n pulses per revolution. The Hall effect sensor
output is fed directly to the 24x/24xx Capture input pin. The capture unit will capture
(the value of it’s base timer counter) on either the rising or the falling edges(whichever
is specified) of the Hall effect sensor output. The captured value is passed to this s/w
module through the variable called time_stamp.
In this module, every time a new input time_stamp becomes available it is compared
with the previous time_stamp. Thus, the tooth-to-tooth period (t2–t1) value is calcu-
lated. In order to reduce jitter or period fluctuation, an average of the most recent n peri-
od measurements can be performed each time a new pulse is detected.
t1
t t t 2 t 1 sec
t2
360 = 14.4°
25
2
radsec
25
25 teeth t n
n1
From the two consecutive time_stamp values the difference between the captured val-
ues are calculated as,
∆ = time_stamp(new) – time_stamp(old)
where,
KP = Prescaler value for the Capture unit time base
TCLK = CPU clock period in sec
2
n
where,
n = number of teeth in the sprocket, i.e., the number of pulses per revolution
Then the speed ω in radian/sec and the normalized speed ωN are calculated as,
SPEED_PRD 5
Running Title—Attribute Reference
2 2
t nt n K p T CLK
N 1
2
max 1
nK P T CLK
Where, ωmax is the maximum value of ω which occurs when ∆=1. Therefore,
max 2
nK PT CLK
For, n=25, KP=32 and TCLK=50x10–9 sec (20MHz CPU clock), the normalized speed
ωN is given by,
N 1
2(25000)
N1 64 64 N speed_scaler N
2(390)
The capture unit in 24x/24xx allows accurate time measurement (in multiples of clock
cycles and defined by a prescaler selection) between events. In this case the events
are selected to be the rising edge of the incoming pulse train. What we are interested
in is the delta time between events and hence for this implementation Timer 1 is al-
6 SPRU451
Background Information
lowed to free run with a prescale of 32 (1.6uS resolution for 20MHz CPU clock) and
the delta time ∆, in scaled clock counts, is calculated as shown in Figure 6.
f(t) T Case 1 f (t 2) f (t 1)
FFFFh
f (t 2) f (t 1)
1
∆ 2
∆ Case 2 f (t 2) f (t 1)
1 f (t 2) f (t 1)
In Figure 6, the vertical axis f(t) represents the value of the Timer counter which is run-
ning in continuous up count mode and resetting when the period register = FFFFh.
Note that two cases need to be accounted for: the simple case where the Timer has
not wrapped around and where it has wrapped around. By keeping the current and pre-
vious capture values it is easy to test for each of these cases.
Once a “robust” period measurement is extracted from the averaging algorithm, the
speed is calculated using the appropriate equations explained before. In order to main-
tain high precision in the calculation for the full range of motor speeds, a 32-bit/16-bit
division is performed as shown in Figure 7 in the following.
Q31
31 30 16 15 1 0
Speed = s i i i i ... i i i f f f ... f f f f f
fraction
sign
Once complete the result is a 32-bit value in Q31 format. This value is subsequently
scaled to a 16 bit, Q15 format value for later calculation of the speed error (see
Figure 7).
SPEED_PRD 7
BC_CALC Averaging Box Car
Description This software module calculates the average value of a s/w variable. The output can
be rescaled and the size of buffer used for storing the averaging data is selectable.
xDAIS ready No No
BC_CALC 1
Direct ASM Interface
The initialization routine must be called during program initialization. The BC_CALC
routine must be called in the control loop.
Variable Declaration:
In the system file, including the following statements before calling the subroutines:
Memory map:
All variables are mapped to an uninitialized named section, bc, which can be allocated
to any one data page. However, the buffer data is mapped to an uninitialized named
section, farmem.
Example:
In the interrupt service routine call the module and read results as follows:
CALL BC_CALC
2 SPRU
C/C–Callable ASM Interface
Object Definition The structure of the BOXCAR object is defined in the header file, box_car.h, as seen
in the following:
#define BC_SIZE 64
BOXCAR_DEFAULTS
Initializer for the BOXCAR object. This provides the initial values to the terminal vari-
ables, internal variables, as well as method pointers. This is initialized in the header
file, box_car.h.
Initialization:
To instance a pre-initialized object:
bc1.calc(&bc1);
bc2.calc(&bc2);
BC_CALC 3
C/C–Callable ASM Interface
Example:
Lets instance two BOXCAR objects, otherwise identical, and compute the averaging
values of two different s/w variables. The following example is the c source code for
the system file.
main()
{
4 SPRU
Background Information
Background Information
This s/w module computes the average of the runtime values of the selected input vari-
able. The size of the buffer used to keep the data is selectable with the power of two,
i.e., 2, 4, 8, 16, 32, 64, …. The default buffer size is 64. For different buffer size modify
the code (valid for both ASM and CcA versions) as required. The following instruction
is added or deleted, according to the buffer size, at the location indicated in the code.
This divides the number in accumulator by two.
BC_CALC 5
RAMP_CNTL Ramp Control Module
Description This module implements a ramp up and ramp down function. The output flag variable
s_eq_t_flg is set to 7FFFh when the output variable setpt_value equals the input vari-
able target_value.
setpt_value
target_value
RAMP_CNTL
s_eq_t_flg
RAMP_CNTL 1
Direct ASM Interface
Variable Declaration:
In the system file include the following statements:
Memory map:
All variables are mapped to an uninitialized named section ‘rmp_cntl’
Example:
CALL RAMP_CNTL
2 SPRU472
C/C–Callable ASM Interface
Object Definition The structure of the RMPCNTL object is defined in the header file, rmp_cntl.h, as
seen in the following:
RMPCNTL_DEFAULTS
Initializer for the RMPCNTL object. This provides the initial values to the terminal vari-
ables, internal variables, as well as method pointers. This is initialized in the header
file, rmp_cntl.h.
Initialization:
To instance a pre-initialized object:
rmpc1.calc(&rmpc1);
rmpc2.calc(&rmpc2);
RAMP_CNTL 3
C/C–Callable ASM Interface
Example:
Lets instance two RMPCNTL objects, otherwise identical, and run two ramp control-
ling variables. The following example is the c source code for the system file.
main()
{
4 SPRU472
Background Information
Background Information
where,
Td = rmp_dly_max . Ts
Ts = Sampling time period
where,
Td = rmp_dly_max . Ts
Ts = Sampling time period
setpt_value
rmp_hi_limit
Td
1
rmp_lo_limit
target_value>
setpt_value target_value > setpt_value
Example:
This means that the time delay for each ramp step is Td = 500x0.000025 = 0.0125 Sec.
Therefore, the total ramp time will be Tramp = 1000x0.0125 Sec = 12.5 Sec
RAMP_CNTL 5
DATA_LOG 2-Channel Data Logging Utility Module
Description This module stores the realtime values of two user selectable s/w variables in the exter-
nal data RAM provided on the 24x/24xx EVM. Two s/w variables are selected by con-
figuring two module inputs, dlog_iptr1 and dlog_iptr2, point to the address of the two
variables. The starting addresses of the two RAM locations, where the data values are
stored, are set to 8000h and 8400h. Each section allows logging of 400 data values.
dlog_iptr1
EXT
dlog_itpr2 DATA_LOG DATA
RAM
DATA_LOG 1
Direct ASM Interface
Outputs none
Variable Declaration:
In the system file include the following statements:
Memory map:
All variables are mapped to an uninitialized named section ‘data_log’
Example:
During the initialization part of the user code, initialize the module inputs with the ad-
dress of the desired variables as shown below:
Then in the interrupt routine just call the module to store the values of the intended vari-
ables in the external RAM.
CALL DATA_LOG
Note:
This module does not have any user configurable s/w outputs and, therefore, does
not need any output parameter passing.
2 SPRU
C/C–Callable ASM Interface
Object Definition The structure of the DATALOG object is defined in the header file, data_log.h, as
shown in the following:
DATALOG_DEFAULTS
Initializer for the DATALOG object. This provides the initial values to the terminal vari-
ables, internal variables, as well as method pointers. This is initialized in the header
file, data_log.h.
Initialization:
To instance a pre-initialized object:
dlog1.update(&dlog1);
dlog2.update(&dlog2);
DATA_LOG 3
C/C–Callable ASM Interface
Example:
Lets instance two DATALOG objects, otherwise identical, and run four data logging
variables. The following example is the c source code for the system file.
main()
{
/* Since dlog1 already occupied the data buffer addressed (by default) from 0x8000 to
0x87FF, the starting buffer address for dlog2 need to set to other empty space of memory */
/* This module does not have any user configurable s/w outputs and, therefore, does not
need any output parameter passing. */
4 SPRU
Background Information
Background Information
This s/w module stores 400 realtime values of each of the selected input variables in
the data RAM as illustrated in the following figures. The starting addresses of two RAM
sections, where the data values are stored, are set to 8000h and 8400h.
dlog_iptr1 dlog_iptr2
input_var1 8000h input_var2 8400h
DATA DATA
RAM RAM
83FFh 87FFh
DATA_LOG 5