C2000™ MCU 1-Day Workshop: Workshop Guide and Lab Manual
C2000™ MCU 1-Day Workshop: Workshop Guide and Lab Manual
F28xMCUodw
Revision 4.2
January 2014
Technical Training
Organization
Workshop Topics
Important Notice
Texas 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 TIs 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 customers 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. TIs publication of
information regarding any third partys products or services does not constitute TIs approval, warranty or
endorsement thereof.
Revision History
April 2009 Revision 1.0
October 2009 Revision 1.1
June 2010 Revision 2.0
December 2010 Revision 2.1
October 2011 Revision 3.0
February 2012 Revision 4.0
January 2013 Revision 4.1
January 2014 Revision 4.2
Mailing Address
Texas Instruments
Training Technical Organization
6500 Chase Oaks Blvd Building 2
M/S 8437
Plano, Texas 75023
Workshop Topics
Workshop Topics
Workshop Topics......................................................................................................................................... 3
Workshop Introduction ............................................................................................................................... 4
Architecture Overview .............................................................................................................................. 11
Programming Development Environment................................................................................................. 16
Code Composer Studio ......................................................................................................................... 16
Linking Sections in Memory ................................................................................................................ 20
Lab 1: Linker Command File .................................................................................................................... 24
Peripheral Register Header Files ............................................................................................................. 29
Reset, Interrupts and System Initialization ............................................................................................... 39
Reset ..................................................................................................................................................... 39
Interrupts............................................................................................................................................... 44
Peripheral Interrupt Expansion (PIE) ................................................................................................... 47
Oscillator / PLL Clock Module ............................................................................................................ 52
Watchdog Timer Module ...................................................................................................................... 54
GPIO ..................................................................................................................................................... 56
Lab 2: System Initialization ...................................................................................................................... 60
Control Peripherals .................................................................................................................................. 65
ADC Module ........................................................................................................................................ 65
Pulse Width Modulation ....................................................................................................................... 69
ePWM ................................................................................................................................................... 71
eCAP .................................................................................................................................................... 87
eQEP ..................................................................................................................................................... 89
Lab 3: Control Peripherals ....................................................................................................................... 92
Flash Programming .................................................................................................................................. 98
Flash Programming Basics ................................................................................................................... 98
Programming Utilities and CCS Flash Programmer ........................................................................... 100
Code Security Module and Password ................................................................................................. 101
Lab 4: Programming the Flash ............................................................................................................... 104
The Next Step ....................................................................................................................................... 111
Training .............................................................................................................................................. 111
controlSUITE ..................................................................................................................................... 112
Development Tools............................................................................................................................. 113
C2000 Workshop Download Wiki ..................................................................................................... 116
Development Support ......................................................................................................................... 117
Notes: ...................................................................................................................................................... 118
Workshop Introduction
Workshop Introduction
C2000 Microcontroller 1-Day Workshop
Texas Instruments
Technical Training
C2000 is trademarks of Texas Instruments. Copyright 2014 Texas Instruments. All rights reserved.
The objective of this workshop is to gain a fully understand and a complete working knowledge
of the C2000 microcontroller. This will be accomplished through detailed presentations and
hands-on lab exercises.
The workshop will start with the basic topics and progress to more advanced topics in a logical
flow such that each topic and lab exercise builds on the previous one presented. At the end of the
workshop, you should be confident in applying the skills learned in your product design.
Workshop Introduction
Introduction
Architecture Overview
Programming Development Environment
Peripheral
Control
Flash
Peripherals
Programming
The
Next Step
The outline for this workshop starts with an introduction covering the materials required and
provides a brief overview of the C2000 product family. Next, we will look at the architectural
details and discuss the block diagram, memory map, and peripherals. From there, we will move
to the programming development environment and gain the basic skills needed to use Code
Composer Studio, as well as learn about a linker command file.
Then we will have a lab exercise to practice the skills learned thus far. We will follow this with
the peripheral register header files. At this point, we have covered the basic foundation. Next,
we will explore the device and learn about reset, interrupts, and system initialization. In this lab
exercise, we will use the watchdog to generate a reset and interrupt, reinforcing what we have just
learned.
Then we will cover the control peripherals, which includes the ADC, ePWM, eCAP, and eQEP.
In this lab exercise, we will generate a PWM waveform, then feed it into the ADC, and graph it
using Code Composer Studio. Additionally, we will learn about the real-time mode emulation
features.
The next topic will be programming the flash. In this lab exercise, we will develop a complete
embedded system using the code from the previous lab exercises. Finally, in the Next Step, we
will discuss where you can find more information, allowing you to continue learning and
exploring on your own.
Workshop Introduction
C2000_Piccolo_OneDay_Workshop_Home_Page
F28069
Install
Run
controlSTICK kit
Student
The materials required for this workshop are available using the links shown at the top of this
slide. Please be sure that you have the F28069 controlSTICK kit. The included jumper wire will
be needed for the lab exercises. Make sure that you have all of the software installed. The lab
directions are written based on the version of Code Composer Studio as shown on this slide. The
workshop installer will automatically install the lab files, solution files, workshop manual, and
documentation.
Workshop Introduction
32-bit
real-time
MCUs
MSP430
C2000
Delfino
Piccolo
Up to
25 MHz
Flash
1 KB to 256 KB
Analog I/O, ADC
LCD, USB, RF
Measurement,
Sensing, General
Purpose
ARM-Based Processors
32-bit ARM
Cortex-M3
MCUs
Stellaris
ARM Cortex-M3
ARM
Cortex-A8
MPUs
Sitara
ARM Cortex-A8
& ARM9
DSP
DSP+ARM
C6000
DaVinci
Multi-core
DSP
Ultra
Low power
DSP
C6000
C5000
video processors
OMAP
300MHz to
Up to
300MHz to >1Ghz
>1GHz
100 MHz
+Accelerator
Cache
Flash
Flash, RAM
Cache,
RAM, ROM
8 KB to 256 KB
16 KB to 512 KB
RAM, ROM
USB, ENET
USB, ENET,
USB, CAN,
PWM, ADC,
MAC+PHY CAN,
PCIe, SATA, SPI
PCIe, EMAC
CAN, SPI, I2C
ADC, PWM, SPI
Motor Control,
Connectivity, Security, Industrial computing, Floating/Fixed Point
Video, Audio, Voice,
POS & portable
Digital Power,
Motion Control, HMI,
Lighting, Ren. Enrgy Industrial Automation
Security, Confer.
data terminals
40MHz to
300 MHz
24.000
MMACS
Cache
RAM, ROM
SRIO, EMAC
DMA, PCIe
Telecom T&M,
media gateways,
base stations
Up to 300 MHz
+Accelerator
Up to 320KB RAM
Up to 128KB ROM
USB, ADC
McBSP, SPI, I2C
Audio, Voice
Medical, Biometrics
The Texas Instruments embedded processing portfolio covers a wide range of embedded
processors from microcontrollers, to ARM-based processors, to digital signal processors. Our
microcontrollers include the 16-bit ultra-low power MSP430 microcontroller family and, the 32bit real-time C2000 microcontroller family. Our ARM-based processors include the 32-bit ARM
Cortex M3 Stellaris microcontroller family, the ARM Cortex A8 Sitara microprocessor family,
and it also includes the OMAP devices, which incorporates a C6000 and ARM processor. Our
digital signal processors include the C6000 DaVinci, as well as multicore DSPs with up to 24
billion multiply accumulates per second. Additionally, there's an ultra-low power C5000 digital
signal processor family.
Workshop Introduction
C2834x
F2803x
F2802x
Performance:
Memory:
16KB-128KB Flash
6KB-100KB SRAM
Performance:
Memory:
Up to 512KB Flash
Up to 516KB SRAM
Key Peripherals:
Package:
Performance:
Dual Core
Up to 150MHz 28x CPU
Up to 100MHz ARM Cortex M3 CPU
Floating Point Unit
VCU Accelerator
Memory:
Key Peripherals:
F28M35x
F2833x
Package:
256KB-1MB Flash
Up to 132KB SRAM
Key Peripherals:
Package:
144 QFP
The C2000 family, which this workshop is based on, includes the C28x Piccolo, C28x Delfino,
and C28x + Cortex-M3 product lines. The Piccolo product line ranges in performance from 40
MHz to 90 MHz and has options for a floating point unit, control law accelerator coprocessor, a
Viterbi complex math CRC unit, and USB. The Delfino product line ranges in performance from
100 MHz to 300 MHz and features a floating point unit and some devices with an external
memory interface. The C28x + Cortex-M3 product line consists of a dual-system architecture,
incorporating a C28X CPU with performance up to 150 MHz and an ARM Cortex M3 CPU with
performance up to 100 MHz. In addition to floating point capabilities, it has a Viterbi complex
math CRC unit. The three product lines provide you with over 150 devices to choose from and
maintain software compatibility.
Workshop Introduction
Renewable Energy
E-bike
Power Tools
White Goods
Industrial Drives
& Motion Control
Lighting
Digital Power
C2000
DC/DC
Converters
Uninterruptable
Power Supplies
LED TV
Backlighting
Auto HID
Telecom / Server
AC/DC Rectifiers
Radar / Collision
Avoidance
Smart Metering
RF
Communication
Automotive
3/14/2014
The C2000 product family has a very broad application base with target markets in motor control,
lighting, smart grid and power line communications, automotive, digital power, and renewable
energy.
F2833x
F2803x
150 MHz
60 MHz
F2806x
90 MHz
128Kw / 34Kw
64Kw / 10Kw
128Kw / 50Kw
On-chip Oscillators
SEQ - based
SOC - based
SOC - based
FPU
6-Channel DMA
CLA
VCU
ePWM / HR ePWM
eCAP / HR eCAP
Watchdog Timer
12-bit ADC
/-
/-
eQEP
LIN
McBSP
USB
External Interface
When comparing the Delfino and Piccolo product lines, you will notice that the Piccolo F2806x
Workshop Introduction
devices share many features with the Delfino product line. The Delfino product line is shown in
the table by the F2833x column; therefore, the F28069, being the most feature-rich Piccolo
device, was chosen as the platform for this workshop. The knowledge learned from this device
will be applicable to all C2000 product lines.
TMS320F28069 controlSTICK
On-board USB
JTAG Emulation
USB JTAG
Interface & Power
LED LD2
(GPIO34)
LED LD1
(Power)
TMS320F28069
Peripheral
Header Pins
The development tool for this workshop will be the TMS320F28069 controlSTICK kit. This
controlSTICK is a self-contained system that plugs into a free USB port on your computer. The
USB port provides power, as well as communicates to the onboard JTAG emulation controller.
LED LD1 illuminates when the board is powered, and LED LD2 is connected to GPIO34. We
will be using this LED as a visual indicator during the lab exercises. Some of the I/O lines from
the F28069 device are pinned out to the peripheral header. We will be using the included jumper
wire to connect various I/O lines on this header.
10
Architecture Overview
Architecture Overview
TMS320F2806x Block Diagram
Program Bus
ePWM
Boot
DMA
Sectored
ROM
RAM
eCAP
6 Ch.
Flash
eQEP
DMA Bus
12-bit ADC
CLA Bus
McBSP
32x32 bit
Multiplier
R-M-W
FPU
Atomic
ALU
CLA
PIE
Interrupt
Manager
VCU
Register Bus
Watchdog
I2C
SCI
SPI
32-bit
CAN 2.0B
Timers
USB 2.0
CPU
Data Bus
GPIO
This block diagram represents an overview of all device features and is not specific to any one
device. The F28069 device is designed around a multibus architecture, also known as a modified
Harvard architecture. This can be seen in the block diagram by the separate program bus and data
bus, along with the link between the two buses. This type of architecture greatly enhances the
performance of the device.
In the upper left area of the block diagram, you will find the memory section, which consists of
the boot ROM, sectored flash, and RAM. Also, you will notice that the six-channel DMA has its
own set of buses.
In the lower left area of the block diagram, you will find the execution section, which consists of
a 32-bit by 32-bit hardware multiplier, a read-modify-write atomic ALU, a floating-point unit,
and a Viterbi complex math CRC unit. The control law accelerator coprocessor is an independent
and separate unit that has its own set of buses.
The peripherals are grouped on the right side of the block diagram. The upper set is the control
peripherals, which consists of the ePWM, eCAP, eQEP, and ADC. The lower set is the
communication peripherals and consists of the multichannel buffered serial port, I2C, SCI, SPI,
CAN, and USB.
The PIE block, or Peripheral Interrupt Expansion block, manages the interrupts from the
peripherals. In the bottom right corner is the general-purpose I/O. Also, the CPU has a watchdog
module and three 32-bit general-purpose timers available.
11
Architecture Overview
Data
Program
M0 SARAM (1Kw)
M1 SARAM (1Kw)
PIE Vectors
(256 w)
PF 0 (6Kw)
reserved
0x002000
0x005000
PF 3 (4Kw)
0x006000
PF 1 (4Kw)
0x007000
PF 2 (4Kw)
0x008000
L0 DPSARAM (2Kw)
0x008800
L1 DPSARAM (1Kw)
0x008C00
L2 DPSARAM (1Kw)
0x009000
L3 DPSARAM (4Kw)
0x00A000
L4 SARAM (8Kw)
0x00C000
L5 DPSARAM (8Kw)
0x00E000
L6 DPSARAM (8Kw)
0x010000
L7 DPSARAM (8Kw)
0x012000
L8 DPSARAM (8Kw)
0x014000
0x014000
0x3D7800
0x3D7C00
0x3D7C80
0x3D7CC0
0x3D8000
reserved
User OTP (1Kw)
reserved
ADC / OSC cal. data
reserved
FLASH (128Kw)
0x3F7FF8
0x3F8000
PASSWORDS (8w)
0x3FFFC0
0x3FFFFF
Data
Program
CSM Protected:
L0, L1, L2, L3, L4,
OTP, FLASH,
ADC CAL,
Flash Regs in PF0
The F28069 utilizes a contiguous memory map, also known as a von-Neumann architecture. This
type of memory map lends itself well to higher-level languages. This can be seen by the labels
located at the top of the memory map where the memory blocks extend between both the data
space and program space.
At the top of the map, we have two blocks of RAM called M0 and M1. Then we see PF0 through
PF3, which are the peripheral frames. This is the area where you will find the peripheral
registers. Also in this space, you will find the PIE block. Memory blocks L0 through L8 are
grouped together. L0 through L3 are accessible by the CPU and CLA. L5 through L8 are
accessible by the DMA.
The user OTP is a one-time, programmable, memory block. TI reserves a small space in the map
for the ADC and oscillator calibration data. The flash block contains a section for passwords,
which are used by the code security module. The boot ROM and boot ROM vectors are located
at the bottom of the memory map.
12
Architecture Overview
96 dedicated PIE
vectors
No software decision
making required
Direct access to RAM
vectors
Auto flags update
Concurrent auto
context save
96
PIE
12 interrupts
IFR
IER
INTM
28x
CPU
Register
Map
The C2000 devices feature a very fast interrupt response manager using the PIE block. This
allows up to 96 possible interrupt vectors to be processed by the CPU. We will cover more
details about this in the reset, interrupts, and system initialization module.
ADC
DINTCH1-6
Result 0-15
L5 DPSARAM
McBSP-A
DMA
SysCtrlRegs.EPWMCNF.bit.CONCNF
6-channels
Triggers
L6 DPSARAM
L7 DPSARAM
L8 DPSARAM
ADCINT1 / ADCINT2
MXEVTA / MREVTA
XINT1-3 / TINT0-2
ePWM1-6 (SOCA-B)
USB0EP1-3RX/TX
software
PWM1
PWM2
PWM3
PWM4
PWM5
PWM6
13
Architecture Overview
from the CPU. The DMA can read data from the ADC result registers, transfer to or from
memory blocks L5 through L8, transfer to or from the McBSP, and also modify registers in the
ePWM. Triggers are used to initiate the transfers, and when completed the DMA can generate an
interrupt.
C28x CPU
&
CMP
PWM
CLA
An
14
Architecture Overview
operations
Decode
Complex
16-bit
for communications
math
Complex
filters
Power
Cyclic
Communications
The Viterbi complex math CRC unit extends the C2000 instruction set to support Viterbi
operations used in communications; complex math, which includes complex FFTs and complex
filters, and is used in power line communications and radar applications; and cyclical redundancy
check, which is used in communications and memory robustness checks. Below lists a summary
of the major architectural features covered in this module.
Architecture Summary
High performance 32-bit CPU
32x32 bit or dual 16x16 bit MAC
IEEE single-precision floating point unit (FPU)
Hardware Control Law Accelerator (CLA)
Viterbi, complex math, CRC unit (VCU)
Atomic read-modify-write instructions
Fast interrupt response manager
128Kw on-chip flash memory
Code security module (CSM)
Control peripherals
12-bit ADC module
Comparators
Direct memory access (DMA)
Up to 54 shared GPIO pins
Communications peripherals
15
Code Composer Studio is an integrated development environment that integrates the edit, code
generation, and debug process. It is simple to use, with single-click access to various functions,
and provides powerful debugging tools. Scripts automate tasks and BIOS is built-in. Code
Composer Studio is based on the Eclipse open source software framework.
16
Edit Perspective
Debug Perspective
Code Composer Studio has Edit and Debug perspectives. Each perspective provides a set of
functionality aimed at accomplishing a specific task. In the edit perspective, views used during
code development are displayed. In the debug perspective, views used during debug are
displayed.
17
CCSv5 Project
Project files contain:
List of files:
Libraries
Project settings:
Build configurations
A project contains files, such as C and assembly source files, libraries, BIOS configuration files,
and linker command files. It also contains project settings, such as build options, which include
the compiler, assembler, linker, and BIOS, as well as build configurations.
2. Advanced Settings
To create a project in Code Composer Studio, you would click on File New CCS Project.
18
First, you would fill in the project name, the location, and the device. Then you would complete
the advanced settings and, finally, the project template. You will have a chance to try this in our
first lab exercise.
Compiler
Linker
${PROJECT_ROOT}
specifies the current
project directory
After a project is created, the build options are configured. In our lab exercise, we will look at the
options for the compiler and linker.
19
Sections
Global vars (.ebss)
int
x = 2;
int
y = 7;
void main(void)
{
long z;
z = x + y;
}
Local vars (.stack)
Code (.text)
All code consists of different parts called sections. All default section names begin with a dot and
are typically lower case. The compiler has default section names for initialized and uninitialized
sections. For example, x and y are global variables, and they are placed in the section .ebss.
Whereas 2 and 7 are initialized values, and they are placed in the section called .cinit. The local
variables are in a section .stack, and the code is placed in a section called .txt.
20
Link Location
.text
code
FLASH
.cinit
FLASH
FLASH
.switch
FLASH
.pinit
FLASH
Uninitialized Sections
Name
Description
Link Location
.ebss
RAM
.stack
stack space
RAM
This is a small list of compiler default section names. The top group is initialized sections, and
they are linked to flash. In our previous code example, we saw .txt was used for code, and .cinit
for initialized values. The bottom group is uninitialized sections, and they are linked to RAM.
Once again, in our previous example, we saw .ebss used for global variables and .stack for local
variables.
21
M0SARAM
(0x400)
0x00 0400
M1SARAM
(0x400)
Sections
.ebss
.stack
0x3E 8000
.cinit
FLASH
(0x10000)
.text
Next, we need to place the sections that were created by the compiler into the appropriate
memory spaces. The uninitialized sections, .ebss and .stack, need to be placed into RAM; while
the initialized sections, .cinit, and .txt, need to be placed into flash.
Linking
Memory description
Link.cmd
.obj
Linker
.out
.map
The linker command file describes the physical hardware memory and specifies where the
22
sections are placed in the memory. The file created during the link process is a .out file. This is
the file that will be loaded into the microcontroller. As an option, we can generate a map file.
This map file will provide a summary of the link process, such as the absolute address and size of
each section.
/* Program Memory */
origin = 0x3E8000, length = 0x10000
PAGE 1:
/* Data Memory */
M0SARAM: origin = 0x000000, length = 0x400
M1SARAM: origin = 0x000400, length = 0x400
}
SECTIONS
{
.text:>
.ebss:>
.cinit:>
.stack:>
}
FLASH
M0SARAM
FLASH
M1SARAM
PAGE
PAGE
PAGE
PAGE
=
=
=
=
0
1
0
1
A linker command file consists of two sections, a memory section and a sections section. In the
memory section, page 0 defines the program memory space, and page 1 defines the data memory
space. Each memory block is given a unique name, along with its origin and length. In the
sections section, the section is directed to the appropriate memory block. In the lab exercise, you
will have an opportunity to work with a linker command file.
Next, in the lab exercise, you will be working with a linker command file and will learn the basic
skills for using Code Composer Studio. You will set up a target configuration, create a project,
build a project, and step through the code.
23
F28069
System Description:
TMS320F28069
0x00 0000
M0SARAM
(0x400)
0x00 A000
0x00 0400
M1SARAM
(0x400)
L4SARAM
(0x2000)
Placement of Sections:
.text into RAM Block L4SARAM on PAGE 0 (program memory)
.cinit into RAM Block L4SARAM on PAGE 0 (program memory)
.ebss into RAM Block M0SARAM on PAGE 1 (data memory)
.stack into RAM Block M1SARAM on PAGE 1 (data memory)
Procedure
24
This folder contains all CCS custom settings, which includes project settings and views
when CCS is closed so that the same projects and settings will be available when CCS is
opened again. The workspace is saved automatically when CCS is closed.
2. The first time CCS opens a Welcome to Code Composer Studio v5 page appears.
Close the page by clicking the X on the TI Resource Explorer tab. You should now
have an empty workbench. The term workbench refers to the desktop development
environment. Maximize CCS to fill your screen.
The workbench will open in the CCS Edit Perspective view. Notice the CCS Edit
icon in the upper right-hand corner. A perspective defines the initial layout views of the
workbench windows, toolbars, and menus which are appropriate for a specific type of
task (i.e. code development or debugging). This minimizes clutter to the user interface.
The CCS Edit Perspective is used to create or build projects. A CCS Debug
Perspective view will automatically be enabled when the debug session is started. This
perspective is used for debugging projects.
25
Click OK.
7. The next section selects the device. Select the Family using the pull-down list and
choose C2000. Set the Variant filter using the pull-down list to 2806x
Piccolo and choose the controlSTICK Piccolo F28069. Leave the
Connection box blank. We have already set up the target configuration.
8. Next, open the Advanced settings section and set the Linker command file to
<none>. We will be using our own linker command file, rather than the one supplied
by CCS. Leave the Runtime Support Library set to <automatic>. This will
automatically select the rts2800_fpu32.lib runtime support library for floating-point
devices.
9. Now open the Project templetes and examples section and select the Empty Project
template. Click Finish.
10. A new project has now been created. Notice the Project Explorer window
contains Lab1. The project is set Active and the output files will be located in the
Debug folder. At this point, the project does not include any source files. The next step
is to add the source files to the project.
11. To add the source files to the project, right-click on Lab1 in the Project Explorer
window and select:
Add Files
or click: Project Add Files
and make sure youre looking in C:\C28x\Labs\Lab1\Files. With the file type
set to view all files (*.*) select Lab1.c and Lab1.cmd then click Open. A File
Operation window will open, choose Copy files and click OK. This will add the
files to the project.
12. In the Project Explorer window, click the plus sign (+) to the left of Lab1 and
notice that the files are listed.
26
Button
1
2
Name
Build
Debug
Description_____________________________________
Full build and link of all source files
Automatically build, link, load and launch debug-session
19. Click the Build button and watch the tools run in the Console window. Check for
errors in the Problems window (we have deliberately put an error in Lab1.c). When
you get an error, you will see the error message in the Problems window. Expand the
error by clicking on the plus sign (+) to the left of the Errors. Then simply double-click
the error message. The editor will automatically open to the source file containing the
error, with the code line highlighted with a question mark (?).
20. Fix the error by adding a semicolon at the end of the z = x + y statement. For
future knowledge, realize that a single code error can sometimes generate multiple error
messages at build time. This was not the case here.
21. Build the project again. There should be no errors this time.
22. CCS can automatically save modified source files, build the project, open the debug
perspective view, connect and download it to the target, and then run the program to the
beginning of the main function.
Click on the Debug button (green bug) or click Run Debug.
Notice the CCS Debug icon in the upper right-hand corner indicating that we are now in
the CCS Debug Perspective view. The program ran through the C-environment
initialization routine in the rts2800_fpu32.lib and stopped at main() in Lab1.c.
27
28
(volatile unsigned
int *)0x00007100
...
void main(void)
{
*ADCCTL1 = 0x1234;
*ADCCTL1 |= 0x4000;
Advantages
Disadvantages
In the traditional approach to C coding, we used a #define to assign the address of the register and
referenced it with a pointer. The first line of code on this slide we are writing to the entire
register with a 16-bit value. The second line, we are ORing a bit field.
Advantages? Simple, fast, and easy to type. The variable names can exactly match the register
names, so it's easy to remember. Disadvantages? Requires individual masks to be generated to
manipulate individual bits, it cannot easily display bit fields in the debugger window, and it will
generate less efficient code in many cases.
29
AdcRegs.ADCCTL1.bit.ADCENABLE = 1;
Advantages
Disadvantages
The structure approach to C coding uses the peripheral register header files. First, a peripheral is
specified, followed by a control register. Then you can modify the complete register or selected
bits. This is almost self-commented code.
The first line of code on this slide we are writing to the entire register. The second line of code
we are modifying a bit field. Advantages? Easy to manipulate individual bits, it works great with
our tools, and will generate the most efficient code. Disadvantages? Can be difficult to
remember the structure names and more to type; however, the edit auto complete feature of Code
Composer Studio will eliminate these disadvantages.
30
With the traditional approach to coding using #define, we can only view the complete register
values. As an example, notice the control register ADCCTL1 has a value of 0x40E4. We would
need to refer to the reference guide to know the settings of the individual bit fields.
With the structure approach, we can add the peripheral to an expressions window, allowing us to
31
view, as well as modify individual bit fields in a register. No need for a reference guide to
identify the bit fields.
All
PeripheralName.RegisterName.half.LSW
PeripheralName.RegisterName.half.MSW
PeripheralName.RegisterName.bit.FieldName
Notes: [1] PeripheralName are assigned by TI and found in the F2806x header files.
They are a combination of capital and small letters (i.e. CpuTimer0Regs).
[2] RegisterName are the same names as used in the data sheet.
They are always in capital letters (i.e. TCR, TIM, TPR,..).
[3] FieldName are the same names as used in the data sheet.
They are always in capital letters (i.e. POL, TOG, TSS,..).
The header files define all of the peripheral structures, all of the register names, all of the bit field
names, and all of the register addresses. The most common naming conventions used are
PeripheralName.RegisterName.all, which will access the full 16 or 32-bit register; and
PeripheralName.RegisterName.bit.FieldName, which will access the specified bit fields of a
register.
32
This demonstrates how the editor auto complete feature works. First, you type AdcRegs. Then,
when you type a . a window opens up, allowing you to select a control register. In this example
ADCCTL1 is selected. Then, when you type the . a window opens up, allowing you to select
all or bit. In this example bit is selected. Then, when you type the . a window opens up,
allowing you to select a bit field. In this example RESET is selected. And now, the structure is
completed.
33
Contains
.h files
\F2806x_headers\cmd
\F2806x_examples
CCS examples
\doc
documentation
The F2806x header file package contains everything needed to use the structure approach. It
defines all the peripheral register bits and register addresses. The header file package includes the
header files, linker command files, code examples, and documentation. The header file package
is available from controlSUITE.
34
F2806x_Adc.h
// ADC Individual Register Bit Definitions:
struct ADCCTL1_BITS {
Uint16 TEMPCONV:1;
// bits description
// 0 Temperature sensor connection
Uint16 ADCREFSEL:1;
Uint16 rsvd1:1;
// 4 reserved
Uint16 ADCREFPWD:1;
Uint16 ADCBGPWD:1;
Uint16 ADCPWDN:1;
// 7 ADC powerdown
Uint16 ADCBSYCHN:5;
Uint16 ADCBSY:1;
Uint16 ADCENABLE:1;
// 14 ADC enable
Uint16 RESET:1;
};
};
all;
Next, we will discuss the steps needed to use the header files with your project. The .h files
contain the bit field structure definitions for each peripheral register.
F2806x_BootVars.h
F2806x_Cla.h
F2806x_Comp.h
F2806x_CpuTimers.h
F2806x_DevEmu.h
F2806x_Device.h
F2806x_Dma.h
F2806x_ECan.h
F2806x_ECap.h
F2806x_EPwm.h
F2806x_EQep.h
F2806x_Gpio.h
F2806x_I2c.h
F2806x_Mcbsp.h
F2806x_NmiIntrupt.h
F2806x_PieCtrl.h
F2806x_PieVect.h
F2806x_Sci.h
F2806x_Spi.h
F2806x_SysCtrl.h
F2806x_Usb.h
F2806x_XIntrupt.h
F2806x_Device.h
Main
include file
Will include all other .h files
Include this file (directly or indirectly)
in each source file:
#include
F2806x_Device.h
The header file package contains a .h file for each peripheral in the device. The
F2806x_Device.h file is the main include file. It will include all of the other .h files. There are
35
three steps needed to use the header files. The first step is to include this file directly or indirectly
in each source files.
Declares
Each
#pragma DATA_SECTION(AdcRegs,"AdcRegsFile");
volatile struct ADC_REGS AdcRegs;
Add
F2806x_GlobalVariableDefs.c
The global variable definition file declares a global instantiation of the structure for each
peripheral. Each structure is placed in its own section using a DATA_SECTION pragma to allow
linking to the correct memory. The second step for using the header files is to add
F2806x_GlobalVariableDefs.c file to your project.
36
#pragma DATA_SECTION(AdcRegs,"AdcRegsFile");
volatile struct ADC_REGS AdcRegs;
F2806x_Headers_nonBIOS.cmd
MEMORY
{
PAGE1:
...
ADC:
...
}
origin=0x007100, length=0x000080
SECTIONS
{
...
AdcRegsFile:
...
}
F2806x_nonBIOS.cmd
or
F2806x_BIOS.cmd
>
ADC
PAGE = 1
The header file package has two linker command file versions; one for non-BIOS projects and
one for BIOS projects. This linker command file is used to link each structure to the address of
the peripheral using the structures named section. The third and final step for using the header
files is to add the appropriate linker command file to your project.
37
The peripheral register header file package includes example projects for each peripheral. This
can be very helpful to getting you started.
code development
Easy to use
Generates most efficient code
Increases effectiveness of CCS watch window
TI has already done all the work!
Use
F2803x
F2804x
F2802x
F281x
In summary, the peripheral register header files allow for easier code development, they are easy
to use, generates the most efficient code, works great with Code Composer Studio, and TI has
already done the work for you. Just make sure to use the correct header file package for your
device.
38
Reset Sources
Missing Clock Detect
F28x core
Watchdog Timer
Power-on Reset
XRS
Brown-out Reset
XRS pin active
To XRS pin
There are various reset sources available for this device: an external reset pin, watchdog timer
reset, power-on reset which generates a device reset during power-up conditions, brownout reset
which generates a device reset if the power supply drops below specifications for the device, as
well as a missing clock detect reset. Additionally, the device incorporates an on-chip voltage
regulator to generate the core voltage.
39
Reset Bootloader
Reset
ENPIE = 0
INTM = 1
YES
TRST = 1
Emulation Boot
Boot determined by
2 RAM locations:
EMU_KEY and EMU_BMODE
Reset vector
fetched from
boot ROM
0x3F FFC0
Emulator
Connected ?
NO
TRST = 0
Stand-alone Boot
Boot determined by
2 GPIO pins and
2 OTP locations:
OTP_KEY and OTP_BMODE
After reset, the PIE block is disabled and the global interrupt line is disabled. The reset vector is
fetched from the boot ROM and the bootloader process begins.
Then the bootloader determines if the emulator is connected by checking the JTAG test reset line.
If the emulator is connected, we are in emulation boot mode. The boot is then determined by two
RAM locations named EMU_Key and EMU_BMODE, which are located in the PIE block. If the
emulator is not connected, we are in stand-alone boot mode. The boot is then determined by two
GPIO pins and two OTP locations named OTP_KEY and OTP_BMODE, which are located in
the OTP.
40
Emulation Boot
Boot determined by
2 RAM locations:
EMU_KEY and EMU_BMODE
EMU_KEY = 0x55AA ?
NO
Boot Mode
Wait
YES
EMU_BMODE =
0x0000
0x0001
0x0003
0x0004
0x0005
0x0006
0x0007
0x000A
0x000B
other
Boot Mode
Parallel I/O
SCI
GetMode
SPI
I2C
OTP
CAN
M0 SARAM
FLASH
Wait
OTP_KEY = 0x005A ?
NO
Boot Mode
FLASH
YES
OTP_BMODE =
0x0001
0x0004
0x0005
0x0006
0x0007
other
Boot Mode
SCI
SPI
I2C
OTP
CAN
FLASH
In emulation boot mode, first the EMU_KEY register is checked to see if it has a value of
0x55AA. If either EMU_KEY or EMU_BMODE are invalid, the wait boot mode is used. These
values can then be modified using the debugger and a reset issued to restart the boot process.
This can be considered the default on power-up. At this point, you would like the device to wait
until given a boot mode.
If EMU_KEY register has a value of 0x55AA, then the hex value in the EMU_BMODE register
determines the boot mode. The boot modes are parallel I/O, SCI, SPI, I2C, OTP, CAN,
M0SARAM, FLASH, and Wait. In addition, there is a GetMode, which emulates the stand-alone
boot mode.
41
Stand-alone Boot
Boot determined by
2 GPIO pins and
2 OTP locations:
OTP_KEY = 0x005A ?
GPIO
37
0
0
1
1
GPIO
34
0
1
0
1
NO
Boot Mode
FLASH
YES
Boot Mode
Parallel I/O
SCI
Wait
GetMode
OTP_BMODE =
0x0001
0x0004
0x0005
0x0006
0x0007
other
Boot Mode
SCI
SPI
I2C
OTP
CAN
FLASH
In stand-alone boot mode, GPIO pins 37 and 34 determine if the boot mode is parallel I/O, SCI,
or wait. The default unconnected pins would set the boot mode to GetMode. In GetMode, first
the OTP_KEY register is checked to see if it has a value of 0x005A. An unprogrammed OTP is
set to the FLASH boot mode, as expected.
If the OTP_KEY register has a value of 0x005A, then the hex value in the OTP_BMODE register
determines the boot mode. The boot modes are SCI, SPI, I2C, OTP, CAN, and FLASH.
42
0x000000
M0 SARAM (1Kw)
0x3D7800
0x3D7800
OTP (1Kw)
0x3D8000
FLASH (128Kw)
0x3F7FF6
0x3F8000
0x3FFFC0
RESET
Execution Entry
determined by
Emulation Boot Mode or
Stand-Alone Boot Mode
Bootloading
Routines
(SCI, SPI, I2C,
CAN, Parallel I/O)
In summary, the reset code flow is as follows: The reset vector is fetched from the boot ROM.
Then, the execution entry is determined by emulation boot mode or stand-alone boot mode. The
boot mode options are M0SARAM, OTP, FLASH, and boot loading routines.
Part
.sect codestart
LB _c_int00
Linker .cmd
MEMORY
{
PAGE 0:
BEGIN_M0
}
SECTIONS
{
codestart
}
Note: the above example is for boot mode set to M0 SARAM; to run out of Flash, the
codestart section would be linked to the entry point of the Flash memory block
After reset how do we get to main? When the bootloader process is completed, a branch to the
43
compiler runtime support library is located at the code entry point. This branch to _c_int00 is
executed, then the compiler environment is set up, and finally main is called.
Interrupts
Interrupt Sources
Internal Sources
TINT2
TINT1
TINT0
ePWM, eCAP, eQEP,
ADC, SCI, SPI, I2C,
eCAN, McBSP,
DMA, CLA, WD
External Sources
XINT1 XINT3
F28x CORE
XRS
NMI
PIE
(Peripheral
Interrupt
Expansion)
INT1
INT2
INT3
INT12
INT13
INT14
TZx
XRS
The internal interrupt sources include the general purpose timers 0, 1, and 2, and all of the
peripherals on the device. External interrupt sources include the three external interrupt lines, the
trip zones, and the external reset pin. The core has 14 interrupt lines. As you can see, the number
of interrupt sources exceeds the number of interrupt lines on the core. The PIE, or Peripheral
Interrupt Expansion block, is connected to the core interrupt lines 1 through 12. This block
manages and expands the 12 core interrupt lines, allowing up to 96 possible interrupt sources.
44
Core
Interrupt
(IFR)
Latch
INT1
INT2
INT14
(IER)
(INTM)
Switch Global Switch
F28x
Core
It is easier to explain the interrupt processing flow from the core back out to the interrupt sources.
The INTM is the master interrupt switch. This switch must be closed for any interrupts to
propagate into the core. The next layer out is the interrupt enable register. The appropriate
interrupt line switch must be closed to allow an interrupt through. The interrupt flag register gets
set when an interrupt occurs. Once the core starts processing an interrupt, the INTM switch
opens to avoid nested interrupts and the flag is cleared.
45
14
RTOSINT DLOGINT
(pending = 1 / absent = 0)
13
12
11
10
INT14
INT13
INT12
INT11
INT10
INT9
INT8
INT7
INT6
INT5
INT4
INT3
INT2
INT1
14
RTOSINT DLOGINT
(enable = 1 / disable = 0)
13
12
11
10
INT14
INT13
INT12
INT11
INT10
INT9
INT3
INT2
INT1
INT8
INT7
INT6
INT5
INT4
Bit 0
INTM
ST1
(enable = 0 / disable = 1)
The core interrupt registers consists of the interrupt flag register, interrupt enable register, and
interrupt global mask bit. Notice that the interrupt global mask bit is zero when enabled and one
when disabled. The interrupt enable register is managed by ORing and ANDing mask values.
The interrupt global mask bit is managed using inline assembly.
46
INT1.8
INT1 INT12
12 Interrupts
INT1
INTM
96
INT1.2
IER
INT1.1
IFR
Peripheral Interrupts
12 x 8 = 96
PIEIFR1 PIEIER1
28x
Core
We have already discussed the interrupt process in the core. Now we need to look at the
peripheral interrupt expansion block. This block is connected to the core interrupt lines 1 through
12. The PIE block consists of 12 groups. Within each group, there are eight interrupt sources.
Each group has a PIE interrupt enable register and a PIE interrupt flag register.
As you can see, the interrupts are numbered from 1.1 through 12.8, giving us a maximum of 96
interrupt sources. Interrupt lines 13, 14, and NMI bypass the PIE block.
47
INTx.7
INTx.6
INTx.5
INTx.4
INTx.3
INTx.2
INTx.1
INT1
WAKEINT
TINT0
ADCINT9
XINT2
XINT1
ADCINT2
ADCINT1
INT2
EPWM8
_TZINT
EPWM7
_TZINT
EPWM6
_TZINT
EPWM5
_TZINT
EPWM4
_TZINT
EPWM3
_TZINT
EPWM2
_TZINT
EPWM1
_TZINT
INT3
EPWM8
_INT
EPWM7
_INT
EPWM6
_INT
EPWM5
_INT
EPWM4
_INT
EPWM3
_INT
EPWM2
_INT
EPWM1
_INT
INT4
HRCAP2
_INT
HRCAP1
_INT
ECAP3
_INT
ECAP2
_INT
ECAP1
_INT
EQEP2
_INT
EQEP1
_INT
INT5
HRCAP4
_INT
HRCAP3
_INT
INT6
MXINTA
MRINTA
SPITX
INTB
SPIRX
INTB
SPITX
INTA
SPIRX
INTA
INT7
DINTCH6
DINTCH5
DINTCH4
DINTCH3
DINTCH2
DINTCH1
I2CINT2A
I2CINT1A
ECAN1
_INTA
ECAN0
_INTA
SCITX
INTB
SCIRX
INTB
SCITX
INTA
SCIRX
INTA
INT8
INT9
INT10
ADCINT8
ADCINT7
ADCINT6
ADCINT5
ADCINT4
ADCINT3
ADCINT2
ADCINT1
INT11
CLA1
_INT8
CLA1
_INT7
CLA1
_INT6
CLA1
_INT5
CLA1
_INT4
CLA1
_INT3
CLA1
_INT2
CLA1
_INT1
INT12
LUF
LVF
XINT3
The interrupt assignment table tells us the location for each interrupt source within the PIE block.
Notice the table is numbered from 1.1 through 12.8, perfectly matching the PIE block.
PIE Registers
PIEIFRx register
15 - 8
(x = 1 to 12)
7
reserved
PIEIERx register
15 - 8
(x = 1 to 12)
7
reserved
11
10
reserved
PIEACKx
PIECTRL register
15 - 1
PIEVECT
ENPIE
#include F2806x_Device.h
PieCtrlRegs.PIEIFR1.bit.INTx4 = 1;
PieCtrlRegs.PIEIER3.bit.INTx2 = 1;
PieCtrlRegs.PIEACK.all = 0x0004;
The PIE registers consist of 12 PIE interrupt flag registers, 12 PIE interrupt enable registers, a
PIE interrupt acknowledge register, and a PIE control register. The enable PIE bit in the PIE
48
control register must be set during initialization for the PIE block to be enabled.
Main.c
// CPU Initialization
InitPieCtrl();
PieVect.c
PieCtrl.c
2
// Initialize PIE_RAM
memcpy(
);
PIE_VECT_TABLE
// Base Vectors
PIE RAM
Vectors
256w
(ENPIE = 1)
Boot ROM
Reset Vector
3
The interrupt vector table, as mapped in the PIE interrupt assignment table, is located in the
PieVect.c file. During initialization in main, we have a function call to PieCtrl.c. In this file, a
memory copy function copies the interrupt vector table to the PIE RAM and then sets ENPIE to
1, enabling the PIE block. This process is done to set up the vectors for interrupts.
49
Reset Vector
CodeStartBranch.asm
.sect codestart
M0SARAM Entry Point
<0x00 0000> = LB _c_int00
_c_int00:
rts2800_fpu32.lib
Interrupt
CALL main()
PIE Vector Table
Main.c
main()
{ initialization();
}
Initialization()
{
Load PIE Vectors
Enable the PIE
Enable PIEIER
Enable Core IER
Enable INTM
}
In summary, the PIE initialization code flow is as follows. After the device is reset and executes
the boot code, the selected boot option determines the code entry point. This figure shows two
different entry points. The one on the left is for memory block M0, and the one on the right is for
flash.
In either case, CodeStartBranch.asm has a Long Branch to the entry point of the runtime
support library. After the runtime support library completes execution, it calls main. In main, we
have a function call to initialize the interrupt process and enable the PIE block. When an
interrupt occurs, the PIE block contains a vector to the interrupt service routine located in
DefaultIsr.c.
50
Peripheral
Interrupt
PieCtrlRegs.PIEIERx.bit.INTxy = 1;
IFR
IER
INTM
IER |= 0x0001;
0x0FFF;
DefaultIsr.c
interrupt void name(void)
{
}
INTx.y name
In summary, the following steps occur during an interrupt process. First, a peripheral interrupt is
generated and the PIE interrupt flag register is set. If the PIE interrupt enable register is enabled,
then the core interrupt flag register will be set. Next, if the core interrupt enable register and
global interrupt mask is enabled, the PIE vector table will redirect the code to the interrupt service
routine.
51
Internal
OSC 1
(10 MHz)
OSC1CLK
0* WDCLK
1
Watchdog
Module
OSCCLKSRCSEL
OSCCLKSRC2
OSC2CLK
1
0*
0*
1
OSCCLK
(PLL bypass)
PLL
DIVSEL
MUX
Internal
OSC 2
(10 MHz)
XTAL
X1
X2
0*
1
XTAL OSC
CLKIN
VCOCLK
C28x
Core
SYSCLKOUT
XCLKINOFF
XCLKIN
1/n
DIV
EXTCLK
SYSCLKOUT
TMR2CLKSRCSEL
10
11 CPUTMR2CLK
01
00*
CPU
Timer 2
LOSPCP
LSPCLK
SCI, SPI
All other peripherals
clocked by SYSCLKOUT
* = default
The oscillator/PLL clock module has two internal, 10 MHz oscillators, and the availability of an
external oscillator or crystal. This provides redundancy in case an oscillator fails, as well as the
ability to use multiple oscillators. The asterisks in the multiplexers show the default settings.
This module has the capability to clock the watchdog, core, and CPU timer 2 from independent
clock sources, if needed. Next, we will look at the details for clocking the core.
52
PLL
DIV
00000
00001
00010
00011
00100
00101
00110
00111
01000
01001
01010
01011
01100
01101
01110
01111
10000
10001
10010
1xx11
VCOCLK
SysCtrlRegs.PLLSTS.bit.DIVSEL
MUX
OSCCLK
(PLL bypass)
1/n
CLKIN
C28x
Core
SysCtrlRegs.PLLCR.bit.DIV
CLKIN
OSCCLK / n * (PLL bypass)
OSCCLK x 1 / n
OSCCLK x 2 / n
OSCCLK x 3 / n
OSCCLK x 4 / n
OSCCLK x 5 / n
OSCCLK x 6 / n
OSCCLK x 7 / n
OSCCLK x 8 / n
OSCCLK x 9 / n
OSCCLK x 10 / n
OSCCLK x 11 / n
OSCCLK x 12 / n
OSCCLK x 13 / n
OSCCLK x 14 / n
OSCCLK x 15 / n
OSCCLK x 16 / n
OSCCLK x 17 / n
OSCCLK x 18 / n
reserved
SYSCLKOUT
LOSPCP
LSPCLK
SysCtrlRegs.LOSPCP.bit.LSPCLK
DIVSEL
0x
10
11
* default
n
/4 *
/2
/1
LSPCLK
000
001
010
011
100
101
110
111
A clock source can be fed directly into the core or multiplied using the PLL. The PLL gives us
the capability to use the internal 10 MHz oscillator multiplied by 18/2, and run the device at the
full 90 MHz clock frequency. If the input clock is removed after the PLL is locked, the input
clock failed detect circuitry will issue a limp mode clock of 1 to 4 MHz. Additionally, an internal
device reset will be issued. The low-speed peripheral clock prescaler is used to clock some of the
communication peripherals.
53
Watchdog Timer
Resets
Watchdog
The watchdog timer is a safety feature, which resets the device if the program runs away or gets
trapped in an unintended infinite loop.
The watchdog counter runs independent of the CPU. If the counter overflows, a reset or interrupt
is triggered. The CPU must write the correct data key sequence to reset the counter before it
overflows. The watchdog must be serviced or disabled within 131,072 watchdog clock cycles
after reset. This translates to 13.11 milliseconds with a 10 MHz watchdog clock.
54
WDCLK
/512
WDPS
WDOVERRIDE
Watchdog
Prescaler
WDDIS
8-bit Watchdog
Counter
CLR
WDRST
System
Reset
Output
Pulse
WDINT
WDCHK
55 + AA
Detector
Watchdog
Reset Key
Register
Good Key
/
/
1 0 1
The watchdog clock is divided by 512 and prescaled, if desired. The watchdog disable switch
allows the watchdog to be enabled and disabled. The watchdog override switch is a safety
mechanism, and once closed, it can only be open by resetting the device.
During initialization, 101 is written into the watchdog check bit fields. Any other values will
cause a reset or interrupt. During run time, the correct keys must be written into the watchdog
key register before the watchdog counter overflows and issues a reset or interrupt. Issuing a reset
or interrupt is user-selectable.
55
GPIO
Qual
Input
GPIO Port B
Direction Register
(GPBDIR)
[GPIO 32 to 63]
ANALOG Port
Direction Register
(AIODIR)
[AIO 0 to 15]
Qual
ANALOG Port
Input
GPIO Port B
Internal Bus
GPIO Port A
Direction Register
(GPADIR)
[GPIO 0 to 31]
GPIO Port A
Each general-purpose I/O pin has a maximum of four options, either general-purpose I/O or up to
three possible peripheral pin assignments. This is selected using the GPIO port multiplexer. If
the pin is set to GPIO, the direction register sets it as an input or an output. The input
qualification will be explained shortly.
56
GPxSET
GPxCLEAR
GPxTOGGLE
Peripheral
3
GPxDIR
10
11
00
GPxDAT
01
Out
I/O DAT
Bit (R/W)
Peripheral
2
In
GPxPUD
Input
Qualification
(GPIO 0-44)
Internal Pull-Up
0 = enable (default GPIO 12-58)
1 = disable (default GPIO 0-11)
GPxMUX1
GPxMUX2
MUX Control Bits *
00 = GPIO
01 = Peripheral 1
10 = Peripheral 2
11 = Peripheral 3
GPxQSEL1
GPxQSEL2
GPxCTRL
Pin
* See device datasheet for pin function selection matrices
This figure shows a single GPIO pin. If the pin is set as a GPIO by the GPIO multiplexer, the
direction will be set by the GPIO direction register. The GPIO data register will have the value of
the pin if set as an input or write the value of the data register to the pin if set as an output.
The data register can be quickly and easily modified using set, clear, or toggle registers. As you
can see, the GPIO multiplexer can be set to select up to three other possible peripheral pin
assignments. Also, the pin has an option for an internal pull-up.
57
pin
to GPIO and
peripheral
modules
Input
Qualification
SYSCLKOUT
samples taken
T = qual period
The GPIO input qualification feature allows filtering out noise on a pin. The user would select
the number of samples and qualification period. Qualification is available on ports A and B only
and is individually selectable per pin.
58
This lab exercise consists of two parts. In the first part we will test the behavior of the watchdog
when disabled and enabled. In the second part we will initialize the peripheral interrupt
expansion vectors and use the watchdog to generate an interrupt.
59
Setup the clock module PLL, LOSPCP = /4, low-power modes to default values, enable all
module clocks
Setup the watchdog and system control registers DO NOT clear WD OVERRIDE bit,
configure WD to generate a CPU reset
Setup the shared I/O pins set all GPIO pins to GPIO function (e.g. a "00" setting for GPIO
function, and a 01, 10, or 11 setting for peripheral function)
The first part of the lab exercise will setup the system initialization and test the watchdog
operation by having the watchdog cause a reset. In the second part of the lab exercise the PIE
vectors will be tested by using the watchdog to generate an interrupt. This lab will make use of
the F2806x C-code header files to simplify the programming of the device, as well as take care of
the register definitions and addresses. Please review these files, and make use of them in the
future, as needed.
Procedure
60
Lab.h
Lab_2_3.cmd
Main_2.c
PieCtrl.c
PieVect.c
SysCtrl.c
Watchdog.c
System Initialization
5. Open and inspect SysCtrl.c. Notice that the PLL and module clocks have been
enabled.
6. Open and inspect Watchdog.c. Notice that the watchdog control register (WDCR) is
configured to disable the watchdog, and the system control and status register (SCSR) is
configured to generate a reset.
7. Open and inspect Gpio.c. Notice that the shared I/O pins have been set to the GPIO
function, except for GPIO0 which will be used in the next lab exercise. Close the
inspected files.
61
If the device is power cycled between lab exercises, or within a lab exercise, be sure to
re-configure the boot mode to EMU_BOOT_SARAM.
62
to generate an interrupt. This part will demonstrate the interrupt concepts learned in this
module.
18. Switch to the CCS Edit Perspective view by clicking the CCS Edit icon in the upper
right-hand corner. Notice that the following files are included in the project:
DefaultIsr_2.c
PieCtrl.c
PieVect.c
19. In Main_2.c, uncomment the code used to call the InitPieCtrl() function. There
are no passed parameters or return values, so the call code is simply:
InitPieCtrl();
20. Using the PIE Interrupt Assignment Table shown in the slides find the location for the
watchdog interrupt, WAKEINT. This is used in the next step.
PIE group #:
# within group:
21. In main() notice the code used to enable global interrupts (INTM bit), and in
InitWatchdog() the code used to enable the WAKEINT interrupt in the PIE
(using the PieCtrlRegs structure) and to enable core INT1 (IER register).
22. Modify the system control and status register (SCSR) to cause the watchdog to generate
a WAKEINT rather than a reset. In Watchdog.c change the SCSR register value to
0x0002. Save the modified files.
23. Open and inspect DefaultIsr_2.c. This file contains interrupt service routines. The
ISR for WAKEINT has been trapped by an emulation breakpoint contained in an inline
assembly statement using ESTOP0. This gives the same results as placing a breakpoint
in the ISR. We will run the lab exercise as before, except this time the watchdog will
generate an interrupt. If the registers have been configured properly, the code will be
trapped in the ISR.
24. Open and inspect PieCtrl.c. This file is used to initialize the PIE RAM and enable
the PIE. The interrupt vector table located in PieVect.c is copied to the PIE RAM to
setup the vectors for the interrupts. Close the modified and inspected files.
63
64
Control Peripherals
Control Peripherals
ADC Module
S/H
A
MUX
A
ADCINB0
ADCINB1
MUX
ADCINA7
S/H
B
MUX
B
Result
MUX
SOCx
ADCINB7
ADC full-scale
input range is
0 to 3.3V
12-bit A/D
Converter
ADC
EOCx
Generation
Logic
CHSEL
SOCx Signal
RESULT0
RESULT1
RESULT2
RESULT15
ADC
ADCINT1-9
Interrupt
Logic
ADCINT1
TRIGSEL
TRIGSEL
TRIGSEL
TRIGSEL
CHSEL
CHSEL
CHSEL
CHSEL
ACQPS
ACQPS
ACQPS
ACQPS
SOCx Triggers
ADCINT2
SOC0
SOC1
SOC2
SOC3
Software
CPU Timer (0,1,2)
EPWMxSOCA (x = 1 to 8)
EPWMxSOCB (x = 1 to 8)
External Pin
(GPIO/XINT2_ADCSOC)
The ADC module is based around a 12-bit converter. There are 16 input channels and 16 result
registers. The SOC configuration registers select the trigger source, channel to convert, and the
acquisition prescale window size. The triggers include software by selecting a bit, CPU timers 0,
1 and 2, EPWMA and EPWMB 1 through 8, and an external pin. Additionally, ADCINT 1 and 2
can be fed back for continuous conversions.
The ADC module can operate in sequential sampling mode or simultaneous sampling mode. In
simultaneous sampling mode, the channel selected on the A multiplexer will be the same channel
on the B multiplexer. The ADC interrupt logic can generate up to nine interrupts. The results for
SOC 0 through 15 will appear in result registers 0 through 15.
65
Control Peripherals
SOC0
Channel
A2
Sample
7 cycles
Result0
no interrupt
SOC1
Channel
B3
Sample
10 cycles
Result1
no interrupt
SOC2
Channel
A7
Sample
8 cycles
Result2
ADCINT1
ADCINT2
SOC3
Channel
A0
Sample
10 cycles
Result3
no interrupt
SOC4
Channel
B0
Sample
15 cycles
Result4
no interrupt
SOC5
Channel
A5
Sample
12 cycles
Result5
ADCINT2
The top example on this slide shows channels A2, B3, and A7 being converted with a trigger
from EPWM1SOCB. After A7 is converted, ADCINT1 is generated.
The bottom examples extends this with channels A0, B0, and A5 being converted initially with a
software trigger. After A5 is converted, ADCINT2 is generated, which is fed back as a trigger to
start the process again.
66
Control Peripherals
SOC0
Channel
A0:B0
Sample
7 cycles
Result0
Result1
no interrupt
SOC2
Channel
A1:B1
Sample
7cycles
Result2
Result3
no interrupt
SOC4
Channel
A2:B2
Sample
7 cycles
Result4
Result5
no interrupt
SOC6
Channel
A3:B3
Sample
7 cycles
Result6
Result7
ADCINT1
SOC8
Channel
A4:B4
Sample
7 cycles
Result8
Result9
no interrupt
SOC10
Channel
A5:B5
Sample
7 cycles
Result10
Result11
no interrupt
SOC12
Channel
A6:B6
Sample
7 cycles
Result12
Result13
no interrupt
SOC14 Channel
Sample
7 cycles
Result14
Result15
ADCINT2
ADCINT2
A7:B7
The example on this slide shows channels A/B 0 through 7 being converted in simultaneous
sampling mode, triggered initially by software. After channel A/B three is converted, ADCINT1
is generated. After channel A/B seven is converted, ADCINT2 is generated and fed back to start
the process again. ADCINT1 and ADCINT2 are being used as ping-pong interrupts.
67
Control Peripherals
Comparator
A0
B0
A1
B1
A2
B2
AIO2
AIO10
10-bit
DAC
COMP1
AIO4
AIO12
10-bit
DAC
COMP2
AIO6
AIO14
10-bit
DAC
COMP3
COMP1OUT
A3
B3
A4
B4
COMP2OUT
ADC
A5
B5
A6
B6
COMP3OUT
A7
B7
This device has three analog comparators that share the input pins with the analog-to-digital
converter module. If neither the ADC or comparator input pins are needed, the input pins can be
used as analog I/O pins. As you can see, one of the inputs to the comparator comes directly from
the input pin, and the other input can be taken from the input pin or the 10-bit digital-to-analog
converter. The output of the comparator is fed into the ePWM digital compare sub-module.
ADCTRL1
ADCSOCxCTL
INTSELxNy
ADCSAMPLEMODE
trigger source
channel
acquisition sampling window
ADCINTSOCSELx
ADCRESULTx
68
Control Peripherals
The previous slide is a brief overview covering a few of the ADC control registers. It can be used
as a reference during the lab exercise.
is a scheme to represent a
signal as a sequence of pulses
fixed
carrier frequency
fixed pulse amplitude
pulse width proportional to
instantaneous signal amplitude
PWM energy original signal energy
Original Signal
PWM representation
69
Control Peripherals
DC Supply
?
Desired
signal to
system
PWM
PWM approx.
of desired
signal
Power-switching devices are difficult to control in the proportional region but are easy to control
in the saturation and cutoff region. Since PWM is a digital signal and easy for microcontrollers to
generate, it is ideal for use with power-switching devices.
70
Control Peripherals
ePWM
GPIO
MUX
eQEP1
SYSCTRL
CPU
TZ1 TZ3
EPWMxSYNCI
EPWMxINT
EQEP1ERR TZ4
CLOCKFAIL TZ5
EPWMxTZINT
EPWMxA
ePWMx
EPWMxB
PIE
GPIO
MUX
EMUSTOP TZ6
COMP
EPWMxSOCA
COMPxOUT
EPWMxSOCB
ADC
EPWMxSYNCO
ePWMx+1
An ePWM module can be synchronized with adjacent ePWM modules. The generated PWM
waveforms are available as outputs on the GPIO pins. Additionally, the EPWM module can
generate ADC starter conversion signals and generate interrupts to the PIE block. External trip
zone signals can trip the output and generate interrupts, too. The outputs of the comparators are
used as inputs to the digital compare sub-module. Next, we will look at the internal details of the
ePWM module.
71
Control Peripherals
TBCLK
Shadowed
Shadowed
Compare
Register
Compare
Register
16-Bit
Time-Base
Counter
EPWMxSYNCI
Compare
Logic
EPWMxSYNCO
Period
Register
Action
Qualifier
Dead
Band
EPWMxA
Shadowed
PWM
Chopper
Trip
Zone
EPWMxB
SYSCLKOUT
TZy
Digital
Compare
TZ1-TZ3
COMPxOUT
The ePWM, or enhanced PWM block diagram, consists of a series of sub-modules. In this
section, we will learn about the operation and details of each sub-module.
TBCLK
Shadowed
Shadowed
Compare
Register
Compare
Register
16-Bit
Time-Base
Counter
EPWMxSYNCI
EPWMxSYNCO
Compare
Logic
Period
Register
Shadowed
Action
Qualifier
Dead
Band
EPWMxA
PWM
Chopper
Trip
Zone
EPWMxB
SYSCLKOUT
TZy
Digital
Compare
TZ1-TZ3
COMPxOUT
In the time-base sub-module, the clock prescaler divides down the device core system clock and
clocks the 16-bit time-base counter. The time-base counter is used to generate asymmetrical and
72
Control Peripherals
symmetrical waveforms using three different count modes: count-up mode, countdown mode, and
count up and down mode. A period register is used to control the maximum count value.
Additionally, the time-base counter has the capability to be synchronized and phase-shifted with
other ePWM units.
The upper two figures show the time-base counter in the count-up mode and countdown mode.
These modes are used to generate asymmetrical waveforms. The lower figure shows the timebase counter in the count up and down mode. This mode is used to generate symmetrical
waveforms.
73
Control Peripherals
SyncIn
En
o o
EPWM1A
o
CTR=zero o
CTR=CMPB o o
o
X
SyncOut
Phase
=120
EPWM1B
To eCAP1
SyncIn
SyncIn
En
o o
=120
EPWM2A
o
CTR=zero o
CTR=CMPB o o
o
X
EPWM2B
SyncOut
Phase
=240
SyncIn
En
o o
o
o
o o
o
CTR=zero
CTR=CMPB
X
=120
EPWM3A
EPWM3B
=240
SyncOut
TBCLK
Shadowed
Shadowed
Compare
Register
Compare
Register
16-Bit
Time-Base
Counter
EPWMxSYNCI
EPWMxSYNCO
Compare
Logic
Period
Register
Shadowed
Action
Qualifier
Dead
Band
EPWMxA
PWM
Chopper
Trip
Zone
EPWMxB
SYSCLKOUT
TZy
Digital
Compare
TZ1-TZ3
COMPxOUT
The compare sub-module uses two compare registers to detect time-base count matches. These
74
Control Peripherals
compare match events are fed into the action qualifier sub-module. Notice that the output of this
block feeds two signals into the action qualifier.
. .. ..
.
. .
. . . . .
Asymmetrical
Waveform
Count Up Mode
TBCTR
TBPRD
CMPA
CMPB
.. .. ..
. .. .. ..
Asymmetrical
Waveform
TBCTR
TBPRD
CMPA
CMPB
..
..
.
.
.. ... ..
Symmetrical
Waveform
The figures above show the compare matches that are fed into the action qualifier. Notice that
with the count up and countdown mode, there are matches on the up-count and down-count.
TBCLK
Shadowed
Shadowed
Compare
Register
Compare
Register
16-Bit
Time-Base
Counter
EPWMxSYNCI
EPWMxSYNCO
Compare
Logic
Period
Register
Shadowed
Action
Qualifier
Dead
Band
EPWMxA
PWM
Chopper
Trip
Zone
EPWMxB
SYSCLKOUT
TZy
Digital
Compare
TZ1-TZ3
COMPxOUT
The action qualifier sub-module uses the inputs from the compare logic and time-base counter to
75
Control Peripherals
generate various actions on the output pins. These first few modules are the main components
used to generate a basic PWM waveform.
S/W
Force
EPWM
Output
Actions
Zero
CMPA
CMPB
TBPRD
SW
X
Z
X
CA
X
CB
X
P
X
Do Nothing
SW
CA
CB
Clear Low
SW
CA
CB
Set High
SW
T
Z
T
CA
T
CB
T
P
T
Toggle
This table shows the various action qualifier compare-match options for when the time-base
counter equals zero, compare A match, compare B match, and period match. Based on the
selected match option, the output pins can be configured to do nothing, clear low, set high, or
toggle. Also, the output pins can be forced to any action using software.
76
Control Peripherals
CMPA
CMPB
. .
.
P
X
CB
X
CA
P
X
CB
X
CA
P
X
P
X
CB
CA
X
P
X
CB
CA
X
P
X
EPWMA
EPWMB
The next few figures show how the action qualifier uses the compare matches to modulate the
output pins. Notice that the output pins for EPWMA and EPWMB are completely independent.
Here, on the EPWMA output, the waveform will be set high on zero match and clear low on
compare A match. On the EPWMB output, the waveform will be set high on zero match and
clear low on compare B match.
77
Control Peripherals
CMPB
CMPA
TBPRD
CA
CA
CB
.
CB
EPWMA
Z
T
Z
T
Z
T
EPWMB
This figure has the EPWMA output set high on compare A match and clear low on compare B
match, while the EPWMB output is configured to toggle on zero match.
CMPA
...
.
.
CA
CA
...
CA
CA
EPWMA
CB
CB
CB
CB
EPWMB
Here you can see that we can have different output actions on the up-count and down-count using
a single compare register. So, for the EPWMA and EPWMB outputs, we are setting high on the
78
Control Peripherals
compare A and B up-count matches and clearing low on the compare A and B down-down
matches.
TBCTR
TBPRD
CMPB
CMPA
..
.
CA
..
.
CA
CB
CB
EPWMA
Z
EPWMB
And finally, again using different output actions on the up-count and down-count, we have the
EPWMA output set high on the compare A up-count match and clear low on the compare B
down-count match. The EPWMB output will clear low on zero match and set high on period
match.
79
Control Peripherals
TBCLK
Shadowed
Shadowed
Compare
Register
Compare
Register
16-Bit
Time-Base
Counter
EPWMxSYNCI
EPWMxSYNCO
Compare
Logic
Period
Register
Shadowed
Action
Qualifier
Dead
Band
EPWMxA
PWM
Chopper
Trip
Zone
EPWMxB
SYSCLKOUT
TZy
Digital
Compare
TZ1-TZ3
COMPxOUT
The dead-band sub-module provides a means to delay the switching of a gate signal, thereby
allowing time for gates to turn off and preventing a short circuit.
to power
switching
device
To explain further, power-switching devices turn on faster than they shut off. This issue would
momentarily provide a path from supply rail to ground, giving us a short circuit. The dead-band
80
Control Peripherals
TBCLK
Shadowed
Shadowed
Compare
Register
Compare
Register
16-Bit
Time-Base
Counter
EPWMxSYNCI
Compare
Logic
EPWMxSYNCO
Action
Qualifier
Period
Register
Dead
Band
EPWMxA
PWM
Chopper
Shadowed
Trip
Zone
EPWMxB
SYSCLKOUT
TZy
Digital
Compare
TZ1-TZ3
COMPxOUT
The PWM chopper sub-module uses a high-frequency carrier signal to modulate the PWM
waveform. This is used with pulsed transformer-based gate drives to control power-switching
elements.
Used with pulse transformer-based gate drivers to control power switching elements
EPWMxA
EPWMxB
CHPFREQ
EPWMxA
EPWMxB
OSHT
EPWMxA
Programmable
Pulse Width
(OSHTWTH)
Sustaining
Pulses
As you can see in this figure, a high-frequency carrier signal is ANDed with the ePWM outputs.
81
Control Peripherals
Also, this circuit provides an option to include a larger, one-shot pulse width before the sustaining
pulses.
TBCLK
Shadowed
Shadowed
Compare
Register
Compare
Register
16-Bit
Time-Base
Counter
EPWMxSYNCI
EPWMxSYNCO
Compare
Logic
Period
Register
Shadowed
Action
Qualifier
Dead
Band
EPWMxA
PWM
Chopper
Trip
Zone
EPWMxB
SYSCLKOUT
TZy
Digital
Compare
TZ1-TZ3
COMPxOUT
The trip zone and digital compare sub-modules provide a protection mechanism to protect the
output pins from abnormalities, such as over-voltage, over-current, and excessive temperature
rise.
82
Control Peripherals
TZ1
Digital Trip
Event A1
Compare
DCAEVT1
blanking
TZ2
DCAL
TZ3
Time-Base Sub-Module
Generate PWM Sync
Event-Trigger Sub-Module
Generate SOCA
Trip-Zone Sub-Module
Trip PWMA Output
Digital Trip
Event A2
Compare
COMP1OUT
DCBH
COMP2OUT
Digital Trip
Event B1
Compare
DCBEVT1
blanking
COMP3OUT
DCBL
Digital Trip
Event B2
Compare
Time-Base Sub-Module
Generate PWM Sync
Event-Trigger Sub-Module
Generate SOCB
Trip-Zone Sub-Module
Trip PWMB Output
Generate Trip Interrupt
DCBEVT2
DCTRIPSEL
TZDCSEL
DCACTL / DCBCTL
The inputs to the digital compare sub-module are the trip zone pins and the analog comparator
outputs. This module generates compare events that can generate a PWM sync, generate an ADC
start of conversion, trip a PWM output, and generate a trip interrupt. Optional blinking can be
used to temporarily disable the compare action in alignment with PWM switching to eliminate
noise effects.
83
Control Peripherals
Trip-Zone Features
Trip-Zone has a fast, clock independent logic path to high-impedance
the EPWMxA/B output pins
Interrupt latency may not protect hardware when responding to over
current conditions or short-circuits through ISR software
Supports:
Over
Current
Sensors
COMPxOUT
TZ1
TZ2
TZ3
TZ4
TZ5
TZ6
eQEP1
SYSCTRL
CPU
CPU
core
Digital
Compare
P
W
M
EPWMxA
EPWMxTZINT
O
U
T
P
U
T
S
Cycle-by-Cycle
Mode
EQEP1ERR
EPWMxB
One-Shot
CLOCKFAIL
Mode
EMUSTOP
The PWM trip zone has a fast, clock-independent logic path to the PWM output pins where the
outputs can be forced to high impedance. Two actions are supported: One-shot trip for major
short circuits or over-current conditions, and cycle-by-cycle trip for current limiting operation.
TBCLK
Shadowed
Shadowed
Compare
Register
Compare
Register
16-Bit
Time-Base
Counter
EPWMxSYNCI
EPWMxSYNCO
Compare
Logic
Period
Register
Shadowed
Action
Qualifier
Dead
Band
EPWMxA
PWM
Chopper
Trip
Zone
EPWMxB
SYSCLKOUT
TZy
Digital
Compare
TZ1-TZ3
COMPxOUT
The event-trigger sub-module is used to provide a triggering signal for interrupts and the start of
84
Control Peripherals
CMPA
.. .
...
EPWMA
EPWMB
CTR = 0
CTR = PRD
CTR = 0 or PRD
CTRU = CMPA
CTRD = CMPA
CTRU = CMPB
CTRD = CMPB
Event-trigger interrupts and start of conversions can be generated on counter equals zero, counter
equal period, counter equal zero or period, counter up equal compare A, counter down equal
compare A, counter up equal compare B, counter down equal compare B. Notice counter up and
down are independent and separate.
85
Control Peripherals
Regular
PWM Step
(i.e. 11.1 ns)
Device Clock
(i.e. 90 MHz)
HRPWM divides a clock
cycle into smaller steps
called Micro Steps
(Step Size ~= 150 ps)
ms
ms
ms
ms
ms
ms
Calibration Logic
HRPWM
Micro Step (~150 ps)
TBCTL
CMPCTL
(Trip-Zone Control)
ETSEL
TZCTL
(PWM-Chopper Control)
enable / disable; chopper CLK freq. & duty cycle; 1-shot pulse width
DCTRIPSEL
(Dead-Band Control)
PCCTL
DBCTL
(Compare Control)
AQCTLA/B
(Time-Base Control)
counter mode (up, down, up & down, stop); clock prescale; period shadow
load; phase enable/direction; sync select
(Event-Trigger Selection)
86
Control Peripherals
The previous slide is a brief overview covering a few of the ePWM control registers. It can be
used as a reference during the lab exercise.
eCAP
Timer
Trigger
pin
Timestamp
Values
The
Auxiliary
PWM generation
The capture module allows time-based logging of external signal transitions on the capture input
pins.
87
Control Peripherals
Polarity
Select 1
Capture 1
Register
32-Bit
Time-Stamp
Counter
Capture 3
Register
Event Logic
CAP2POL
Capture 2
Register
Polarity
Select 2
PRESCALE
CAP3POL
Event
Prescale
Polarity
Select 3
ECAPx
pin
SYSCLKOUT
CAP4POL
Polarity
Select 4
Capture 4
Register
The capture module features a 32-bit time-stamp counter to minimize rollover. Each module has
four capture registers. Polarity can be set to trigger on rising or falling edge, and trigger events
can be pre-scaled. The capture module can operate in absolute time-stamp mode or difference
mode where the counter resets on each capture.
immediate
mode
32-Bit
Time-Stamp
Counter
Period
Register
(CAP1)
Period
Register
(CAP3)
PWM
Compare
Logic
shadow
mode
ECAP
pin
SYSCLKOUT
immediate
mode
Compare
Register
(CAP2)
Shadowed
88
Compare
Register
(CAP4)
shadow
mode
Control Peripherals
If the capture module is not used, it can be configured as an asynchronous PWM module.
eQEP
/4
Ch. A
Ch. B
shaft rotation
Incremental Optical Encoder
The QEP circuit decodes and counts the quadrature encoded input pulses. This circuit can be
used to interface with an optical encoder to get position and speed information from a rotating
machine.
89
Control Peripherals
(A,B) =
(00) (11)
(10) (01)
Ch. A
increment
counter
00
decrement
counter
10
Illegal
Transitions;
generate
phase error
interrupt
11
Ch. B
01
Quadrature Decoder
State Machine
Using a quadrature decoder state machine, we can determine if the counter is incrementing or
decrementing, and therefore know if the disc is moving clockwise or counterclockwise.
Quadrature
Capture
Ch. B
EQEPxA/XCLK
32-Bit Unit
Time-Base
EQEPxB/XDIR
QEP
Watchdog
SYSCLKOUT
Quadrature
Decoder
EQEPxI
Index
EQEPxS
Strobe
Position/Counter
Compare
The QEP module features a direct interface to encoders. In addition to channels A and B being
used for rotational directional information, the index can be used to determine rotational speed,
90
Control Peripherals
and the strobe can be used for position from a homing sensor.
Next, in this lab exercise, a 2 kHz, 25 percent duty cycle PWM waveform will be generated by
ePWM1. The waveform will be fed into ADC channel A0 using the jumper wire. The ADC is
being triggered by ePWM2 at a rate of 50 kHz. After each conversion, the CPU will copy the
results into a circular buffer. Using Code Composer Studio, we will view the waveform in the
time domain and frequency domain. Additionally, we will experiment with the real-time
emulation features.
91
Used as a timebase for triggering ADC samples (period match trigger SOCA)
connector
wire
ADC
RESULT0
CPU copies
result to
buffer during
ADC ISR
data
memory
ADCINA0
...
ePWM2 triggering
ADC on period match
using SOCA trigger every
20 s (50 kHz)
View ADC
buffer PWM
Samples
ePWM2
Code Composer
Studio
The software in this exercise configures the ePWM modules and the ADC. It is entirely interrupt
driven. The ADC end-of-conversion interrupt will be used to prompt the CPU to copy the results
of the ADC conversion into a results buffer in memory. This buffer pointer will be managed in a
circular fashion, such that new conversion results will continuously overwrite older conversion
results in the buffer. The ADC interrupt service routine (ISR) will also toggle LED LD2 on the
TMS320F28069 controlSTICK as a visual indication that the ISR is running.
92
Notes
ADC ISR will also toggle the LED LD2 as a visual indication that it is running
Procedure
Gpio.c
Lab.h
Lab_2_3.cmd
Main_3.c
PieCtrl.c
PieVect.c
SysCtrl.c
Watchdog.c
93
50
50000
Start Address
AdcBuf
50
94
Marker Mode. Move the mouse to the first measurement position and left-click.
Again, left-click on the Toggle Measurement Marker Mode icon. Move the
mouse to the second measurement position and left-click. The graph will automatically
calculate the difference between the two values taken over a complete waveform period.
When done, clear the measurement points by right-clicking on the graph and select
Remove All Measurement Marks (or Ctrl+Alt+M).
50
50000
Start Address
AdcBuf
Bar
FFT Order
10
95
Click OK.
Note: Decreasing the Continuous refresh interval causes all enabled continuous refresh
windows to refresh at a faster rate. This can be problematic when a large number of
windows are enabled, as bandwidth over the emulation link is limited. Updating too
many windows can cause the refresh frequency to bog down. In this case you can just
selectively enable continuous refresh for the individual windows of interest.
14. Next we need to enable the graph window for continuous refresh. Select the Single
Time graph. In the graph window toolbar, left-click on the yellow icon with the arrows
rotating in a circle over a pause sign. Note when you hover your mouse over the icon, it
will show Enable Continuous Refresh. This will allow the graph to
continuously refresh in real-time while the program is running.
15. Enable the memory window for continuous refresh using the same procedure as the
previous step.
16. Run the code and watch the windows update in real-time mode. Click:
Scripts Realtime Emulation Control Run_Realtime_with_Reset
17. Carefully remove and replace the connector wire from ADCINA0 (pin # 3). Are the
values updating as expected?
18. Fully halt the CPU in real-time mode. Click:
Scripts Realtime Emulation Control Full_Halt
Optional Exercise
You might want to experiment with this code by changing some of the values or just modify the
code. Try generating another waveform of a different frequency and duty cycle. Also, try to
generate complementary pair PWM outputs. Next, try to generate additional simultaneous
waveforms by using other ePWM modules. Hint: dont forget to setup the proper shared I/O pins,
etc. (This optional exercise requires some further working knowledge of the ePWM.
Additionally, it may require more time than is allocated for this lab. Therefore, you may want to
try this after the class).
End of Exercise
96
ADC-A6
COMP3 (+VE)
ADC-A2
COMP1 (+VE)
ADC-A0
3V3
ADC-A4
COMP2 (+VE)
ADC-B1
EPWM-4B
GPIO-07
TZ1
GPIO-12
10
11
12
SCL-A
GPIO-33
ADC-B6
COMP3 (-VE)
EPWM-4A
GPIO-06
ADC-A1
13
14
15
16
SDA-A
GPIO-32
ADC-B0
EPWM-3B
GPIO-05
5V0
(Disabled by
Default)
17
18
19
20
EPWM-1A
GPIO-00
ADC-B4
COMP2 (-VE)
EPWM-3A
GPIO-04
SPISOMI-A
GPIO-17
21
22
23
24
EPWM-1B
GPIO-01
ADC-A5
EPWM-2B
GPIO-03
SPISIMO-A
GPIO-16
25
26
27
28
SPISTE-A
GPIO-19
ADC-B2
COMP1 (-VE)
EPWM-2A
GPIO-02
GND
29
30
31
32
SPICLK-A
GPIO-18
GPIO-34
(LED)
PWM1A-DAC
(Filtered)
GND
97
Flash Programming
Flash Programming
Flash Programming Basics
Emulator
CPU
JTAG
RAM
SCI
Flash
Data
I2C
CAN
ROM
SPI
Bootloader
RS232
GPIO
TMS320F2806x
The CPU itself performs the flash programming. The flash utility code is loaded into RAM and
executed. It then reads the flash data and writes it into the flash memory. The flash utility code
and the flash data can be loaded into the RAM directly using JTAG or through the ROM
bootloader using SCI, SPI, I2C, CAN, or GPIO.
98
Flash Programming
Algorithm
Function
1. Erase
2. Program
3. Verify
Minimum
99
Flash Programming
Code-Skin (http://www.code-skin.com)
Elprotronic FlashPro2000
BP Micro programmer
Data I/O programmer
There is a wide variety of flash programming utilities available. They include JTAG emulators,
SCI serial port bootloaders, production test/programming equipment, and building your own
custom utilities with flash API algorithms provided by TI. The TI website has links to all utilities
available.
100
Flash Programming
The on-chip flash programmer is integrated into the CCS debugger. The programmer lets you
configure the device clock configuration and specify flash program settings, such as eraseprogram-verify, select sectors to erase, set the code security password, as well as frequency test,
depletion recovery, and calculate check sum. These options are available in the Debug
perspective by clicking tools On-Chip Flash.
Flash Registers
0x008000
0x008800
0x008C00
0x009000
0x00A000
0x00C000
0x3D7800
0x3D7C00
0x3D7C80
0x3D7CC0
0x3D8000
0x3F7FF8
0x3F8000
L0 DPSARAM (2Kw)
L1 DPSARAM (1Kw)
L2 DPSARAM (1Kw)
L3 DPSARAM (4Kw)
L4 DPSARAM (8Kw)
reserved
User OTP (1Kw)
reserved
ADC / OSC cal. data
reserved
FLASH (128Kw)
PASSWORDS (8w)
The code security module prevents reverse engineering and protects valuable intellectual
property. Once a user-define password is stored in flash, data reads and writes from restricted
memory are only allowed from code running from restricted memory. All other data read-write
accesses are blocked. This includes JTAG emulated debugger, ROM bootloader, code running in
external memory, or unrestricted internal memory.
101
Flash Programming
CSM Password
0x3D8000
FLASH (128Kw)
0x3F7FF8
128-bit
CSM Password
Locations (PWL)
0x3F7FF8 - 0x3F7FFF
128-Bit Password
128-bit
The code security module 128-bit user-define password is stored in flash starting at address
0x3F7FF8. The 128-bit key registers are used to lock and unlock the device. The key registers
are mapped in memory space 0x000AE0 through 0x000AE7, and they are EALLOW protected.
Is PWL =
all 0s?
Yes
No
Flash device
secure after
reset or runtime
Is PWL =
all Fs?
Yes
No
Do dummy reads of PWL
0x3F 7FF8 0x3F 7FFF
Correct
password?
Yes
Device unlocked
User can access onchip secure memory
No
The password match flow is as follows: Flash is secured after reset or run-time. A dummy read
102
Flash Programming
of the passwords is performed. If the passwords are all 0s, then the device is permanently
locked. If the passwords are all Fs, then the device is unlocked. If neither case, then the
passwords are written into the key registers until the correct password is written to unlock the
device. All new devices are shipped with passwords set to Fs, and the device is unlocked.
Next, in the lab exercise, we will program and execute code from the on-chip flash memory. This
device has been designed for stand-alone operation in an embedded system. Using the on-chip
flash eliminates the need for external, nonvolatile memory or a host processor from which to
bootload. The step required to properly configure the software for execution from internal flash
memory will be covered.
103
ADC
ePWM1
TB Counter
Compare
Action Qualifier
ADCINA0
RESULT0
ePWM2 triggering
ADC on period match
using SOCA trigger every
20 s (50 kHz)
ePWM2
Objective:
...
CPU copies
result to
buffer during
ADC ISR
connector
wire
View ADC
buffer PWM
Samples
Code Composer
Studio
Procedure
104
Adc.c
CodeStartBranch.asm
DefaultIsr_3_4.c
DelayUs.asm
EPwm.c
F2806x_DefaultIsr.h
F2806x_GlobalVariableDefs.c
F2806x_Headers_nonBIOS.cmd
Flash.c
Gpio.c
Lab.h
Lab_4.cmd
Main_4.c
Passwords.asm
PieCtrl.c
PieVect.c
SysCtrl.c
Watchdog.c
.cinit
.const
.econst
.pinit
.switch
105
106
Build Lab.out
14. Click the Build button to generate the Lab.out file to be used with the CCS Flash
Programmer. Check for errors in the Problems window.
107
where everything is in your code. Clicking the Debug button in the CCS Edit Perspective
will automatically launch the debugger, connect to the target, and program the flash memory in a
single step.
15. Program the flash memory by clicking the Debug button (green bug). (If needed,
when the Progress Information box opens select Details >> in order to watch
the programming operation and status). After successfully programming the flash
memory the Progress Information box will close.
108
109
FLASH
length = 0x1FF80
page = 0
Lab_4.cmd
SECTIONS
{
0x3F 7F80
0x3F 7FF6
CSM_RSVD
codestart
length = 0x76
page = 0
BEGIN_FLASH
PAGE = 0
length = 0x2
page = 0
0x3F 7FF8
PASSWORDS
length = 0x8
page = 0
_c_int00
FLASH (128Kw)
rts2800_ml.lib
0x3F 7FF6
LB
_c_int00
Passwords (8w)
0x3F 8000
0x3F F75C
{SCAN GPIO}
RESET
110
In-depth hands-on
TMS320F28069 Design
and Peripheral
Training
111
controlSUITE
controlSUITE
ControlSUITE is a single portal for all C2000 software and has been designed to minimize
software development time. Included in controlSUITE are device-specific drivers and support
software, as well as complete system design examples used in sophisticated applications.
ControlSUITE is a one-stop, single centralized location to find all of your C2000 software needs.
Download controlSUITE from the TI website.
112
Development Tools
Part Number:
TMDSDOCK28069
TMDSDOCK28035
TMDSDOCK28027
TMDSDOCK28335
TMDSDOCK2808
TMDSDOCKH52C1
TMDSDOCK28377D
JTAG emulator required for:
TMDSDOCK28343
TMDSDOCK28346-168
controlCARD
USB docking station
C2000 Applications Software CD
with example code and full
hardware details
Code Composer Studio
The C2000 development kits are designed to be modular and robust. These kits are complete,
open source, evaluation and development tools where the user can modify both the hardware and
software to best fit their needs.
The various Experimenters Kits shown on this slide include a specific controlCARD and
Docking Station. Most have onboard USB JTAG emulation and no external emulator or power
supply is required. However, where noted, the kits based on a DIMM-168 controlCARD include
a 5-volt power supply and require an external JTAG emulator.
113
TMDSPREX28335
F28335 controlCARD
Peripheral Explorer baseboard
C2000 Applications Software CD with
example code and full hardware details
Code Composer Studio
The Peripheral Explorer Kit provides a simple way to learn and interact with all F28335
peripherals. It includes onboard USB JTAG emulation.
Part Number:
TMDX28069USB
TMDS28027USB
The controlSTICK is an entry-level evaluation kit. It is a simple, stand-alone tool that allows
users to learn the device and software quickly and easily.
114
Part Number:
LAUNCHXL-F28027
LAUNCHXL-F28027F
The LaunchPad is a low-cost evaluation kit. Like the controlSTICK, it is a simple, stand-alone
tool that allows users to learn the device and software quickly and easily. Additionally, various
BoosterPacks are available.
The controlCARD based Application Kits demonstrate the full capabilities of the C2000 device in
115
an application. All kits are completely open source with full documentation.
http://www.ti.com/hands-on-training
Please be sure to visit the C2000 Workshop Download Wiki. Here, you will find all of the
materials for the C2000 One-day Workshop and the C2000 Multi-day Workshop, as well as the
C2000 archived workshops, which include support for the F2407, F2812, F2808, and F28335
device families.
116
Development Support
E-mail: [email protected]
http://www.ti.com/training
TI eStore
http://processors.wiki.ti.com
TI Training
http://e2e.ti.com
http://estore.ti.com
TI website
http://www.ti.com
For more information and support, you can contact the product information center, visit the TI
E2E community, embedded processor Wiki, TI training web page, TI eStore, and the TI website.
Thank you for attending this C2000 Microcontroller One-Day Workshop. We hope it was
beneficial to you. For more technical information on the C2000 devices, please consider taking a
multi-day hands-on workshop.
117
Notes:
Notes:
118