Micro-2407 User Must Read
Micro-2407 User Must Read
Micro-2407 User Must Read
User Manual
Version 1.0
This manual consists of seven chapters. In Chapter 1, the hardware features of the Digital
Signal Processor TMS320LF2407A is discussed. The complete technical aspects of
TMS320LF2407A can be had from "TMS320LF/LC240xA DSP Controllers Reference
Guide System and Peripherals " from Texas Instruments.
Example programs aimed at explaining the key software features of TMS320LF2407A using line
assembler are given in Chapter 4. These examples have been selected for a reasonable and
balanced exposure to the important aspects of TMS320LF2407A.
Chapter 5 describes how to execute the programs in the serial monitor mode using cross
assembler.
Chapter-6 describes how to generate various PWM outputs like Fixed Frequency PWM, Sine
Modulated PWM etc. These examples helps to study the generation of PWM signal using
TMS320LF2407A and useful in developing the real time application programs. For more
examples and application, refer the manual "Applications of Micro-2407A in Power Electronics"
We assume that the reader is familiar with the fundamentals of DSP. Further we assume that the
reader is familiar with the general ideas of assembly level programming. For the beginners of
DSP, it will be very helpful to refer the good fashioned DSP book "A Practical approach to
Digital Signal Processing" by Dr.K.Padmanabhan, B.E., M.Sc. (Engg), Ph.d., Dr.S. Ananthi, B.E.,
M.E., Ph.d., Mr.R.Vijayarajeswaran, B.E., M.E.
Write to:
CHAPTER – 1
DIGITAL CONTROL FOR ELECTRIC DRIVES
1.1. INTRODUCTION:
The Motor Control industry is a strong aggressive sector. Each industry to remain
competitive, must reduce costs but also has to answer to power consumption
reduction and EMI radiation reduction issues imposed by governments and power
plant lobbies. The results of these constraining factors are the need of enhanced
algorithms. DSP technology allows to achieve both, a high level of performance as
well as a system cost reduction. Texas Instruments launches a new DSP, referenced
TMS320C240, specifically designed for the Digital Motor Control segment. This
device combining a 16 bit fixed-point DSP core with microcontroller peripherals in a
single chip solution is part of a new generation of DSPs called the DSP controllers.
Electric motors now form a big part in our daily life especially with domestic
applications like hairdryers, fans, mixers and drills …that we do not really pay any
attention to them. We just expect all these items to do their job without even giving a
thought to the motor itself and its rather complex electronics.
Among all the existing motors on the market there are three ‘classical’ motors: the
Direct Current with commutators (wound field) and two Alternative Current motors
the synchronous and the asynchronous motors. These motors, when properly
controlled, produce constant instantaneous torque (very little torque ripple) and
operate from pure DC or AC sine wave supplies.
Implementation of advanced motor drive systems requires the following features from
a typical motor controller
A new class of DSP controllers has addressed these issues effectively. These
controllers provide the computational capability of a DSP core and integrate useful
peripherals on chip to reduce the total chip count.
Market analysis shows that most of all industrial motor applications use AC induction
motors. The reasons for this include high robustness, reliability, low price and high
efficiency (up to 80%). However, the use of induction motors also has its
disadvantages, these lie mostly in its difficult controllability, due to its complex
mathematical model, its non linear behaviour during saturation effect and the
electrical parameter oscillation which depends on the physical influence of the
temperature.
Traditionally motor control was designed with analog components, they are easy to
design and can be implemented with relatively inexpensive components. However,
there are several drawbacks with analog systems. Aging and temperature can bring
about component variation causing the system to need regular adjustment, as the parts
count increases the reliability of the system decreases. Analog components raise
tolerance issues and upgrades are difficult as the design is hardwired. Digital systems
offer improvements over analog designs. Drift is eliminated since most functions are
performed digitally, upgrades can easily be made in software and part count is also
reduced since digital systems can handle several functions on chip.
Digital Signal Processors go on further to provide high speed, high resolution and
sensor less algorithms in order to reduce system costs. Providing a more precise
control to achieve better consumption or radiation performances often means
performing more calculations, the use of some 1-cycle multiplication & addition
instructions included in a DSP speeds-up calculations. Generally fixed point DSPs are
preferred for motor control for two reasons. Firstly, fixed point DSPs cost much less
than the floating point DSPs. Secondly, for most application a dynamic range of 16
bits is enough. If and when needed, the dynamic range can be increased in a fixed-
point processor by doing floating-point calculations in software.
The performances of a motor are strongly dependent on its control. DSP controllers
enable enhanced real time algorithms as well as sensor less control. The combination
of both allows reducing the number of components and to optimize the design of
silicon, to achieve a system cost reduction. A powerful processor such as a DSP
controller does the following:
For advanced controls, DSPs controllers may also performs the following:
The TMS320C24x DSP includes the same advantages as the microcontroller but also
offers higher speed, higher resolution, and capabilities to implement the math-
intensive algorithms to lower the system cost. The high speed is attributable mainly to
the dual bus of the Harvard architecture as well as single-cycle multiplication and
addition instructions. One bus is used for data and the other is used for program
instructions. This saves time because each is utilized simultaneously. Traditionally,
cost has been a potential disadvantage of the DSP solution, but this aspect has
diminished with the continuing decline of DSP costs. DSP controllers enable
enhanced, real-time algorithms as well as sensor less control. The combination
reduces the number of components and optimizes the design of silicon to achieve a
system cost reduction.
DSPs are capable of processing data at much faster rates than microcontrollers. For
example, the speed of the DSP allows it to estimate motor velocity, a task
accomplished by a tachometer in analog and microcontroller systems.
1.5. APPLICATIONS
The target applications for a fixed point DSP controller having the necessary features
are where the above-mentioned advantages meet the customer’s needs. Typical end
equipment applications with an advanced control are:
A new class of DSP controllers is becoming a viable option for even the most cost
sensitive applications like appliances, HVAC systems etc. In addition to traditional
mathematical functions like digital filter, FFT implementations, this new class of
DSPs integrates all the important power electronics peripherals to simplify the overall
system implementation. This integration lowers over all part count of the system and
reduces the board size.
The TMS320C24x, the first single-chip DSP solution for the digital control system
market, integrates the TI 16 bit, fixed-point TMS320C2xLP DSP core with several
microcontroller peripherals. The DSP core itself has up to 20 MIPS (50 ns cycle time)
speed and can perform the useful multiply/accumulate instruction in a single cycle.
Six PWM channels (PWM1 through PWM6) control the three-phase voltage source
inverter. These six PWM channels are grouped in three pairs (PWM 1&2, PWM 3&4,
PWM 5&6). Three compare registers, called Full Compare, are associated with each
PWM channel pair. The compare register values are updated to obtain the proper
PWM output. The on-chip software programmable, dead band module provides
sufficient dead time to avoid shoot through fault. There are three more PWM channels
left to implement other functions like power factor correction.
New generations of motor control digital signal processors (DSPs) lower their supply
voltages from 5V to 3.3V to offer higher performance at lower cost. Replacing
traditional 5V digital control circuitry by 3.3V designs introduce no additional system
cost and no significant complication in interfacing with TTL and CMOS compatible
components, as well as with mixed voltage ICs such as power transistor gate drivers.
Just like 5V-based designs, good engineering practice should be exercised to
minimize noise and EMI effects by proper component layout and PCB design when
3.3V DSP, ADC, and digital circuitry are used in a mixed signal environment, with
high and low voltage analog and switching signals, such as a motor control system. In
addition, software techniques such as Random PWM method can be used by special
features of the Texas Instruments (TI) TMS320x24xx DSP controllers to significantly
reduce noise effects caused by EMI radiation.
The new TMS320LF2407A digital signal processor (DSP) controller, part of the
TMS320C2000 DSP platform of control-optimized DSPs, is ideal for space-
constrained applications that require the control peripherals and ease-of-use of a
traditional microcontroller and the processing power of a DSP. At only 49mm2, the
LF2407A DSP provides 150 MIPS of processing power for precise control in space
Constrained consumer and industrial applications. The detailed architecture of the
TMS320F2407 will be discussed in the next chapter.
The era of analog control systems for electric motor drives is definitely over, and a
wide array of digital devices is available for drive designers. Digital controllers allow
implementation of sophisticated operating algorithms, offering significant technical
advantages thanks to their ability of fast processing of vast data, high operational
flexibility, and ease of integration into automated industrial systems. If the digital
processors involved are so efficient that reserves of computing power remain after the
basic control algorithms have been realized, additional enhancing features can be
implemented, such as the self commissioning and auto tuning, efficiency
optimization, or automated fault diagnostics of the drives.
CHAPTER – 2
TMS320F2407A DEVICE OVERVIEW
2.1 INTRODUCTION:
It is needless to say that in order to utilize the full feature of the DSP chip
TMS320LF2407A, the DSP engineer must have a complete knowledge of the DSP
device. This chapter gives you an introduction to the hardware aspects of the
TMS320LF2407A DSP processor.
The new Texas Instruments TMS320LF2407A digital signal processor (DSP) controller,
part of the TMS320C2000 (24xx series) of control-optimized DSPs, is ideal for space-
constrained applications that require the control peripherals and ease-of-use of a
traditional microcontroller and the processing power of a DSP.
The TMS320LF2407A DSP contains the DSP core processor and useful peripherals
integrated onto a single piece of silicon. The TMS320F2407A combines the powerful
CPU with on-chip memory and peripherals. With the DSP core and control-oriented
peripherals integrated into a single chip, users can design very compact and cost effective
digital control systems, and so Texas named this family of chips are Digital Signal
Controllers (DSC).
• Up to 40-MIPS operation
• Three power-down modes
• Code-compatible control-optimized DSPs
• JTAG scan-based emulation
• 3.3-V and 5-V designs
Texas Instruments offers various DSP processors in the 24xx series. In our trainer kit we
used the latest TMS320LF2407A for design purpose. The below table gives the detailed
information about 24xx family.
The heart of the TMS320LF2407A DSP controller is the c2xx DSP core. This core is a
16-bit fixed-point processor, meaning that it works with 16-bit binary numbers. The C2xx
core has its own native instruction set of assembly mnemonics or commands. The user
can program either in assembly or ‘C’ language. However, to write compact, fast
executing programs, it is best to write code in assembly language.
The DSP core performs 2s-complement arithmetic using the 32-bit CALU. The CALU
uses 16-bit words taken from the data memory, derived from an immediate instruction, or
from the 32-bit multiplier result. In addition to arithmetic operations, the CALU can
perform Boolean operations.
The TMS320LF2407A contains a 32-bit ALU and accumulator for support of double
precision, two's complement arithmetic. The ALU is a general-purpose arithmetic unit
that operates on 16-bit words taken from the data RAM or derived from immediate
instructions. In addition to the usual arithmetic instructions, the ALU can perform
Boolean operations, providing the bit manipulation ability required of a high-speed
controller. The accumulator stores the output from the ALU and is often an input to the
ALU. Its word length is 32-bit. The accumulator is divided into a high-order word (bits
31 through 16) and a low-order word (bits 15 through 0). Instructions are provided for
storing and loading the high and lower order accumulator words to memory.
2.3.3 SHIFTERS:
The core contains three 32-bit shifters that allow for scaling, bit extraction, extended
arithmetic, and overflow-prevention operations. The three shifters are mentioned below.
The scaling shifters make possible commands that shift data left or right.
* 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.
* Output 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 is remain unchanged.
The ARAU generates data memory addresses when an instruction uses indirect
addressing to access data memory. Eight auxiliary registers (AR0 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 registers are mainly used as “pointers” to data
memory locations to more easily facilitate looping or repeating algorithms. The auxiliary
register pointer (ARP) embedded in status register ST0 references the auxiliary register.
2.4 MEMORY
The LF2407A has 544 16-bit words on-chip dual access random access memory
(DARAM) that are divided into three main memory blocks named B0,B1, and B2.In
addition to the DARAM, there are also 2000 16-bit words of single access random access
memory (SARAM). The main difference between DARAM and SARAM is that
DARAM memory can be accessed twice per clock cycle and SARAM can only be
accessed once per cycle. Thus, DARAM reads and writes twice as fast as SARAM.
In addition to the RAM present on the LF2407A, there is also non-volatile flash memory
(32KW). Unlike RAM, the flash memory does not lose its contents when the LF2407
loses power. The flash memory of the LF2407A is used only to store a program that is to
be run. This flash memory is always enabled in devices that lack an external memory
interface. For the 2407A, which has an external memory interface, the MP/MC pin
determines whether the on-chip program memory (flash) or the off-chip program memory
(customer design specific) is accessed.
The 2407A design is based on an enhanced Harvard architecture. These devices have
multiple memory spaces accessible on three parallel buses: a program address bus (PAB),
a data-read address bus (DRAB), and a data-write address bus (DWAB). Each of the
three buses access different memory spaces for different phases of the device’s operation.
Because the bus operations are independent, it is possible to access both the program and
data spaces simultaneously. Within a given machine cycle, the CALU can execute as
many as three concurrent memory operations.
The 240xA address map is organized into three individually selectable spaces:
These spaces provide a total address space of 192K words. The advantage of operating
from external memory is the ability to access a larger address space.
While the brain of the TMS320LF2407A DSP is the C2xx core, the TMS320LF2407A
contains several control-oriented peripherals on-chip. The peripherals on the LF2407A
make virtually any digital control requirement possible. Their applications range from
analog to digital conversion (ADC) to pulse width modulation (PWM) generation.
Communication peripherals make possible the communication with external peripherals,
personal computers, or other DSP processors. The embedded peripherals inside the
LF2407A are listed below.
There are two Event Managers on the TMS320LF2407A, the EVA and EVB. The Event
Manger 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, capture units for triggering on an event,
PWM logic circuits, Quadrature-encoder-pulse (QEP) circuits, and interrupt logic.
The ADC on the TMS320LF2407A is used whenever an external analog signal needs to
be sampled and converted to a digital number. The following are the features of the on-
chip ADC.
The ADC in the LF2407A is mainly used in control feedback loop to monitor motor
performance and the ADC also allows current sensing using a shunt resistor instead of an
expensive current sensor in motor control applications.
The controller area network (CAN) uses a serial multi-master communication protocol
that efficiently supports distributed real-time control with a very high level of data
integrity, and communication speeds of up to 1 Mbps. The CAN bus is ideal for
applications operating in noisy and harsh environments, such as in the automotive and
other industrial fields that require reliable communication. Prioritized messages of up to
eight bytes in data length can be sent on a multi-master serial bus using an arbitration
protocol and an error-detection mechanism for a high level of data integrity.
The CAN protocol supports four different frame types for communication:
• Data frames that carry data from a transmitter node to receiver node(s)
• Remote frames that are transmitted by a node to request the transmission of a
data frame with the same identifier
• Error frames that are transmitted by any node on a bus-error detection
• Overload frames that provide an extra delay between the preceding and the
succeeding data frames or remote frames
2.5.4 Serial Peripheral Interface (SPI) and Serial Communication Interface (SCI)
The serial peripheral interface (SPI) is a high-speed synchronous serial input/ output (I/O)
port that allows a serial bit stream of programmed length (one to sixteen bits) to be
shifted into and out of the device at a programmed bit-transfer rate. The SPI is normally
used for communications between the DSP controller and external peripherals or another
controller. Typical applications include external I/O or peripheral expansion via devices
such as shift registers, display drivers, and analog-to-digital converters (ADCs).
The watchdog (WD) timer peripheral monitors software and hardware operations, and
implements system reset functions upon CPU disruption. The WD timer (when enabled)
will count for a specific amount of time. It is necessary for the user’s software to reset the
WD timer periodically so that an unwanted rest does not occur. If the software goes into
an improper loop, or if the CPU becomes temporarily disrupted, the WD timer overflows
to assert a system reset. Most conditions that temporarily disrupt chip operation and
inhibit proper CPU function can be cleared and reset by the watchdog function. By its
consistent performance, the watchdog increases the reliability of the CPU, thus ensuring
system integrity. All registers in this peripheral are eight bits in width and are attached to
the lower byte of the peripheral data bus of the 16-bit CPU.
Since there are only a finite number of pins available on the LF2407A device, many of
the pins are multiplexed to either their primary function or the secondary GPIO function.
The digital I/O ports module provides a flexible method for controlling both dedicated
I/O and shared pin functions. All I/O and shared pin functions are controlled using nine
16-bit registers. These registers are divided into two types:
• I/O MUX Control registers (MCRx) – Used to control the multiplexor selection
that chooses between the primary function of a pin or the general purpose I/O
function.
• Data and Direction Control registers (PxDATDIR) – Used to control the data and
data direction of bidirectional I/O pins.
The phased-locked loop (PLL) module contains a crystal oscillator, clock monitor circuit,
clock enable circuit, and prescaler unit. The purpose of using a PLL is to multiply the
external frequency reference to a higher frequency for use internally. This avoids having
high frequency signals sent to externally packaged pins, which could cause excessive
EMI. PLLs also avoid the use of crystals above 20 – 25 MHz. Such crystals usually
operate in overtone mode and require extra tank circuit components.
The interrupts on the LF2407A allow the device hardware to trigger the CPU of the
LF2407A (CPU=C2xx DSP core) to break from the current task, branch to a new section
of code and start a new task, then return back to the initial task. The new task refereed to
in the previous sentence is known as the Interrupt Service Routine (ISR).
The LF2407A CPU supports one non-maskable interrupt (NMI) and six maskable
prioritized interrupt requests (INT1–INT6) at the core level. The LF2407A devices have
many peripherals, and each peripheral is capable of generating one or more interrupts in
response to many events at the peripheral level. Because the LF2407A CPU does not
have sufficient capacity to handle all peripheral interrupt requests at the core level, a
centralized interrupt controller (PIE) is required to arbitrate the interrupt requests from
various sources such as peripherals and other external pins.
The JTAG port provides a standard method of interfacing a personnel computer with the
DSP controller for emulation and development. An external parallel port based emulation
pod provides the connection between the JTAG module on the LF2407A and the personal
computer. The JTAG module allows the PC to take full control over the DSP processor.
CHAPTER - 3
HARDWARE OVERVIEW
3.1. INTRODUCTION:
This chapter gives brief hardware features available on the Micro-2407A trainer kit. It has many
useful onboard features like a 16x2 LCD Display and IBM PC Keyboard interface to use the
trainer kit in stand alone mode. The student can use these hardware features to set maximum
knowledge on TMS320LF2407A and interface many hardware peripherals to it. The following
section describes the various interface used, memory configuration and I/O configuration available
in the trainer kit.
Data entry to the kit can be done through 104 keys IBM PC/AT keyboard, interfaced to the CPU
TMS320LF2407A with the help of CD4015 keyboard controller. The 16x2 LCD display is
interfaced to the CPU through the 74LS244 latch.
There are two ways of using the physical memory on board the LF2407A: storing a program or
storing a data. A program that is to be run must be stored in memory that is mapped to program
space. Likewise, only memory that is data space may be used to store data. Program memory is
written to when a program is loaded into the LF2407A. Data memory is normally written to
during the execution of a program, where the program might use the data memory as temporary
storage for calculation variables and results.
When a program is loaded into the LF2407A, the code resides in and run from program memory
space. In addition to storing the user code, the program memory can also store immediate
operands and table information. The below table shows the program memory mapping for
LF2407A.
For the execution of a program, it is necessary to store calculation results or look up tables in
memory. The memory allocated for this function is called data memory. In order to store a value
to a data memory address, the corresponding memory block must reside in data memory space.
Block B1 and B2 permanently reside in data space, while block B0 and the SARAM are
configurable for either program or data using the CNF bit.
The data memory space has the second functionality of providing an easy way to access on-chip
configuration registers and peripherals. The internal data memory includes the memory mapped
registers, DARAM blocks, and peripheral memory-mapped registers. The remaining 32K words
of memory (8000 to FFFFh) form part of the external data memory. The data memory mapping
for the LF2407A is shown below.
Note: During power-on reset all the three blocks are used for Micro-2407A initialization by
monitor.
I/O memory is solely used for accessing external peripherals such as the digital-to-analog
converter (DAC), LCD etc. The assembly instruction “OUT” is used to write to an address that is
mapped to I/O memory. It is important to make sure the Linker Command File is configured
properly and the correct Data Page (DP) is set to avoid in advertently writing to an undesired or
reserved memory address. The memory mapping for I/O spaces are given below.
All the peripherals are I/O mapped. The I/O addresses are given in the table below.
CHAPTER - 4
SOFTWARE OVERVIEW
This chapter illustrates the use of program and execution mainly in the standalone mode. The
Micro-2407A has 3 software development tools namely
1. Standalone Mode
2. Monitor program
3. Serial Mode
In "Standalone Mode" the Micro-2407A works with a 104 keys keyboard and 16x2 LCD display
and line assembler. With this configuration, the user can enter these program through the
keyboard and edit and display it on the LCD display. The user can enter the Mnemonics using the
Line Assembler, and debug the program to run it on Micro-2407A.
"Monitor Program" is used to enter data directly into Data or Program memory, display the data
etc. It has several commands to enter the user program, for editing and debugging. In "Serial
Mode", it works with a IBM PC computer and program entry and debugging is done at the PC
level.
For program entry and execution the use can either use stand alone mode or serial mode facility
available in the trainer kit.
In this stand alone mode user can follow the procedure given below to enter and execute the
program.
Program prepared can be entered by using Line assembler in the user program memory starting
from: C000H.
Caution: Line Assembler has the following limitations. Please take care of this while
entering your program under Line Assembler.
1. While using "SHIFT" key, press only once. Don't keep pressing "SHIFT" key with some
other keys at the same time.
2. If you happen to enter instructions like RETC cond, [cond], [...] where the conditions are EQ,
NEQ, LT, ... in the standalone mode, Do enter values as given below instead of condition like
EQ, NEQ, NT
Vi Microsystems
Microsystems Pvt. Ltd., [4-1]
MICRO - 2407A User Manual Software Overview
Value Condition
0 EQ
1 NEQ
2 LT
3 LEQ
4 GT
5 GEQ
6 NC
7 C
8 NOV
9 OV
A BIO
B NTC
C TC
D UNC
for e.g., in Standalone mode, you can enter RETC 0 instead of entering RETC EQ
EXAMPLE:
The program can be entered through the Line Assemblers provided in the "Standalone Mode".
The line assembler takes directly mnemonics of TMS320LF2407A processor, like a Assembler.
But only one instruction can be assembled at a time, which in turn is converted to machine code.
This machine code is displayed in the LCD display for verification for the user. Any program can
be written like this and assembler using the "Line assembler" and the codes are loaded into the
memory of Micro-2407A. Then, the user can use the Debugger commands of monitor program
like Substitute Data, GO, and Fill etc for debugging the program and executing it.
The actual entry and corresponding LCD display for two instructions will be as follows.
Vi Microsystems
Pvt. Ltd. Chennai
Micro-2407A Trainer
#_
Vi Microsystems
Microsystems Pvt. Ltd., [4-2]
MICRO - 2407A User Manual Software Overview
Micro-2407A Trainer
#AS
Line Assembler
Start Address:
In the start address enter the starting address of the program to be loaded, usually "C000". Now
enter C000 and press the Enter key
Start Address:
C000
Now we can start entering the mnemonics. We will enter 2 mnemonics for trial basis
i) LACC #2345, 0
ii) LAR 1, #2000
C000-LACC #2345,0
C000
C002-
C000 BF80 2345
Whereas the Line Assembler assembles the mnemonics and generates the corresponding code.
Vi Microsystems
Microsystems Pvt. Ltd., [4-3]
MICRO - 2407A User Manual Software Overview
C004
C002 BF09 2000
Keep repeating this operation for the next mnemonic entry. To terminate the entering mnemonics,
enter the (.) and press enter key and display will be as follows
Micro-2407A Trainer
#
If you want to go in to dis-assembler to see mnemonics, which we have entered already through
assembler, Enter DS as follows
Micro-2407A Trainer
#DS
Dis-assembler
Start:
Where as do enter the address (for e.g. C000) and it will appear as
Start: C000
End:
Start: C000
End: C003
After pressing the "ENTER" key, you can see the mnemonics with opcodes which we have
Vi Microsystems
Microsystems Pvt. Ltd., [4-4]
MICRO - 2407A User Manual Software Overview
Micro-2407A Trainer
#
EXAMPLE PROGRAM
The following sample program fills 16-bit data in data memory from 9000H to A000H. The data
to be filled in this example is 2345H.
Enter the above assembly program instructions one after another pressing enter key after the
completion of one line, once the program entry is completed, to terminate the entry mode, enter
dot (.) and press the enter key to come out to the command prompt.
To execute the program use the "GO" command given in the display below (Refer Technical
reference for more clarifications)
Vi Microsystems
Microsystems Pvt. Ltd., [4-5]
MICRO - 2407A User Manual Software Overview
Micro-2407A Trainer
#GO C000
Press the enter key, where C000H is the program starting address. Once GO command is given,
and then the following display is found in the screen.
Executing.....
To terminate the execution of the program press the "Reset" switch to come to the prompt screen.
Now verify the data "2345" is filled in data memory location 9000H to A000H using "SD"
(Substitute Data Memory) command.
Vi Microsystems
Microsystems Pvt. Ltd., [4-6]
MICRO-2407A User Manual Examples on Standalone Mode
CHAPTER - 5
GETTING STARTED WITH BASIC EXAMPLES ON
STANDALONE MODE
This chapter mainly described about examples of TMS320LF2407A assembly program using line
assembler in the standalone mode for Arithmetic manipulations and usage of various instruction
of TMS320LF2407A processor. Since the user are in the beginning stage, the examples do not
involve much complexity. Each example is presented in the following format.
AIM:
THEORY:
PROGRAM:
The complete assembly language program in TMS320LF2407A code is given for every
example. These programs will guide the user for understanding the instruction set of the DSP
TMS320LF2407A.
AIM:
THEORY:
Numerical analysis, floating point computations or other operations may require arithmetic to be
executed with more than 32-bits of precision. Since, the TMS320LF2407A is 16-bit fixed-point
processor, software is required for the extended precision of arithmetic operations. For proper
operation, the overflow mode bit should be reset (OVM = 0) so that the accumulator result will
not be loaded with the saturation value.
X3 X2 X1 X0
+ Y3 Y2 Y1 Y0
))))))))))))))))
W3 W2 W1 W0
))))))))))))))))
Where all the numbers X3, X2, X1, X0, Y3, Y2, Y1 & Y0 are 16-bit numbers.
TMS320LF2407A has provision to add two 32-bit numbers, so we can add X1 X0 with Y1 Y0.
But how can we add 64-bit numbers X3 X2 X1 X0 with Y3 Y2 Y1 Y0.
TMS320LF2407A has two features that help to make extended precision calculation more
efficient. One of the feature is the carry status bit. The carry bit is set whenever the addition of
a value from the input scaling shifter or the P-register to the accumulator content generate a carry
out of bit 31. Otherwise, the carry bit is reset since the carry out of bit 31 is zero. One exception
to this case is that ADD 5,10h instruction which can only set the carry bit. This allows the
accumulator to generate proper single carry when either the addition to the lower or upper half
of the accumulator actually causes the carry.
The other feature which eases the extended-precision addition is the ADD7,10h instruction.
ADD7,10h instruction adds the 16-bit data memory content to the higher part of accumulator.
PROGRAM EXPLANATION:
In this example, the X operand X3 X2 X1 X0, is made of 16-bit numbers X3, X2, X1 and X0,
with X3 the most significant 16-bits and X0 the least significant 16-bits. The Y operand is Y3 Y2
Y1 Y0, where Y3 is the most significant 16-bits and Y0 is the least significant 16-bits. On
addition, both the operand results in W3 W2 W1 W0. For example the addition of
5432109876543210 and 0123456789012345 results in 555555FFFF555555, as shown:
X-Operand: X3 X2 X1 X0
5432 1098 7654 3210
Y-Operand: Y3 Y2 Y1 Y0
0123 4567 8901 2345
Result: W3 W2 W1 W0
5555 55FF FF55 5555
First load X1 in higher accumulator using LACC instruction and add X0 with accumulator by
using ADDS instruction. Now, the whole 32-bit of X1 X0 is in accumulator. Add Y0 with sign
extension suppressed using ADDS instruction and in the same way Y1 is added to the higher part
of accumulator using ADD instruction with shift. The result of 0-15 bits are stored in data
memory as W0 and 16-31 bits are stored in data memory as W1.
The next section adds the 32-bit numbers X2 X3 and Y2 Y3, and the result is stored in data
memory as W2 and W3.
Caution: We are giving the variables like X0, X1, X2... only for understanding the logic in
standalone mode. Do enter the address directly, as given below in the table instead
of entering variables in the standalone. In the case of serial monitor you can enter
variables like X0, X1, Y0, Y1 directly, since we have assembler directives in the cross
assembler.That will be described in coming chapters.
Caution:
By default,LDP #120H instruction considers address values 0000 ,0001,0002 ...which you
have entered in the programs as 9000, 9001, 9002,... respectively.
PROGRAM LISTING:
RESULT:
AIM:
THEORY:
Similar to extended-precision addition, the carry bit of the TMS320LF2407A is reset whenever
the input scaling shifter or the P-register value subtracted from the accumulator content generates
a borrow into bit 31. Otherwise, the carry bit is set, since, no borrow into bit-31 is required.
One exception to this case is the SUB5,10h instruction which can only reset the carry bit. This
allows the generation of the proper single carry when either the subtraction from the lower or
upper half of the accumulator actually causes the borrow.
In this example two 64-bit numbers X and Y are subtracted to give the result W as:
X3 X2 X1 X0
- Y3 Y2 Y1 Y0
-------------------------------
W3 W2 W1 W0
-------------------------------
PROGRAM EXPLANATION:
X3 X2 X1 X0
2222 2222 2222 2222
Y3 Y2 Y1 Y0
1111 1111 1111 1111
))))))))))))))))))))))))-)
W3 W2 W1 W0
1111 1111 1111 1111
)))))))))))))))))))))))-))
First, the X1 and X0 are loaded in accumulator using LACC and ADDS instruction then Y0 and
Y1 are subtracted with accumulator and the results are stored in W0 and W1. In the same fashion
Y3 Y2 is subtracted from X3 X2.
Fill the data memory using SD command as the values given below.
PROGRAM LISTING:
RESULT:
AIM:
THEORY:
With fixed point DSP, the fractional numbers are represented in Q15 format. Q-format is a
number representation commonly used when performing operations on non-integer numbers. In
a Q-format, the Q-number (15 in Q15) denotes how many bits are located to the right of the
binary point.
For example a 16-bit Q number has a assumed binary point, a sign bit, i integer bits and 15-i
fractional bits as shown below:
0 0000010 10100000
* .))0))- * .)))0))-
* * * .)))))))) Fraction Part
* * .)))))))))))))) Binary Point
* .))))))))))))))))))) Integer Part
.))))))))))))))))))))))))) Sign
has a value of 2.625. This particular number is said to be represented in a Q8 format (8 factorial
bits). Its range is between - 128 (10000000000000000) and 127.996 (01111111111111111).
The factorial accuracy of a Q8 number is about 0.004 (one part in 28 or 256).
It is more common to work entirely with fractions represented in a Q15 format or integers in Q0
format. This is especially true for signal processing algorithms where multiply and accumulate
operations and dominant. The result of a fraction times a fraction remains a fraction and the result
of an integer times and integer remains an integer. No overflow occurs in this case. For example,
multiplication of two Q15 numbers result in a Q30 number.
The fraction 0.5 is represented as 9000 in Q15 format. The multiplication of two Q15 numbers
result in a Q30 number as shown below.
Two sign bits remain after multiply. Generally, a single precision (16-bit) result is saved, rather
than maintaining the full intermediate precision. The upper half of the result does not contain a
full 15-bits of fractional precision, since, the multiply operation actually creates a second sign bit.
In order to recover that precision, the product most be shifted left by one bit.
TMS320LF2407A supports the fractional multiplication. The multiplication of two Q15 numbers
is implemented in the same way as integer multiplication except that the result is left shifted by
one-bit left as shown in the following code excerpt:
PROGRAM DESCRIPTION:
The following program implement the multiplication 0.5 x 0.5 = 0.25. The fraction 0.5 is
represented in Q15 format and the result is in Q15 format.
PROGRAM LISTING:
RESULT:
AIM:
THEORY:
The TMS320LF2407A hardware multiplier normally perform two's complement 16-bit by 16-bit
multiplies and produces a 32-bit result in a single processor cycle. To multiply two operands, one
operand must be loaded into the T-register. The second operand is moved by the multiply
instruction to the multiplier, which then produces the product in the P-register. Before another
multiply can be performed, the content of the P-register should be moved to the accumulator or
should be stored in data memory.
PROGRAM EXPLANATION:
The following program stores the data 37A at data memory 9000 and the data 12E at the data
memory address 9001. The instruction LT OP1(0000h) loads the first operand from dma 8000
to T register. The instruction MPY OP2(0001h) multiplies the content of dma 9001 with the T
register. The result is stored in P register. The instruction PAC transfers the content of P register
to accumulator. The SACL and SACH instructions store the lower and higher order results in
dma 9002 and 9003.
PROGRAM LISTING:
RESULT:
The results are stored in data memory locations 9002 and 9003 as shown below.
EXAMPLE 5
DIVISION
AIM:
To divide two binary two's complement numbers of any sign where the numerator is less than
denominator.
THEORY:
Binary division is the inverse of multiplication. Multiplication consists of a series of shift and add
operations, while division can be broken into a series of subtracts and shifts. Although the
TMS320LF2407A does not have an explicit divide instruction, it is possible to implement an
efficient, flexible divide capability using the conditional subtract instruction, SUBC.
SUBC implements binary division in the same manner as is commonly done in long division.
Given a 16-bit positive dividend and divisor, the repetition of the SUBC command 16 times
produces 16-bit quotient in the low accumulator and a 16-bit remainder in high accumulator.
With each SUBC, the divisor is left-shifted 15 bits and subtracted from the accumulator. For each
subtract not producing a negative answer, a one is put in the LSB of the quotient and then shifted.
For each subtract producing a negative answer, the accumulator is simply left-shifted. The
shifting of the remainder and quotient after each subtract produces the separation of the quotient
and remainder in the low and high halves of the accumulator. The similarities between long
division and the SUBC method of division are shown below where 33 is divided by 5.
Long Division:
0000000000000110 Quotient
+))))))))))))))))))))
0000000000000101 *0000000000100001
-101
))))
110
-101
))))
11 Remainder
SUBC Method:
HIGH ADC LOW ADC
000000000000000
0 0000000000100010 2) 2nd subtract produces negative answer, so
-10 1000000000000000 discard result and shift ACC (dividend)
left
-10 . 0111111110111110
.
.
000000000000000 1010000000000000
1
15) Result is again positive. Shift result left
000000000000001 0100000000000001 and replace LSB with 1.
1 1000000000000000
-10
000000000000000 1100000000000001
0
1000000000000011 16) Last subtract. Negative answer, so
000000000000000 1000000000000000 discard
1 result and shift ACC left.
-10
- 1111111111111101
REMAINDER QUOTIENT
The condition of the divisor, less than the shifted dividend, is determined by the sign of the result.
The only restriction for the use of the SUBC instruction is that both the dividend and divisor
MUST be positive. Thus, the sign of the quotient must be determined and the quotient computed
using the absolute value of the dividend and divisor. In addition, when implementing a divide
algorithm, it is important to know if the quotient can be represented as a fraction and the degree
of accuracy to which the quotient is to be computed. Each of these considerations can affect how
the SUBC instruction is used. Not that the next instruction after SUBC cannot use the
accumulator.
PROGRAM EXPLANATION:
The program given below checks the sign of the quotient and stores the sign in data memory.
After eliminating the sign make both operands positive by using ABS instruction. As explained
in theory part, execute SUBC instruction 15 times using RPT. Now the quotient is in lower
accumulator and remainder is in higher accumulator.
Enter numerator value of 15 in data memory 9000 and denominator value as 24 in 9001 as:
PROGRAM LISTING:
RESULT:
AIM:
THEORY:
TMS320LF2407A has three status registers called STS0, STS1 and PMST. All the three status
registers are of 16-bit wide. These registers contain the status of various conditions and modes
of TMS320LF2407A. The function of status register 0 bits is shown below:
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
ARP OV OVM 1 INTM DP
STATUS REGISTER 0:
The bits 0-8 of STS0 are called Data Page Pointer. TMS320LF2407A can address 64KW of data
memory. This whole data memory is divided into 512 pages, with each page of length 128 words.
Out of the 512 pages only one page is active at a time. This active page concept is used only
when accessing the memory using the Direct addressing mode. The active page is indicated by
the Data Page Pointer. The Data Page Pointer can be loaded using the instruction LDP. The
LDP instruction loads an immediate value onto the Data Page Pointer.
Bit 9 of STS0 is Interrupt Mode bit (INTM). When this bit is 1, all maskable interrupts are
disabled. When this bit is 0, all maskable interrupts are disabled. This bit can be set by SETC
instruction and reset by CLRC instruction.
Bit 10 is always 1. Bit 11 controls the Overflow Mode of the accumulator. This bit is called
OVM bit. When 0, overflowed results overflow normally in accumulator. When this bit is 1, and
when overflow occur in accumulator, the accumulator is set to either most positive or negative
value upon encountering the overflow. This bit can be set to 1 by SOVM instruction and reset
to 0 by ROVM instruction.
Bit 12 of STS0 is overflow flag bit. This bit indicates the status of accumulator overflow. When
overflow occurs in accumulator this bit is set.
TMS320LF2407A have 8 auxiliary registers called AR0 to AR7. Out of the 8 auxiliary register
only one is active at a time. This active auxiliary register concept is used when accessing the
memory indirectly through auxiliary register. The current auxiliary register is indicated by the bits
13-15 of STS0. When bits 13-15 is 000 the active auxiliary register is AR0, when bits 13-15 is
111 the AR7 is the current auxiliary register and so on. These three bits are called auxiliary
register pointer. The auxiliary register pointer can be set using the instruction LARP. For
example LARP 3, selects AR3 as active auxiliary register.
PROGRAM DESCRIPTION:
The following program initializes the Status Register 0 of TMS320LF2407A. The Data page
pointer is set as 0. Overflow mode is disabled and the Auxiliary register 0 is selected as current
Auxiliary register.
PROGRAM LISTING:
CONCLUSION:
Verify that the content of status register 0 is stored at data memory location 8000H.
AIM:
THEORY:
STATUS REGISTER 1:
The bits 0-1 of STS1 are to set the Product Shift Mode (PM). In TMS320LF2407A, the output
of the multiplier is stored in P register. This P register is of 32-bit wide. The content of the P
register can be transferred to the accumulator. When the PM bits are 00, the content of P register
is transferred to accumulator as it is. When PM bits are 01, the content of P register is left shifted
by one-bit and the result is transferred to accumulator. When PM = 10, the P register is left
shifted by 4 bits and the results is transferred to accumulator. When PM = 11, the P register is
right shifted by six bits and the result is transferred to accumulator. The shifting of bits is useful
in DSP algorithms, which we will consider later. The instruction SPM will set the PM bits.
Bit 4 denoting `XF' indicates the status of the XF pin of the processor.
Bit 9 of STS1 is carry bit. This bit is set to 1 if the result of addition in accumulator generates a
carry or reset to 0 if the result of subtraction generates a borrow. The instruction SC sets the
carry bit deliberately and RC reset the carry bit.
Bit 10 of STS1 is Set Sign extension Mode bit (SXM). When the accumulator is loaded with data
from data memory, the data can shifted on-the-way. The SXM bit decides the mode of shifting.
When SXM is 1, the shifter extends the sign of the data. When SXM = 0, no extension occur.
The instruction SSXM set the SXM bit and the instruction RSXM reset the SXM bit.
Bit 11 of STS1 is Test/Control Flag bit. Bit 12 is Configure memory block bit (CNF). The on
chip data memory block 100 to 2FF can be configured as program memory also. When CNF bit
is 0 the data memory block 100 to 2FF is configured as data memory and when CNF is 1 the data
memory block can be accessed as program memory with address FF00 to FFFF. When mapped
as program memory user cannot use the data memory address 100 to 2FF. The instruction
"SETC CNF" configures the block as program memory and the instruction "CLRC CNF"
configures it as data memory.
Bit 13-15 of STS1 are the Auxiliary register buffer ARB. Whenever the ARP of STS0 is loaded,
the old value of ARP is copied to ARB.
PROGRAM DESCRIPTION:
The following program initializes the Status Register 1 of TMS320LF2407A. The SPM bits are
reset to 00, on-chip block of memory is configured as data memory and the sign extension mode
is set.
PROGRAM LISTING:
CONCLUSION:
Verify that the content of status register 1 is stored at data memory location 9000. Verify that
the bits 0 and 1 of dma 8000 is 00, bit 10 is 1 and bit 12 is 1.
DMA CONTENT
9000 15AC
AIM:
THEORY:
Scaling is shifting the data right or left. Let us shift the constant 40. The left shift of one bit gives
the result 80 and right shift of one bit gives the result 20.
01000000 -> 40
Left Shift 10000000 -> 80
Right Shift 00100000 -> 20
Thus, the shift of a bit left is usually considered as multiplication by constant two and one bit right
shift is considered as division by constant two.
In TMS320LF2407A, accumulator is involved in all arithmetic and logic operations, say, for
example to add two numbers one number is in accumulator and the other number is in data
memory. After addition the result is stored in the accumulator. During addition overflow may
occur in accumulator. To prevent the overflow, shifter is provided in the accumulator input and
output. The accumulator input shifter left-shift the input data by a value of 0 to 16. The
accumulator is 32-bit width, and is spilt into two 16-bit registers using LACC THIRD(0002),F.
Shifters are available at the output of LACC THIRD(0002),F and LACC FIRST(0000),10. Both
the shifters shift the data by 0 to 7 places left.
PROGRAM DESCRIPTION:
The program given below add three number FFFE, 1 and 80. These numbers are stored in data
memory locations 9000, 9001 and 9002. The instruction LACC THIRD(0002),F loads the
accumulator with the third data 80 with 15-bit left shift. Note that the shifting of data 80 is done
on-the-way from data memory to accumulator. There is no need to implement a separate
instruction for shifting, the load instruction itself will do the shifting automatically. This is the
speciality of TMS320LF2407A. After shifting the data 80 by 15-bits left, the content of
accumulator is as shown below:
ACCH ACCL
+))))))))))))))))))), +))))))))))))))))))),
40 00
The higher-order accumulator holds the data 40 and the lower order accumulator holds the data
00. Thus the shifting of data 80 by 15-positions left is equivalent to shifting the data by 1-bit right
and storing the result in higher order accumulator. The data 40 in LACC THIRD(0002),F is
stored in data memory location 8003.
The next instruction LACC FIRST(0000), 0 loads the accumulator with data in data memory
8000 with no shift. The next instruction adds the accumulator with data in data memory 9001 and
store the result in accumulator. The accumulator content is stored in data memory location 9000.
The instruction LACC FIRST(0000),F loads the data at data memory location 9000 into
accumulator with 15 bit left shift. This amount to 1-bit right shift and storing the data in higher
order accumulator. Now the shifted data in higher order accumulator is added with the data at
location 9003. The ADD2,10H instruction adds the data memory content with theLACC
THIRD(0002),10H. The result is again stored back to data memory address 9000.
PROGRAM LISTING:
RESULT:
AIM:
THEORY:
The LTA instruction is equivalent to two instructions: LT and APAC. The LT instruction loads
the T register from data memory and APAC instruction adds the content of P register with
accumulator and stores the result in accumulator. In DSP applications we usually encounter the
computation of following type:
PROGRAM DESCRIPTION:
The following program implements the multiplication A*x1 + B*x2 + C*x3. The constants A,
B, C, x1, x2 and x3 are to be stored in dma from 9000 to 9005 as shown below:
PROGRAM LISTING:
RESULT:
AIM:
THEORY:
The LTD instruction is equivalent to three instructions: LT, DMOV and APAC. The DMOV
instruction moves the content of dma to the next higher address. The LT instruction loads the
T register from data memory and APAC instruction adds the content of P register with
accumulator and stores the result in accumulator.
The LTD instruction is used to implement the Digital Filtering algorithms. The digital filtering
algorithm works with two set of data : one, the set of data to be filtered and the other, the filter
coefficients ( to be precise "impulse response coefficients"). For simplicity, let us assume that the
filter coefficients are of length 3. We call this coefficients as H(0), H(1) and H(2). We also
assume that the data to be filtered can be inputted from a port continuously. For the data to be
filtered, allocate three memory locations, let us call this X(0), X(1) and X(2).
Initialize the location X(0), X(1) and X(2) to zero. Input the data from port and store in X(0).
Multiply X(0) with H(0), X(1) with H(1) and X(2) with H(2) and sum up the results. This is our
first output. Before inputting the next data from port move, the content of X(1) to X(2) and X(0)
to X(1). The old value of X(2) is discarded. Input the data from port and store in X(0). Now
implement the multiplication and sum up and output the result. This process goes on continuing.
Note that in every loop, the location X(0) is always meant for new data from port. The old value
of X(0) is moved to X(1) and the old value of X(1) is moved to X(2) and the old value of X(2)
is discarded. Thus, in digital filtering three basic operations are involved: multiplication of input
data with coefficients, addition and the data movement.
With TMS320LF2407A all the three operations of multiplication, addition and data movement
can be implemented with two instructions: LTD and MPY instructions. While the multiplication
is implemented using MPY instruction, the addition and data movement can be done using LTD
instruction.
NOTE: Data memory will take place only in on-chip memory blocks.
PROGRAM DESCRIPTION:
In the following program, the data memory location XN(0000H) meant for the current sample,
XNM1(0001H) for the previous sample and XNM2(0002) for the sample previous to XNM1.
The first set of multiplication LT XNM2 and MPY H2 multiplies the two operands and the result
is in the P register. The next pair of instructions LTD XNM1 and MPY H1(0004H) multiplies
the two operands and add the result with the previous result with accumulator. Since initially the
accumulator is zero accumulator now holds the result of x(n-2)h(2). The LTD XNM1 instruction
also moves the content of XNM1 to XNM2. The next instruction pair LTD XN and MPY
H0(0005), first add the P register to accumulator so now accumulator holds the result of
x(n-2)h(2)+x(n-1)h(1), multiplies XN and H0 and moves the content of XN to XNM1. The
APAC result sum up the remaining product terms and the result is stored in data memory location
YN(0006).
PROGRAM LISTING:
RESULT:
AIM:
Repeat the execution of particular instruction upto "N" times using RPT instruction.
THEORY:
RPT instruction is an immediate addressing mode instruction. The eight bit constant N specified
by the RPT instruction is loaded in to the Repeat counter of TMS320LF2407A. This causes the
instruction following RPT instruction to be executed N+1 times. This instruction is especially
useful for repeating instructions, such as BLKP, BLKD, IN, MAC, MACD, NORM, OUT,
TBLR, TBLW, etc.
PROGRAM DESCRIPTION:
In order to illustrate the RPT instruction, in this example, the value 3 is added 10 times
continuously and the result is stored in data memory location 9000. Initially, the value 3 is stored
in data memory location 9000. The repeat counter is loaded with 9 using RPT instruction. The
following instruction adds content of data memory address 9000 with the accumulator ten times.
The result is stored in data memory address 9000.
Before executing the program set the data memory as given below.
PROGRAM LISTING:
RESULT:
AIM:
Transfer of nine words from data memory to program memory using TBLW instruction.
THEORY:
The TBLW instruction transfers a word from a location in data memory to a program memory
location. In order to execute the transfer, the program memory and data memory address must
be specified. The program memory address is defined by accumulator. The data memory address
is directly or indirectly specified in the TBLW instruction.
When in the repeat mode, TBLW effectively becomes a single-cycle instruction. In repeat mode,
the content of the accumulator is incremented once each cycle, thus automatically pointing the
next program memory address.
PROGRAM EXPLANATION:
In this program, the nine words of data memory from data memory address 9000 to 9008 is
transferred to the program memory D100 to D108.
The source and destination addresses are 9000 and D100. The auxiliary register 0 (AR0) is
loaded with data 8 for loop counting. AR1 is loaded with the source pointer 9000 and the
accumulator is loaded with the source address D100.
The instruction MAR *, AR1 select AR1 as current auxiliary register. The following instruction
TBLW *+,0 transfer the content of the data memory address specified by the current auxiliary
register (i.e., dma 9000)to program memory specified by the Accumulator (i.e., the address
D100). The instruction ADD #1, increment the accumulator by one, so that it point to next
program memory on next loop. The BANZ instruction implements the TBLW operation for 9
times.
Before executing the program, substitute the data memory with the data as shown below:
PROGRAM LISTING:
RESULT:
After executing the program, check the program memory content from D200 to D208 USING
SP COMMAND for the following result.
AIM:
THEORY:
The BIT instruction copies the specified bit of the data memory content to the TC-bit of status
register STS1. The BCND instruction checks the TC-bit of STS1. If TC is set then the control
passes to the address specified by the BCND instruction otherwise the instruction next to BCND
is executed.
PROGRAM EXPLANATION:
In this example, AR1 is selected as current auxiliary register and the data memory address 9000
is stored in AR1. The instruction BIT *,8, test the eighth bit of the content of data memory
location 9000. If the eighth bit is zero, then the program sequence jumps to the label NEXT and
the value 0 is stored onto the data memory location 9001. If the eighth bit of data memory
location is 1, then the instruction next to BCND is executed, which actually stores the data 1 in
data memory 9001.
To edit and execute the program, go through chapter 4. Verify the results for both cases.
CASE (i) : Set the data memory address 9000 with FFFF.
CASE (ii): Set the data memory address 9000H with FF7FH.
PROGRAM LISTING:
RESULT:
Verify that the value 1 is stored in data memory location 9001, in case loading data in 9000H as
FFFF.
Verify that the value 0 is stored in data memory location 9001, in case loading data in 9000H as
FF7F.
AIM:
THEORY:
CMPL instruction replaces the content of accumulator with its logical inversion (one's
complement). By adding one with a one's complement number we will get the two's complement
of a number.
PROGRAM DESCRIPTION:
In this program, the accumulator is loaded with data 5. The CMPL instruction complements the
accumulator value and the result is FFFA. Now, add one with accumulator which gives the result
as FFFB. This is the two's complement of 5 and the result is stored in data memory location
9000.
PROGRAM LISTING:
RESULT:
CHAPTER - 6
GETTING STARTED WITH BASIC EXAMPLES
ON SERIAL MONITOR MODE
This chapter mainly described about how to construct the TMS320LF24077A assembly program
in Serial Monitor Mode for Arithmetic manipulations and usage of instruction of
TMS320LF2407A processor.
Connect the serial monitor cable from COM2 (P2) of Micro-2407A kit to the serial port COM1
or COM2 of PC XT/AT (prefer COM1 for default selection). Now execute communication
software (XTALK.EXE) in PC.
Power on the Micro-2407A Kit with all its set up ready and enter the following command at the
prompt.
Micro-2407A Trainer
#SM
Press the enter key to enter into serial monitor mode and the screen displays the following
message
SERIAL MODE 1....
Now enter "HE" to view the help menu of the serial monitor.
To assemble the program given in the examples enter "AS" at the prompt and press the Enter
Key, the screen displays the following message.
Vi Microsystems
Microsystems Pvt. Ltd., [6-1]
MICRO - 2407A USER MANUAL EXAMPLES ON SERIAL MONITOR MODE
Now enter the program memory starting address "C000H" and press Enter Key. Now the screen
display next consequent message as
C000H
Enter the mnemonics of the program sequentially viewing opcodes of the respective mnemonics
after pressing enter key.
On completion of assembling enter dot (.) and press the enter key to come out to prompt.
To execute the program use the command "GO C000" and press the Enter Key, where C000 is
program memory starting address.
To abort the execution, press the reset switch once to reset the Micro-2407A Kit. Now enter
"SM" in Micro-2407A trainer to re-enter into serial mode. To verify the execution, dump the data
memory from 9000H to A000H using "DD" command. This operation is same as Line assembler
in standalone mode.
Note: 1) At any occasion to abort the serial monitor from the execution of the program press
the reset switch of Micro-2407A kit.
2) To quit of serial monitor mode enter "QU" at the prompt and press enter key.
Method 3:
Edit assembly program using any editor like Edit, Notepad etc., the program is then assembled
and converted to corresponding "BIN" and "ASC" formats, which can be transferred to the kit,
using serial communication packages like DATACOM.EXE, or XTALK.EXE etc.
Before going to download the program from the host to M2407A kit. We should have to convert
ASM files into ASCII files. The ways to use like that:
ii) Then, to convert “ASM” file into “ASCII” file type assemble test (if the file name is “test.asm
in dos mode). If the Assemble .Bat file which utilizes the DSPA.EXE, DSPLINK.EXE,
DSPHEX.EXE, MPOBIN.EXE and BIN2ASC files. More details, please refer Technical
Reference. Please make the path of the source program and conversion utilities in the same
folder before converting to ASCII file.
iii) To download ASC files to M2407A kit use XTALK.EXE communication software
XTALK:
i) Before going to communicate with a XTALK software, we must do some initial setup. The
ways to use like this
Vi Microsystems
Microsystems Pvt. Ltd., [6-2]
MICRO - 2407A USER MANUAL EXAMPLES ON SERIAL MONITOR MODE
a) Enter C:\>XTALK and you are viewing tree chart as shown below.
b) To change the contents in the scroll bar, which is under the Tree, chart, Enter ESC key
and enter the following commands respectively.
1. SP 96 <CR>
2. IN OFF <CR>
3. OU OFF <CR>
Finally 4. GO LO <CR>
c) After entering GO LO command in the scroll bar, In addition, to initiate serial mode of
M2407A, Enter `SM' command in the kit.
It will start to interact with host and M2407A kit. Then the following message with
prompt will be displayed in the monitor.
d) Then to download the ASC files intoM2407A kit, enter as #PI C000, in command
window.
#PI C000.
Downloading from the host...
f) Next you have to send the ASC files as such away to enter ESC key and type the
command as SE TEST.ASC and enter it.
#PI C000
Downloading from the host....
Sending TEST.ASC file
#
#
#
Vi Microsystems
Microsystems Pvt. Ltd., [6-3]
MICRO - 2407A USER MANUAL EXAMPLES ON SERIAL MONITOR MODE
h) After sending the ASC files into M2407A, enter GO C000 to execute the program
TEST.ASM
i) Reset the M2407A kit and to see the data which is stored in between 9000 to A000
memory location, enter as #SD 9000.
Note:
i) If you will happen to specify the sampling rate = 80 Khz in program for understanding
purpose
It must write as
ii) In every program you should include the memory mapped registers as
.mmregs
.text
iii) To assign memory address for our convenient name, we just write as convenient name
.SET Address
Vi Microsystems
Microsystems Pvt. Ltd., [6-4]
MICRO - 2407A USER MANUAL EXAMPLES ON SERIAL MONITOR MODE
ii) ADC:
iii) Arithmat:
iv) Assemble:
v) Test:
It is only for user purpose, whereas the user can user this directory for their assemble
the assembly language of TMS320LF2407A processor using Cross assembler EXE
files and store the files in this directory.
ARITHMETIC MANIPULATIONS:
AIM:
THEORY:
Numerical analysis, floating point computations or other operations may require arithmetic to be
executed with more than 32-bits of precision. Since, the TMS320LF2407A is 16-bit fixed-point
processor, software is required for the extended precision of arithmetic operations. For proper
operation, the overflow mode bit should be reset (OVM = 0) so that the accumulator result will
not be loaded with the saturation value.
Vi Microsystems
Microsystems Pvt. Ltd., [6-5]
MICRO - 2407A USER MANUAL EXAMPLES ON SERIAL MONITOR MODE
X3 X2 X1 X0
+ Y3 Y2 Y1 Y0
W3 W2 W1 W0
Where all the numbers X3, X2, X1, X0, Y3, Y2, Y1 & Y0 are 16-bit numbers.
TMS320LF2407A has provision to add two 32-bit numbers, so we can add X1 X0 with Y1 Y0.
But how can we add 32-bit numbers X3 X2 X1 X0 with Y3 Y2 Y1 Y0.
TMS320LF2407A has two features that help to make extended precision calculation more
efficient. One of the feature is the carry status bit. The carry bit is set whenever the addition of a
value from the input scaling shifter or the P-register to the accumulator content generated a carry
out of bit 31. Otherwise, the carry bit is reset since the carry out of bit 31 is zero. One exception
to this case is that ADDH instruction which can only set the carry bit. This allows the
accumulator to generate proper single carry when either the addition to the lower or upper half of
the accumulator actually causes the carry.
The other feature which eases the extended-precision addition is the ADDH instruction. ADDH
instruction adds the 16-bit data memory content to the higher part of accumulator.
PROGRAM EXPLANATION:
In this example, the X operand X3 X2 X1 X0, is made of 16-bit numbers X3, X2, X1 and X0,
with X3 the most significant 16-bits and X0 the least significant 16-bits. The Y operand is Y3 Y2
Y1 Y0, where Y3 is the most significant 16-bits and Y0 is the least significant 16-bits. On
addition, both the operands result in W3 W2 W1 W0.
X-Operand: X3 X2 X1 X0
5432 1098 7654 3210
Y-Operand: Y3 Y2 Y1 Y0
0123 4567 8901 2345
Result: W3 W2 W1 W0
5555 55FF FF55 5555
Vi Microsystems
Microsystems Pvt. Ltd., [6-6]
MICRO - 2407A USER MANUAL EXAMPLES ON SERIAL MONITOR MODE
First load X1 in higher accumulator using LACC instruction and add X0 with accumulator by
using ADDS instruction. Now, the whole 32-bit of X1 X0 is in accumulator. Add Y0 with sign
extension suppressed using ADDS instruction and in the same way Y1 is added to the higher part
of accumulator using ADDH instruction. The result of 0-15 bits are stored in data memory as
W0 and 16-31 bits are stored in data memory as W1.
The next section adds the 32-bit numbers X2 X3 and Y2 Y3, and the result is stored in data
memory as W2 and W3.
9000 3210
9001 7654
9002 1098
9003 5432
9004 2345
9005 8901
9006 4567
9007 0123
To edit and execute the program, go through the topic program and execution.
PROGRAM LISTING:
START: FUNCTION
Vi Microsystems
Microsystems Pvt. Ltd., [6-7]
MICRO - 2407A USER MANUAL EXAMPLES ON SERIAL MONITOR MODE
LDP #120H
;OPERATION UP TO 1'ST 32 BITS
LACC X1,16 ;ACC=X1 00
ADDS X0 ;ACC=X1 X0
ADDS Y0 ;ACC=X1 X0 +00 Y0
ADDH Y1 ;ACC=X1 X0 +Y1 Y0
SACL W0 ;ACCL =W0
SACH W1 ;ACCH=W1
;OPERATION UP TO 2ND 32 BITS
LACC X3,16 ;ACC=X3 00
ADDC X2 ;ACC=X3X2+CARRY
ADDS Y2 ;ACC=X3X2+00 Y2+CARRY
ADDH Y3 ;ACC=X3X2+Y3Y2+CARRY
SACL W2 ;ACCL=W2
SACH W3 ;ACCH=W3
H: B H
.END
RESULT:
9008 5555
9009 FF55
900A 55FF
900B 5555
AIM:
THEORY:
Similar to extended-precision addition, the carry bit of the TMS320LF2407A is reset whenever
the input scaling shifter or the P-register value subtracted from the accumulator content generates
a borrow into bit 31. Otherwise, the carry bit is set, since, no borrow into bit-31 is required.
One exception to this case is the SUBH instruction which can only reset the carry bit. This allows
the generation of the proper single carry when either the subtraction from the lower or upper half
of the accumulator actually causes the borrow.
Vi Microsystems
Microsystems Pvt. Ltd., [6-8]
MICRO - 2407A USER MANUAL EXAMPLES ON SERIAL MONITOR MODE
In this example two 64-bit numbers X and Y are subtracted to give the result W as:
X3 X2 X1 X0
- Y3 Y2 Y1 Y0
-------------------------------
W3 W2 W1 W0
-------------------------------
PROGRAM EXPLANATION:
X3 X2 X1 X0
2222 2222 2222 2222
Y3 Y2 Y1 Y0
1111 1111 1111 1111
-
W3 W2 W1 W0
1111 1111 1111 1111
-
First, the X1 and X0 are loaded in accumulator using LACC and ADDS instruction then Y0 and
Y1 are subtracted with accumulator and the results are stored in W0 and W1. In the same fashion
Y3 Y2 is subtracted from X3 X2.
To edit and execute the program, go through the topic program and execution.
9000 2222
9001 2222
9002 2222
9003 2222
9004 1111
9005 1111
9006 1111
9007 1111
Vi Microsystems
Microsystems Pvt. Ltd., [6-9]
MICRO - 2407A USER MANUAL EXAMPLES ON SERIAL MONITOR MODE
PROGRAM LISTING:
9008 1111
9009 1111
900A 1111
900B 1111
Vi Microsystems
Microsystems Pvt. Ltd., [ 6 - 10 ]
MICRO - 2407A USER MANUAL EXAMPLES ON SERIAL MONITOR MODE
AIM:
THEORY:
With fixed point DSP, the fractional numbers are represented in Q15 format. Q-format is a
number representation commonly used when performing operations on non-integer numbers. In a
Q-format, the Q-number (15 in Q15) denotes how many bits are located to the right of the binary
point.
For example a 16-bit Q number has a assumed binary point, a sign bit, i integer bits and 15-i
fractional bits as shown below:
0 0000010 10100000
Fraction Part
Binary Point
Integer Part
Sign
has a value of 2.625. This particular number is said to be represented in a Q8 format (8 factorial
bits). Its range is between - 128 (10000000000000000) and 127.996 (01111111111111111).
The factorial accuracy of a Q8 number is about 0.004 (one part in 28 or 256).
It is more common to work entirely with fractions represented in a Q15 format or integers in Q0
format. This is especially true for signal processing algorithms where multiply and accumulate
operations and dominant. The result of a fraction times a fraction remains a fraction and the result
of an integer times and integer remains an integer. No overflow occurs in this case. For example,
multiplication of two Q15 numbers result in a Q30 number.
The fraction 0.5 is represented as 8000 in Q15 format. The multiplication of two Q15 numbers
result in a Q30 number as shown below.
Vi Microsystems
Microsystems Pvt. Ltd., [ 6 - 11 ]
MICRO - 2407A USER MANUAL EXAMPLES ON SERIAL MONITOR MODE
TMS320LF2407A supports the fractional multiplication. The multiplication of two Q15 numbers
is implemented in the same way as integer multiplication except that the result is left shifted by
one-bit left as shown in the following code excerpt:
PROGRAM DESCRIPTION:
The following program implement the multiplication 0.5 x 0.5 = 0.25. The fraction 0.5 is
represented in Q15 format and the result is in Q15 format.
To edit and execute the program, go through the topic program and execution.
PROGRAM LISTING:
OP1 .SET 0
OP2 .SET 1
RES .SET 2
.TEXT
.MMREGS
START:
LDP #120H
LACC #04000H
SACL OP1
SACL OP2
LT OP1 ;T=4000
MPY OP2 ;P=4000*4000 = 1000 0000
PAC ;ACC=1000 0000
SACH RES,1 ;RES=2000
H: B H
.END
RESULT:
9002 2000
Vi Microsystems
Microsystems Pvt. Ltd., [ 6 - 12 ]
MICRO - 2407A USER MANUAL EXAMPLES ON SERIAL MONITOR MODE
AIM:
THEORY:
The TMS320LF2407A hardware multiplier normally perform two's complement 16-bit by 16-bit
multiplies and produces a 32-bit result in a single processor cycle. To multiply two operands, one
operand must be loaded into the T-register. The second operand is moved by the multiply
instruction to the multiplier, which then produces the product in the P-register. Before another
multiply can be performed, the content of the P-register should be moved to the accumulator or
should be stored in data memory.
PROGRAM EXPLANATION:
The following program stores the data 37A at data memory 9000 and the data 12E at the data
memory address 9001. The instruction LT OP1 loads the first operand from dma 8000 to T
register. The instruction MPY OP2 multiplies the content of dma 9001 with the T register. The
result is stored in P register. The instruction PAC transfers the content of P register to
accumulator. The SACL and SACH instructions store the lower and higher order results in dma
9002 and 9003.
To edit and execute the program, go through the topic program and execution.
PROGRAM LISTING:
;INTEGER MULTIPLICATION
OP1 .SET 0
OP2 .SET 1
RESL .SET 2
RESH .SET 3
.TEXT
.MMREGS
START:
LDP #120H
LACC #037AH
SACL OP1
LACC #012EH
SACL OP2
LT OP1 ;T=37A
Vi Microsystems
Microsystems Pvt. Ltd., [ 6 - 13 ]
MICRO - 2407A USER MANUAL EXAMPLES ON SERIAL MONITOR MODE
RESULT:
The results are stored in data memory locations 8002 and 8003 as shown below.
9002 19EC
9003 0004
EXAMPLE 5 - DIVISION:
AIM:
To divide two binary two's complement numbers of any sign where the numerator is less than
denominator.
THEORY:
Binary division is the inverse of multiplication. Multiplication consists of a series of shift and add
operations, while division can be broken into a series of subtracts and shifts. Although the
TMS320LF2407A does not have an explicit divide instruction, it is possible to implement an
efficient, flexible divide capability using the conditional subtract instruction, SUBC.
SUBC implements binary division in the same manner as is commonly done in long division.
Given a 16-bit positive dividend and divisor, the repetition of the SUBC command 16 times
produces 16-bit quotient in the low accumulator and a 16-bit remainder in high accumulator.
With each SUBC, the divisor is left-shifted 15 bits and subtracted from the accumulator. For each
subtract not producing a negative answer, a one is put in the LSB of the quotient and then shifted.
For each subtract producing a negative answer, the accumulator is simply left-shifted. The
shifting of the remainder and quotient after each subtract produces the separation of the quotient
and remainder in the low and high halves of the accumulator. The similarities between long
division and the SUBC method of division are shown below where 33 is divided by 5.
Vi Microsystems
Microsystems Pvt. Ltd., [ 6 - 14 ]
MICRO - 2407A USER MANUAL EXAMPLES ON SERIAL MONITOR MODE
Long Division:
0000000000000110 Quotient
0000000000000101 0000000000100001
-101
110
-101
11 Remainder
SUBC Method:
000000000000000 1010000000000000
1
15) Result is again positive. Shift result left
000000000000001 0100000000000001 and replace LSB with 1.
1 1000000000000000
-10
000000000000000 1100000000000001
0
1000000000000011 16) Last subtract. Negative answer, so discard
000000000000000 1000000000000000 result and shift ACC left.
1
-10
- 1111111111111101
REMAINDER QUOTIENT
Vi Microsystems
Microsystems Pvt. Ltd., [ 6 - 15 ]
MICRO - 2407A USER MANUAL EXAMPLES ON SERIAL MONITOR MODE
The condition of the divisor, less than the shifted dividend, is determined by the sign of the result.
The only restriction for the use of the SUBC instruction is that both the dividend and divisor
MUST be positive. Thus, the sign of the quotient must be determined and the quotient computed
using the absolute value of the dividend and divisor. In addition, when implementing a divide
algorithm, it is important to know if the quotient can be represented as a fraction and the degree
of accuracy to which the quotient is to be computed. Each of these considerations can affect how
the SUBC instruction is used. Not that the next instruction after SUBC cannot use the
accumulator.
PROGRAM EXPLANATION:
The program given below checks the sign of the quotient and stores the sign in data memory.
After eliminating the sign make both operands positive by using ABS instruction. As explained in
theory part, execute SUBC instruction 15 times using RPT. Now the quotient is in lower
accumulator and remainder is in higher accumulator.
To edit and execute the program, go through the topic program and execution.
Enter numerator value of 15 in data memory 9000 and denominator value as 24 in 9001 as:
9000 15
9001 24
PROGRAM LISTING:
Vi Microsystems
Microsystems Pvt. Ltd., [ 6 - 16 ]
MICRO - 2407A USER MANUAL EXAMPLES ON SERIAL MONITOR MODE
ABS
SACL DMR
LACC NMR ;MAKE NUMERATOR +'VE
ABS
;DIVIDE LOOP
RPT #15 ;16 CYCLE DIVIDE LOOP
SUBC DMR
SACL QUOT
SACH REM
LACC SIGN
BCND H,GEQ ;TEST SIGN
LACL #0
SUB QUOT ;NEGATE QUOTIENT
SACL QUOT ;STORE QUOTIENT
H: B H
.END
RESULT:
9002 1
9003 F
AIM:
THEORY:
TMS320LF2407A has three status registers called STS0, STS1 and PMST. All the three status
registers are of 16-bit wide. These registers contain the status of various conditions and modes of
TMS320LF2407A. The function of status register 0 bits is shown below:
Vi Microsystems
Microsystems Pvt. Ltd., [ 6 - 17 ]
MICRO - 2407A USER MANUAL EXAMPLES ON SERIAL MONITOR MODE
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
STATUS REGISTER 0:
The bits 0-8 of STS0 are called Data Page Pointer. TMS320LF2407A can address 64KW of data
memory. This whole data memory is divided into 512 pages, with each page of length 128 words.
Out of the 512 pages only one page is active at a time. This active page concept is used only
when accessing the memory using the Direct addressing mode. The active page is indicated by
the Data Page Pointer. The Data Page Pointer can be loaded using the instruction LDP. The
LDP instruction loads an immediate value onto the Data Page Pointer.
Bit 9 of STS0 is Interrupt Mode bit (INTM). When this bit is 1, all maskable interrupts are
disabled. When this bit is 0, all maskable interrupts are disabled. This bit can be set by SETC
instruction and reset by CLRC instruction.
Bit 10 is always 1. Bit 11 controls the Overflow Mode of the accumulator. This bit is called
OVM bit. When 0, overflowed results overflow normally in accumulator. When this bit is 1, and
when overflow occur in accumulator, the accumulator is set to either most positive or negative
value upon encountering the overflow. This bit can be set to 1 by SOVM instruction and reset to
0 by ROVM instruction.
Bit 12 of STS0 is overflow flag bit. This bit indicates the status of accumulator overflow. When
overflow occurs in accumulator this bit is set.
TMS320LF2407A have 8 auxiliary registers called AR0 to AR7. Out of the 8 auxiliary register
only one is active at a time. This active auxiliary register concept is used when accessing the
memory indirectly through auxiliary register. The current auxiliary register is indicated by the bits
13-15 of STS0. When bits 13-15 is 000 the active auxiliary register is AR0, when bits 13-15 is
111 the AR7 is the current auxiliary register and so on. These three bits are called auxiliary
register pointer. The auxiliary register pointer can be set using the instruction LARP. For
example LARP 3, selects AR3 as active auxiliary register.
PROGRAM DESCRIPTION:
The following program initializes the Status Register 0 of TMS320LF2407A. The Data page
pointer is set as 0. Overflow mode is disabled and the Auxiliary register 0 is selected as current
Auxiliary register.
To edit and execute the program, go through the topic program and execution.
PROGRAM LISTING:
Vi Microsystems
Microsystems Pvt. Ltd., [ 6 - 18 ]
MICRO - 2407A USER MANUAL EXAMPLES ON SERIAL MONITOR MODE
CONCLUSION:
Verify that the content of status register 0 is stored at data memory location 8000H.
9000 0600H
AIM:
THEORY:
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Vi Microsystems
Microsystems Pvt. Ltd., [ 6 - 19 ]
MICRO - 2407A USER MANUAL EXAMPLES ON SERIAL MONITOR MODE
STATUS REGISTER 1:
The bits 0-1 of STS1 are to set the Product Shift Mode (PM). In TMS320LF2407A, the output
of the multiplier is stored in P register. This P register is of 32-bit wide. The content of the P
register can be transferred to the accumulator. When the PM bits are 00, the content of P register
is transferred to accumulator as it is. When PM bits are 01, the content of P register is left shifted
by one-bit and the result is transferred to accumulator. When PM = 10, the P register is left
shifted by 4 bits and the results is transferred to accumulator. When PM = 11, the P register is
right shifted by six bits and the result is transferred to accumulator. The shifting of bits is useful in
DSP algorithms, which we will consider later. The instruction SPM will set the PM bits.
Bit 4 denoting `XF' indicates the status of the XF pin of the processor.
Bit 9 of STS1 is carry bit. This bit is set to 1 if the result of addition in accumulator generates a
carry or reset to 0 if the result of subtraction generates a borrow. The instruction SC sets the
carry bit deliberately and RC reset the carry bit.
Bit 10 of STS1 is Set Sign extension Mode bit (SXM). When the accumulator is loaded with data
from data memory, the data can shifted on-the-way. The SXM bit decides the mode of shifting.
When SXM is 1, the shifter extends the sign of the data. When SXM = 0, no extension occur.
The instruction SSXM set the SXM bit and the instruction RSXM reset the SXM bit.
Bit 12 is Configure memory block bit (CNF). The on chip data memory block 100 to 2FF can be
configured as program memory also. When CNF bit is 0 the data memory block 100 to 2FF is
configured as data memory and when CNF is 1 the data memory block can be accessed as
program memory with address FF00 to FFFF. When mapped as program memory user cannot
use the data memory address 100 to 2FF. The instruction "SETC CNF" configures the block as
program memory and the instruction "CLRC CNF" configures it as data memory.
Bit 13-15 of STS1 are the Auxiliary register buffer ARB. Whenever the ARP of STS0 is loaded,
the old value of ARP is copied to ARB.
PROGRAM DESCRIPTION:
The following program initializes the Status Register 1 of TMS320LF2407A. The SPM bits are
reset to 00, on-chip block of memory is configured as data memory and the sign extension mode
is set.
To edit and execute the program, go through the topic program and execution.
Vi Microsystems
Microsystems Pvt. Ltd., [ 6 - 20 ]
MICRO - 2407A USER MANUAL EXAMPLES ON SERIAL MONITOR MODE
PROGRAM LISTING:
CONCLUSION:
Verify that the content of status register 1 is stored at data memory location 8000. Verify that the
bits 0 and 1 of dma 8000 are 00, bit 10 is 1 and bit 12 is 1.
DMA CONTENT
9000 15AC
Vi Microsystems
Microsystems Pvt. Ltd., [ 6 - 21 ]
MICRO - 2407A USER MANUAL EXAMPLES ON SERIAL MONITOR MODE
AIM:
THEORY:
Scaling is shifting the data right or left. Let us shift the constant 40. The left shift of one bit gives
the result 80 and right shift of one bit gives the result 20.
01000000 -> 40
Left Shift 10000000 -> 80
Right Shift 00100000 -> 20
Thus, the shift of a bit left is usually considered as multiplication by constant two and one bit right
shift is considered as division by constant two.
In TMS320LF2407A, accumulator is involved in all arithmetic and logic operations, say, for
example to add two numbers one number is in accumulator and the other number is in data
memory. After addition the result is stored in the accumulator. During addition overflow may
occur in accumulator. To prevent the overflow, shifter is provided in the accumulator input and
output. The accumulator input shifter left-shift the input data by a value of 0 to 16. The
accumulator is 32-bit width, and is spilt into two 16-bit registers using LACC address, shift value:
. Shifters are available at the output of LACC FIRST,16 and LACC THIRD,15. Both the shifters
shift the data by 0 to 7 places left.
PROGRAM DESCRIPTION:
The program given below adds three number FFFE, 1 and 80. These numbers are stored in data
memory locations 9000, 9001 and 9002. The instruction LACC THIRD,15 loads the accumulator
with the third data 80 with 15-bit left shift. Note that the shifting of data 80 is done on the way
from data memory to accumulator. There is no need to implement a separate instruction for
shifting; the load instruction itself will do the shifting automatically. This is the speciality of
TMS320LF2407A. After shifting the data 80 by 15-bits left, the content of accumulator is as
shown below:
ACCH ACCL
40 00
Vi Microsystems
Microsystems Pvt. Ltd., [ 6 - 22 ]
MICRO - 2407A USER MANUAL EXAMPLES ON SERIAL MONITOR MODE
The higher-order accumulator holds the data 40 and the lower order accumulator holds the data
00. Thus the shifting of data 80 by 15-positions left is equivalent to shifting the data by 1-bit right
and storing the result in higher order accumulator. The data 40 in ACCH is stored in data memory
location 9003.
The next instruction LACC FIRST, 0 loads the accumulator with data in data memory 8000 with
no shift. The next instruction adds the accumulator with data in data memory 8001 and store the
result in accumulator. The accumulator content is stored in data memory location 8000.
The instruction LACC FIRST, 15 loads the data at data memory location 8000 into accumulator
with 15 bit left shift. This amount to 1-bit right shift and storing the data in higher order
accumulator. Now the shifted data in higher order accumulator is added with the data at location
8003. The ADDH instruction adds the data memory content with the LACC FIRST,16. The
result is again stored back to data memory address 8000.
To edit and execute the program, go through the topic program and execution.
PROGRAM LISTING:
; CONCEPT OF SCALING
FIRST .set 0
SECOND .set 1
THIRD .set 2
.mmregs
.text
START:
LDP #120H
LACC #0FFFEH
SACL FIRST
LACL #1
SACL SECOND
LACL #080H
SACL THIRD
LACC THIRD,15 ; ACC = 0040 0000
SACH THIRD
LACC FIRST ; ACCL = FFFE
ADD SECOND ; ACCL = FFFF
SACL FIRST
LACC FIRST,16 ; ACC = FFFF 0000
ADDH THIRD ; ACC = 003F FFFF
SACH FIRST
HERE: B HERE
.end
Vi Microsystems
Microsystems Pvt. Ltd., [ 6 - 23 ]
MICRO - 2407A USER MANUAL EXAMPLES ON SERIAL MONITOR MODE
RESULT:
AIM:
THEORY:
The LTA instruction is equivalent to two instructions: LT and APAC. The LT instruction loads
the T register from data memory and APAC instruction adds the content of P register with
accumulator and stores the result in accumulator. In DSP applications we usually encounter the
computation of following type:
PROGRAM DESCRIPTION:
The following program implements the multiplication A*x1 + B*x2 + C*x3. The constants A, B,
C, x1, x2 and x3 are to be stored in dma from 9000 to 9005 as shown below:
Vi Microsystems
Microsystems Pvt. Ltd., [ 6 - 24 ]
MICRO - 2407A USER MANUAL EXAMPLES ON SERIAL MONITOR MODE
9000 1
9001 2
9002 3
9003 4
9004 5
9005 6
PROGRAM LISTING:
LDP #120H
LACL #0
LT A ;T=1
MPY X1 ;P=1*4=4
LTA B ;ACC=4,T=2
MPY X2 ;ACC=4,P=2*5=A
LTA C ;ACC=E,T=3
MPY X3 ;ACC=E,P=3*6=12
APAC ;ACCL=0020
SACL RES
H: B H
.END
Vi Microsystems
Microsystems Pvt. Ltd., [ 6 - 25 ]
MICRO - 2407A USER MANUAL EXAMPLES ON SERIAL MONITOR MODE
RESULT:
9006 20
AIM:
THEORY:
The LTD instruction is equivalent to three instructions: LT, DMOV and APAC. The DMOV
instruction moves the content of dma to the next higher address. The LT instruction loads the T
register from data memory and APAC instruction adds the content of P register with accumulator
and stores the result in accumulator.
The LTD instruction is used to implement the Digital Filtering algorithms. The digital filtering
algorithm works with two set of data : one, the set of data to be filtered and the other, the filter
coefficients ( to be precise "impulse response coefficients"). For simplicity, let us assume that the
filter coefficients are of length 3. We call this coefficients as H(0), H(1) and H(2). We also
assume that the data to be filtered can be inputted from a port continuously. For the data to be
filtered, allocate three memory locations, let us call this X(0), X(1) and X(2).
Initialize the location X(0), X(1) and X(2) to zero. Input the data from port and store in X(0).
Multiply X(0) with H(0), X(1) with H(1) and X(2) with H(2) and sum up the results. This is our
first output. Before inputting the next data from port move, the content of X(1) to X(2) and X(0)
to X(1). The old value of X(2) is discarded. Input the data from port and store in X(0). Now
implement the multiplication and sum up and output the result. This process goes on continuing.
Note that in every loop, the location X(0) is always meant for new data from port. The old value
of X(0) is moved to X(1) and the old value of X(1) is moved to X(2) and the old value of X(2) is
discarded. Thus, in digital filtering three basic operations are involved: multiplication of input
data with coefficients, addition and the data movement.
With TMS320LF2407A all the three operations of multiplication, addition and data movement
can be implemented with two instructions: LTD and MPY instructions. While the multiplication
Vi Microsystems
Microsystems Pvt. Ltd., [ 6 - 26 ]
MICRO - 2407A USER MANUAL EXAMPLES ON SERIAL MONITOR MODE
is implemented using MPY instruction, the addition and data movement can be done using LTD
instruction.
NOTE: Data memory will take place only in on-chip memory blocks.
Vi Microsystems
Microsystems Pvt. Ltd., [ 6 - 27 ]
MICRO - 2407A USER MANUAL EXAMPLES ON SERIAL MONITOR MODE
PROGRAM DESCRIPTION:
In the following program, the data memory location XN meant for the current sample, XNM1 for
the previous sample and XNM2 for the sample previous to XNM1. The first set of multiplication
LT XNM2 and MPY H2 multiplies the two operands and the result is in the P register. The next
pair of instructions LTD XNM1 and MPY H1 multiplies the two operands and add the result with
the previous result with accumulator. Since initially the accumulator is zero accumulator now
holds the result of x(n-2)h(2). The LTD XNM1 instruction also moves the content of XNM1 to
XNM2. The next instruction pair LTD XN and MPY H0, first add the P register to accumulator
so now accumulator holds the result of x(n-2)h(2)+x(n-1)h(1), multiplies XN and H0 and moves
the content of XN to XNM1. The APAC result sum up the remaining product terms and the
result is stored in data memory location YN.
To edit and execute the program, go through the topic program and execution.
9000 1
9001 2
9002 3
9003 4
9004 5
9005 6
PROGRAM LISTING:
; USAGE OF LTDINSTRUCTION
XN .SET 0
XNM1 .SET 1
XNM2 .SET 2
H2 .SET 3
H1 .SET 4
H0 .SET 5
YN .SET 6
.MMREGS
.TEXT
START:
LDP #120H
LACL #0
LT XNM2 ;X(N-2)H(2)
Vi Microsystems
Microsystems Pvt. Ltd., [ 6 - 28 ]
MICRO - 2407A USER MANUAL EXAMPLES ON SERIAL MONITOR MODE
MPY H2
LTD XNM1 ;X(N-2)H(2)+X(N-1)H(1)
MPY H1
LTD XN ;X(N-20H(2)+X(N-1)H91)+X(N)H(0)
MPY H0
BE04 APAC
SACL YN
H: B H
.END
RESULT:
9006 1C
AIM:
Repeat the execution of particular instruction upto "N" times using RPT instruction.
THEORY:
RPT instruction is an immediate addressing mode instruction. The eight-bit constant N specified
by the RPT instruction is loaded in to the Repeat counter of TMS320LF2407A. This causes the
instruction following RPT instruction to be executed N+1 times. This instruction is especially
useful for repeating instructions, such as BLKP, BLKD, IN, MAC, MACD, NORM, OUT,
TBLR, TBLW, etc.
PROGRAM DESCRIPTION:
In order to illustrate the RPT instruction, in this example, the value 3 is added 10 times
continuously and the result is stored in data memory location 9000. Initially, the value 3 is stored
in data memory location 9000. The repeat counter is loaded with 9 using RPT instruction. The
following instruction adds content of data memory address 9000 with the accumulator ten times.
The result is stored in data memory address 9000. To edit and execute the program, go through
the topic program and execution.
Before executing the program set the data memory as given below.
Vi Microsystems
Microsystems Pvt. Ltd., [ 6 - 29 ]
MICRO - 2407A USER MANUAL EXAMPLES ON SERIAL MONITOR MODE
9000 0003
PROGRAM LISTING:
LDP #120H
LACL #3
SACL SUM
LACL #0 ;CLEAR ACC
RPT #9 ;SET REPEAT COUNT 9 TIMES
ADD SUM
SACL SUM
H: B H
.END
RESULT:
9000 001E
AIM:
Transfer of nine words from data memory to program memory using TBLW instruction.
THEORY:
The TBLW instruction transfers a word from a location in data memory to a program memory
location. In order to execute the transfer, the program memory and data memory address must be
specified. The program memory address is defined by accumulator. The data memory address is
directly or indirectly specified in the TBLW instruction.
When in the repeat mode, TBLW effectively becomes a single-cycle instruction. In repeat mode,
Vi Microsystems
Microsystems Pvt. Ltd., [ 6 - 30 ]
MICRO - 2407A USER MANUAL EXAMPLES ON SERIAL MONITOR MODE
the content of the accumulator is incremented once each cycle, thus automatically pointing the
next program memory address.
PROGRAM EXPLANATION:
In this program, the nine words of data memory from data memory address 9000 to 9008 is
transferred to the program memory D100 to D108.
The source and destination addresses are 9000 and D100. The auxiliary register 0 (AR0) is
loaded with data 8 for loop counting. AR1 is loaded with the source pointer 9000 and the
accumulator is loaded with the source address D100.
The instruction MAR *, AR1 select AR1 as current auxiliary register. The following instruction
TBLW *+,0 transfer the content of the data memory address specified by the current auxiliary
register (i.e., dma 9000)to program memory specified by the Accumulator (i.e., the address
D100). The instruction ADD #1, increment the accumulator by one, so that it point to next
program memory on next loop. The BANZ instruction implements the TBLW operation for 9
times.
Before executing the program, substitute the data memory with the data as shown below:
9000 1234
9001 5678
9002 9012
9003 3456
9004 7890
9005 1234
9006 5678
9007 9012
9008 3456
To edit and execute the program, go through the topic program and execution.
PROGRAM LISTING:
Vi Microsystems
Microsystems Pvt. Ltd., [ 6 - 31 ]
MICRO - 2407A USER MANUAL EXAMPLES ON SERIAL MONITOR MODE
LACL #0
LAR AR1,#SOURCE ;LOAD SOURCE ADD IN AR1
LACC #DEST ;LOAD DEST ADDRESS IN ACC
NEXT: MAR *,AR1
TBLW *+,AR0 ;MOVE DATA FROM DM TO PM AND
;ARP=AR0
ADD #1 ;INCREMENT PMA
BANZ NEXT,*- ;BRANCH UNTILL AR0=0
H: B H
.END
RESULT:
After executing the program, check the program memory content from D100 to D108 for the
following result.
D200 1234
D201 5678
D202 9012
D203 3456
D204 7890
D205 1234
D206 5678
D207 9012
D208 3456
AIM:
THEORY:
The BIT instruction copies the specified bit of the data memory content to the TC-bit of status
register STS1. The BCND instruction checks the TC-bit of STS1. If TC is set then the control
passes to the address specified by the BCND instruction otherwise the instruction next to BCND
is executed.
PROGRAM EXPLANATION:
Vi Microsystems
Microsystems Pvt. Ltd., [ 6 - 32 ]
MICRO - 2407A USER MANUAL EXAMPLES ON SERIAL MONITOR MODE
In this example, AR1 is selected as current auxiliary register and the data memory address 9000 is
stored in AR1. The instruction BIT *,8, test the eighth bit of the content of data memory
location 9000. If the eighth bit is zero, then the program sequence jumps to the label NEXT and
the value 0 is stored onto the data memory location 8001. If the eighth bit of data memory
location is 1, then the instruction next to BCND is executed, which actually stores the data 1 in
data memory 9001.
To edit and execute the program, go through the topic program and execution.. Verify the
results for both cases.
CASE (i) : Set the data memory address 9000 with FFFF.
CASE (ii): Set the data memory address 9000H with FF7FH.
PROGRAM LISTING:
LDP #120H
MAR *,AR1
LAR AR1,#09000H
LACL #1
SACL RES
B H
NEXT: LACL #0
SACL RES
H: B H
.END
RESULT:
Verify that the value 1 is stored in data memory location 9001, in case loading data in 9000 as
FFFF.
Vi Microsystems
Microsystems Pvt. Ltd., [ 6 - 33 ]
MICRO - 2407A USER MANUAL EXAMPLES ON SERIAL MONITOR MODE
Verify that the value 0 is stored in data memory location 9001, in case loading data in 9000 as
FF7F.
Vi Microsystems
Microsystems Pvt. Ltd., [ 6 - 34 ]
MICRO - 2407A USER MANUAL EXAMPLES ON SERIAL MONITOR MODE
AIM:
THEORY:
CMPL instruction replaces the content of accumulator with its logical inversion (one's
complement). By adding one with a one's complement number we will get the two's complement
of a number.
PROGRAM DESCRIPTION:
In this program, the accumulator is loaded with data 5. The CMPL instruction complements the
accumulator value and the result is FFFA. Now, add one with accumulator which gives the result
as FFFB. This is the two's complement of 5 and the result is stored in data memory location
9000.
To edit and execute the program, go through the topic program and execution.
PROGRAM LISTING:
LDP #120H
LACL #5 ;LOAD 5 TO ACC
CMPL ;COMPLEMENT ACC
ADD #1
SACL RES ;STORE 2'S COMPLEMENT RES
H: B H
.END
RESULT:
Vi Microsystems
Microsystems Pvt. Ltd., [ 6 - 35 ]
MICRO - 2407A USER MANUAL PWM GENERATION WITH LF2407A
CHAPTER - 7
PWM GENERATION WITH LF2407A
INTRODUCTION:
This chapter describes the LF2407A Event Manager (EV) Module, and also explain how to
generate PWM outputs (Symmetric and Asymmetric) using EV Module. The EV Manager
provides a broad range of functions and features that are particularly useful in motion control and
motor control applications. In this chapter programs are given for PWM signal generation. The
PWM signal is used to control the speed of the motors. The Analog-to Digital Converter (ADC)
is also dependent with motor control applications and so ADC is also described in this chapter.
Before going to in-depth of the event manager module, the PWM generation methods are
discussed.
For any analog or digital industrial drive, the desired voltage across the motor phases relates to
the output signals of the controller. “Pulse Width Modulation” is a technique to recreate these
desired waveforms from a DC voltage using a direct converter. The control technique consists in
first, changing the turn on and turn off time of this converter’s power switches but also in
controlling the strategy modifying these times. For the controller to generate the correct PWM
output that mimics a sine wave for example, it must use a carrier wave. In motor control
applications, the carrier wave is the signal used to generate the PWM signal (either triangular or
sawtooth). The PWM signal results from the comparison between the carrier wave and the
reference signal.
Figure
In the above figure, the current of a motor is converted into a controlled pulse width that is
proportional to the amplitude of the sine wave, so that it may become a sine wave on the average.
Figure shows the principle of the method. A comparator compares a triangular carrier wave
oscillating with constant frequency and amplitude, and the sine wave output from the current
amplifier.
As shown in the figure, extracting the portions where the value of the sine wave exceeds those of
the carrier wave outputs pulses of unequal widths. The duty ratio of the pulse width is increased
or decreased, centering around 50 percent by the sine wave and modulated to make a sine wave
on the average, because the inverter output is 0V when the duty ratio is 50 percent. It is
important to decide the method of selecting the oscillating frequency of the chopping waveform.
As the carrier frequency equals the switching frequency of the power transistor, it increases the
switching loss proportionally as it is made higher and it reduces the speed of response of the
motor as it is made lower. Further more, ripples appear more frequently, and the torque change
and the core losses are increased.
Generally, a carrier frequency of 1-3KHz is selected when the inverter consist of bipolar
transistors, and that of 5-20KHz when it consists of FETs. The current ripples developed at these
levels of frequency make the iron core of the motor vibrate. This generates unpleasant noises
when the frequency is within audio range.
In order to solve this problem, the carrier frequency is made 16KHz or more by using FETs.
Another means to solve the problem the generation of noises by moulding the iron core and the
coil of a motor into one body.
The shape and frequency of the phase currents and voltages and the amount of energy delivered to
the motor windings control the required speed and torque of the motor. The command voltage or
current to be applied to the motor is the modulating signal. The frequency of the modulating
signal is typically much lower than the PWM carrier frequency.
In many industrial applications, Sinusoidal Pulse Width Modulation (SPWM), also called Sine
coded Pulse Width Modulation, is used to control the inverter output voltage. SPWM maintains
good performance of the drive in the entire range of operation between zero and 78 percent of the
value that would be reached by square-wave operation. If the modulation index exceeds this
value, linear relationship between modulation index and output voltage is not maintained and the
over-modulation methods are required.
For efficient energy delivery to the motor, it is important that the correct inverter-switching
scheme is employed. Space vector pulse width modulation is one such switching scheme that
offers definite benefits over simpler and less efficient schemes like Sine PWM. It has been shown
that SVPWM has a higher DC bus utilization and reduced harmonic copper losses. For a given
DC link voltage output, SVPWM has the effect of boosting power output of a three-phase motor
by 16% as compared to a Sine PWM fed motor.
A different approach to SPWM is based on the space vector representation of voltages in the d, q
plane. The d, q components are found by Park transform, where the total power, as well as the
impedance, remains unchanged. Fig. 1 shows 8 space vectors in according to 8 switching
positions of inverter, V* is the phase-to-center voltage which is obtained by proper selection of
adjacent vectors V1 and V2.
The reference space vector V* is given by Equation (1), where T1, T2 are the intervals of
application of vector V1 and V2 respectively, and zero vectors V0 and V7 are selected for T0.
Fig. 3(a) shows that the inverter switching state for the period T1 for vector V1 and Fig. 3(b) is
for vector V2, resulting switching patterns of each phase of inverter are shown in Fig. 4.
In the above shown figure, U is the phaseto- center voltage containing the triple order harmonics
that are generated by space vector PWM, and U1 is the sinusoidal reference voltage. But the triple
order harmonics are not appeared in the phase-to-phase voltage as well. This leads to the higher
modulation index compared to the SPWM.
As mentioned above, SPWM only reaches to 78 percent of squarewave operation, but the
amplitude of maximum possible voltage is 90 percent of square-wave in the case of space vector
PWM. The maximum phase-to-center voltage by sinusoidal and space vector PWM are
respectively;
This means that Space Vector PWM can produce about 15 percent higher than Sinusoidal PWM
in output voltage.
Simulation results in Figure show that the higher modulation index is, the less the harmonics of
current and torque by space vector PWM are than those of sinusoidal PWM.
There are two identical event managers (EVA & EVB) on-chip in the LF2407A. All control
oriented features of the LF2407A are centered in the EV. The event manager peripheral is made
up of components such as timers and pulse width modulation generators. Since the two EVs
(EVA/EVB) are identical to one another in terms of functionality and register/bit definition, only
the EVA will be explained detail. The main difference between two EV module is both have
different register names and addresses.
Figure shows above the block diagram of EVA module. Like all peripherals, the EV registers
occupy a range of 16-bit memory addresses in data memory space. Most of these registers are
programmable control and data registers, but read only status registers are also present. EVA
registers are located in the data memory range 7400h to 7431h. EVB registers are located in the
range of 7500h to 7531h.
The event manager interrupt sub-system is slightly different from that of the main interrupt
system. Each EV has its own local interrupt sub-system which includes its own interrupt mask and
flag registers. After the EV interrupt pass through the sub-system, they flow into the PIE just like
any other interrupt on the LF2407A. The EV interrupts are arranged into three groups (A,B,C).
Each group is assigned one CPU interrupt (INT2, 3 or 4). The EV interrupts table for EVA
module is shown below.
EVA Interrupts
A General Purpose (GP) timer is simply a 16-bit counter, which may be configured to count up,
down, or continuously up and down. There are two GP timers in each EV: Timer 1 and Timer 2
for EVA and Timer 3 and Timer 4 for EVB. All timers use the CPU clock as general timing
reference, but each individual timer may use a pre-scaled or frequency reduced time base which is
specified in each timer’s control register.
• One readable and writeable (RW) 16-bit up and up/down counter register TxCNT (x = 1,
2, 3, 4). This register stores the current value of the counter and keeps incrementing or
decrementing depending on the direction of counting
• One RW 16-bit timer compare register TxCMPR (x = 1, 2, 3, 4)
• One RW 16-bit timer period register TxPR (x = 1, 2, 3, 4)
• RW 16-bit individual timer control register, TxCON (x = 1, 2, 3, 4)
• Programmable prescaler applicable to both internal and external clock inputs
The operational mode of a timer is controlled by its individual control register TxCON. Bits in the
TxCON register determine:
The control register GPTCONA/B specifies the action to be taken by the timers on different timer
events and indicates their counting directions.
The compare register associated with a GP timer stores the value to be constantly compared with
the counter of the GP timer. When a match happens, the following events occur:
• A transition occurs on the associated compare output according to the bit pattern in
GPTCONA/B
• The corresponding interrupt flag is set
• A peripheral interrupt request is generated if the interrupt is unmasked The compare
operation of a GP timer can be enabled or disabled by the appropriate bit in TxCON.
The value in the period register of a GP timer determines the period of the timer. A GP timer
resets to 0, or starts counting downward when a match occurs between the period register and the
timer counter, depending on which counting mode the timer is in.
GP Timer Interrupts:
There are 16 combined interrupt flags in the EVAIFRA, EVAIFRB, EVBIFRA, EVBIFRB
registers for the GP timers. Each of the GP timers has the capability to generate up to four
interrupts on the events listed below.
GP PURPOSE TIMER INTERRUPTS
Interrupt Interrupt Name (x = condition for Generation
Event 1, 2, 3, 4)
Underflow TxUFINT When the counter reaches
0000h
Over flow TxOFINT When the counter reaches
FFFFh
Compare TxCINT When the counter register
match contents match that of
the compare register
Period TxPINT When the counter register
Match contents match that of
the period register
The counting directions of the GP timers are reflected by their respective bits in GPTCONA/B
during all timer operations as follows:
The input pin TDIRA/B determines the direction of counting when a GP timer is in directional
up-/down-counting mode. When TDIRA/B is high, upward counting is specified; when TDIRA/B
is low, downward counting is specified.
• Stop/Hold mode
• Continuous Up-Counting mode
• Directional Up-/Down-Counting mode
• Continuous Up-/Down-Counting mode
The bit pattern in the corresponding timer control register TxCON determines the counting mode
of a GP timer. The timer enabling bit, TxCON, enables or disables the counting operation of a
timer. When the timer is disabled, the counting operation of the timer stops and the prescaler of
the timer is reset to x/1. When the timer is enabled, the timer starts counting according to the
counting mode specified by other bits of TxCON. Continuous Up-Counting mode and Continuous
Up-/Down Counting mode is mainly used for motor control applications and so these two
methods are only discussed below.
The GP timer in this mode counts up according to the scaled input clock until the value of the
timer counter matches that of the period register. On the next rising edge of the input clock after
the match, the GP timer resets to zero and starts counting up again. The period interrupt flag of
the timer is set one clock cycle after the match between the timer counter and period register. A
peripheral interrupt request is generated if the flag is not masked. An ADC start is sent to the
ADC module at the same time the flag is set, if the period interrupt of this timer has been selected
by the appropriate bits in GPTCONA/B to start the ADC.
One clock cycle after the GP timer becomes 0, the underflow interrupt flag of the timer is set. A
peripheral interrupt request is generated by the flag if it is unmasked. An ADC start is sent to the
ADC module at the same time if the underflow interrupt flag of this timer has been selected by
appropriate bits in GPTCONA/B to start ADC. The overflow interrupt flag is set one clock cycle
after the value in TxCNT matches FFFFh. A peripheral interrupt request is generated by the flag if
it is unmasked.
The duration of the timer period is (TxPR) + 1 cycles of the scaled clock input except for the first
period. The duration of the first period is the same if the timer counter is zero when counting
starts. The initial value of the GP timer can be any value between 0h and FFFFh inclusive. When
the initial value is greater than the value in the period register, the timer counts up to FFFFh,
resets to zero, and continues the operation as if the initial value was zero. When the initial value in
the timer counter is the same as that of the period register, the timer sets the period interrupt flag,
resets to zero, sets the underflow interrupt flag, and then continues the operation again as if the
initial value was zero. If the initial value of the timer is between zero and the contents of the
period register, the timer counts up to the period value and continue to finish the period as if the
initial counter value was the same as that of the period register.
The counting direction indication bit in GPTCONA/B is one for the timer in this mode. Either the
external or internal device clock can be selected as the input clock to the timer. TDIRA/B input is
ignored by the GP timer in this counting mode.
The continuous up-counting mode of the GP timer is particularly useful for the generation of
edge-triggered or asynchronous PWM waveforms and sampling periods in many motor and
motion control systems. Figure shows the continuous up-counting mode of the GP timer.
The continuous up/down counting mode is useful in generating symmetric PWM waveforms.
The counting direction only changes from up to down when the timer reaches the period value (or
FFFFh if the initial timer value is greater than the period). The timer direction only changes from
down to up when the timer reaches zero. The period of the timer in this mode is 2*(TxPR) cycles
of the scaled clock input, except for the first period. The duration of the first counting period is
the same if the timer counter is zero when counting starts.
The initial value of the GP timer counter can be any value between 0h and FFFFh inclusive. When
the initial value is greater than that of the period register, the timer counts up to FFFFh, resets to
zero, and continues the operation as if the initial value was zero. When the initial value in the
timer counter is the same as that of the period register, the timer counts down to zero and
continues again as if the initial value was zero. If the initial value of the timer is between zero and
the contents of the period register, the timer counts up to the period value and continues to finish
the period as if the initial counter value was the same as that of the period register.
The period, underflow, and overflow interrupt flags, interrupts, and associated actions are
generated on respective events in the same manner as they are generated in continuous up-
counting mode. The counting direction indication bit for this timer in GPTCONA/B is one when
the timer counts upward and zero when the timer counts downward. Either the external clock
from the TCLKINA/B pin or the internal device clock can be selected as the input clock. DIRA/B
input is ignored by the timer in this mode. Figure shows the continuous up-/down-counting mode
of the GP timer.
Each GP timer can independently be used to provide a PWM output channel. Thus, up to two
PWM outputs may be generated by the GP timers. To generate a PWM output with a GP timer, a
continuous up- or up-/down counting mode can be selected. Edge-triggered or asymmetric PWM
waveforms are generated when a continuous-up count mode is selected. Centered or symmetric
PWM waveforms are generated when a continuous-up/-down mode is selected. To set up the GP
timer for the PWM operation, do the following configuration:
1. Note what the PLL module is set to. The PLL provides the clock signals to the DSP
and hence to the EV. In the timer control registers we have the option of pre-scaling
(dividing) the clock signal to choose a time base for the GP timers.
2. The corresponding EV pins need to be configured for their primary function in the
appropriate MCRx register.
3. Initialize TxCNT (usually set the count value to zero)
4. Initialize TxCMPR to first desired compare value
5. To create a PWM signal, the registers GPTCONA/B and TxCON need to be
configured for TxCMP enabled, desired counting mode etc.
6. To create an asymmetric PWM signal, the timer is set to the continuous up count
mode. If a symmetric PWM is desired, then the timer should be set to the continuous
up/down counting mode.
7. During run time, the GP timer compare register (TxCMPR) will need to be
periodically updated with new compare values corresponding to the modulation signal
or new duty cycle. This can be done during an interrupt service routine.
Compare Units
There are three (full) compare units (compare units 1, 2, and 3) in the EVA module and three
(full) compare units (compare units 4, 5, and 6) in the EVB module. Each compare unit has two
associated PWM outputs. The time base for the compare units is provided by GP timer 1 (for
EVA) and by GP timer 2 (for EVB).
The compare units in each EV module include:
• Three 16-bit compare registers (CMPR1, CMPR2, and CMPR3 for EVA; and CMPR4,
CMPR5, and CMPR6 for EVB), all with an associated shadow register, (RW)
• One 16-bit compare control register (COMCONA for EVA, and COMCONB for EVB),
(RW)
• One 16-bit action control register (ACTRA for EVA, and ACTRB for EVB), with an
associated shadow register, (RW)
• Six PWM (3-state) output (compare output) pins (PWMy, y = 1, 2, 3, 4, 5, 6 for EVA
and PWMz, z = 7, 8, 9, 10, 11, 12 for EVB)
• Control and interrupt logic
The time base for the compare units and the associated PWM circuits is provided by GP timer 1
(for EVA) or GP timer 2 (for EVB), which can be in any of its counting modes when the compare
operation is enabled. Transitions occur on the compare outputs.
The operation mode of the compare units is determined by the bits in COMCONx. These bits
determine:
• Whether the compare operation is enabled
• Whether the compare outputs are enabled
• The condition on which the compare registers are updated with the values in their shadow
registers
• Whether space vector PWM mode is enabled
The value of the GP timer 1 counter is continuously compared with that of the compare register.
When a match is made, a transition appears on the two outputs of the compare unit according to
the bits in the action control register (ACTRA). The bits in ACTRA can individually specify each
output to be toggle active high or toggle active-low (if not forced high or low) on a compare
match. The compare interrupt flag associated with a compare unit is set when a compare match is
made between GP timer 1 and the compare register of this compare unit, if compare is enabled. A
peripheral interrupt request is generated by the flag if the interrupt is unmasked. The timing of
output transitions, setting of interrupt flags, and generation of interrupt requests are the same as
that of the GP timer compare operation. The outputs of the compare units in compare mode are
subject to modification by the output logic, dead band units, and the space vector PWM logic.
The compare action control registers (ACTRA and ACTRB) control the action that takes place
on each of the six compare output pins (PWMx, where x = 1–6 for ACTRA, and x = 7–12 for
ACTRB) on a compare event, if the compare operation is enabled by COMCONx[15]. ACTRA
and ACTRB are doublebuffered. The condition on which ACTRA and ACTRB is reloaded is
defined by bits in COMCONx. ACTRA and ACTRB also contain the SVRDIR, D2, D1, and D0
bits needed for space vector PWM operation.
The PWM circuits associated with compare units make it possible to generate six PWM output
channels (per EV) with programmable dead-band and output polarity. The EVA PWM circuits
functional block diagram is shown in Figure below. It includes the following functional units:
The EVB PWM circuits functional block diagram is identical to that of the EVA’s with the
corresponding change of configuration registers. The asymmetric/symmetric waveform generators
are the same as those of the GP timers.
The PWM circuits are designed to minimize CPU overhead and user intervention when generating
pulse width modulated waveforms used in motor control and motion control applications. PWM
generation with compare units and associated PWM circuits are controlled by the following
control registers: T1CON, COMCONA, ACTRA, and DBTCONA (in case of EVA); and
T3CON, COMCONB, ACTRB, and DBTCONB (in case of EVB).
In many motion/motor and power electronics applications, two power devices, an upper and a
lower, are placed in series on one power converter leg. The turn-on periods of the two devices
must not overlap with each other in order to avoid a shoot-through fault. Thus, a pair of non-
overlapping PWM outputs is often required to properly turn on and off the two devices. A dead
time (deadband) is often inserted between the turning-off of one transistor and the turning- on of
the other transistor. This delay allows complete turning-off of one transistor before the turning-on
of the other transistor. The required time delay is specified by the turning-on and turning-off
characteristics of the power transistors and the load characteristics in a specific application.
EVA and EVB have their own programmable dead-band units (DBTCONA and DBTCONB,
respectively). The programmable dead-band unit features:
The Programmable Dead band can be calculated using the following formula:
The operation of the dead-band unit is controlled by the dead-band timer control registers
(DBTCONA and DBTCONB).
Each of the three compare units, together with GP timer 1 (in the case of EVA) or GP timer 3 (in
the case of EVB), the dead-band unit, and the output logic in the event manager module, can be
used to generate a pair of PWM outputs with programmable dead-band and output polarity on
two dedicated device pins. There are six such dedicated PWM output pins associated with the
three compare units in each EV module. These six dedicated output pins can be used to
conveniently control 3-phase AC induction or brushless DC motors. The flexibility of output
behavior control by the compare action control register (ACTRx) also makes it easy to control
switched reluctance and synchronous reluctance motors in a wide range of applications. The
PWM circuits can also be used to conveniently control other types of motors such as DC brush
and stepper motors in single or multi-axis control applications. Each GP timer compare unit, if
desired, can also generate a PWM output based on its own timer.
Asymmetric and Symmetric PWM Generation
Both asymmetric and symmetric PWM waveforms can be generated by every compare unit on the
EV module. In addition, the three compare units together can be used to generate 3-phase
symmetric space vector PWM outputs.
All three kinds of PWM waveform generations with compare units and associated circuits require
configuration of the same Event Manager registers. The setup process for PWM generation
includes the following steps:
The edge-triggered or asymmetric PWM signal is characterized by modulated pulses which are
not centered with respect to the PWM period, as shown in Figure. The width of each pulse can
only be changed from one side of the pulse.
Asymmetric PWM Waveform Generation With Compare Unit and PWM Circuits
(x = 1, 3, or 5)
To generate an Asymmetric PWM signal, GP timer 1 is put in the continuous up-counting mode
and its period register is loaded with a value corresponding to the desired PWM carrier period.
The COMCONx is configured to enable the compare operation, set the selected output pins to be
PWM outputs, and enable the outputs. If dead-band is enabled, the value corresponding to the
required dead-band time should be written by software into the DBT(3:0) bits in
DBTCONx(11:8). This is the period for the 4-bit dead-band timers. One deadband value is used
for all PWM output channels. By proper configuration of ACTRx with software, a normal PWM
signal can be generated on one output associated with a compare unit while the other is held low
(or off) or high (or on), at the beginning, middle, or end of a PWM period. Such software
controlled flexibility of PWM outputs is particularly useful in switched reluctance motor control
applications.
A centered or symmetric PWM signal is characterized by modulated pulses which are centered
with respect to each PWM period. The advantage of a symmetric PWM signal over an asymmetric
PWM signal is that it has two inactive zones of the same duration: at the beginning and at the end
of each PWM period. This symmetry has been shown to cause less harmonics than an asymmetric
PWM signal in the phase currents of an AC motor, such as induction and DC brushless motors,
when sinusoidal modulation is used. Figure shows two examples of symmetric PWM waveforms.
The generation of a symmetric PWM waveform with a compare unit is similar to the generation of
an asymmetric PWM waveform. The only exception is that GP timer 1 (or GP timer 3) now needs
to be put in continuous up-/down-counting mode.
The EV module has built-in hardware to greatly simplify the generation of symmetric space vector
PWM waveforms. Software is used to generate space vector PWM outputs.
The user software then needs to determine the voltage Uout to be applied to the motor phases in
the two-dimensional d-q plane, decompose Uout, and perform the following for each PWM
period:
• Determine the two adjacent vectors, Ux and Ux+60
• Determine the parameters T1, T2, and T0
• Write the switching pattern corresponding to Ux in ACTRx[14–12] and 1 in ACTRx[15],
or the switching pattern of Ux+60 in ACTRx[14–12] and 0 in ACTRx[15]
• Put (1/2 T1) in CMPR1 and (1/2 T1 + 1/2 T2) in CMPR2
The space vector PWM hardware in the EV module does the following to complete a space
vector PWM period:
• At the beginning of each period, sets the PWM outputs to the (new) pattern Uy defined by
ACTRx[14–12]
• On the first compare match during up-counting between CMPR1 and GP timer 1 at (1/2
T1), switches the PWM outputs to the pattern of Uy+60 if ACTRx[15] is 1, or to the
pattern of Uy if ACTRx[15] is 0 (U0–60 = U300, U360+60 = U60)
• On the second compare match during up-counting between CMPR2 and GP timer 1 at
(1/2 T1 + 1/2 T2), switches the PWM outputs to the pattern (000) or (111), whichever
differs from the second pattern by one bit
• On the first compare match during down-counting between CMPR2 and GP timer 1 at
(1/2 T1 + 1/2 T2), switches the PWM outputs back to the second output pattern
• On the second compare match during down-counting between CMPR1 and GP timer 1 at
(1/2 T1), switches the PWM outputs back to the first pattern
The space vector PWM waveforms generated are symmetric with respect to the middle of each
PWM period; and for this reason, it is called the symmetric space vector PWM generation
method. Figure below shows examples of the symmetric space vector PWM waveforms.
Capture Units
Capture units enable logging of transitions on capture input pins. There are six capture units, three
is each EV module. Capture Units 1, 2, and 3 are associated with EVA and Capture Units 4, 5,
and 6 are associated with EVB. Each capture unit is associated with a capture input pin. Each
EVA capture unit can choose GP timer 2 or 1 as its time base; however, CAP1 and CAP2 cannot
choose a different timer between themselves as their time base. Each EVB capture unit can
choose GP timer 4 or 3 as its time base; however, CAP4 and CAP5 cannot choose a different
timer between themselves as their time base. The value of the GP timer is captured and stored in
the corresponding 2-leveldeep FIFO stack when a specified transition is detected on a capture
input pin (CAPx).
The capture units are useful in applications where the time of an external trigger needs to be
captured. For example, if we want to measure the time between the rising edges of two pulses, we
would configure the appropriate registers for capture operation on a specific capture pin. At each
rising edge, the capture unit would then store the corresponding timer values. The user program
could then subtract the second capture value from the first value and determine the time between
the pulses.
QEPs are two sequences of pulses which have a variable frequency and are 900 out of phase with
one another. QEP signals are usually generated by a position/ speed sensing device such as a
rotary optical encoder. When the encoder is rotated, the direction can be determined by which
sequence of pulses leads the other. Rotational speed and position can be determined from the
count and frequency of the pulses.
Each Event Manager module has a quadrature encoder pulse (QEP) circuit. The QEP circuit,
when enabled, decodes and counts the quadrature encoded input pulses on pins CAP1/QEP1 and
CAP2/QEP2 (in case of EVA) or CAP4/QEP3 and CAP5/QEP4 (in case of EVB). The QEP
circuit can be used to interface with an optical encoder to get position and speed information from
a rotating machine. When the QEP circuit is enabled, the capture function on CAP1/CAP2 and
CAP4/CAP5 pins is disabled.
The analog to digital converter (ADC) on the LF2407A allows the DSP to sample analog
voltage signals. The output of the ADC is integer number which represents the voltage level
sampled. The resolution of the ADC is 10 bits, meaning that the ADC will generate a 10-bit
number for every conversion it performs. However, the ADC stores the conversion results in
registers that are 16 bits wide. The 10 most significant bits are the ADC result, while the least
significant bits are filled with “0”s. We usually want to truncate the useless zeros, so the value
in the result register is simply right shifted by six places.
For using the ADC the user first needs to configure the ADC for the desired operation. Like all
peripherals, all registers relating to ADC operation have addresses in data memory space. The first
step in configuring the ADC should be to reset the ADC. After the ADC is reset, the next step is
configure the main ADC control registers (ADCTRL1, ADCTRL2) for desired ADC operation.
Then, load the MAXCONV register with the desired number of automatic conversion minus 1.
For example, if seven auto conversions are required, MAXCONV would be loaded with 6. The
desired input channels and their order of conversion need to be specified in the CHSELSEQn
registers. Finally, a SOC trigger will start the sampling process.
After the conversion process is complete, each 10-bit result can be read from the result registers
RESULTn. The conversion results are stored sequentially in result registers RESULT0 to
RESULT15. The first result is stored in RESULT0, the second result in RESULT1, and so on.
The ADC sequencer consists of two independent 8-state sequencers (SEQ1 and SEQ2) that can
also be cascaded together to form one 16-state sequencer (SEQ). The word “state” represents the
number of autoconversions that can be performed with the sequencer. Block diagrams of the
single (16-state, cascaded) and dual (two 8-state, separated) sequencer modes are shown in
Figures.
In both cases, the ADC has the ability to autosequence a series of conversions. For every
conversion, any one of the available 16 input channels can be selected through the analog mux.
After conversion, the digital value of the selected channel is stored in the appropriate result
register (RESULTn). It is also possible to sample the same channel multiple times, allowing the
user to perform “over-sampling”, which gives increased resolution over traditional single sampled
conversion results.
7429h CAP3FBOT
7529h CAP3FBOT