0% found this document useful (0 votes)
14 views74 pages

MC Unit 1

This document outlines a course on microcontrollers, specifically focusing on the MSP430 architecture and programming. It includes course objectives, syllabus details, outcomes, and program educational objectives, emphasizing the understanding of microcontroller systems, programming skills, and practical applications. The content covers various topics such as digital I/Os, interrupts, low power modes, clock systems, timers, and communication interfaces, along with references for further reading.

Uploaded by

Siddu Uttur
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views74 pages

MC Unit 1

This document outlines a course on microcontrollers, specifically focusing on the MSP430 architecture and programming. It includes course objectives, syllabus details, outcomes, and program educational objectives, emphasizing the understanding of microcontroller systems, programming skills, and practical applications. The content covers various topics such as digital I/Os, interrupts, low power modes, clock systems, timers, and communication interfaces, along with references for further reading.

Uploaded by

Siddu Uttur
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 74

Unit – 1

Introduction

Dr.Shobha K R
Professor
Dept of ETE, MSRIT

slides are used for academic purpose only 1


Course Objectives
Credits: 3:1:0:0
Prerequisite Courses with codes :
⚫ Fundamentals of Computing ( CS 201)

⚫ Course Objectives
⚫ Provide a basic understanding of microcontroller &
Instruction-set architectures
⚫ Develop skills of Programming MSP430 using assembly/ C
languages
⚫ Teach the details of I/Os, Interrupts & LP modes of MSP430
⚫ Discuss the concepts of clocks and timers in MSP430
⚫ Impart the knowledge of using mixed mode peripherals
and Communication peripherals

slides are used for academic purpose only 2


Syllabus
Unit I
Introduction to Microcontroller: Small Microcontroller, Anatomy of a Typical Small Microcontroller, Memory,
Software, where does MSP430 fit, The Outside View—Pin-Out, Functional Block Diagram, Central Processing
Unit, Memory-Mapped Input and Output, Clock Generator, Exceptions: Interrupts and Resets, Development
Environment, Assembly Language., Access to the Microcontroller for Programming and Debugging.

Unit II
Architecture of the MSP430 Processor: Central Processing Unit., Addressing Modes, Constant Generator and
Emulated Instructions, Instruction Set, Examples, Reflections on the CPU and Instruction Set, Resets.

Unit III
Digital I/Os, Interrupts and LP Modes: Parallel ports, Interrupts on Inputs, Application: examples of hex keypad,
multiplexed display, LCD and DC motor interfaces. Interrupts and ISRs. Low Power Modes of operation.
Development Environment: Introduction, Aspects of C for Embedded Systems, Access for debugging, MSP430-
starter kit

Unit IV
Clock System & Timers: Clock modules; Crystal oscillators, VLO and DCO, Clock module control, Oscillator
Faults, FLL+.
Timers: Watchdog timer, Basic Timer1, RTC, Timer_A; Timer block, Capture and compare channels, Interrupts,
Example application –Generation of a precise frequency and a simple PWM.

Unit V
Mixed Signal Systems and Communication Interfaces: General and practical issues with ADCs, Architecture
and Basic operations of - The ADC10 Successive-Approximation, Basic introduction to DAC12, Serial Peripheral
Interface, SPI with USCI, Software UART using Timer_A.

slides are used for academic purpose only 3


Text books and References

Text Books:
1. John H. Davies, MSP430 Microcontroller
Basics, Newnes ,Elsevier, 2008.
2. Cris Nagy, Embedded Systems Design
using the TI MSP430 Series, Newnes,
Elsevier,
2003.
References:
1. www.msp430.com

slides are used for academic purpose only 4


Course Outcomes
1. Analyze the concepts of Microcontroller
2. Design and implement basic programs
3. Develop, Implement, analyze and debug C
programs to interact with built in Peripherals
4. Design simple applications using Timers
5. Design applications using mixed signal and
communication Interfaces

slides are used for academic purpose only 5


Program Outcomes
1. An ability to apply knowledge of mathematics, science and engineering fundamentals appropriate to
telecommunication Engineering.
2. An ability to identify, formulate, research literature and analyze a complex electronic and
telecommunication engineering problem.
3. An ability to design a system, component, or process to meet specified needs with societal,
environmental, public health, safety and cultural considerations.
4. An Ability to analyze, interpret, design and synthesize complex engineering problems to provide valid
conclusions.
5. An Ability to use current technology and modern tools for solving complex engineering problems with
an understanding of its limitations.
6. An ability to apply reasoning based on contextual knowledge to access societal, health, safety, legal and
cultural issues and responsibilities relevant to professional engineering.
7. An Ability to understand the impact of telecommunication engineering solutions in societal and
environmental contexts and demonstrate the need of sustainable development.
8. An understanding of ethical principles and commit to professional ethics, responsibilities and norms of
engineering practice.
9. An ability to function effectively as an individual and as a member or leader in diverse and
multi-disciplinary teams.
10. An ability to communicate effectively on complex engineering activities with engineering community and
with society at large through skills to comprehend and write effective reports and design documents,
making effective presentations and deliver /receiver instructions.
11. Recognition of the need for and an ability to engage in independent and life-long learning.
12. An ability to demonstrate Knowledge and understanding of engineering and management principles
and apply these to one’s own work, as a member and leader in a team, to manage projects in
multidisciplinary environments.

slides are used for academic purpose only 6


Program Educational
Objectives
1. Graduates will excel in professional careers in
Industry, Academic, Research and
Development that meet the needs of
Organizations.
2. Graduates will be able to analyze real life problems
and be able to suggest solutions to design complex
engineering systems that are technically sound,
economically feasible and socially acceptable.
3. Graduates will exhibit all-round education that
includes communication skills, the ability to function
well in a team, an appreciation for ethical behavior
and the ability to engage in lifelong learning

slides are used for academic purpose only 7


Applications

slides are used for academic purpose only 8


slides are used for academic purpose only 9
slides are used for academic purpose only 10
slides are used for academic purpose only 11
slides are used for academic purpose only 12
slides are used for academic purpose only 13
slides are used for academic purpose only 14
slides are used for academic purpose only 15
slides are used for academic purpose only 16
slides are used for academic purpose only 17
slides are used for academic purpose only 18
slides are used for academic purpose only 19
slides are used for academic purpose only 20
Microprocessor
and
Microcontroller

slides are used for academic purpose only 21


Microprocessor

⚫ CPU for Computing


⚫ RAM, ROM, I/O are outside CPU

Many chips on motherboard


Data Bus
CPU
General-Pur
pose Serial
RAM ROM I/O Timer
Micro-proc COM
Port
essor Port

Address Bus

slides are used for academic purpose only 22


Microcontroller :

⚫ A single-chip computer
⚫ On-chip RAM, ROM, I/O ports...
⚫ Example:Motorola’s 6811, Intel’s 8051, Zilog’s Z8 and PIC 16X,
MSP 430

CPU RAM ROM


A single chip
Serial
I/O Timer COM
Port
Port
Microcontroller

slides are used for academic purpose only 23


Microprocessor v/s. Microcontroller
Microprocessor Microcontroller
⚫ CPU is stand-alone, RAM, • CPU, RAM, ROM, I/O and timer
ROM, I/O, timer are separate are all on a single chip
⚫ designer can decide on the • fixed amount of on-chip ROM,
amount of ROM, RAM and RAM, I/O ports
I/O ports.
• for applications in which cost,
⚫ expensive
power and space are critical
⚫ versatility
• single-purpose (control-oriented)
⚫ general-purpose
• Low processing power
⚫ High processing power
• Low power consumption
⚫ High power consumption
• Bit-level operations
⚫ Instruction sets focus on
processing-intensive • Instruction sets focus on control
operations and bit-level operations
⚫ Typically 32/64 – bit • Typically 8/16 bit
⚫ Typically deep pipeline (5-20 • Typically single-cycle/two-stage
stages) pipeline

slides are used for academic purpose only 24


Microprocessor v/s Microcontroller
⚫ Microprocessor uses operating system such as linux,
MacOS, or Windows
⚫ microcontrollers usually do use an operating system at all,
instead uses Software written to run directly on the
hardware without any additional support. If OS is used it
uses RTOS because microcontrollers are often used in
real-time applications
⚫ RTOS is quite different from that of a program and the
operating system on a desktop computer. When you turn on
a desktop computer, you have to wait for the operating
system to load before you can do anything. In contrast, a
microcontroller starts up with the user’s program, whose
first job is to start the RTOS, configure it, and launch the
desired tasks.
⚫ A more obvious difference is that an RTOS may occupy
only a few hundred bytes of memory, not megabytes

slides are used for academic purpose only 25


Washing machine as an Embedded System
⚫ The switches on the front panel are usually on–off buttons, which provide digital
inputs to the MCU. On the other hand, there might be some knobs that offer
continuous adjustment of the temperature or spin speed, in which case the MCU
must also handle an analog input.
⚫ Some sensors, such as one to check that the door is closed, give digital inputs.
⚫ Other sensors, such as those that measure the temperature and level of the
water, require analog inputs.
⚫ The front panel has some sort of display. This may be something very simple,
such as a few light-emitting diodes (LEDs), which need only a digital output (on
or off).
⚫ Numerical seven-segment displays are also simple to drive, although they may be
multiplexed to reduce the number of connections needed
⚫ On the other hand, specialized hardware is needed for a liquid crystal display
(LCD), which may be either in the microcontroller or built into the display itself.
⚫ Some components inside the washing machine, such as the valves for water, need
only to be switched on or off which can be driven from a digital output,
⚫ motor rotates slowly for washing and through a range of increasing speeds for
spinning. This appears to need an analog output, but in practice, this is simulated
using pulse-width modulation (PWM)
⚫ What must be the power of the microcontroller used ?
⚫ key point is that the demanding tasks are handled by special hardware, so the
processor itself need not be particularly powerful
slides are used for academic purpose only 26
Anatomy of a Typical Small Microcontroller

⚫ Central processing unit:


⚫ Arithmetic logic unit (ALU), which performs computation.
⚫ Registers needed for the basic operation of the CPU, such as the program
counter (PC), stack pointer (SP), and status register (SR).
⚫ Other registers to hold temporary results.
⚫ Instruction decoder and other logic to control the CPU, handle resets, and
interrupts, and so on.
⚫ Memory for the program: Nonvolatile (read-only memory, ROM), meaning
that it retains its contents when power is removed.
⚫ Memory for data: Known as random-access memory (RAM) and usually volatile.
⚫ Input and output ports: To provide digital communication with the outside
world.
⚫ Address and data buses: To link these subsystems to transfer data and
instructions
slides are used for academic purpose only 27
Anatomy of a Typical Small Microcontroller
⚫ Clock:To keep the whole system synchronized. It
may be generated internally or obtained from a
crystal or external source; modern MCUs offer
considerable choice of clocks.
⚫ Timers: Most microcontrollers have at least one
timer because of the wide range of functions that
they provide.
⚫ The time at which transitions occur on an input can be
recorded.
⚫ Outputs can be driven on and off automatically at a
specified frequency.
⚫ They provide a regular “tick” that can be used to schedule
tasks in a program. Many programs are awakened periodically
by the timer to perform some action and then go to sleep
(enter a low-power mode) until awakened again. This
conserves power, which is vital in battery-powered
applications.

slides are used for academic purpose only 28


Anatomy of a Typical Small Microcontroller
⚫ Watchdog timer: This is a safety feature, which resets the processor if the
program becomes stuck in an infinite loop.
⚫ Communication interfaces: A wide choice of interfaces is available to
exchange information with another IC or system. They include serial peripheral
interface (SPI), inter-integrated circuit (I²C or IIC), asynchronous (such as RS-232),
universal serial bus (USB), controller area network (CAN), Ethernet, and many others.
⚫ Nonvolatile memory for data: This is used to store data whose value must be
retained when power is removed. Serial numbers for identification and network
addresses are two obvious candidates.
⚫ Analog-to-digital converter:This is very common because so many quantities
in the real world vary continuously.
⚫ Digital-to-analog converter: This is much less common, because most analog
outputs can be simulated using PWM. An important exception used to be sound, but
even here, the use of PWM is growing in what are called class D amplifiers.
⚫ Real-time clock:These are needed in applications that must track the time of
day. Clocks are obvious examples but data loggers are also an important case.
⚫ Monitor, background debugger, and embedded emulator: These are used to
download the program into the MCU and communicate with a desktop computer
during development.
⚫ The processor communicates with these peripherals by reading from, and writing to,
particular addresses in memory. These memory locations are called special function
registers or peripheral registers to distinguish them from ordinary memories and they
do not need any special command slides are used for academic purpose only 29
Memory
⚫ heart of any computer.
⚫ Each location can typically store one byte
⚫ Memory is linked to the CPU by buses for data, address,
and control,
⚫ Control bus ensures that two components do not try to
write at the same time
⚫ processors are commonly characterized by width of the
data bus
⚫ The address bus need not have the same width as the data
bus and is often wider
⚫ Addresses are always quoted in hexadecimal (hex)
notation
⚫ buses usually remain hidden inside small microcontrollers
(but are exposed in microprocessor and in large
microcontrollers). External memory can be added using a
separate interface such as SPI.

slides are used for academic purpose only 30


Memory
⚫ Broad classification - Volatile , Non
Volatile
⚫ Features of volatile memory
⚫ The vital feature is that data can be read or written with equal
ease.
⚫ Volatile memory is used for data, and small microcontrollers
often have very little RAM,
⚫ The memory is usually static RAM, which means that it retains its
data even if the clock is stopped (provided that power is
maintained)
⚫ Features of Nonvolatile memory
⚫ Retains its contents when power is removed
⚫ used for the program and constant data.
⚫ It is usually called read-only memory or ROM.
⚫ Most modern microcontrollers can write to their nonvolatile
memory but it is much slower and more complicated than
writing to RAM. slides are used for academic purpose only 31
Types of Non Volatile Memories
1. Masked ROM:
⚫ The data are encoded into one of the masks used for
photolithography and written into the IC during manufacture.
⚫ This memory really is read-only.
⚫ It is used for the high-volume production of stable products, because any
change to the data requires a new mask to be produced at great expense
2. EPROM (electrically programmable ROM):
⚫ As its name implies, it can be programmed electrically but not
erased.
⚫ Devices must be exposed to ultraviolet (UV) light for about ten minutes to
erase them
3. OTP (one-time programmable memory):This is just EPROM in a
normal package without a window, which means that it cannot be erased
4. Flash memory:
⚫ This can be both programmed and erased electrically
⚫ the most common type of memory. It has largely superseded electrically
erasable, programmable ROM (EEPROM). T
⚫ individual bytes of EEPROM can be erased but flash can be erased only in
blocks.

slides are used for academic purpose only 32


slides are used for academic purpose only 33
Von Neumann architecture
▪ Von Neumann architecture
▪ provides a single memory space - storing program instructions
and data
▪ provides a single bus - to transfer data between the processor
and the memory
▪ Slow processing speed - each data transfer requires a separate
clock

slides are used for academic purpose only 34


Harvard architecture
▪ Harvard architecture
▪ provides separate memory spaces - storing program
instructions and data
▪ each memory space is interfaced with the processor with a
separate data bus
▪ program instructions and data can be accessed at the same
time
▪ a special single instruction, multiple data (SIMD) operation, a
special arithmetic operation and a bit reverse
▪ supports multi-tasking operating systems; but does not
provide virtual memory protection

slides are used for academic purpose only 35


Super-Harvard architecture
▪ Super-Harvard architecture (best known: SHARC)
▪ an extension of the Harvard architecture
▪ adds two components to the Harvard architecture:
▪ internal instruction cache - temporarily store frequently used
instructions - enhances performance
▪ an underutilized program memory can be used as a temporary
relocation place for data
▪ Direct Memory Access (DMA)
▪ costly CPU cycles can be invested in a different task
▪ program memory bus and data memory bus accessible from
outside the chip

slides are used for academic purpose only 36


Super-Harvard architecture

slides are used for academic purpose only 37


Criteria for Choosing
Microcontroller
While choosing a microcontroller, make sure it meets the task at hand and that it
is cost effective. We must see whether an 8-bit, 16-bit or 32-bit microcontroller
can best handle the computing needs of a task. In addition, the following points
should be kept in mind while choosing a microcontroller −
Speed − What is the highest speed the microcontroller can support?
Packaging − Is it 40-pin DIP (Dual-inline-package) or QFP (Quad flat package)?
This is important in terms of space, assembling, and prototyping the end-product.
Power Consumption − This is an important criteria for battery-powered
products.
Amount of RAM and ROM on the chip.
Count of I/O pins and Timers on the chip.
Cost per Unit − This is important in terms of final cost of the product in which
the microcontroller is to be used.

slides are used for academic purpose only 38


CISC V/s RISC

slides are used for academic purpose only 39


CISC V/s RISC

slides are used for academic purpose only 40


CISC V/s RISC

slides are used for academic purpose only 41


CISC V/s RISC

slides are used for academic purpose only 42


Software
1.Machine code
⚫ The binary data that the processor understands. (e.g oxCF)
⚫ Each instruction has a binary value called an opcode.
⚫ It is unrecognizable to humans, unless you spent a very long time on low-level
debugging
2. Assembly language
⚫ Little more than machine code translated into English.
E.g MOV R1,R2
⚫ The instructions are written as words called mnemonics rather than binary
values
⚫ assembler translates the mnemonics into machine code.
⚫ A few operations, notably bitwise rotations, cannot be written directly in C,
and for these assembly language is efficient
⚫ Very useful for debugging
⚫ disadvantage 1: it is intimately tied to a processor and is therefore
different for each architecture
⚫ disadvantage 2: detailed usage varies between development
environments for the same processor
⚫ Disassembly is the opposite process to assembly, the translation of machine
code to assembly language
slides are used for academic purpose only 43
Software

3. High level language


⚫ C , C++
⚫ A compiler translates C into machine
code that the CPU can process
⚫ Easy programming
⚫ Port used are still specific to controllers
so called as embedded C

slides are used for academic purpose only 44


Where does MSP 430 fit ?
⚫ CPU uses RISC and Von Neumann architecture
⚫ Both the address and data buses are 16 bits wide.
⚫ The registers in the CPU are also 16 bits wide and can be
used interchangeably for either data or addresses.
⚫ The MSP430 has 16 registers in its CPU, which enhances
efficiency because they can be used for local variables,
parameters passed to subroutines, as either addresses or data.
This is a typical feature of a RISC, but unlike a “pure” RISC,
it can perform arithmetic operations directly on
values in main memory.
⚫ The CPU is small and efficient, with a large number of
registers.
⚫ It is extremely easy to put the device into a low-power
mode. No special instruction is needed: The mode is
controlled by bits in the status register. The MSP430 is
awakened by an interrupt and returns automatically to its
low-power mode after handling the interrupt.

slides are used for academic purpose only 45


Where does MSP 430 fit ?
⚫ There are several low-power modes, depending on how much
time the device should remain active and how quickly it should
return to full-speed operation we can select the modes.
⚫ There is a wide choice of clocks. Typically, a low-frequency
watch crystal runs continuously at 32 KHz and is used to
wake the device periodically. The CPU is clocked by an
internal, digitally controlled oscillator (DCO), which restarts
in less than 1s in the latest devices. Therefore the MSP430 can
wakeup from a standby mode rapidly, perform its tasks, and return
to a low-power mode.
⚫ A wide range of peripherals is available, many of which can run
autonomously without the CPU for most of the time.
⚫ Many portable devices include liquid crystal displays, which the
MSP430 can drive directly.
⚫ Some MSP430 devices are classed as application-specific
standard products (ASSPs) and contain specialized analog
hardware for various types of measurement.

slides are used for academic purpose only 46


Significance of naming convention
(MSP430F449IPZ)

slides are used for academic purpose only 47


slides are used for academic purpose only 48
MSP430F449IPZ – PINOUT
DIAGRAM

slides are used for academic purpose only 49


Features of MSP430F449

slides are used for academic purpose only 50


Features of MSP430F449

slides are used for academic purpose only 51


Key features of the MSP430x4xx
family
⚫ Ultralow-power architecture extends battery life
✔ 0.1-μA RAM retention
✔ 0.8-μA real-time clock mode
✔ 250-μA / MIPS active
⚫ High-performance analog ideal for precision measurement
✔ 12-bit or 10-bit ADC — 200 ksps, temperature sensor,VRef
✔ 12-bit dual-DAC
✔ Comparator-gated timers for measuring resistive elements
✔ Supply voltage supervisor
⚫ 16-bit RISC CPU enables new applications at a fraction of the code size.
✔ Large register file eliminates working file bottleneck
✔ Compact core design reduces power consumption and cost
✔ Optimized for modern high-level programming
✔ Only 27 core instructions and seven addressing modes
✔ Extensive vectored-interrupt capability
⚫ In-system programmable Flash permits flexible code changes, field upgrades and data
logging

slides are used for academic purpose only 52


Functional block diagram

slides are used for academic purpose only 53


Functional block diagram
⚫ On the left is the CPU and its supporting hardware,
including the clock generator. The emulation, JTAG interface
and Spy-Bi-Wire are used to communicate with a desktop
computer when downloading a program and for debugging
⚫ The main blocks are linked by the memory address bus
(MAB) and memory data bus (MDB).
⚫ Six blocks are shown for peripheral functions (there are
many more in larger devices). All MSP430s include
input/output ports, Timer_A, and a watchdog timer, although
the details differ.
⚫ The universal serial interface (USI) and sigma–delta
analog-to-digital converter (SD16_A) are particular features
of this device.
⚫ The brownout protection comes into action if the supply
voltage drops to a dangerous level. Most devices include this
but not some of the MSP430x1xx family.

slides are used for academic purpose only 54


Memory organization
There are no connections for bringing the
buses outside the chip to attach external
memory. Nor is there any provision
for increasing the amount of memory
in the MSP430 by selecting banks or pages,
as in some other processors.
Little-endian ordering: The low-order
byte is stored at the lower address
and the high-order byte at the higher
address. This is used by the MSP430 and is
the more common format.
Big-endian ordering: The high-order
byte is stored at the lower address.
This is used by the Freescale HCS08, for
instance.

slides are used for academic purpose only 55


Memory mapping
Special function registers:
• Mostly concerned with enabling functions of some modules
and enabling and signalling interrupts from peripherals.
• These must be accessed using byte instructions only
Peripheral registers with byte access and
peripheral registers with word access:
• Provide the main communication between the CPU and
peripherals.
• Some must be accessed as words and others as bytes.
• They are grouped in this way to avoid wasting addresses.
• If the bytes and words were mixed, numerous unused
bytes would be needed to ensure that the words were
correctly aligned on even addresses
Random access memory:
• Used for variables.
• This always starts at address 0x0200
• the upper limit depends on the size of the RAM
• RAM can be used for both code and data
Flash/ROM:
• The start address of Flash/ROM depends on the amount of
Flash/ROM present and varies by device.
• The end address for Flash/ROM is 0FFFFh.
• Flash can be used for both code and data.
• Word or byte tables can be stored and used in Flash/ROM
without the need to copy the tables to RAM before using
them.
The interrupt vector table is mapped into the upper 16 words of Flash/ROM address space, with the
highest priority interrupt vector at the highest Flash/ROM word address (0FFFEh).
slides are used for academic purpose only 56
CPU
⚫ The central processing unit (CPU) executes
the instructions stored in memory.
⚫ It steps through the instructions in the
sequence in which they are stored in
memory until it encounters a branch or
when an exception occurs (interrupt or
reset).
⚫ It includes the arithmetic logic unit (ALU),
which performs computation, a set of 16
registers designated R0–R15 and the logic
needed to decode the instructions and
implement them.
⚫ The CPU can run at a maximum clock
frequency fMCLK of 16MHz in the
MSP430F2xx family and some newer
MSP430x4xx devices, and 8MHz in the
others.
⚫ It is built using static logic, which means that
there is no minimum frequency of operation:
The CPU can be stopped and will retain its
state until it is restarted. This is essential for
low-power operation to be straightforward.

slides are used for academic purpose only 57


Registers in the CPU of the MSP430.

▪ The first four registers have dedicated functions with alternative names,
while the remaining 12 : R4–R15 are GPRs
▪ Either words or bytes can be written to the CPU registers.
▪ The behavior for bytes is different from main memory: The destination is
always the low byte and the high byte is cleared (reset to 0).

slides are used for academic purpose only 58


Registers in the CPU of the MSP430.

PC: This contains the address of the next instruction to be executed.


Instructions are composed of 1–3 words, which must be aligned to even addresses, so
the lsb of the PC is hard-wired to 0.
SP: Some processors use separate hardware for the stack but the MSP430 uses
the top (high addresses) of the main RAM. The stack pointer holds the address
of the most recently added word and is automatically adjusted as the stack grows
downward in memory.
SR: This contains a set of flags (single bits), whose functions fall into three categories.

slides are used for academic purpose only 59


Status
Register

slides are used for academic purpose only 60


slides are used for academic purpose only 61
Registers in CPU
GPR s: The remaining 12 registers, R4–R15, are general working
registers. They may be used for either data or addresses because
both are 16-bit values, which simplifies the operation significantly.

CG : This provides the six most frequently used values by


exploiting the CPU’s addressing modes : so that they need not
be fetched from memory whenever they are needed .

It uses both R2 and R3 to provide a range of useful values

slides are used for academic purpose only 62


Ports
⚫ Typical pins can be configured for either input or output and some inputs
may generate interrupts when the voltage on the pin changes
⚫ Port P1 input, P1IN:
⚫ Reading returns the logical values on the inputs if they are
configured for digital input and output.
⚫ This input register is read-only.
⚫ It is also volatile, which means that it may change at a time that a program
cannot predict. This is of course why the input port is there, so that the
MCU can react to its surroundings.You want to know when a user presses
a button, for instance.
⚫ P1IN is not just a simple memory and that some care is needed when
programming as input
⚫ Port P1 output, P1OUT:
⚫ Writing sends the value to be driven onto the pin if it is configured
as a digital output.
⚫ If the pin is not currently an output, the value is stored in a buffer and
appears on the pin if it is later switched to be an output.
⚫ Port P1 direction, P1DIR: A bit of 0 configures the pin as an input,
which is the default. Writing a ,’1’ switches the pin to become an
output. slides are used for academic purpose only 63
Memory mapped I/O
⚫ The MSP430, in common with most
processors, uses memory-mapped input and
output.
⚫ ports simply appear to the CPU as particular
memory registers called peripheral registers.
⚫ Each port is associated with a byte and each
bit corresponds to a pin on the package (if
implemented).
⚫ These registers can be read, written , and
modified in almost the same way as simple
registers in RAM.
⚫ arithmetic operations can be done with
them, with some restrictions.

slides are used for academic purpose only 64


Clock System
⚫ Clocks for microcontrollers used to be simple. Usually a crystal with a frequency of a
few MHz would be connected to two pins. It would drive the CPU directly and was typically
divided down by a factor of 2 or 4 for the main bus.

⚫ Unfortunately, the conflicting demands for high performance and low power mean
that most modern microcontrollers have much more complicated clocks, often with
two or more sources.

⚫ In many applications

◦ The MCU spends most of its time in a LPM : Upon Interrupt, it runs to handle the event
rapidly.

◦ It is often necessary to keep track of real time, either so that the MCU can wake
periodically, or to time-stamp external events.

⚫ Therefore, two clocks with quite different specifications are often needed:

slides are used for academic purpose only 65


Clock System
⚫ A fast clock to drive the CPU, which can be started and stopped
rapidly to conserve energy but usually need not be
particularly accurate.

⚫ A slow clock that runs continuously to monitor real time, which


must therefore use little power and may need to be accurate.

slides are used for academic purpose only 66


Different Sources for Clock generation

1. Crystal:
✔ Accurate and stable
✔ Crystals for microcontrollers typically run at either a high
frequency of a few MHz to drive the main bus or a low
frequency of 32,768 Hz for a RTC.
The disadvantages are
• Crystals are expensive and delicate : the oscillator draws a
relatively large current, particularly at high frequency.
• Crystal oscillators also take a long time to start up and stabilize,
often around 105 cycles, which is an unavoidable side effect of
their high stability.

slides are used for academic purpose only 67


Different Sources for Clock generation

2. RC Oscillator :

▪ Cheap and quick to start but have poor accuracy and stability.
▪ The components can be external / integrated
▪ The quality of integrated RC oscillators has improved dramatically
in
recent years and the F20xx provides four frequencies calibrated
at the factory to within ± 1%.

3. Ceramic resonators : Cheaper but less accurate & stable than


crystals.

Future : MEMS : Integration of a mechanical resonator on the


same wafer High accuracy with low power.

slides are used for academic purpose only 68


Clock System in MSP 430
The MSP430 addresses the conflicting demands for high
performance, low power, and a precise frequency by
using three internal clocks, which can be derived from
up to four sources.
These are the internal clocks, which are the same in
all devices:
• Master clock, MCLK, is used by the CPU and a few
peripherals.
• Subsystem master clock, SMCLK, is distributed to
peripherals andDCO,
• Auxiliary clock, ACLK, is also distributed to
peripherals. [Low-frequency crystal oscillator, typically
at 32 KHz.]
slides are used for academic purpose only 69
Interrupt
⚫ Usually generated by hardware (although they can be
initiated by software) and often indicate that an event
has occurred that needs an urgent response.
Eg. A data might have been received from a connected
sensor, and needs to be processed before the next data
arrives.
⚫ The processor stops what it was doing, stores enough
information (the contents of the program counter and
status register) for it to resume later on
⚫ When triggered executes an Interrupt Service Routine
(ISR). It returns to its previous activity when the ISR has
been completed.
⚫ ISR is something like a subroutine called by hardware (at
an unpredictable time) rather than software.
⚫ A second use of interrupts, which is particularly
important in the MSP430, is to wake the processor from
a low-power state.
slides are used for academic purpose only 70
Interrupt
⚫ Types of Interrupts: vectored , Non vectored
⚫ The MSP430 uses vectored interrupts
⚫ Each ISR has its own vector, which is stored at a predefined
address in a vector table at the end of the program memory
(addresses 0xFFC0–0xFFFF).
⚫ The address for each interrupt vector is listed in the data
sheet.
⚫ The vector table is at a fixed location, but the ISRs
themselves can be located anywhere in memory.
⚫ There is no need to hunt for the source of the interrupt in
most cases, although a few interrupts have multiple sources.
⚫ For example, the interrupt vector for the watchdog timer is
stored at address 0xFFF4. When the watchdog timer
requests an interrupt, the processor fetches the vector
from the word stored at 0xFFF4, loads it into the program
counter, and fetches its next instruction from this address
to start the ISR.
slides are used for academic purpose only 71
Exception - Reset
⚫ Generated by hardware, either when
power is applied or when something
catastrophic has happened and normal
operation cannot continue.
⚫ This can happen accidentally if the
watchdog timer has not been disabled,
which is easy to forget.
⚫ A reset causes the device to (re)start
from a well-defined state

slides are used for academic purpose only 72


Exception - Reset
⚫ Reset vector is stored in the very last word of memory
at 0xFFFE.
Operations on reset
⚫ most registers in the device are loaded with the initial
conditions specified in the family user’s guide.
⚫ program counter is then loaded with the reset vector.
This is the address of the first instruction, which is next
fetched from memory to start normal operation. Thus
the first instruction can be stored anywhere in memory.
⚫ watchdog timer must be configured or disabled before
it times out and resets the device.
⚫ The stack will be initialized if subroutines or interrupts
are used, which applies to all but the most trivial
programs.
⚫ code to configure the other peripherals like the ports
and clock are executed.

slides are used for academic purpose only 73


Emulator and Debugger
An emulator is a piece of hardware that looks like a processor, has memory
like a processor, and executes instructions like a processor, but is not a
processor. It often has the advantage that you can probe points of the
circuit that are not accessable inside a chip. Generally it is a combination
of hardware and software. They are often quite expensive.

A debugger is a program that finds and fixes bugs in programs. As a


program it usually takes the form of a small monitor that runs on the target
processor, and can examine memory, install breakpoints, and trigger on
various conditions. Sometimes it can allow changes in programs for fixing
a problem and trying again.

slides are used for academic purpose only 74

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy