T exas Instruments and its subsidiaries (TI) reserve the right to make changes to their products or to discontinue
any product or service without notice, and advise customers to obtain the latest version of relevant information
to verify, before placing orders, that information being relied on is current and complete. All products are sold
subject to the terms and conditions of sale supplied at the time of order acknowledgment, including those
pertaining to warranty, patent infringement, and limitation of liability.
TI warrants performance of its semiconductor products to the specifications applicable at the time of sale in
accordance with TI’s standard warranty. Testing and other quality control techniques are utilized to the extent
TI deems necessary to support this warranty . Specific testing of all parameters of each device is not necessarily
performed, except those mandated by government requirements.
Customers are responsible for their applications using TI components.
In order to minimize risks associated with the customer’s applications, adequate design and operating
safeguards must be provided by the customer to minimize inherent or procedural hazards.
TI assumes no liability for applications assistance or customer product design. TI does not warrant or represent
that any license, either express or implied, is granted under any patent right, copyright, mask work right, or other
intellectual property right of TI covering or relating to any combination, machine, or process in which such
semiconductor products or services might be or are used. TI’s publication of information regarding any third
party’s products or services does not constitute TI’s approval, warranty or endorsement thereof.
Copyright 2000, Texas Instruments Incorporated
About This Manual
How to Use This Manual
Preface
Read This First
The MSP430x1xx User’s Guide is intended to assist the development of
MSP430x1xx family products by assembling together and presenting
hardware and software information in a manner that is easy for engineers and
programmers to use.
This manual discusses modules and peripherals of the MSP430x1xx family of
devices. Each discussion presents the module or peripheral in a general
sense. Not all features and functions of all modules or peripherals are present
on all devices. In addition, modules or peripherals may differ in their exact
implementation between device families, or may not be fully implemented on
an individual device or device family. Therefore, a user must always consult
the data sheet of any device of interest to determine what peripherals and
modules are implemented, and exactly how they are implemented on that
particular device.
How to Use This Manual
This document contains the following chapters:
Chapter 1 – Introduction
For related documentation see the web site http://www.ti.com/sc/msp430.
This equipment is intended for use in a laboratory test environment only . It generates, uses, and can radiate radio frequency energy and has not been tested
for compliance with the limits of computing devices pursuant to subpart J of
part 15 of FCC rules, which are designed to provide reasonable protection
against radio frequency interference. Operation of this equipment in other environments may cause interference with radio communications, in which case
the user at his own expense will be required to take whatever measures may
be required to correct this interference.
This chapter outlines the features and capabilities of the Texas Instruments
(TI) MSP430x1xx family of microcontrollers.
The MSP430 employs a von-Neumann architecture, therefore, all memory
and peripherals are in one address space.
The MSP430 devices constitute a family of ultralow-power, 16-bit RISC
microcontrollers with an advanced architecture and rich peripheral set. The
architecture uses advanced timing and design features, as well as a highly
orthogonal structure to deliver a processor that is both powerful and flexible.
The MSP430 consumes less than 400 µA in active mode operating at 1 MHz
in a typical 3-V system and can wake up from a <2-µA standby mode to fully
synchronized operation in less than 6 µs. These exceptionally low current
requirements, combined with the fast wake-up time, enable a user to build a
system with minimum current consumption and maximum battery life.
Additionally , the MSP430x1xx family has an abundant mix of peripherals and
memory sizes enabling true system-on-a-chip designs. The peripherals
include a 12-bit A/D, slope A/D, multiple timers (some with capture/compare
registers and PWM output capability), on-chip clock generation, H/W
multiplier, USART(s), Watchdog Timer, GPIO, and others.
See http://www.ti.com for the latest device information and literature for the
MSP430 family.
The TI MSP430x1xx family of controllers has the following features and
capabilities:
-
Ultralow-power architecture:
0.1– 400 µA nominal operating current @1 MHz
1.8 – 3.6 V operation (2.5–5.5 V for C11x, P11x, and E11x devices)
6 µs wake-up from standby mode
Extensive interrupt capability relieves need for polling
-
Flexible and powerful processing capabilities:
Seven source-address modes
Four destination-address modes
Only 27 core instructions
Prioritized, nested interrupts
No interrupt or subroutine level limits
Large register file
Ram execution capability
Efficient table processing
Fast hex-to-decimal conversion
Powerful, easy-to-use development tools including:
Simulator (including peripheral and interrupt simulation)
C compiler
Assembler
Linker
Emulators
Flash emulator kit
Evaluation kits
Device programmer
Application notes
Example code
1-2
1.211x Devices
11x Devices
-
Versatile ultralow-power device options including:
Masked ROM
OTP (in-system programmable)
Flash (in-system programmable)
EPROM (UV-erasable, in-system programmable)
–40°C to +85°C operating temperature range
Up to 64K addressing space
Memory mixes to support all types of applications
The 11x devices contain the following peripherals:
-
Basic Clock System (on-chip DCO + one or two crystal oscillators)
-
Watchdog Timer/General Purpose Timer
-
Timer_A3 (16-bit timer with 3 capture/compare registers and PWM output)
The architecture of the MSP430 family is based on a memory-to-memory
architecture, a common address space for all functional blocks, and a reduced
instruction set applicable to all functional blocks as illustrated in Figure 2–1.
See specific device data sheets for complete block diagrams of individual
devices.
Figure 2–1.MSP430 System Configuration
Oscillator
System
Clock
CPU
Incl.
16 Reg.
Random
Logic
ACLK
MCLK
MAB, 16 Bit
MDB, 16 Bit
Module Select
PROGRAM
Watchdog
2.2Central Processing Unit
The CPU incorporates a reduced and highly transparent instruction set and a
highly orthogonal design. It consists of a 16-bit arithmetic logic unit (ALU), 16
registers, and instruction control logic. Four of these registers are used for
special purposes. These are the program counter (PC), stack pointer (SP),
status register (SR), and constant generator (CGx). All registers, except the
constant-generator registers R3/CG2 and part of R2/CG1, can be accessed
using the complete instruction set. The constant generator supplies instruction
constants, and is not used for data storage. The addressing mode used on
CG1 separates the data from the constants.
DATAI/O PortI/O PortI/O Port
Bus
Conv.
Timer_B
ComparatorUSART
USART
MAB, 4 Bit
R/W
MDB, 8 Bit
2-2
The CPU control over the program counter, the status register, and the stack
pointer (with the reduced instruction set) allows the development of
applications with sophisticated addressing modes and software algorithms.
2.3Program Memory
Instruction fetches from program memory are always 16-bit accesses,
whereas data memory can be accessed using word (16-bit) or byte (8-bit)
instructions. Any access uses the 16-bit memory data bus (MDB) and as many
of the least-significant address lines of the memory address bus (MAB) as
required to access the memory locations. Blocks of memory are automatically
selected through module-enable signals. This technique reduces overall
current consumption. Program memory is integrated as programmable or
mask-programmed memory.
In addition to program code, data may also be placed in the ROM section of
the memory map and may be accessed using word or byte instructions; this
is useful for data tables, for example. This unique feature gives the MSP430
an advantage over other microcontrollers, because the data tables do not
have to be copied to RAM for usage.
Sixteen words of memory are reserved for reset and interrupt vectors at the
top of the 64-kilobytes address space from 0FFFFh down to 0FFE0h.
Program Memory
2.4Data Memory
The data memory is connected to the CPU through the same two buses as the
program memory (ROM): the memory address bus (MAB) and the memory
data bus (MDB). The data memory can be accessed with full (word) data width
or with reduced (byte) data width.
Additionally, because the RAM and ROM are connected to the CPU via the
same busses, program code can be loaded into and executed from RAM. This
is another unique feature of the MSP430 devices, and provides valuable,
easy-to-use debugging capability.
2.5Operation Control
The operation of the different MSP430 members is controlled mainly by the
information stored in the special–function registers (SFRs). The different bits
in the SFRs enable interrupts, provide information about the status of interrupt
flags, and define the operating modes of the peripherals. By disabling
peripherals that are not needed during an operation, total current consumption
can be reduced. The individual peripherals are described later in this manual.
Architectural Overview
2-3
Peripherals
2.6Peripherals
Peripheral modules are connected to the CPU through the MAB, MDB, and
interrupt service and request lines. The MAB is usually a 5-bit bus for most of
the peripherals. The MDB is an 8-bit or 16-bit bus. Most of the peripherals
operate in byte format. Modules with an 8-bit data bus are connected by
bus-conversion circuitry to the 16-bit CPU. The data exchange with these
modules must be handled with byte instructions. The SFRs are also handled
with byte instructions. The operation for 8-bit peripherals follows the order
described in Figure 2–2.
Figure 2–2.Bus Connection of Modules/Peripherals
MAB
MDB
Interrupt Request
Module/Peripheral
Interrupt Bus Grant
2.7Oscillator and Clock Generator
The LFXT1 oscillator is designed for the commonly used 32,768 Hz,
low-current- consumption clock crystal or to be used with a high-speed crystal.
All analog components for the 32,768 Hz oscillator are integrated into the
MSP430; only the crystal needs to be connected with no other external
components required. When using the LFXT1 oscillator with a high-speed
crystal, additional load capacitors are required. Some MSP430 devices have
an additional high-speed crystal oscillator (LFXT2). Refer to the clock chapter
and the specific device data sheets for details.
In addition to the crystal oscillator(s), all MSP430 devices contain a digitallycontrolled RC oscillator (DCO). The DCO is different from RC oscillators found
on other microcontrollers because it is digitally controllable and tuneable.
Interrupt Request
Interrupt Bus Grant
PUC
2-4
Clock source selection for peripherals and CPU is very flexible. Most
peripherals are capable of using the 32768-Hz crystal oscillator clock, the
high-speed crystal oscillator clock (where applicable), or the DCO clock. The
CPU is capable of executing from the DCO clock or from either of the two
crystal oscillator clocks. See Chapter 7 for details on the clock system.
Chapter 3
System Resets, Interrupts,
and Operating Modes
This chapter discusses the MSP430x1xx system resets, interrupts, and operating modes.
The MSP430 system reset circuitry (shown in Figure 3–1) sources two internal
reset signals: power-on reset (POR) and power-up clear (PUC). Different
events trigger these reset signals and different initial conditions exist
depending on which signal was generated.
Figure 3–1.Power-On Reset and Power-Up Clear Schematic
V
V
CC
CC
POR Delay
POR
Detect
0 V
RST/MNI
NMI(WDTCTL.5)
TIMSEL
WDTQn
WDTIFG
EQU
KEYV
(from flash module)
†
From watchdog timer peripheral module
S
POR
S
Latch
R
0 V0 V
Delay
†
†
†
†
†
Resetwd1
Resetwd2
S
S
S
S
S
R
POR
Latch
MCLK
POR
PUC_DCO
PUC
A POR is a device reset. It is only generated by the two following events:
-
Powering up the device
-
A low signal on the RST/NMI pin when configured in the reset mode
A PUC is always generated when a POR is generated, but a POR is not
generated by a PUC. The following events trigger a PUC:
3-2
-
A POR signal
-
Watchdog timer expiration (in watchdog mode only)
-
Watchdog timer security key violation
-
A low signal on the RST/NMI pin when configured in the NMI mode
-
A Flash memory security key violation
Note:
If desired, software can cause a PUC by simply writing to the watchdog timer
control register with an incorrect password.
Note:
Generation of the POR/PUC signals does not necessarily generate a system
reset interrupt. Anytime a POR is activated, a system reset interrupt is
generated. However, when a PUC is activated, a system reset interrupt may
or may not be generated. Instead, a lower priority interrupt vector may be
generated, depending on what action caused the PUC. Each device data
sheet gives a detailed table of what action generates each interrupt. This
table should be consulted for the proper handling of all interrupts.
When the VCC supply provides a fast rise time as shown in Figure 3–2, the
POR delay provides enough active time on the POR signal to allow the signal
to initialize the circuitry correctly after power up. When the V
slow, as shown in Figure 3–3, the POR detector holds the POR signal active
until Vcc has risen above the V
level. This also ensures a correct
(POR)
initialization.
Figure 3–2.Power-On Reset Timing on Fast VCC Rise Time
V
System Reset and Initialization
rise time is
CC
V
CC
POR
t
POR_Delay
If power to the chip is cycled, the supply voltage VCC must fall below the V
(see Figure 3–3) to ensure that another POR signal occurs when VCC is
powered up again. If VCC does not fall below V
a POR is not generated and power-up conditions do not set correctly.
Figure 3–3.Power-on Reset Timing on Slow VCC Rise Time
V
V
CC
V
(POR)
No POR
V
(min)
POR
during a cycle or a glitch,
(min)
POR
t
(min)
t
System Resets, Interrupts, and Operating Modes
3-3
System Reset and Initialization
3.1.2Device Initialization After System Reset
After a device reset (POR/PUC combination), the initial system conditions are:
-
I/O pins switched to input mode (see note below).
-
I/O flags are cleared as described in the I/O chapter (see note below).
-
Other peripherals and registers initialized as described in their respective
chapters.
-
Status register is reset.
-
Program counter is loaded with address contained at reset vector location
(0FFFEh). CPU execution begins at that address.
Note:
I/O pins and flags are only initialized after power-up. After the ’430 is
powered and running, if a reset is generated with RST/NMI pin (in reset
mode), the I/O pins are unaffected.
After a system reset, the user program can evaluate the various flags to
determine the source of the reset and take appropriate action.
The initial state of registers and peripherals is discussed in each applicable
section of this manual. Each register is shown with a key indicating the
rw–(0)
accessibility of the register and the initial condition, for example,
rw–0
. In these examples, the r indicates read, the w indicates write, and the
, or
value after the dash indicates the initial condition. If the value is in parenthesis,
the initial condition takes effect only after a POR – a PUC alone will not effect
the bit(s). If the value is not in parenthesis, it takes effect after a PUC alone or
after a POR/PUC combination. Some examples follow:
TypeDescription
rw–(0)Read/write, reset with POR
rw–0Read/write, reset with POR or PUC
r–1Read only, set with POR or PUC
rRead only, no initial state
wWrite only, no initial state
3-4
3.2Global Interrupt Structure
There are four types of interrupts:
-
System reset
-
Maskable
-
Non-maskable
-
(Non)-maskable
System reset (POR/PUC) is discussed in section 3.1.
Maskable interrupts are caused by:
-
A watchdog-timer overflow (if timer mode is selected)
-
Other modules with interrupt capability
Non-maskable interrupts are not maskable in any way. No individual interrupt
enable bit is implemented for them, and the general interrupt enable bit (GIE)
has no effect on them.
(Non)-maskable interrupts are not masked by the general interrupt enable bit
(GIE) but are individually enabled or disabled by an individual interrupt enable
bit. When a (non)-maskable interrupt is accepted, the corresponding interrupt
enable bit is automatically reset, therefore disabling the interrupt for execution
of the interrupt service routine (ISR). The RETI (return from interrupt)
instruction has no effect on the individual enable bits of the (non)-maskable
interrupts. So the software must set the corresponding interrupt enable bit in
the ISR before execution of the RETI instruction for the interrupt to be
re-enabled after the ISR.
Global Interrupt Structure
A (non)-maskable NMI interrupt can be generated by an edge on the RST/NMI
pin (if NMI mode is selected), an oscillator fault occurs (if the oscillator fault
interrupt is enabled), or an access violation to the flash memory takes place
(if the access violation interrupt is enabled).
System Resets, Interrupts, and Operating Modes
3-5
MSP430 Interrupt-Priority Scheme
3.3MSP430 Interrupt-Priority Scheme
The interrupt priority of the modules, as shown in Figure 3–4, is defined by the
arrangement of the modules in the connection chain: the nearer a module is
to the CPU/NMIRS, the higher the priority.
Figure 3–4.Interrupt Priority Scheme
Priority
High
GMIRS
Low
CPU
PUC
Flash Security Key
PUC
Circuit
WDT Security Key
GIE
NMIRS
OSCfault
Flash ACCV
Reset/NMI
MAB – 5LSBs
Module
1
Module
2
121212121
Bus
Grant
WD
Timer
Module
m
Module
Reset and NMI, as shown in Figure 3–5, can only be used as alternative
interrupts because they use the same input pin. The associated control bits are
located in the watchdog timer control register shown in Figure 3–6, and are
password protected.
n
3-6
Figure 3–5.Block Diagram of NMI Interrupt Sources
ACCV
ACCVIFG
S
FCTL1.1
MSP430 Interrupt-Priority Scheme
IE1.5
PUC
RST/NMI
IFG1.4
PUC
IE1.4
PUC
OSCFault
IFG1.1
IE1.1
PUC
Clear
S
Clear
Clear
S
Clear
ACCVIE
NMIFG
NMIIE
OFIFG
OFIE
NMI_IRQA
Counter
NMITMSELNMIES
WDT
IFG1.0
POR
IRQA
TIMSEL
IE1.0
Flash Module
Flash Module
PORPUC
KEYV
System Reset
Generator
WDTQnEQU
S
Clear
Clear
WDTIFG
WDTIE
Flash Module
VCC
PUC
POR
NMIRS
PUCPOR
IRQ
IRQA: Interrupt Request Accepted
Watchdog Timer Module
PUC
System Resets, Interrupts, and Operating Modes
3-7
MSP430 Interrupt-Priority Scheme
Figure 3–6.RST/NMI Mode Selection
70
WDTCTL
0120h
rw-0rw-0rw-0rw-0(w)-0rw-0rw-0rw-0
NMIESHOLDNMITMSEL CNTCLSSELIS1IS0
BITS 0–4,7 See Watchdog Timer chapter.
BIT 5:The NMI bit selects the function of the RST/NMI input pin. It is cleared after
a PUC signal.
NMI = 0:The RST/NMI input works as reset input. As long as the
RST/NMI pin is held low, the internal PUC signal is active
(level-sensitive).
NMI = 1:The RST
/NMI input works as an edge-sensitive, nonmaskable
interrupt input.
BIT 6:This bit selects the activating edge of the RST/NMI input if the NMI function
is selected. It is cleared after a PUC signal.
NMIES = 0: A rising edge triggers an NMI interrupt.
NMIES = 1: A falling edge triggers an NMI interrupt.
3.3.1Operation of Global Interrupt—Reset/NMI
If the RST/NMI pin is set to the reset function, the CPU is held in the reset state
as long as the RST/NMI pin is held low. After the input changes to a high state,
the CPU starts program execution at the word address stored in word location
0FFFEh (reset vector).
If the RST/NMI pin is set to the NMI function, a signal edge (selected by the
NMIES bit) will generate an interrupt if the NMIIE bit is set. When accepted,
program execution begins at the address stored in location 0FFFCh. The RST
NMI flag in the SFR IFG1.4 is also set.
Note:
When configured in the NMI mode, a signal generating an NMI event should
not hold the RST
/NMI pin low, unless it is intended to hold the processor in
reset. When an NMI event occurs on the pin, the PUC signal is activated, thus
resetting the bits in the WDTCTL register. This results in the RST
/NMI pin
being configured in the reset mode. If the signal on the RST/NMI pin that
generated the NMI event remains low, the processor will be held in the reset
state.
When NMI mode is selected and the NMI edge select bit is changed, an NMI
can be generated, depending on the actual level at RST/NMI pin. When the
NMI edge select bit is changed before selecting the NMI mode, no NMI is
generated.
/
3-8
The NMI interrupt is maskable by the NMIIE bit.
3.3.2Operation of Global Interrupt—Oscillator Fault Control
The oscillator fault signal warns of a possible error condition with the crystal
oscillator.
3.3.2.1Oscillator Fault Control in the Basic Clock System
The oscillator-fault signal is triggered when the LFXT1 oscillator is configured
to run in HF mode but is not running, stops running after being operational, or
is switched off. The oscillator-fault signal is also triggered under the same
conditions for the XT2 oscillator, present in some devices. Note that a PUC signal can trigger an oscillator fault, because the PUC switches the LFXT1 to LF
mode, therefore switching off the HF mode. The PUC signal also switches off
the XT2 oscillator.
The oscillator fault signal can be enabled to generate an NMI by bit OFIE in
the SFRs. The interrupt flag OFIFG in the SFRs can then be tested by the
interrupt service routine to determine if the NMI was caused by an oscillator
fault. See Basic Clock Module chapter for more details on the operation of the
crystal oscillators LFXT1 and XT2.
Interrupt Processing
3.4Interrupt Processing
The MSP430 programmable interrupt structure allows flexible on-chip and
external interrupt configurations to meet real-time interrupt-driven system
requirements. Interrupts may be initiated by the processor’s operating
conditions such as watchdog overflow; or by peripheral modules or external
events. Each interrupt source can be disabled individually by an interrupt
enable bit, or all maskable interrupts can be disabled by the general interrupt
enable (GIE) bit in the status register.
Whenever an interrupt is requested and the appropriate interrupt enable bit
and general interrupt enable (GIE) bit are set, the interrupt service routine
becomes active as follows:
1) CPU active: The currently executing instruction is completed.
2) CPU stopped: The low-power modes are terminated.
3) The program counter pointing to the next instruction is pushed onto the
stack.
4) The status register is pushed onto the stack.
5) The interrupt with the highest priority is selected if multiple interrupts
occurred during the last instruction and are pending for service.
6) The appropriate interrupt request flag resets automatically on singlesource flags. Multiple source flags remain set for servicing by software.
7) The GIE bit is reset; the CPUOff bit, the OscOff bit, and the SCG1 bit are
cleared; the status bits V , N, Z, and C are reset. SCG0 is left unchanged.
System Resets, Interrupts, and Operating Modes
3-9
Interrupt Processing
8) The content of the appropriate interrupt vector is loaded into the program
counter: the program continues with the interrupt handling routine at that
address.
The interrupt latency is six cycles, starting with the acceptance of an interrupt
request, and lasting until the start of execution of the appropriate
interrupt-service routine first instruction, as shown in Figure 3–7.
Figure 3–7.Interrupt Processing
Before
Interrupt
Item1
SPTOS
Item2
SPTOS
After
Interrupt
Item1
Item2
PC
SR
The interrupt handling routine terminates with the instruction:
RETI (return from an interrupt service routine)
which performs the following actions:
1) The status register with all previous settings pops from the stack. All previous settings of GIE, CPUOFF, etc. are now in effect, regardless of the
settings utilized during the interrupt service routine.
2) The program counter pops from the stack and begins execution at the
point where it was interrupted.
The return from the interrupt is illustrated in Figure 3–8.
Figure 3–8.Return From Interrupt
SPTOS
A RETI instruction takes five cycles. Interrupt nesting is activated if the GIE bit
is set inside the interrupt handling routine. The GIE bit is located in status
register SR/R2, which is included in the CPU as shown in Figure 3–9.
3-10
BeforeAfter
Return From Interrupt
Item1
Item2
PC
SR
SPTOS
Item1
Item2
PC
SR
Figure 3–9.Status Register (SR)
150
Reserved For Future Enhancements
Apart from the GIE bit, other sources of interrupt requests can be enabled/
disabled individually or in groups. The interrupt enable flags are located
together within two addresses of the special-function registers (SFRs). The
program-flow conditions on interrupt requests can be easily adjusted using the
interrupt enable masks. The hardware serves the highest priority within the
empowered interrupt source.
87
SCG1V
rw-0
CPU
SCG0GIEZ C
OSC
Off
Off
3.4.1Interrupt Control Bits in Special-Function Registers (SFRs)
Most of the interrupt control bits, interrupt flags, and interrupt enable bits are
collected in SFRs under a few addresses, as shown in Table 3–1. The SFRs
are located in the lower address range and are implemented in byte format.
SFRs must be accessed using byte instructions.
Interrupt Processing
N
Table 3–1.Interrupt Control Bits in SFRs
Address70
000FhNot yet defined or implemented
000EhNot yet defined or implemented
000DhNot yet defined or implemented
000ChNot yet defined or implemented
000BhNot yet defined or implemented
000AhNot yet defined or implemented
0009hNot yet defined or implemented
0008hNot yet defined or implemented
0007hNot yet defined or implemented
0006hNot yet defined or implemented
0005hModule enable 2 (ME2.x)
0004hModule enable 1 (ME1.x)
0003hInterrupt flag reg. 2 (IFG2.x)
0002hInterrupt flag reg. 1 (IFG1.x)
0001hInterrupt enable 2 (IE2.x)
0000hInterrupt enable 1 (IE1.x)
The MSP430 family supports SFRs by applying the correct logic and functions
to each individual module. Each module interrupt source can be individually
enabled or disable using the bits described in Table 3–2.
The interrupt-flag registers are described in Table 3–3. The module-enable
bits are described in Table 3–4.
System Resets, Interrupts, and Operating Modes
3-11
Interrupt Processing
Table 3–2.Interrupt Enable Registers 1 and 2
Bit Position Short Form Initial State†Comments
IE1.0WDTIEResetWatchdog timer enable signal. Inactive if watchdog mode is
selected. Active if watchdog timer is configured as general-purpose
The interrupt vectors and the power-up starting address are located in the
ROM, using the address range 0FFFFh – 0FFE0h as described in Table 3–5.
The vector contains the 16-bit address of the appropriate interrupt handler
instruction sequence. The interrupt vectors for 14x devices are shown in T able
3–5 in decreasing order of priority . See device data sheet for interrupt vectors
for a specific device.
Table 3–5.Interrupt Sources, Flags, and Vectors of 14x Configurations
INTERRUPT SOURCEINTERRUPT FLAGSYSTEM
Power-up
External Reset
Watchdog
Flash memory
NMI
Oscillator Fault
Flash memory access violation
Timer_B7BCCIFG0 (see Note 2)Maskable0FFFAh13
Timer_B7
Comparator_ACMPAIFGMaskable0FFF6h11
Watchdog timerWDTIFGMaskable0FFF4h10
USART0 receiveURXIFG0Maskable0FFF2h9
USART0 transmitUTXIFG0Maskable0FFF0h8
ADCADCIFG (see Notes 1 & 2)Maskable0FFEEh7
Timer_A3CCIFG0 (see Note 2)Maskable0FFECh6
Timer_A3
I/O port P1 (eight flags)
USART1 receiveURXIFG1Maskable0FFE6h3
USART1 transmitUTXIFG10FFE4h2
I/O port P2 (eight flags)
NOTES: 1. Multiple source flags
2. Interrupt flags are located in the module.
3. (Non)maskable: the individual interrupt-enable bit can disable an interrupt event, but the general-interrupt enable
can not disable it.
Note:Some MSP430 devices have different implementations, See device datasheet for details.
NMIIFG (see Notes 1 & 3)
ACCVIFG (see Notes 1 & 3)
P1IFG.0 (see Notes 1 & 2)
P1IFG.7 (see Notes 1 & 2)
P2IFG.0 (see Notes 1 & 2)
P2IFG.7 (see Notes 1 & 2)
WDTIFG
KEYV
(see Note 1)
OFIFG (see Notes 1 & 3)
BCCIFG1 to BCCIFG6
TBIFG (see Notes 1 & 2)
CCIFG1,
CCIFG2,
TAIFG (see Notes 1 & 2)
To
To
INTERRUPT
Reset0FFFEh15, highest
(Non)maskable
(Non)maskable
(Non)maskable
Maskable0FFF8h12
Maskable0FFEAh5
Maskable0FFE8h4
Maskable0FFE2h1
ADDRESS
Interrupt Processing
WORD
0FFFCh14
0FFE0h0, lowest
PRIORITY
3.4.2.1External Interrupts
All eight bits of ports P1 and P2 are designed for interrupt processing of
external events. All individual I/O bits are independently programmable. Any
combinations of inputs, outputs, and interrupt conditions are possible. This
allows easy adaptation to different I/O configurations. See Chapter I/O Ports
for more details on I/O ports.
System Resets, Interrupts, and Operating Modes
3-15
Operating Modes
3.5Operating Modes
The MSP430 family was developed for ultralow-power applications and uses
different levels of operating modes. The MSP430 operating modes, shown in
Figure 3–10, give advanced support to various requirements for ultralow
power and ultralow energy consumption. This support is combined with an
intelligent management of operations during the different module and CPU
states. An interrupt event wakes the system from each of the various operating
modes and the RETI instruction returns operation to the mode that was
selected before the interrupt event.
The ultra-low power system design which uses complementary metal-oxide
semiconductor (CMOS) technology , takes into account three different needs:
-
-
-
There are four bits that control the CPU and the main parts of the operation
of the system clock generator: CPUOff, OscOff, SCG0, and SCG1. These four
bits support discontinuous active mode (AM) requests, to limit the time period
of the full operating mode, and are located in the status register. The major
advantage of including the operating mode bits in the status register is that the
present state of the operating condition is saved onto the stack during an
interrupt service request. As long as the stored status register information is
not altered, the processor continues (after RETI) with the same operating
mode as before the interrupt event. Another program flow may be selected by
manipulating the data stored on the stack or the stack pointer. Being able to
access the stack and stack pointer with the instruction set allows the program
structures to be individually optimized, as illustrated in the following program
flow:
The desire for speed and data throughput despite conflicting needs for
ultra-low power
Minimization of individual current consumption
Limitation of the activity state to the minimum required by the use of low
power modes
3-16
-
Enter interrupt routine
The interrupt routine is entered and processed if an enabled interrupt awakens
the MSP430:
J
The SR and PC are stored on the stack, with the content present at the
interrupt event.
J
Subsequently, the operation mode control bits OscOff, SCG1, and
CPUOff are cleared automatically in the status register.
Operating Modes
-
Return from interrupt
Two dif ferent modes are available to return from the interrupt service routine
and continue the flow of operation:
J
Return with low-power mode bits set. When returning from the
interrupt, the program counter points to the next instruction. The
instruction pointed to is not executed, since the restored low power
mode stops CPU activity.
J
Return with low-power mode bits reset. When returning from the
interrupt, the program continues at the address following the
instruction that set the OscOff or CPUOff-bit in the status register . To
use this mode, the interrupt service routine must reset the OscOff,
CPUOff, SCGO, and SCG1 bits on the stack. Then, when the SR
contents are popped from the stack upon RETI, the operating mode
will be active mode (AM).
There are six operating modes that the software can configure:
-
Active mode AM; SCG1=0, SCG0=0, OscOff=0, CPUOff=0:
CPU clocks are active
-
Low power mode 0 (LPM0); SCG1=0, SCG0=0, OscOff=0, CPUOff=1:
CPU is disabled
MCLK is disabled
SMCLK and ACLK remain active
-
Low power mode 1 (LPM1); SCG1=0, SCG0=1, OscOff=0, CPUOff=1:
CPU is disabled
MCLK is disabled
DCO’s dc generator is disabled if the DCO is not used for MCLK or
SMCLK when in active mode. Otherwise, it remains enabled.
SMCLK and ACLK remain active
System Resets, Interrupts, and Operating Modes
3-17
Operating Modes
-
Low power mode 2 (LPM2); SCG1=1, SCG0=0, OscOff=0, CPUOff=1:
CPU is disabled
MCLK is disabled
SMCLK is disabled
DCO oscillator automatically disabled because it is not needed for MCLK
or SMCLK
DCO’s dc-generator remains enabled
ACLK remains active
-
Low power mode 3 (LPM3); SCG1=1, SCG0=1, OscOff=0, CPUOff=1:
CPU is disabled
MCLK is disabled
SMCLK is disabled
DCO oscillator is disabled
DCO’s dc-generator is disabled
ACLK remains active
-
Low power mode 4 (LPM4); SCG1=X, SCG0=X, OscOff=1, CPUOff=1:
CPU is disabled
ACLK is disabled
MCLK is disabled
SMCLK is disabled
DCO oscillator is disabled
DCO’s dc-generator is disabled
Crystal oscillator is stopped
Note:
Peripheral operation is not halted by CPUOff. Peripherals are controlled by
their individual control registers.
3-18
Table 3–6.Low Power Mode Logic Chart for Basic Clock System
SCG1SCG0OscOffCPUOff
LPM00001
LPM10101
LPM21001
LPM31101
LPM41111
These modes are illustrated in Figure 3–11.
Figure 3–10. MSP430x1xx Operating Modes For Basic Clock System
Operating Modes
WDT Active,
Time Expired, Overflow
WDT Active,
Security Key Violation
CPUOff = 1
SCG0,1 = 0
LP Mode LPM0
CPU Off, MCLK Off,
SMCLK, ACLK On
CPUOff = 1
SCG0 = 1
SCG1 = 0
LP Mode LPM1
CPU Off, MCLK Off,
SMCLK, ACLK On
DC Generator Off if DCO
not used in active mode
RST/NMI
Reset Active
POR
WDTIFG = 1
WDTIFG = 1
V arious Modules Are Active
CPUOff = 1
SCG0 = 0
SCG1 = 1
CPU Off, MCLK Off,
SMCLK Off, DCO Off,
PUC
Active Mode
CPU Is Active
LP Mode LPM2
ACLK On
VCC On
WDTIFG = 0
/NMI is Reset Pin
RST
WDT is Active
CPUOff = 1
SCG0,1 = 1
RST/NMI
NMI Active
CPUOff = 1
OscOff = 1
SG0,1 = 1
LP-Mode LPM4
CPU Off, MCLK Off,
DCO Off, ACLK Off
DC Generator Off
LP Mode LPM3
CPU Off, MCLK Off,
SMCLK Off, DCO Off
ACLK On
DC Generator Off
System Resets, Interrupts, and Operating Modes
3-19
Operating Modes
Figure 3–11. Typical Current Consumption of 13x and 14x Devices vs. Operating Modes
90
45
340
225
70
65
0
AM
LPM0LPM2LPM3LPM4
315
270
225
Aµ
180
135
ICC/
The low-power modes 1–4 enable or disable the CPU and the clocks. In
addition to the CPU and clocks, enabling or disabling specific peripherals may
further reduce total current consumption of the individual modes. The activity
state of each peripheral is controlled by the control registers for the individual
peripherals. In addition, the SFRs include module enable bits that may be used
to enable or disable the operation of specific peripheral modules (see
Table 3–4).
3.5.1Low-Power Mode 0 and 1 (LPM0 and LPM1)
Low power mode 0 or 1 is selected if bit CPUOff in the status register is set.
Immediately after the bit is set the CPU stops operation, and the normal
operation of the system core stops. The operation of the CPU halts and all
internal bus activities stop until an interrupt request or reset occurs. The
system clock generator continues operation, and the clock signals MCLK,
SMCLK, and ACLK stay active depending on the state of the other three status
register bits, SCG0, SCG1, and OscOff.
17
11
Operating Modes
2
VCC = 3 V
= 2.2 V
V
CC
1
0.1 0.1
3-20
The peripherals are enabled or disabled with their individual control register
settings, and with the module enable registers in the SFRs. All I/O port pins
and RAM/registers are unchanged. Wake up is possible through all enabled
interrupts.
The following are examples of entering and exiting LPM0. The method shown
is applicable to all low-power modes.
The following example describes entering into low-power mode 0.
;===Main program flow with switch to CPUOff Mode==============
;
BIS #18h,SR;Enter LPM0 + enable general interrupt GIE
;(CPUOff=1, GIE=1). The PC is incremented
;during execution of this instruction and
;points to the consecutive program step.
......;The program continues here if the CPUOff
;bit is reset during the interrupt service
;routine. Otherwise, the PC retains its
;value and the processor returns to LPM0.
The following example describes clearing low-power mode 0.
;===Interrupt service routine=================================
......;CPU is active while handling interrupts
BIC #10h,0(SP) ;Clears the CPUOff bit in the SR contents
;that were stored on the stack.
RETI;RETI restores the CPU to the active state
;because the SR values that are stored on
;the stack were manipulated. This occurs
;because the SR is pushed onto the stack
;upon an interrupt, then restored from the
;stack after the RETI instruction.
3.5.2Low-Power Modes 2 and 3 (LPM2 and LPM3)
Low-power mode 2 or 3 is selected if bits CPUOff and SCG1 in the status
register are set. Immediately after the bits are set, CPU, MCLK, and SMCLK
operations halt and all internal bus activities stop until an interrupt request or
reset occurs.
Peripherals that operate with the MCLK or SMCLK signal are inactive because
the clock signals are inactive. Peripherals that operate with the ACLK signal
are active or inactive according with the individual control registers and the
module enable bits in the SFRs. All I/O port pins and the RAM/registers are
unchanged. Wake up is possible by enabled interrupts coming from active
peripherals or RST
/NMI.
Operating Modes
3.5.3Low-Power Mode 4 (LPM4)
In low power mode 4 all activities cease; only the RAM contents, I/O ports, and
registers are maintained. Wake up is only possible by enabled external
interrupts.
Before activating LPM4, the software should consider the system conditions
during the low power mode period . The two most important conditions are
environmental (that is, temperature effect on the DCO), and the clocked
operation conditions.
The environment defines whether the value of the frequency integrator should
be held or corrected. A correction should be made when ambient conditions
are anticipated to change drastically enough to increase or decrease the
system frequency while the device is in LPM4.
System Resets, Interrupts, and Operating Modes
3-21
Basic Hints for Low-Power Applications
3.6Basic Hints for Low-Power Applications
There are some basic practices to follow when current consumption is a critical
part of a system application:
-
Switch off analog circuitry when possible.
-
Select the lowest possible operating frequency for the core and the
individual peripheral module.
-
Use the interrupt driven software; the program starts execution rapidly.
-
Tie all unused inputs to an applicable voltage level. The list below defines
the correct termination for all unused pins.
-
AVCC:
-
AVSS:
-
Xout:
-
XIN
-
XT2IN
-
XT2OUT
-
Px.0 to Px.7:
-
RST/NMI:
-
Test/V
-
Test
-
TDO:
-
TDI:
-
TMS:
-
TCK:
Pin
PP
PotentialComment
DV
CC
DV
SS
open
DV
SS
DV
SS
open13x and 14x devices
openUnused ports switched to port function and
resp.VCCPullup resistor 100k
DV
CC
DV
SS
DV
SS
Refer to device specific datasheets for the correct termination of these pins.
13x and 14x devices
output direction
11x devices
11x1 devices
3-22
Chapter 4
Memory
MSP430 devices are configured as a von-Neumann architecture. It has code
memory , data memory , and peripherals in one address space. As a result, the
same instructions are used for code, data, or peripheral accesses. Also, code
may be executed from RAM.
All of the physically separated memory areas (ROM, RAM, SFRs, and
peripheral modules) are mapped into the common address space, as shown
in Figure 4–1 for the MSP430 family . The addressable memory space is 64KB.
Future expansion is possible.
Figure 4–1.Memory Map of Basic Address Space
Address
(Hex.)
0FFFFh
0FFE0h
0FFDFh
0200h
01FFh
0100h
0FFh
010h
0Fh
0h
Interrupt Vector Table
Program Memory
Branch Control Tables
Data Tables...
Data Memory
16-Bit Peripheral Modules
8-Bit Peripheral Modules
Special Function Registers
Function
ROM
ROM
RAM
Timer,
ADC, . . .
I/O, LCD
8bT/C, . . .
SFR
Access
Word/Byte
Word/Byte
Word/Byte
Word
Byte
Byte
The memory data bus (MDB) is 16- or 8-bits wide. For those modules that can
be accessed with word data the width is always 16 bits. For the other modules,
the width is 8 bits, and they must be accessed using byte instructions only . The
program memory (ROM) and the data memory (RAM) can be accessed with
byte or word instructions.
Figure 4–2.Memory Data Bus
Address Range 0000h – 00FFh
LCDUSARTROMRAM
SFRsCOMPARATOR_A
8-Bit Peripheral Modules,
Byte Access
4-2
High Byte
Data Bus
Low Byte
Byte/Word
Access
CPU
ADCWDT
16-Bit Peripheral Modules,
Word Access
4.2Data in the Memory
Bytes are located at even or odd addresses as shown in Figure 4–3. However,
words are only located at even addresses. Therefore, when using word
instructions, only even addresses may be used. The low byte of a word is
always at an even address. The high byte of a word is at the next odd address
after the address of the word. For example, if a data word is located at address
xxx2h, then the low byte of that data word is located at address xxx2h, and the
high byte of that word is located at address xxx3h.
Figure 4–3.Bits, Bytes, and Words in a Byte-Organized Memory
Data in the Memory
xxxAh
157146. . Bits . .
. . Bits . .9180
Byte
Byte
Word (High Byte)
Word (Low Byte)
xxx9h
xxx8h
xxx7h
xxx6h
xxx5h
xxx4h
xxx3h
Memory
4-3
Internal ROM Organization
4.3Internal ROM Organization
V arious sizes of ROM (OTP , masked-ROM, EPROM, or FLASH) are available
within the 64-kB address space, as shown in Figure 4–4. The common
address space is shared with SFRs, peripheral module registers, data and
code memory . The SFRs and peripheral modules are mapped into the address
range, starting with 0 and ending with 01FFh. The remaining address space,
0200h to 0FFFFh, is shared by data and code memory . The start address for
ROM depends on the amount of ROM present. The interrupt vector table is
mapped into the the upper 16 words of ROM address space, with the highest
priority interrupt vector at the highest ROM word address (0FFFEh). See the
individual data sheets for specific memory maps.
Figure 4–4.ROM Organization
0FFFEh
0FFE0h
0F000h
0EFFFh
0D000h
0CFFFh
08000h
4.3.1Processing of ROM Tables
The MSP430 architecture allows for the storage and usage of large tables in
ROM without the need to copy the tables to RAM before using them. This ROM
accessing of tables allows fast and clear programming in applications where
data tables are necessary . This offers the flexible advantages listed below, and
saves on ROM and RAM requirements. To access these tables, all word and
byte instructions can be used.
4 k
12 k
32 k
VectorsVectorsVectorsVectors
Vectors
xx k
4-4
-
ROM storage of an output programmable logic array (OPLA) for display
character conversion
-
The use of as many OPLA terms as needed (no restriction on n terms)
-
OTP version automatically includes OPLA programmability
-
Computed table accessibility (for example, for a bar graph display)
-
Table-supported program flows
4.3.2Computed Branches and Calls
Computed branches and subroutine calls are possible using standard
instructions. The call and branch instructions use the same addressing modes
as the other instructions.
The addressing modes allow indirect-indirect addressing that is ideally suited
for computed branches and calls. This programming technique permits a
program structure that is different from conventional 8- and 16-bit
microcontrollers. Most of the routines can be handled easily by using software
status handling instead of flag-type program-flow control.
The computed branch and subroutine calls are valid throughout the entire
ROM space.
Internal ROM Organization
Memory
4-5
RAM and Peripheral Organization
4.4RAM and Peripheral Organization
The entire RAM can be accessed with byte or word instructions using the
appropriate instruction suffix. The peripheral modules, however, are located
in two different address spaces and must be accessed with the appropriate
instruction length.
-
The SFRs are byte-oriented and mapped into the address space from 0h
up to 0Fh.
-
Peripheral modules that are byte-oriented are mapped into the address
space from 010h up to 0FFh.
-
Peripheral modules that are word-oriented are mapped into the address
space from 100h up to 01FFh.
4.4.1Random Access Memory
RAM can be used for both code and data memory . Code accesses are always
performed on even byte addresses.
The instruction mnemonic suffix defines the data as being word or byte data.
Example:
A word consists of two bytes: a high byte (bit 15 to bit 8), and a low byte
(bit 7 to bit 0) as shown in Figure 4–5. It must always align to an even address.
;High byte is 0
Mem (0203h) = 0A1hR5 = 00061h
C = 0, Z = 0, N = 1C = 0, Z = 0, N = 0
(Low byte of register)(Addressed byte)
+ (Addressed byte)+ (Low byte of register)
–>(Addressed byte)
–>(Low byte of register,
zero to High byte)
Memory
4-7
RAM and Peripheral Organization
Note: Word-Byte Operations
Word-byte or byte-word operations on memory data are not supported. Each
register-byte or byte-register is performed as a byte operation.
4.4.2Peripheral Modules—Address Allocation
Some peripheral modules are accessible only with byte instructions, while
others are accessible only with word instructions. The address space from
0100 to 01FFh is reserved for word modules, and the address space from 00h
to 0FFh is reserved for byte modules.
Peripheral modules that are mapped into the word address space must be
accessed using word instructions (for example, MOV R5,&WDTCTL).
Peripheral modules that are mapped into the byte address space must be
accessed with byte instructions (MOV.B #1,&P1OUT).
The addressing of both is through the absolute addressing mode or the 16-bit
working registers using the indexed, indirect, or indirect autoincrement
addressing mode. See Figure 4–7 for the RAM/peripheral organization.
Figure 4–7.Example of RAM/Peripheral Organization
Address
(Hex.)
01FFh
0100h
0FFh
010h
0Fh
0h
4.4.2.1Word Modules
70
16-Bit Peripheral Modules
8-Bit Peripheral Modules
Special Function Registers
Word modules are peripherals that are connected to the 16-bit MDB.
Word modules can be accessed with word or byte instructions. If byte
instructions are used, only even addresses are permissible, and the high byte
of the result is always ’0’.
The peripheral file address space is organized into sixteen frames with each
frame representing eight words as described in Table 4–1.
Byte modules are peripherals that are connected to the reduced (eight LSB)
MDB. Access to byte modules is always by byte instructions. The hardware
in the peripheral byte modules takes the low byte (the LSBs) during a write
operation.
Byte instructions operate on byte modules without any restrictions. Read
access to peripheral byte modules using word instructions results in
unpredictable data in the high byte. Word data is written into a byte module by
writing the low byte to the appropriate peripheral register and ignoring the high
byte.
The peripheral file address space is organized into sixteen frames as
described in Table 4–2.
00F0h – 00FFhReserved
00E0h – 00EFhReserved
00D0h – 00DFhReserved
00C0h – 00CFhReserved
00B0h – 00BFhReserved
00A0h – 00AFhReserved
0090h – 009FhReserved
0080h – 008FhADC12 memory control
0070h – 007FhUSART0, USART1
0060h – 006FhReserved
0050h – 005FhSystem clock generator, Comparator A
0040h – 004FhReserved
0030h – 003FhDigital I/O port P5, digital I/O port P6
0020h – 002FhDigital I/O port P1 and P2 control
0010h – 001FhDigital I/O port P3, and P4 control
0000h – 000Fh
Special function
4.4.3Peripheral Modules-Special Function Registers (SFRs)
The system configuration and the individual reaction of the peripheral modules
to the processor operation is configured in the SFRs as described in
Table 4–3. The SFRs are located in the lower address range, and are
organized by bytes. SFRs must be accessed using byte instructions only.
4-10
Table 4–3.Special Function Register Address Map
AddressData Bus
000FhNot yet defined or implemented
000EhNot yet defined or implemented
000DhNot yet defined or implemented
000ChNot yet defined or implemented
000BhNot yet defined or implemented
000AhNot yet defined or implemented
0009hNot yet defined or implemented
0008hNot yet defined or implemented
0007hNot yet defined or implemented
0006hNot yet defined or implemented
0005hModule enable 2; ME2.2
0004hModule enable 1; ME1.1
0003hInterrupt flag reg. 2; IFG2.x
0002hInterrupt flag reg.1; IFG1.x
0001hInterrupt enable 2; IE2.x
0000hInterrupt enable 1; IE1.x
RAM and Peripheral Organization
70
The system power consumption is influenced by the number of enabled
modules and their functions. Disabling a module from the actual operation
mode reduces power consumption while other parts of the controller remain
fully active (unused pins must be tied appropriately or power consumption will
increase; see
Basic Hints for Low Power Applications
in section 3.6.
Memory
4-1 1
4-12
Chapter 5
16-Bit CPU
The MSP430 von-Neumann architecture has RAM, ROM, and peripherals in
one address space, both using a single address and data bus. This allows
using the same instruction to access either RAM, ROM, or peripherals and
also allows code execution from RAM.
Sixteen 16-bit registers (R0, R1, and R4 to R15) are used for data and
addresses and are implemented in the CPU. They can address up to
64 Kbytes (ROM, RAM, peripherals, etc.) without any segmentation. The
complete CPU-register set is described in Table 5–1. Registers R0, R1, R2,
and R3 have dedicated functions, which are described in detail later.
Table 5–1.Register by Functions
Program counter (PC)R0
Stack pointer (SP)R1
Status register (SR)
Constant generator (CG1)
Constant generator (CG2)R3
Working register R4R4
Working register R5R5
::
::
Working register R13R13
Working register R14R14
Working register R15R15
5.1.1The Program Counter (PC)
The 16-bit program counter points to the next instruction to be executed. Each
instruction uses an even number of bytes (two, four, or six), and the program
counter is incremented accordingly. Instruction accesses are performed on
word boundaries, and the program counter is aligned to even addresses.
Figure 5–1 shows the program counter bits.
Figure 5–1.Program Counter
150
Program Counter Bits 15 to 1
5.1.2The System Stack Pointer (SP)
The system stack pointer must always be aligned to even addresses because
the stack is accessed with word data during an interrupt request service. The
system SP is used by the CPU to store the return addresses of subroutine calls
and interrupts. It uses a predecrement, postincrement scheme. The
advantage of this scheme is that the item on the top of the stack is available.
The SP can be used by the user software (PUSH and POP instructions), but
the user should remember that the CPU also uses the SP. Figure 5–2 shows
the system SP bits.
1
0
Figure 5–2.System Stack Pointer
150
System Stack Pointer Bits 15 to 1
5-2
1
0
5.1.2.1Examples for System SP Addressing (Refer to Figure 5–4)
MOVSP,R4; SP –> R4
MOV@SP,R5; Item I3 (TOS) –> R5
MOV2(SP),R6; Item I2 –> R6
MOVR7,0(SP); Overwrite TOS with R7
MOVR8,4(SP); Modify item I1
PUSHR12; Store R12 in address 0xxxh – 6; SP points to same address
POPR12; Restore R12 from address 0xxxh – 6; SP points to
0xxxh – 4
MOV@SP+,R5; Item I3 –> R5 (popped from stack); same as POP
instruction
Figure 5–3 shows stack usage.
Figure 5–3.Stack Usage
PUSH #1POP R8Address
CPU Registers
0xxxh
0xxxh – 2
0xxxh – 4
0xxxh – 6
0xxxh – 8
I1
I2
I3
5.1.2.2Special Cases—PUSH SP and POP SP
The special cases of using the SP as an argument to the PUSH and POP
instructions are described below.
Figure 5–4.PUSH SP and POP SP
PUSH SP
SP
old
SP
1
The stack pointer is changed after
a PUSH SP instruction.
SP
1
SP
I1
I2
I3
#1
SP
The stack pointer is not changed
after a POP SP instruction.
SP
2
I1
I2
I3
POP SP
SP
1
SP
After the sequence
PUSH SP
I
I
POP SP; SP2 is stack pointer after this instruction
; SP1 is stack pointer after this instruction
The stack pointer is two bytes lower than before this sequence.
16-Bit CPU
5-3
CPU Registers
5.1.3The Status Register (SR)
The status register SR contains the following CPU status bits:
-
VOverflow bit
-
SCG1System clock generator control bit 1
-
SCG0System clock generator control bit 0
-
OscOffCrystal oscillator off bit
-
CPUOffCPU off bit
-
GIEGeneral interrupt enable bit
-
NNegative bit
-
ZZero bit
-
CCarry bit
Figure 5–5 shows the SR bits.
Figure 5–5.Status Register Bits
150
Reserved For Future Enhancements
879
CPU
SCG1V
rw-0
SCG0GIEZ C
OSC
Off
Off
N
Table 5–2 describes the status register bits.
Table 5–2.Description of Status Register Bits
BitDescription
VOverflow bit. Set if the result of an arithmetic operation overflows the signed-variable range. The
bit is valid for both data formats, byte and word:
ADD(.B), ADDC(.B)Set when:
SCG1, SCG0These bits control four activity states of the system-clock generator and therefore influence the
operation of the processor system.
OscOFFIf set, the crystal oscillator enters off mode: all activities cease; however, the RAM contents, the
port, and the registers are maintained. Wake up is possible only through enabled external
interrupts when the GIE bit is set and from the NMI.
CPU OffIf set, the CPU enters off mode: program execution stops. However , the RAM, the port registers,
and especially the enabled peripherals (for example, Timer_A, UART, etc.) stay active. Wake
up is possible through all enabled interrupts.
GIEIf set, all enabled maskable interrupts are handled. If reset, all maskable interrupts are disabled.
The GIE bit is cleared by interrupts and restored by the RETI instruction as well as by other
appropriate instructions.
NSet if the result of an operation is negative.
Word operation:Negative bit is set to the value of bit 15 of the result
Byte operation:Negative bit is set to the value of bit 7 of the result
ZSet if the result of byte or word operation is 0; cleared if the result is not 0.
C
Set if the result of an operation produced a carry; cleared if no carry occurred. Some instructions
modify the carry bit using the inverted zero bits.
5-4
Note: Status Register Bits V, N, Z, and C
The status register bits V , N, Z, and C are modified only with the appropriate
instruction. For additional information, see the detailed description of the
instruction set in Appendix B.
5.1.4The Constant Generator Registers CG1 and CG2
Commonly-used constants are generated with the constant generator
registers R2 and R3, without requiring an additional 16-bit word of program
code. The constant used for immediate values is defined by the addressing
mode bits (As) as described in T able 5–3. See Section 5.3 for a description of
the addressing mode bits (As).
Table 5–3.Values of Constant Generators CG1, CG2
RegisterAsConstantRemarks
R200– – – – –Register mode
R201(0)Absolute address mode
R21000004h+4, bit processing
R21100008h+8, bit processing
R30000000h0, word processing
R30100001h+1
R31000002h+2, bit processing
R3110FFFFh–1, word processing
CPU Registers
The major advantages of this type of constant generation are:
-
No special instructions required
-
Reduced code memory requirements: no additional word for the six most
used constants
-
Reduced instruction cycle time: no code memory access to retrieve the
constant
The assembler uses the constant generator automatically if one of the six
constants is used as a source operand in the immediate addressing mode.
The status register SR/R2, used as a source or destination register, can be
used in the register mode only. The remaining combinations of
addressing-mode bits are used to support absolute-address modes and bit
processing without any additional code. Registers R2 and R3, used in the
constant mode, cannot be addressed explicitly; they act like source-only
registers.
16-Bit CPU
5-5
CPU Registers
The RISC instruction set of the MSP430 only has 27 instructions. However, the
constant generator allows the MSP430 assembler to support 24 additional,
emulated instructions. For example, the single-operand instruction:
CLRdst
is emulated by the double-operand instruction with the same length:
MOVR3,dst
or the equivalent
MOV#0,dst
where #0 is replaced by the assembler, and R3 is used with As = 00, which
results in:
-
One word instruction
-
No additional control operation or hardware within the CPU
-
Register-addressing mode for source: no additional fetch cycle for the
constant (#0)
5-6
5.2Addressing Modes
All seven addressing modes for the source operand and all four addressing
modes for the destination operand can address the complete address space.
The bit numbers in T able 5–4 describe the contents of the As and Ad mode bits.
See Section 5.3 for a description of the source address As and the destination
address Ad bits.
00/0Register modeRnRegister contents are operand
01/1Indexed modeX(Rn)(Rn + X) points to the operand
01/1Symbolic modeADDR(PC + X) points to the operand
01/1Absolute mode&ADDRThe word following the instruction
10/–Indirect register
mode
11/–Indirect
autoincrement
1 1/–
Immediate mode#NThe word following the instruction
@RnRn is used as a pointer to the
@Rn+Rn is used as a pointer to the
Addressing Modes
X is stored in the next word
X is stored in the next word.
Indexed mode X(PC) is used.
contains the absolute address.
operand.
operand. Rn is incremented
afterwards.
contains the immediate constant
N. Indirect autoincrement mode
@PC+ is used.
The seven addressing modes are explained in detail in the following sections.
Most of the examples show the same addressing mode for the source and
destination, but any valid combination of source and destination addressing
modes is possible in an instruction.
16-Bit CPU
5-7
Addressing Modes
5.2.1Register Mode
The register mode is described in Table 5–5.
Table 5–5.Register Mode Description
Assembler CodeContent of ROM
MOV R10,R11MOV R10,R11
Length:One or two words
Operation:Move the content of R10 to R11. R10 is not affected.
Comment:Valid for source and destination
Example:MOV R10,R1 1
Before:After:
R1 1
PC
0A023hR10
0FA15h
PC
old
R1 1
PCPC
0A023hR10
0A023h
+ 2
old
Note: Data in Registers
The data in the register can be accessed using word or byte instructions. If
byte instructions are used, the high byte is always 0 in the result. The status
bits are handled according to the result of the byte instruction.
5-8
5.2.2Indexed Mode
The indexed mode is described in Table 5–6.
Table 5–6.Indexed Mode Description
Assembler CodeContent of ROM
MOV 2(R5),6(R6)MOV X(R5),Y(R6)
Length:Two or three words
Operation:Move the contents of the source address (contents of R5 + 2)
Comment:Valid for source and destination
Addressing Modes
X = 2
Y = 6
to the destination address (contents of R6 + 6). The source
and destination registers (R5 and R6) are not affected. In
indexed mode, the program counter is incremented
automatically so that program execution continues with the
next instruction.
Example:MOV 2(R5),6(R6):
Before:
0FF16h
0FF14h
0FF12h
01094h
01092h
01090h
01084h
01082h
01080h
Address
Space
00006h
00002h
04596h PC
0xxxxh
05555h
0xxxxh
0xxxxh
01234h
0xxxxh
Register
R5
R6
01080h
0108Ch
0108Ch
+0006h
01092h
01080h
+0002h
01082h
After:
0FF16h
0FF14h
0FF12h
01094h
01092h
01090h
01084h
01082h
01080h
Address
Space
0xxxxh
00006h
00002h
04596h
0xxxxh
01234h
0xxxxh
0xxxxh
01234h
0xxxxh
PC
Register
R5
R6
01080h
0108Ch
16-Bit CPU
5-9
Addressing Modes
5.2.3Symbolic Mode
The symbolic mode is described in Table 5–7.
Table 5–7.Symbolic Mode Description
Assembler CodeContent of ROM
MOV EDE,TONIMOV X(PC),Y(PC)
Length:Two or three words
Operation:Move the contents of the source address EDE (contents of
PC + X) to the destination address TONI (contents of PC + Y).
The words after the instruction contain the differences
between the PC and the source or destination addresses.
The assembler computes and inserts offsets X and Y
automatically . With symbolic mode, the program counter (PC)
is incremented automatically so that program execution
continues with the next instruction.
X = EDE – PC
Y = TONI – PC
Comment:Valid for source and destination
Example:MOV EDE,TONI;Source address EDE = 0F016h,
;dest. address TONI=01114h
Before:
0FF16h
0FF14h
0FF12h
0F018h
0F016h
0F014h
01116h
01114h
01112h
Address
Space
011FEh
0F102h
04090h PC
0xxxxh
0A123h
0xxxxh
0xxxxh
01234h
0xxxxh
Register
0FF14h
+0F102h
0F016h
0FF16h
+011FEh
01114h
After:
0FF16h
0FF14h
0FF12h
0F018h
0F016h
0F014h
01116h
01114h
01112h
Address
Space
0xxxxh
011FEh
0F102h
04090h
0xxxxh
0A123h
0xxxxh
0xxxxh
0A123h
0xxxxh
Register
PC
5-10
5.2.4Absolute Mode
The absolute mode is described in Table 5–8.
Table 5–8.Absolute Mode Description
Assembler CodeContent of ROM
MOV &EDE,&TONIMOV X(0),Y(0)
Length:Two or three words
Operation:Move the contents of the source address EDE to the
destination address TONI. The words after the instruction
contain the absolute address of the source and destination
addresses. With absolute mode, the PC is incremented
automatically so that program execution continues with the
next instruction.
Comment:Valid for source and destination
Example:MOV &EDE,&TONI;Source address EDE = 0F016h,
Addressing Modes
X = EDE
Y = TONI
;dest. address TONI=01114h
Before:
0FF16h
0FF14h
0FF12h
0F018h
0F016h
0F014h
01116h
01114h
01112h
Address
Space
01114h
0F016h
04292h PC
0xxxxh
0A123h
0xxxxh
0xxxxh
01234h
0xxxxh
Register
After:
0FF16h
0FF14h
0FF12h
0F018h
0F016h
0F014h
01116h
01114h
01112h
Address
Space
0xxxxh
01114h
0F016h
04292h
0xxxxh
0A123h
0xxxxh
0xxxxh
0A123h
0xxxxh
Register
PC
This address mode is mainly for hardware peripheral modules that are located
at an absolute, fixed address. These are addressed with absolute mode to
ensure software transportability (for example, position-independent code).
16-Bit CPU
5-11
Addressing Modes
5.2.5Indirect Mode
The indirect mode is described in table 5–9.
Table 5–9.Indirect Mode Description
Assembler CodeContent of ROM
MOV @R10,0(R11)MOV @R10,0(R11)
Length:One or two words
Operation:Move the contents of the source address (contents of R10) to
Comment:Valid only for source operand. The substitute for destination
Example:MOV.B @R10,0(R11)
the destination address (contents of R11). The registers are
not modified.
operand is 0(Rd).
Before:
0FF16h
0FF14h
0FF12h
0FA34h
0FA32h
0FA30h
002A8h
002A7h
002A6h
Address
Space
0xxxxh
0000h
04AEBh
0xxxxh
0xxxxh
05BC1h
0xxxxh
0xxh
012h
0xxh
PC
R10
R1 1
Register
0FA33h
002A7h
After:
0FF16h
0FF14h
0FF12h
0FA34h
0FA32h
0FA30h
002A8h
002A7h
002A6h
Address
Space
0xxxxh
0000h
04AEBh
0xxxxh
0xxxxh
05BC1h
0xxxxh
0xxh
05Bh
0xxh
PC
R10
R1 1
Register
0FA33h
002A7h
5-12
5.2.6Indirect Autoincrement Mode
The indirect autoincrement mode is described in Table 5–10.
Length:One or two words
Operation:Move the contents of the source address (contents of R10) to
the destination address (contents of R11). Register R10 is
incremented by 1 for a byte operation, or 2 for a word
operation after the fetch; it points to the next address without
any overhead. This is useful for table processing.
Comment:Valid only for source operand. The substitute for destination
operand is 0(Rd) plus second instruction INCD Rd.
Example:MOV @R10+,0(R1 1)
Addressing Modes
Before:
0FF18h
0FF16h
0FF14h
0FF12h
0FA34h
0FA32h
0FA30h
010AAh
010A8h
010A6h
Address
Space
0xxxxh
00000h
04ABBh
0xxxxh
0xxxxh
05BC1h
0xxxxh
0xxxxh
01234h
0xxxxh
PC
R10
R1 1
Register
0FA32h
010A8h
After:
0FF18h
0FF16h
0FF14h
0FF12h
0FA34h
0FA32h
0FA30h
010AAh
010A8h
010A6h
Address
Space
0xxxxh
00000h
04ABBh
0xxxxh
0xxxxh
05BC1h
0xxxxh
0xxxxh
05BC1h
0xxxxh
PC
R1 1
Register
0FA34hR10
010A8h
The autoincrementing of the register contents occurs after the operand is
fetched. This is shown in Figure 5–6.
Figure 5–6.Operand Fetch Operation
InstructionAddressOperand
+1/ +2
16-Bit CPU
5-13
Addressing Modes
5.2.7Immediate Mode
The immediate mode is described in Table 5–11.
Table 5–11.Immediate Mode Description
Assembler CodeContent of ROM
MOV #45,TONIMOV @PC+,X(PC)
Length:Two or three words
It is one word less if a constant of CG1 or CG2 can be used.
Operation:Move the immediate constant 45, which is contained in the
word following the instruction, to destination address TONI.
When fetching the source, the program counter points to the
word following the instruction and moves the contents to the
destination.
Comment:Valid only for a source operand.
45
X = TONI – PC
Example:MOV #45,TONI
Before:
0FF16h
0FF14h
0FF12h
010AAh
010A8h
010A6h
Address
Space
01192h
00045h
040B0h PC
0xxxxh
01234h
0xxxxh
Register
0FF16h
+01192h
010A8h
After:
0FF18h
0FF16h
0FF14h
0FF12h
010AAh
010A8h
010A6h
Address
Space
0xxxxh
01192h
00045h
040B0h
0xxxxh
00045h
0xxxxh
Register
PC
5-14
5.2.8Clock Cycles, Length of Instruction
The operating speed of the CPU depends on the instruction format and
addressing modes. The number of clock cycles refers to the MCLK.
5.2.8.1Format-I Instructions
Table 5–12 describes the CPU format-I instructions and addressing modes.
Table 5–12.Instruction Format I and Addressing Modes
Addressing Modes
Address Mode
AsAd
00, Rn
00, Rn1, x(Rm)
01, x(Rn)
01, EDE
01, &EDE
01, x(Rn)
01, EDE
01, &EDE
10, @Rn0, Rm21AND@R4,R5
10, @Rn1, x(Rm)
11, @Rn+
11, #N
11, @Rn+
11, #N
11, @Rn+
11, #N
0, Rm
0, PC
1, EDE
1, &EDE
0, Rm32
1, x(Rm)
1, TONI
1, &TONI
1, EDE
1, &EDE
0, Rm
0, PC
0, Rm
0, PC
1, x(Rm)
1, EDE
1, &EDE
No. ofLength ofExample
CyclesInstruction
1
2
42
63
52
2
3
2
3
52
1
1
2
2
2
2
3
3
3
2
2
1
1
2
2
3
2
3
MOVBRR5,R8
R9
ADD
XOR
MOR
MOV
AND
MOV
ADD
CMP
MOV
ADD
XOR
MOV
XOR
ADD
BR
MOV
BR
MOV
ADD
MOV
ADD
R5,3(R6)
R8,EDE
R5,&EDE
2(R5),R7
EDE,R6
&EDE,R8
3(R4),6(R9)
EDE,TONI
2(R5),&TONI
EDE,&TONI
@R5,8(R6)
@R5,EDE
@R5,&EDE
@R5+,R6
@R9+
#20,R9
#2AEh
@R9+,2(R4)
#33,EDE
@R9+,&EDE
#33,&EDE
16-Bit CPU
5-15
Addressing Modes
(
)
5.2.8.2Format-II Instructions
Table 5–13 describes the CPU format II instructions and addressing modes.
Table 5–13.Instruction Format-II and Addressing Modes
No. of Cycles
RRA
RRC
Address Mode
A
s/d
00, Rn
01, X(Rn)
01, EDE
01, &EDE
10, @Rn341RRC @R9
11, @Rn+
(see Note)
11, #N
Note: Instruction Format II Immediate Mode
Do not use instructions RRA, RRC, SWPB, and SXT with the immediate
mode in the destination field. Use of these in the immediate mode will result
in an unpredictable program operation.
SWPB
SXT
13/41SWPB R5
4
4
34/51
PUSH/
CALL
5
5
Length of
Instruction
(words)
2
2
2
Example
CALL 2(R7)
PUSH EDE
SXT &EDE
SWPB @R10+
CALL #81H
5.2.8.3Format-III Instructions
Format-III instructions are described as follows:
Jxx—all instructions need the same number of cycles, independent of
whether a jump is taken or not.
Clock cycle:Two cycles
Length of instruction:One word
This section gives a short overview of the instruction set. The addressing
modes are described in Section 5.2.
Instructions are either single or dual operand or jump.
The source and destination parts of an instruction are defined by the following
fields:
srcThe source operand defined by As and S-reg
dstThe destination operand defined by Ad and D-reg
AsThe addressing bits responsible for the addressing mode used
for the source (src)
S-regThe working register used for the source (src)
AdThe addressing bits responsible for the addressing mode used
for the destination (dst)
D-regThe working register used for the destination (dst)
B/WByte or word operation:
0: word operation
1: byte operation
Instruction Set Overview
Note: Destination Address
Destination addresses are valid anywhere in the memory map. However,
when using an instruction that modifies the contents of the destination, the
user must ensure the destination address is writeable. For example, a
masked-ROM location would be a valid destination address, but the contents
are not modifiable, so the results of the instruction would be lost.
16-Bit CPU
5-17
Instruction Set Overview
5.3.1Double-Operand Instructions
Figure 5–7 illustrates the double-operand instruction format.
Figure 5–7.Double Operand Instruction Format
150
Opcode
Table 5–15 describes the effects of an instruction on double operand
instruction status bits.
8714131211109654321
B/WD-Reg
AdS-Reg
Table 5–15.Double Operand Instruction Format Results
*The status bit is affected
–The status bit is not affected
0The status bit is cleared
1The status bit is set
Ad
VNZC
All addressing modes are possible for the CALL instruction. If the symbolic
mode (ADDRESS), the immediate mode (#N), the absolute mode (&EDE) or
the indexed mode X (RN) is used, the word that follows contains the address
information.
16-Bit CPU
5-19
Instruction Set Overview
5.3.3Conditional Jumps
Conditional jumps support program branching relative to the program counter.
The possible jump range is from –511 to +512 words relative to the program
counter state of the jump instruction. The 10-bit program-counter offset value
is treated as a signed 10-bit value that is doubled and added to the program
counter. None of the jump instructions affect the status bits.
The instruction code fetch and the program counter increment technique end
with the formula:
PC
new
= PC
+ 2 + PC
old
Figure 5–9 shows the conditional-jump instruction format.
Figure 5–9.Conditional-Jump Instruction Format
150
Opcode
C10-Bit PC Offset
Table 5–17 describes these conditional-jump instructions.
8714131211109654321
Table 5–17.Conditional-Jump Instructions
Mnemonic
JEQ/JZLabelJump to label if zero bit is set
JNE/JNZLabelJump to label if zero bit is reset
JCLabelJump to label if carry bit is set
JNCLabelJump to label if carry bit is reset
JNLabel
JGELabelJump to label if (N .XOR. V) = 0
JLLabelJump to label if (N .XOR. V) = 1
JMPLabelJump to label unconditionally
S-Reg, D-Reg
× 2
offset
Operation
Jump to label if negative bit is set
5-20
Instruction Set Overview
5.3.4Short Form of Emulated Instructions
The basic instruction set, together with the register implementations of the
program counter, stack pointer, status register, and constant generator, form
the emulated instruction set; these make up the popular instruction set. The
status bits are set according to the result of the execution of the basic
instruction that replaces the emulated instruction.
Table 5–18 describes these instructions.
Table 5–18.Emulated Instructions
MnemonicDescriptionStatus BitsEmulation
VNZC
ArIthmetic Instructions
ADC[.W]dstAdd carry to destination****ADDC#0,dst
ADC.BdstAdd carry to destination****ADDC.B#0,dst
DADC[.W]dstAdd carry decimal to destination****DADD#0,dst
DADC.BdstAdd carry decimal to destination****DADD.B#0,dst
DEC[.W]dstDecrement destination****SUB#1,dst
DEC.BdstDecrement destination****SUB.B#1,dst
DECD[.W]dstDouble-decrement destination****SUB#2,dst
DECD.BdstDouble-decrement destination****SUB.B#2,dst
INC[.W]dstIncrement destination****ADD#1,dst
INC.BdstIncrement destination****ADD.B#1,dst
INCD[.W]dstIncrement destination****ADD#2,dst
INCD.BdstIncrement destination****ADD.B#2,dst
SBC[.W]dstSubtract carry from destination****SUBC#0,dst
SBC.BdstSubtract carry from destination****SUBC.B#0,dst
Logical Instructions
INV[.W]dstInvert destination****XOR#0FFFFh,dst
INV.BdstInvert destination****XOR.B#–1,dst
RLA[.W]dstRotate left arithmetically****ADDdst,dst
RLA.BdstRotate left arithmetically****ADD.Bdst,dst
RLC[.W]dstRotate left through carry****ADDCdst,dst
RLC.BdstRotate left through carry****ADDC.Bdst,dst
Data Instructions (common use)
CLR[.W]Clear destination––––MOV#0,dst
CLR.BClear destination––––MOV.B#0,dst
CLRCClear carry bit–––0BIC#1,SR
CLRNClear negative bit–0––BIC#4,SR
CLRZClear zero bit––0–BIC#2,SR
POPdstItem from stack––––MOV@SP+,dst
SETCSet carry bit–––1BIS#1,SR
SETNSet negative bit–1––BIS#4,SR
SETZSet zero bit––1–BIS#2,SR
BRdstBranch to . . .––––MOVdst,PC
DINTDisable interrupt––––BIC#8,SR
EINTEnable interrupt––––BIS#8,SR
NOPNo operation––––MOV#0h,#0h
RETReturn from subroutine––––MOV@SP+,PC
5.3.5Miscellaneous
Instructions without operands, such as CPUOff, are not provided. Their
functions are switched on or off by setting or clearing the function bits in the
status register or the appropriate I/O register. Other functions are emulated
using dual operand instructions.
Some examples are as follows:
BIS#28h,SR; Enter OscOff mode
; + Enable general interrupt (GIE)
BIS#18h,SR; Enter CPUOff mode
; + Enable general interrupt (GIE)
5-22
5.4Instruction Map
The instruction map in Figure 5–10 is an example of how to encode
instructions. There is room for more instructions, if needed.
The hardware multiplier is a 16-bit peripheral module. It is not integrated into
the CPU. Therefore, it requires no special instructions and operates
independent of the CPU. To use the hardware multiplier, the operands are
loaded into registers and the results are available the next instruction—no
extra cycles are required for a multiplication.
The hardware multiplier module expands the capabilities of the MSP430
family without changing the basic architecture. Multiplication is possible for:
-
16×16 bits
-
16×8 bits
-
8×16 bits
-
8×8 bits
The hardware multiplier module supports four types of multiplication: unsigned
multiplication (MPY), signed multiplication (MPYS), unsigned multiplication
with accumulation (MAC), and signed multiplication with accumulation
(MACS). Figure 6–1 shows how the hardware multiplier module interfaces
with the bus system to support multiplication operations.
Figure 6–1.Connection of the Hardware Multiplier Module to the Bus System
ROMRAM
TDI
TDO
TMS
TCK
CPU
Incl. 16 Reg.
Test
JTAG
MAB, 16 Bit
MDB, 16 Bit
MPY
MPYS
MAC
MACS
Other
Modules
6-2
Hardware Multiplier Operation
6.2Hardware Multiplier Operation
The hardware multiplier has two 16-bit registers for both operands and three
registers to store the results of the multiplication. The multiplication is
executed correctly when the first operand is written to the operand register
OP1 prior to writing the second operand to OP2. Writing the first operand to
the applicable register selects the type of multiplication. Writing the second
operand to OP2 starts the multiplication. Multiplication is completed before the
result registers are accessed using the indexed address mode for the source
operand. When indirect or indirect autoincrement address modes are used,
another instruction is needed between the writing of the second operand and
accessing the result registers. Both operands, OP1 and OP2, utilize all seven
address mode capabilities.
No instruction is necessary for the multiplication; as a result, the real-time
operation does not require additional clock cycles and the interrupt latency is
unchanged.
The multiplier architecture is illustrated in Figure 6–2.
Figure 6–2.Block Diagram of the MSP430 16×16-Bit Hardware Multiplier
0rw15
Operand 1
(address
defines
operation)
MPY 130h
MPYS 132h
MAC 134h
MACS 136h
Operand 1Operand 2 138h
0rw150rw15
Mode
16 x 16 Multiplier
031
Accessible Register
0000
MACS
MPYS
MACMPY
ModeMode
Multiplexer
SumExt 13EhC
S
Product Register
MPY, MPYS
32-Bit Multiplexer
Accumulator ACC
SumLo 013AhSumHi 13Ch
32-Bit Adder
MAC, MACS
0rw150rw150r15
Hardware Multiplier
6-3
Hardware Multiplier Operation
ACC) ≤
ACC) >
ACC) >
ACC) ≤
The sum extension register contents differ, depending on the operation and
on the results of the operation.
Table 6–1.Sum Extension Register Contents
RegisterMPYMPYSMACMACS, see Notes
Operand1x+ –+ +
(OP1×OP2 +
(OP1×OP2 +
(OP1×OP2 +
(OP1×OP2 +
Operand2x+ –– –
SumExt
Note:The following two overflow conditions may occur when using the MACS function and should be handled by software or
avoided.
0000h0000h0FFFFh 0000h0001h0FFFFh0000h
1) The result of a MACS operation is positive and larger than 07FFF FFFFh. In this case, the SumExt register contains
0FFFFh and the ACC register contains a negative number (8000 0000h .... 0FFFF FFFFh).
2) The result of a MACS operation is negative and less than or equal to 07FFF FFFFh. In this case, the SumExt register
contains 0000h and the ACC register contains a positive number (0000 0000h ... 07FFF FFFFh).
The following multiplication operation shows 32 bytes of program code and 32
execution cycles (16×16 bit multiplication).
**********************************************************
*TRANSFER BOTH OPERANDS TO THE REGISTERS IN THE*
*HARDWARE MULTIPLIER MODULE*
*USE CONSTANT OPERAND1 AND OPERAND2 TO IDENTIFY*
*BYTE DATA*
**********************************************************
**********************************************************
*EXAMPLE TO ADD THE RESULT OF THE HARDWARE*
*MULTIPLICATION TO THE RAM DATA, 64BITS*
**********************************************************
ADD&RESLO,&RAM; ADD LOW RESULT TO RAM
ADDC&RESHI,&RAM+2 ; ADD HIGH RESULT TO RAM+2
ADC&RAM+4; ADD CARRY TO EXTENSION WORD
ADC&RAM+6; IF 64 BIT LENGTH IS USED
Hardware Multiplier
6-5
Hardware Multiplier Operation
6.2.2Multiply Signed, 16×16 bit, 16×8 bit, 8×16 bit, 8×8 bit
The following multiplication operation shows 36 bytes of program code and 36
execution cycles (16×16 bit multiplication).
**********************************************************
*TRANSFER BOTH OPERANDS TO THE REGISTERS IN THE*
*HARDWARE MULTIPLIER MODULE*
*IF ONE OF THE OPERANDS IS 8 BIT, SIGN EXTENSION*
*is NEEDED. USE CONSTANT OPERAND1 AND OPERAND2 TO *
*IDENTIFY BYTE DATA*
**********************************************************
**********************************************************
*EXAMPLE TO ADD THE RESULT OF THE HARDWARE*
*MULTIPLICATION TO THE RAM DATA, 64 BITS*
**********************************************************
ADD&RESLO,&RAM; ADD LOW RESULT TO RAM
ADDC &RESHI,&RAM+2 ; ADD HIGH RESULT TO RAM+2
ADDC &SUMEXT,&RAM+4 ; ADD SIGN WORD TO EXTENSION WORD
ADDC &SUMEXT,&RAM+6 ; IF 64 BIT LENGTH IS USED
6-6
Hardware Multiplier Operation
6.2.3Multiply Unsigned and Accumulate, 16x16bit, 16x8bit, 8x16bit, 8x8bit
The following multiplication operation shows 32 bytes of program code and 32
execution cycles (16X16-bit multiplication).
**********************************************************
*TRANSFER BOTH OPERANDS TO THE REGISTERS IN THE*
*HARDWARE MULTIPLIER MODULE*
*THE RESULT OF THE MULTIPLICATION IS ADDED TO THE*
*CONTENT OF BOTH RESULT REGISTERS, RESLO AND RESHI *
*USE CONSTANT OPERAND1 AND OPERAND2 TO IDENTIFY*
*BYTE DATA*
**********************************************************
**********************************************************
*EXAMPLE TO ADD THE RESULT OF THE HARDWARE*
*MULTIPLICATION TO THE RAM DATA, 64BITS*
*THE RESULT OF THE MULTIPLICATION IS HELD IN RESLO*
*AND RESHI REGISTERS. THE UPPER TWO WORDS IN THE *
*EXAMPLE ARE FURTHER LOCATED IN THEIR RAM LOCATION*
**********************************************************
ADDC&SUMEXT,&RAM+4 ; ADD SUMEXTENSTION TO RAM+4
ADC&RAM+6; IF 64 BIT LENGTH IS USED
Hardware Multiplier
6-7
Hardware Multiplier Operation
6.2.4Multiply Signed and Accumulate, 16x16bit, 16x8bit, 8x16bit, 8x8bit
********************************************************************
* TRANSFER BOTH OPERANDS TO THE REGISTERS IN THE HARDWARE *
* MULTIPLIER MODULE *
* USE CONSTANT OPERAND1 AND OPERAND 2 TO IDENTIFY BYTE DATA *
********************************************************************
OPERAND1.EQU0; 0: OPERAND1 IS WORD (16BIT)
; 8: OPERAND1 IS BYTE ( 8BIT)
OPERAND2.EQU0; 0: OPERAND2 IS WORD (16BIT)
; 8: OPERAND2 IS BYTE ( 8BIT)
MPY.EQU0130H
MPYS.EQU0132H
MAC.EQU0134H
MACS.EQU0136H
OP2.EQU0138H
RESLO.EQU013AH
RESHI.EQU013CH
SUMEXT.EQU013EH
MAXMACS.EQU32H;NUMBER OF MACS FUNCTIONS WHICH COULD
********************************************************************
* EXAMPLE TO ADD THE RESULT OF THE HARDWARE MULTIPLICATION *
* TO THE RAM DATA IF NECESSARY *
* THE RESULT OF THE MULTIPLICATION IS HELD IN RESLO AND *
* RESHI REGISTERS. THE UPPER TWO WORDS IN THE EXAMPLE ARE *
* FURTHER LOCATED IN THEIR RAM LOCATION *
INCMCOUNT; INC MACS COUNTER
CMP#MAXMACS,MCOUNT; ONLY ADD TO RAM IF NECESSARY
JNENEXTMACS;
ADDC&RESLO,&RAM+0; ADD SUMEXTENSION TO RAM+0
ADDC&RESHI,&RAM+2; ADD SUMEXTENSION TO RAM+2
ADDC&SUMEXT,&RAM+4; ADD SUMEXTENSION TO RAM+4
ADDC&SUMEXT,&RAM+6; IF 64 BIT LENGTH IS USED
CLRMCOUNT
NEXTMACS
. . .
; 2 BYTES
; MULTIPLICATION
; MULTIPLICATION
6-8
Hardware Multiplier Registers
6.3Hardware Multiplier Registers
Hardware multiplier registers are word structured, but can be accessed using
word or byte processing instructions. Table 6–2 describes the hardware
multiplier registers.
Table 6–2.Hardware Multiplier Registers
RegisterShort FormRegister TypeAddressInitial State
Multiply Unsigned (Operand1)MPYRead/write0130hUnchanged
Multiply Signed (Operand1)MPYSRead/write0132hUnchanged
Multiply+Accumulate (Operand1)MACRead/write0134hUnchanged
Multiply Signed+Accumulate (Operand1)MACSRead/write0136hUnchanged
Second OperandOP2Read/write0138hUnchanged
Result Low WordResLoRead/write013AhUndefined
Result High WordResHiRead/write013ChUndefined
Sum ExtendSumExtRead013EhUndefined
Two registers are implemented for both operands, OP1 and OP2, as shown
in Figure 6–3. Operand 1 uses four different addresses to address the same
register. The dif ferent address information is decoded and defines the type of
multiplication operation used.
Figure 6–3.Registers of the Hardware Multiplier
150
MPY (130h),MPYS (132h)
MAC (134h), MACS(136h)
OP2 (138h)
ResLo (13Ah)
ResHi (13Ch)
SumExt (13Eh)
The multiplication result is located in two word registers: result high (RESHI)
and result low (RESLO). The sum extend register (SumExt) holds the result
sign of a signed operation or the overflow of the multiply and accumulate
(MAC) operation. See Section 6.5.3 for a description of overflow and
underflow when using the MACS operations.
All registers have the least significant bit (LSB) at bit0 and the most significant
bit (MSB) at bit7 (byte data) or bit15 (word data).
Operand 1, OP1
Operand 2, OP2
Result Low Word, ResLo
Result High Word, ResHi
Sum Extension Word, SumExt
Hardware Multiplier
6-9
Hardware Multiplier Special Function Bits
6.4Hardware Multiplier Special Function Bits
Because the hardware multiplier module completes all multiplication
operations quickly, without interrupt intervention, no special function bits are
used.
6.5Hardware Multiplier Software Restrictions
Two restrictions require attention when the hardware multiplier is used:
-
The indirect or indirect autoincrement address mode used to process the
result
-
The hardware multiplier used in an interrupt routine
The result of the multiplication operation can be accessed in indexed, indirect,
or indirect autoincrement mode. The result registers may be accessed without
any restrictions if you use the indexed address mode including the symbolic
and absolute address modes. However, when you use the indirect and indirect
autoincrement address modes to access the result registers, you need at least
one instruction between loading the second operand and accessing one of the
result registers.
**********************************************************
*EXAMPLE: MULTIPLY OPERAND1 AND OPERAND2
**********************************************************
RESLO.SET013AH; RESLO = ADDRESS OF RESLO
PUSHR5; R5 WILL HOLD THE ADDRESS OF
MOV#RESLO,R5; THE RESLO REGISTER
MOV&OPER1,&MPY ; LOAD 1ST OPERAND,
; DEFINES ADD. UNSIGNED MULTIPLY
MOV&OPER2,&OP2 ; LOAD 2ND OPERAND AND START
; MULTIPLICATION
**********************************************************
*EXAMPLE TO ADD THE RESULT OF THE HARDWARE*
*MULTIPLICATION TO THE RAM DATA, 64BITS*
**********************************************************
NOP; MIN. ONE CYCLES BETWEEN MOVING
; THE OPERAND2 TO HW–MULTIPLIER
; AND PROCESSING THE RESULT WITH
; INDIRECT ADDRESS MODE
ADD@R5+,&RAM; ADD LOW RESULT TO RAM
ADDC@R5,&RAM+2 ; ADD HIGH RESULT TO RAM+2
ADC&RAM+4; ADD CARRY TO EXTENSION WORD
ADC&RAM+6; IF 64 BIT LENGTH IS USED
POPR5
The previous example shows that the indirect or indirect autoincrement
address modes, when used to transfer the result of a multiplication operation
to the destination, need more cycles and code than the absolute address
mode. There is no need to access the hardware multiplier using the indirect
addressing mode.
The entire multiplication routine requires only three steps:
1) Move operand OP1 to the hardware multiplier; this defines the type of
multiplication.
2) Move operand OP2 to the hardware multiplier; the multiplication starts.
3) Process the result of the multiplication in the RESLO, RESHI, and
SUMEXT registers.
The following considerations describe the main routines that use hardware
multiplication. If no hardware multiplication is used in the main routine,
multiplication in an interrupt routine is protected from further interrupts,
because the GIE bit is reset after entering the interrupt service routine.
Typically, a multiplication operation that uses the entire data process occurs
outside an interrupt routine and the interrupt routines are as short as possible.
A multiplication operation in an interrupt routine has some feedback to the
multiplication operation in the main routine.
6.5.2.1Interrupt Following an OP1 Transfer
The two LSBs of the first operand address define the type of multiplication
operation. This information cannot be recovered by any later operation.
Therefore an interrupt must not be accepted between the first two steps: move
operand OP1 and OP2 to the multiplier.
6.5.2.2Interrupt Following an OP2 Transfer
After the first two steps, the multiplication result is in the corresponding
registers RESLO, RESHI, and SUMEXT. It can be saved on the stack (using
the PUSH instruction) and can be restored after completing another
multiplication operation (using the POP instruction). However, this operation
takes additional code and cycles in the interrupt routine. You can avoid this,
by making an entire multiplication routine uninterruptible, by disabling any
interrupt (DINT) before entering the multiplication routine, and by enabling
interrupts (EINT) after the multiplication routine is completed. The negative
aspect of this method is that the critical interrupt latency is increased drastically
for events that occur during this period.
6.5.2.3General Recommendation
In general, one should avoid a hardware multiplication operation within an
interrupt routine when a hardware multiplication is already used in the main
program. (This will depend upon the application-specific software, applied
libraries, and other included software.) The methods previously discussed
have some negative implications; therefore, the best practice is to keep
interrupt routines as short as possible.
The multiplier does not automatically detect underflow or overflow in the
MACS mode. An overflow occurs when the sum of the accumulator register
and the result of the signed multiplication exceed the maximum binary range.
The binary range of the accumulator for positive numbers is 0 to 2
(7FFF FFFFh) and for negative numbers is –1 (0FFFF FFFFh) to –2
(8000 0000h). An overflow occurs when the sum of two negative numbers
yields a result that is in the range given above for a positive number. An underflow occurs when the sum of two positive numbers yields a result that is in the
range for a negative number.
The maximum number of successive MACS instructions without underflow or
overflow is limited by the individual application and should be determined using a worst-case calculation. Care should then be exercised to not exceed the
maximum number or to handle the conditions accordingly.
31
–1
31
6-12
Loading...
+ hidden pages
You need points to download manuals.
1 point = 1 manual.
You can buy points or you can get point for every manual you upload.