DCP Unit 4
DCP Unit 4
3.1 INTRODUCTION
The LF2407 DSP controller offers 40 million instructions per second (MIPS)
performance. This high processing speed of the C2xx CPU allows users to conpute
parameters in real time rather than look up approximations from tables stored in memory. This
fast performance is well suited for processing control parameters in applications such as notch
filters or sensor less motor control algorithms where a large amount of calculations must be
computed quickly.
While the brain" of the LF2407 DSP is the C2xx core, the LF2407 contains several
control-orientated peripherals onboard (see Fig. 3.1). The peripherals on the LF2407 make
virtually any digital control requirement possible. Their applications range from analog to digital
conversion to pulse width modulation (PWM) generation. Communication peripherals make
possible the communication with external peripherals, personal computers, or other DSP
processors. Below is a brief listing of the different peripherals onboard the LF2407 followed by a
graphical layout depicted in Fig. 3.1.
PLL cADck.
CLOUe
DARAM IB1
264 VIcrds
10-Bt AD V
Ve
auocecuror
DARAM (E4 Vae
191
CANTAIOcs
FcPcA CAP
CAVSa
4K/12K712K44
Pot A0)PÁUn
12
JTAG Pat
CACOVCNA
CASOLNIHO
Bt
-3 Csptur Inputs
-8 CanparaPMOdputz -8ComparaPVaaOtote
-2GPToruPMM -20P TImercPYA
uisotes
IVONTIcuNo
t3cyOPus
2
Event Managers (EVA, EVB)
There are two Event Managers on the LF2407, the EVA and EVB. The Event Manager IS
the most important peripheral in digital motor control. It contains the necessary functions
needed to control electromechanical devices. Each EV is composed of functional blocks
including timers, comparators, and capture units for triggering on an event, PWM logiC
circuits,quadrature-encoder-pulse (QEP) circuits, and interrupt logic.
The Analog-to-Digital Converter (ADC)
The ADCon the LF2407 is used whenever an external analog signal needs to be
sampled and converted to a digital number. Examples of ADC applications range from
a
sampling a control signal for use in a digital notch filtering algorithm or using the ADC in
useful in motor
control feedback loop to monitor motor performance. Additionally, the ADC is
resistor instead of an
control applications because it allows for current sensing using a shunt
expensive current sensor.
The Control Area Network (CAN) Module
for
While the CAN module will not be covered in this text, it is a useful peripheral
multi-master serial
specific applications of the LF2407. The CAN module is used for
integrity
communication between external hardware. The CAN bus has a high level of data
automobile, or industrial
and is ideal for operation in noisy environments such as in an
environments that require reliable communication and data integrity.
Serial Peripheral Interface (SPI) and Serial Communications Interface (SCI)
used for
The SPI is a high-speed synchronous communication port that is mainly
communicating between the DSP and external peripherals or another DSP device. Typical
uses of the SPI include communication with external shift registers, display drivers, or ADCs.
The SCI is an asynchronous communication port that supports asynchronous serial (UART)
digital communication between the CPU and other asynchronous peripherals that use the
standard NRZ (non-return-to-zero) format. It is useful in communication between external
devices and the DSP. Since these communication peripherals are not directly related to motion
control applications, they will not be discussed further in this text.
3
Watchdog Timer (WD)
The Watchdog timer (WD) peripheral monitors software and hardware operations and
enabled) wilI
asserts a system reset when its internal counter overflows. The WD timer (when
the WD
count for a specific amount of time. It is necessary for the user's software to reset
there is a
timer periodically so that an unwanted reset does not occur. If for some reason
enters
CPUdisruption, the watchdog will generate a system reset. For example, if the software
timer will overflow and a
an endless loop or if the CPUbecomes temporarily disrupted, the WD
starting point.
DSP reset will occur, which will cause the DSP program to branch to its initial
CPU function
Most error conditions that temporarily disrupt chip operation and inhibit proper
of the CPU, thus
can be cleared by the WD function. In this way, the WD increases the reliability
ensuring system integrity.
General Purpose Bi-Directional Digital I/O(GPIO) Pins
LF2407 device, many of the
Since there are only a finite number of pins available on the
the secondary GPIO function. In
pins are multiplexed to either their primary function or
general-purpose input/output pin. The GPIO
most cases, a pin's second function will be as a
controlling the functionality of pins and
capability of the LF2407 is very useful as a means of
data to and from the device. Nine 16-bit control
also provides another method to input or output
these registers:
registers control all L/O and shared pins. There are two types of
to control the multiplexer selection that
" I/O MUX Control Registers (MCRx) - Used
general-purpose LO function.
Chooses between the primary function of a pin or the
(PxDATDIR) - Used to control the data and data
" Data and Direction Control Registers
Direction of bi-directional I/O pins.
5
Non-Volutile Flaslh Memory
The LF2407contains 32K of on-chip tlash memory that can be mapped to program space
if the MP/MC-pin is made logie 0(tied to ground), The Ilush memory provides a permanent
location to store code that is unaflected by cutting power to the device. The flash mecmorycan be
clectronically programmed and erased many times to allow for code development. Usually, the
external RAM on the LF2407 Evaluation Module (EVM) board is used instead of the flash lor
code development due to the fact that aseparate "lash progranmming" routine must be performed
lo lash code into the flash memory. 'The on-chip Ilash is normally used in situations where the
DSP program necds to be tested where a JTAG connection is not practical or where the DSP
needs to be tested as a "stand-alone" device, F'or example, if a LF2407 was used to develop a
DSP control solution to an automobile braking system, it would be somewhat impractical to have
a DSP/JTAG/PCinterface inacar that is
undergoing perfornmance testing.
3.4 Introduction to the C2xx DSP Core and Code
Generation
The heart of the LF2407 DSP Controller is the C2xx DSP corc. This core is a l6-bit fixed
point processor, meaning that it works with 16-bit binary numbers. One can think of the C2xx as
the central processor in a personal computer. The LF2407 DSP consists of the C2Xx DSP core
plus many peripherals such as Event Managers, ADC, etc., all integrated onto one single chip.
3.5 The Components of the C2xx DSP Core:
The DSP core (like all microprocessors) consists of several
subcomponents necessary to
perform arithmetic operations on 16-bit binary numbers. The following is a list of the multiple
subcomponents found in the C2xx core which we will discuss further:
"A 32-bit central arithmetic logic unit (CALU)
"A32-bit accumulator (used frequently in programs)
" Inputand output data-scaling shifters for the CALU
" A(16-bit by 16-bit) multiplier
"A product-scaling shifter
Eight auxiliary registers (ARO - AR7) and an auxiliary register arithmetic unit
(ARAU)
Each of the above components is eitlher accessed directly by the user code or is indirectly
uscd during the execution of an assembly command.
6
oROCES
Accumulator
The accumulator stores the output from the CALUand also serves as another input to the CALU
(many arithmetic commands perform operations on numbers that are currently stored in the
accumulator; versus other memory locations). The accumulator is 32 bits wide and is divided
into two sections, each consisting of 16 bits. The high-order bits consist of bits 31 through 16,
and the low-order bits are made up of bits 15 through 0. Assembly language instructions are
provided for storing the high- and low-order accumulator words to data memory. In most cases,
the accumulator is written to and read from directly by the user code via assembly commands. In
some instances, the accumulator is also transparent to the user (similar to the CALUoperation in
that it is accessed "behind the scenes).
Scaling Shifters
The C2xx has three 32-bit shifters that allow for scaling, bit extraction, extended arithmetic, and
overflow-prevention operations. The scaling shifters make possible commands that shift data left
or right. Like the CALU, the operation of the scaling shifters is transparent" to the user. For
example, the user needs only to use a shift command, and observe the result. Any one of the
three shifters could be used by the C2xx depending on the specific instruction entered. The
following is a description of the three shifters:
" Input data-scaling shifter (input shifter): This shifter left-shifts 16-bit input data by 0 to 16
bits to align the data to the 32-bit input of the CALU. For example, when the
user uses a
command such as *ADD 300h, 5", the input shifter is responsible for first shifting the data in
memory address $300h" to the left by five places before it is added to the
contents of the
accumulator.
7
" Qutput data-scaling shifter (output shifter): This shifter left-shifts data from the accumulator
by 0 to 7 bits before the output is stored to data memory. The content of the accumulator
remains unchanged. For example, when the user uses a command such as "SACL 30Oh, 4",
the output shifter is responsible for first shifting the contents of the accumulator to the left by
four places before it is stored to the memory address "300h".
Product-scaling shifter (product shifter): The product register (PREG) receives the output
of the multiplier. The product shifter shifts the output of the PREG before that output is sent
to the input of the CALU.The product shifter has four product shift modes (no shift, left shift
by one bit, left shift by four bits, and right shift by six bits), which are useful for performing
multiply/accumulate operations, fractional arithmetic, or justifying fractional products.
Multiplier
The multiplier performs 16-bit, 2s-complement multiplication and creates a 32-bit result.
In conjunction with the multiplier, the C2xx uses the l6-bit temporary register (TREG) and the
32-bit product register (PREG).
The operation of the multiplier is not as "transparent' as the CALUor shifters. The
TREG always needs to be loaded with one of the numbers that are to be multiplied. Other than
this prerequisite, the multiplication commands do not require any more actions from the user
code. The output of the multiply is stored in the PREG, which can later be read by the user code.
Auxiliary Register Arithmetic Unit (ARAU) and Auxiliary Registers
The ARAU generates data memory addresses when an instruction uses indirect addressing to
access data memory (more on indirect addressing will be covered later along with assembly
programming). Eight auxiliary registers (ARO through AR7) support the ARAU, each of which
can be loaded with a 16-bit value from data memory or directly from an instruction. Each
auxiliary register value can also be stored in data memory. The auxiliary registers are mainly
used as "pointers" to data memory locations to more easily facilitate looping or repeating
algorithms. They are directly written to by the user code and are automatically incremented or
decremented by particular assembly instructions during a looping or repeating operation. The
auxiliary register pointer (ARP) embedded in status register STO references the auxiliary register.
The status registers (ST0, STI) are core level registers where values such as the Data Page (DP)
and ARP located.
8
3.6 Sstem Configuration Registers:
configure or
The System Control and Status Registers (SCSRI, SCSR2) are used to
the
display fundamental settings of the LF2407. For exanmple,these fundamental settings include
peripherals are enabled.
clock speed (clock pre-scale setting) of the LF2407, which
microprocessor microcontroller mode, etc. Bits are controlled by writing to the corresponding
an external pin as with the
data memory address or the logic level
microprocessormicrocontroller (MPMC) select bit. The bit descriptions of these two registers
Bit 8 Reserved
control bit.
Bit 7 ADC CLKEN, ADC module clock enable
Clock to module is disabled (i.e., shut down to conserve power).
Clock to module is enabled and running normally.
Bit6 SCI CLKEN. SCI module clock enable control bit.
0 Clock to module is disabled (i.e., shut down to conserve power).
Clock to module is enabled and running normally.
If an illegal address has occurred, this bit will be set. It is up to software to clear this bit
following an illegal address detects. This bit is cleared by writing a l to it and should be cleared
as part of the initialization sequence. Note: An illegal address will cause a Non-Mask able
Interrupt (NMI).
System Control and Status Register 2 (SCSR2) Address 07019h
15-8
Reserved
RW-O
7 6 3 2
WDDIS bitin the WDCR. Once cleared, however, this bit can no longer be set to Iby software,
thereby protecting the integrity of the WD timer.
Bit 4 XMIF Hi-Z Control
This bit controls the state of the external memory interface (XMIF) signals.
XMIF signals in normal driven mode; i.e., not Hi-Z (high impedance).
1 AllXMIF signals are forced to Hi-Z state.
Bit 3Boot Enable
This bit reflects the state of the B00T EN /XF pin at the time of reset. After reset and device
has "booted up'", this bit can be changed in software to re-enable Flash memory visibility or
return to active Boot ROM.
Enable Boot ROM - Address space 0000 00FF is now occupied by the on
chip Boot ROM Block. Flash memory is totally disabled in this mode. Note: There is no on-chip
boot ROM in ROM devices (i.e., LC240xA)
Disable Boot ROM Program address space 0000 -- 7FFF is mapped to on
chip Flash memory in the case of LF2407A and LF2406A. In the case of LF2402A, addresses
0000 - 1FFF are mapped
Bit 2Microprocessor/Microcontroller Select
This bit reflecis the state of the MP/MC pin at time of reset. After reset, this bit can be changed
in software to allow dynamic mapping of memory on and off chip.
Set to Microcontroller mode - Program Address range 0000 -- 7FFF is mapped
internally (ie., Flash)
Set to Microprocessor mode Program Address range 0000 -7FFF is mapped
extemally (i.e.,customer provides external memory device.)
12
3.7 Memory Addressing Modes:
used by the C2xx instruction set. The three
There are three basic memory addressing modes
modes are:
Ar Immediate addressing mode (does not actually access memory)
I" Direct addressing mode
1" Indirect addressing mode
3.7.1 Immediate Addressing Mode
instruction contains a constant to be manipulated by the
In the immediate addressing mode, the
addressing" suggests that a memory location is
instruction. Even though the name immediate
usually
with a user-specified constant which is
accessed, immediate addressing is simply dealing an immediate
assembly command syntax. The #" sign indicates that the value
included in the
immediate addressing modes are:
address (just a constant).The two types of
short-immediate addressing have an 8
Short-immediate addressing. The instructions that use
bit, 9-bit, or 13-bit constant as the operand.
For example, the instruction:
LACL #44h ;loads lower bits of accumulator with
;Eight-bit constant (44h in this case)
a long
command will work only with ashort 8-bit constant. If you want to load
Note: The LACL
LACC command.
16-bit constant, then use the
long-immediate addressing have a 16-bit
Long-immediate addressing. Instructions that use
constant or as a 2s
operand. This 16-bit value can be used as an absolute
constant as an
complement value.
instruction:
For example, the
LACC #4444h :loads accumulator with up to a l6-bit
;Constant (4444h in this case)
you must use either direct or
access locations in data memory,
If you need to use registers or
indirect addressing.
3.7.2 Direct Addressing Mode words called data
addressing, data memory is first addressed in blocks of 128
In direct 511, as shown in
64K of data memory consists of 512 DPs labeled 0 through
pages. The entire register
DP is determined by the value in the 9-bit DP pointer in status
the Fig. 3.2. The current 14
0. If the DP value is "0
For example, if the DP value is "0 0000 0000", the current DP is
STO.
particular memory address can be found
0000 0010", the current data page is 2. The DP of a
15
Data page potnter (DP) Instruction rogister (|R)
17
LDP #5 ;Set data page to 5 (addresses 0280n-02?Pa)
ADD 9h, 16 :The contents of ata adiress 0289n are
:left shifted 16 bits and a ied to thE
:contents oÍ the accumulator.
18
A 3.7.3 lndirect Addressing Mode
Indirect addressing is a powerful way of addressing data memory. Indirect
mode is not dependent on the current data page as is direct addressing
addressing. Instead, when using
indirect addressing you load the memory space that you
would like to access into one of e
auxiliary registers (ARx). The current auxiliary register acts as a
pointer that pointsto a specitic
memory address,
"The register pointed to by the ARP is referred to as
the current auxiliary register or
current AR.To select a specific auxiliary register, load the 3-bit
auxiliary register pointer (ARP)
with a value from 0 to 7. The ARP can be
loaded with the MAR instruction or by the LARP
instruction. An ARP value can also be loaded by using the ARX
operand after any instruction
that supports indirect addressing as seen below.
Example of using MAR:
ADD *, ARI ;Adds using current *, then makes ARI the
;New current AR for future uses
Example of using LARP
LARP #2 : this will make AR2 the current AR
The C2xX provides four types of indirect addressing options:
No increment or decrement. The instruction uses the
content of the current auxiliary
register as the data memory addresses but neither increments nor decrements the content
of the current auxiliary register.
Increment or decrement by 1. The instruction uses the content of the current auxiliary
register as the data memory address and then increments or decrements the content of the
current auxiliary register by one.
Increment or decrement by an index amount. The value in ARO is the index amount.
The instruction uses the content of the current auxiliary register as the data
memory
address and then increments or decrements the content of the current auxiliary register by
the index amount.
Increment or decrement by an index amount using reverse carry. The value in AR0 i
the index amount. After the instruction uses the content of the current auxiliary register as
the data memory address, that content is incremented or decremented by the index
19
Example 2, illustrates how the
instruction register is loaded with the value
instruction is fetched from program shown when the ADD
Example 2. Indirect memory.
ADD *+,8,AR4
Addressing-Increment by I
;Operates
;in
as in Examp le 1 but
addition,
¿register
the current
byauxiliary
is
;AR4 ig chosenincremented
as the next one, and
;register. auxiliary
15 14 13 12
11 10 7 6 5 4
1 3 2 1
1
0 1 1 0
ADD opcode Shift = 8
NAR = 4
Addressing mode= indirect N= next AR specified
ARU= increment current AR
by 1
Example 3. Indirect Addressing
-Decrement by 1
ADD *-,8 :Operates as in Example 1 but in
¡addition, the current
iis
decremented by one. auxiliary register
Example 4. Indirect
Addressing-Increment by Index Amount
ADD *0+,8 ;Operates as in Example 1 but in
;addition, the content of
;isadded to the current register ARO
¡register. auxiliary
21
amount. The addition and subtraction process is accomplished with the carry propagation
reversed and is useful in fast Fourier transforms algorithms.
Table 3.1 displays the various operands that are available for use with instructions while using
indirect addressing mode.
Operand Option Exomplo
No increment or decrement
LT loads the temporary register TREG with the content of
the data mennory address referenced by the current AR.
Increment by 1
LT loads the TREG ith the content of the data memory
address referenced by the current AR and then adds 1 to the
content of the current AR.
Decrement by 1 LT - loads the TREG WIth the content of the data memory
address referenced by the current AR and then subtracts
from the content of the current AR.
"0+ Incrennent by index amount LT '0+ loads the TREG with the content of the
data memory
address referenced by the current AR and then adds the
content of ARO to the content of the current AR.
"0 Decrement by index amount LT "0- oads the TREG With the content of the
data memory
address referenced by the current AR and then subtracts the
content of ARO from the content of the current AR.
*BRO+ Increment by index amount, LT BR0+ loads the TREG with the
adding with reverse carry content of the data
memory address referenced by the current AR and then adds
the content of ARO to the content of the current AR,
with reverse carry adding
*BRO Decrement by index anount, propagation.
LT BR0- loads the TREG with the
subtracting with reverse carry content of the data
memory address referenced by the current AR
subtracts the content of ARO from the content of theand then
AR, subtracting with bit reverse carry current
propagation.
Table 3.1 Indirect addressing operands.
Examples of Indirect Addressing
Examplel illustrates how the instruction register is loaded with the value
shown when the ADD
instruction is fetched from program memory.
Example 1. Indirect Addressing-No Increment or
Decrement
ADD *,8 :Add to the
accumulator the content of the
;data-memory
; current address referenced by the
:is auxiliary register. The data
left shifted 8 bits
before being added.
15 14 13 12
10 8 7 6 5 3 2 1 0
1 1
1
X X x
ADD opcode Shift =8
20
nabledig 97 contaiTheLF240 nntrol-orient
*iaitalcontrol cecond MI
Taxas
Or
LACC 200h
22
LACC V ; where "v" is any variable assigned to data memory
Where *, 200h, and v are the duta memory addresses
Boldiace Characters Boldface characters must be included in the syntax.
Example:
LAR dma, l6 : direct addressing with left shift of 16
LAR ARI, 60h, 16 ; load auxiliary ARI register with the memory contents of 60h that
was left shifted 16 bits
Example:
LACC dna, [shifi] optional lefl shift from0, 15; defaults to O
LACC nain coumter, 8 ;shifts contents of the variable "main counter" data 8 places to
the left before loading accumulator
)An optionaloperand may be placed in the placed here.
Example:
LACCind [, shift [, AR n)_] Indirect addressing
LACC %
; load Accum. W/contents of the memory
;Location pointed to by the current AR.
LACC *, 5 ; load Accum. With the contents of the
memory
;Location pointed to by the current AR after
;The memory contents are left shifted by 5
; Bits.
LACC *, 0, AR3 :load Accum. With the contents of the memory
;Location pointed to by the current AR after
;The memory contents are left shifted by 5
;Bits. Now you have the option of
choosing
:A new AR. In this case, AR3 will become the
:New AR.
|, xl[, x2]] Operands x1 and x2 are optional, but you cannot
include x2 without also including
xl.
23
nrogrammat LF2407 contaihs ontrol-oriented
combin peripherals integ
LF2407
nn,The '*nlcontrol systems.
(MIPS)
Looping algorithms are very common inallprogramming languages, In high-level languages, the
"For" and "While" loops can be used, However, in assembly, we necd a slightly different
approach to perlorm arepeating algorithm. The following example is an algorithm that stores the
value " to memory locations 300h, 301h, 302h, 303h,and 304h.
25