Microchip Technology Inc.: Digital Signal Controller
Microchip Technology Inc.: Digital Signal Controller
Microchip Technology Inc.: Digital Signal Controller
2004 Microchip Technology Incorporated. All Rights Reserved. Introduction to the dsPIC30F Architecture (Part 2) 1
DS
Digital Signal Controller
Introduction to the dsPIC30F
Architecture (Part 2 of 2)
Microchip Technology Inc.
Welcome to the third dsPIC30F web seminar: Introduction to the
dsPIC30F Architecture, Part 2. The focus in todays seminar will be on
various features related to device system integration, which will be
followed by an overview of Program Flash Memory and Data EEPROM.
Page 2
2004 Microchip Technology Incorporated. All Rights Reserved. Introduction to the dsPIC30F Architecture (Part 2) 2
System Integration Features
Let us start todays session by looking at some useful features provided
by the dsPIC30Fs System Integration hardware. First we will take a
look at how the dsPIC30F handles interrupts, traps and resets. Then we
will look at methods of clock generation, ways of saving power, and
features that increase system robustness and security.
Page 3
2004 Microchip Technology Incorporated. All Rights Reserved. Introduction to the dsPIC30F Architecture (Part 2) 3
Interrupts
l Prioritized, vectored interrupts
l Up to 45 sources (excluding traps and
reset)
l 7 levels of priority
l Fixed latency : 5 cycles (from IRQ to
ISR entry)
l PC and lower byte of Status Register
saved
The dsPIC30F has an efficient and robust interrupt system that works in
tandem with buffered peripheral events to minimize CPU time spent
handling interrupts.
Depending on the variant, the dsPIC30F can respond to up to 45
individual interrupt sources, excluding traps and reset. Each individual
interrupt is assigned to one of seven priority levels. Within each level,
the lower the interrupt vector number, the higher its relative priority.
Interrupt latency time is fixed at 5 cycles, from the latching of the
interrupt request to the start of interrupt service routine, or ISR,
processing. This deterministic and consistent interrupt latency is very
crucial for applications with real-time response requirements, such as
when processing streaming audio signals.
Page 4
2004 Microchip Technology Incorporated. All Rights Reserved. Introduction to the dsPIC30F Architecture (Part 2) 4
Interrupts
l Interrupt stack built in on-chip SRAM
with automatic bounds checking
l Nesting of Interrupts - Higher priority
interrupts can interrupt lower priority
interrupts
l DISI instruction suspends interrupts for
N cycles
l Quick way to protect critical code
segments
l Priority 0 6 interrupts disabled
When an interrupt occurs, some basic processor context is
automatically saved on to the software stack. Similarly, the context data
is automatically restored when code execution returns from the
interrupt.
Interrupts may optionally be nested, that is, a higher priority interrupt
may occur and be serviced while a lower priority interrupt is being
serviced.
A novel feature of the dsPIC30F is the DISI instruction. This command
temporarily suspends processing of all interrupts up to level 6, for a
user-programmable number of instruction cycles. This is a quick and
easy way to protect critical code sequences or operating system
resources.
Page 5
2004 Microchip Technology Incorporated. All Rights Reserved. Introduction to the dsPIC30F Architecture (Part 2) 5
Traps
l Oscillator Failure Trap:
l Main clock failure (switches to Internal RC)
l Address Error Trap:
l Unimplemented data space access
l Any access of unimplemented program space
l Misaligned data read or write
l Stack Error Trap:
l Programmable overflow limit register
l Hardwired underflow limit to protect SFRs
l Math Error Trap:
l Divide by Zero
l Unsaturated Accumulator Overflow
Traps, also known as processor exceptions, help guard against
unexpected events. They are processed similar to interrupts, with the
application code including Trap Service Routines to handle such events
and take corrective action. In the dsPIC30F, there are 4 types of events
that generate traps, each with a unique trap vector with a fixed vector
processing priority.
An oscillator failure, typically due to a fault in the external system,
causes the dsPIC30F to switch to a back-up clock source inside the
chip, before processing the exception.
Address Error Traps guard against invalid data accesses, such as a
data read or write of unimplemented data space, or a misaligned data
read or write. It also guards against invalid program memory accesses,
such as trying to execute out of unimplemented program space or the
interrupt vector table.
When the stack pointer grows beyond the user-specified Stack Pointer
Limit, a Stack Error Trap occurs. A Stack Error Trap is also generated if
the stack underflows into the region of data memory reserved for
special function registers.
In general, there are 2 types of events that cause math errors: divide by
zero and unsaturated accumulator overflow. The former occurs when
the CPU detects that the divisor used in a divide instruction equals zero.
The latter occurs if either of the two 40-bit accumulators overflows into
either bit 31 or bit 39. This provides a mechanism to detect and correct
overflows without loss of data when saturation is not being used.
Page 6
2004 Microchip Technology Incorporated. All Rights Reserved. Introduction to the dsPIC30F Architecture (Part 2) 6
System Resets
l Power-On Reset (POR):
l Programmable delay timer: 0, 4, 16, 64ms
l MCLR (External Reset Pin)
l Reset Instruction execution
l Watchdog Timer (WDT) Reset:
l Runs from its own RC oscillator
l Programmable timeout: 2 ms - 16 sec
l Brown-out Reset (BOR):
l Programmable voltage levels
l Illegal Program Operation Reset:
l Illegal Opcode fetch
l Uninitialized W register used as an address pointer
The dsPIC30F can be reset for several different reasons. Shown here is
a complete list of such events:
Power-On Reset, or POR, is the standard reset that occurs when the
supply voltage to the device is turned on. This has been enhanced by
the dsPIC30F with the addition of a user programmable delay. This
delay provides some time for external crystals with slow rise times to
start operation before the CPU starts executing instructions.
If needed, the user can force a device reset in one of two ways, either
by pulling the external Master Clear pin low, or by executing the RESET
instruction in software.
The dsPIC30F devices contain an on-chip Watchdog Timer to improve
system robustness. The Watchdog Timer runs from an internal RC
oscillator source, and which is independent of system clock operation.
The programmable time-out ranges from 2 milliseconds to 16 seconds,
providing a wide response time range for the user to clear the timer.
Failure to respond within this time period results in a device reset.
The Brown-Out Reset, or BOR, occurs when the supply voltage drops
below a user-programmable voltage threshold. This prevents glitches in
the power-line from adversely affecting system operation.
Illegal program operations can also reset the device. These include an
attempt to fetch an illegal opcode or an attempt to use an uninitialized
W register as an address pointer in an instruction.
Page 7
2004 Microchip Technology Incorporated. All Rights Reserved. Introduction to the dsPIC30F Architecture (Part 2) 7
Clock Sources
XTL, XT, HS
Primary
Xtal OSC
Clock Divide
By
1, 4, 16, 64
32KHz
Timer1 Xtal
OSC
System
Clock
Fast RC 8.0 MHz
Low Pwr RC 512KHz
EC Clock
SOSCI
SOSCO
OSC1
OSC2
PLL
4x,
8x,
16x
or bypass
l Primary Oscillator for Crystals
l 32 kHz for Real Time Clock
l 2 internal RC oscillators
l PLL multiplies oscillator source for
high frequency operation
l Clock divide can optionally slow
clock to conserve power
The dsPIC30F has a very flexible set of oscillator sources to generate the
system clock. Each instruction cycle consists of 4 system clock cycles. For
example, a 120 MHz system clock would result in a 30 MHz instruction clock,
or approximately 30 MIPS performance.
The system clock may be obtained from a variety of internal or external
sources. An external crystal oscillator is a popular clock source option. This
may be further categorized into three frequency ranges, called XTL, XT, and
HS. Alternatively, one could directly use an external clock signal. Internal
sources provided on the dsPIC30F include an 8 Megahertz Fast RC oscillator
and a 512 kilohertz Low Power RC oscillator.
There is also a secondary 32 kHz low power crystal oscillator input which can
be used to provide the time base for the Timer1 counter, thereby using Timer1
as a Real Time Clock. This clock source can also be used as the system clock
source to minimize power consumption.
In order to get the maximum performance out of the dsPIC30F, the output of
an XT crystal, an external clock signal or the output of the Fast RC Oscillator,
can be applied to an on chip Phase Locked Loop, or PLL. This input signal, in
the 4 MHz to 10 MHz range is then multiplied by 4, 8, or 16 to achieve a
system clock frequency between 16 and 120 MHz. Using the Fast RC
oscillator with the PLL provides a means to generate high clock frequencies
without using external system components like crystals and resonators.
The dsPIC30F oscillator system also provides a method of conserving power
by temporarily slowing down the system clock, using a user-programmable
clock post-scaler which divides the clock frequency by 4, 16, or 64.
Page 8
2004 Microchip Technology Incorporated. All Rights Reserved. Introduction to the dsPIC30F Architecture (Part 2) 8
Power Management
l Execute the PWRSAV Instruction:
l IDLE mode:
l CPU is stopped, but the system clock continues to run
l Peripherals continue to run (unless disabled)
l Wake up: WDT, change notification pin, interrupt,
Reset
l SLEEP mode:
l CPU and system clock are stopped
l Peripherals are stopped, unless clocked externally
l Wake up: WDT, change notification pin, external
interrupt pin, Reset, or certain peripheral events
An important requirement of many embedded applications is the need to
conserve energy. The dsPIC30F provides several mechanisms to lower its
power consumption.
Depending on your application, you may be able to use the Power Save
instruction to obtain the most reduction in energy consumption. Executing this
instruction can put the device in one of two states:
Idle Mode halts the CPU, thereby stopping bus activity and data transfers.
The system clock and peripherals continue running so that an interrupt can
be used to restart CPU operation. Additionally, each peripheral can be
individually configured to stop operation during Idle mode.
Sleep Mode places the device in the lowest power consumption state. In this
state, the CPU as well as the system clock are halted. A few peripherals may
optionally continue to run during Sleep Mode. These peripherals include
serial communication modules that can operate in a clock slave mode, or
peripherals that can generate their own clock. Some I/O pins, if enabled, can
asynchronously wake up the CPU on a change in input.
Page 9
2004 Microchip Technology Incorporated. All Rights Reserved. Introduction to the dsPIC30F Architecture (Part 2) 9
Power Management
l Use the System Clock Postscaler: 1, 4,
16, 64
l Reduce the PLL Multiplier, e.g. from x16
to x8
l Switch to a slower clock source: FRC,
LPRC, LP, EC
As current consumption bears a direct relation to processor speed, reducing
the speed of operation is a very effective way of reducing overall power
consumption. This can be accomplished either by postscaling the system
clock by 4, 16, or 64, or by reducing the PLL multiplier.
It is also possible to switch to a slower clock source at run time. During any
clock switch, the dsPIC30F monitors the new clock source to ensure a
successful clock switch. If the new clock source fails to start up, the device
will continue operation using the original clock source.
Page 10
2004 Microchip Technology Incorporated. All Rights Reserved. Introduction to the dsPIC30F Architecture (Part 2) 10
Fail-Safe Operation
l Clock monitor with automatic switch to an internal
clock
l Watchdog Timer with its own RC Osc and fuse
protection
l Resets
l Traps
l Programmable Low Voltage Detect (LVD) Interrupt
l Program Memory Read and Write Protection
Sometimes the best offense is a good defense, and the dsPIC30F provides an array of
defensive techniques to protect your application.
A key element ensuring robust operation is a clock monitor that keeps an eye on the
primary clock source. Should the system clock fails, the clock monitor can automatically
switch operation to the low power internal Fast RC Oscillator and notify the CPU.
A Watchdog Timer helps detect errant software operation. It runs from the Low Power
RC oscillator, so that even applications which do not use the clock monitor can be
protected.
Resets prevent catastrophic events from adversely affecting system operation. The
dsPIC30F resets itself upon a watch dog timer timeout, a dip in the power supply, or an
unrecoverable program addressing error. In addition, the cause of the most recent
system reset is saved in a status register and can be accessed by user code.
Traps allow recovery from processor exceptions by interrupting the CPU and executing
user-programmed Trap Service Routines. Several abnormal conditions can cause traps,
including oscillator failure, data addressing errors, stack errors, and math errors.
The Low Voltage Detect, or LVD, provides a convenient means of monitoring supply
voltage level in an application. This is particularly useful for battery-powered systems. It
may be configured to generate an interrupt, which provides the application sufficient time
to save data and perform a clean shutdown before the falling battery level causes a
potential system failure.
Finally, the Flashprogram memory can be read-protected to prevent unauthorized
access of proprietary code, or write-protected to prevent accidental or malicious
modification of program memory contents.
Page 11
2004 Microchip Technology Incorporated. All Rights Reserved. Introduction to the dsPIC30F Architecture (Part 2) 11
Program Flash and
Data EEPROM
The final section of this presentation briefly describes the on-chip Flash
Program Memory and Data EEPROM of the dsPIC30F.
Page 12
2004 Microchip Technology Incorporated. All Rights Reserved. Introduction to the dsPIC30F Architecture (Part 2) 12
Flash Performance Summary
l All dsPIC