Ecap
Ecap
Reference Guide
Preface ....................................................................................................................................... 6
1
Introduction ........................................................................................................................ 8
2
Description ......................................................................................................................... 8
3
Capture and APWM Operating Mode ..................................................................................... 9
4
Capture Mode Description .................................................................................................. 10
........................................................................................................
4.2
Edge Polarity Select and Qualifier ...................................................................................
4.3
Continuous/One-Shot Control ........................................................................................
4.4
32-Bit Counter and Phase Control ...................................................................................
4.5
CAP1-CAP4 Registers ................................................................................................
4.6
Interrupt Control ........................................................................................................
4.7
Shadow Load and Lockout Control ..................................................................................
4.8
APWM Mode Operation ...............................................................................................
5
Capture Module - Control and Status Registers .....................................................................
6
Register Mapping ..............................................................................................................
7
Application of the ECAP Module .........................................................................................
7.1
Example 1 - Absolute Time-Stamp Operation Rising Edge Trigger .............................................
7.2
Example 2 - Absolute Time-Stamp Operation Rising and Falling Edge Trigger ...............................
7.3
Example 3 - Time Difference (Delta) Operation Rising Edge Trigger ...........................................
7.4
Example 4 - Time Difference (Delta) Operation Rising and Falling Edge Trigger .............................
8
Application of the APWM Mode ...........................................................................................
8.1
Example 1 - Simple PWM Generation (Independent Channel/s) ................................................
Appendix A Revision History ......................................................................................................
4.1
Event Prescaler
Table of Contents
Copyright 2009, Texas Instruments Incorporated
10
11
11
12
13
13
14
15
16
24
24
25
27
29
31
33
33
34
www.ti.com
List of Figures
1
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
.............................................................................
Details of the Counter and Synchronization Block ....................................................................
Interrupts in eCAP Module ...............................................................................................
PWM Waveform Details Of APWM Mode Operation .................................................................
Time-Stamp Counter Register (TSCTR) ...............................................................................
Counter Phase Control Register (CTRPHS) ..........................................................................
Capture-1 Register (CAP1) ..............................................................................................
Capture-2 Register (CAP2) ..............................................................................................
Capture-3 Register (CAP3) ..............................................................................................
Capture-4 Register (CAP4) ..............................................................................................
ECAP Control Register 1 (ECCTL1) ....................................................................................
ECAP Control Register 2 (ECCTL2) ....................................................................................
ECAP Interrupt Enable Register (ECEINT) ............................................................................
ECAP Interrupt Flag Register (ECFLG) ................................................................................
ECAP Interrupt Clear Register (ECCLR) ...............................................................................
ECAP Interrupt Forcing Register (ECFRC) ............................................................................
Capture Sequence for Absolute Time-stamp and Rising Edge Detect .............................................
Capture Sequence for Absolute Time-stamp With Rising and Falling Edge Detect ..............................
Capture Sequence for Delta Mode Time-stamp and Rising Edge Detect .........................................
Capture Sequence for Delta Mode Time-stamp With Rising and Falling Edge Detect ..........................
PWM Waveform Details of APWM Mode Operation ..................................................................
List of Figures
12
13
14
15
16
16
16
16
17
17
17
18
21
22
22
23
25
27
29
31
33
www.ti.com
List of Tables
1
10
11
23
12
23
13
14
........................................................
.....................................................
Control and Status Register Set .........................................................................................
Changes Made in This Revision .........................................................................................
List of Tables
Copyright 2009, Texas Instruments Incorporated
24
34
Preface
SPRUFZ8A May 2009 Revised October 2009
Preface
www.ti.com
SPRUFN6 TMS320x2802x Piccolo Boot ROM Reference Guide describes the purpose and features
of the bootloader (factory-programmed boot-loading software) and provides examples of code. It
also describes other contents of the device on-chip boot ROM and identifies where all of the
information is located within that memory.
SPRUGE6 TMS320x2803x Piccolo Control Law Accelerator (CLA) Reference Guide describes the
operation of the Control Law Accelerator (CLA).
SPRUGE2 TMS320x2803x Piccolo Local Interconnect Network (LIN) Module Reference Guide
describes the operation of the Local Interconnect Network (LIN) Module.
SPRUFK8 TMS320x2803x Piccolo Enhanced Quadrature Encoder Pulse (eQEP) Reference Guide
describes the operation of the Enhanced Quadrature Encoder Pulse (eQEP) module, which is used
for interfacing with a linear or rotary incremental encoder to get position, direction, and speed
information from a rotating machine in high performance motion and position control systems. It
includes the module description on registers.
SPRUGL7 TMS320x2803x Piccolo Enhanced Controller Area Network (eCAN) Reference Guide
describes the operation of the Enhanced Controller Area Network (eCAN) which uses established
protocol to communicate serially with other controllers in electrically noisy environments.
SPRUGE5 TMS320x2802x, 2803x Piccolo Analog-to-Digital Converter (ADC) and Comparator
Reference Guide describes how to configure and use the on-chip ADC module, which is a 12-bit
pipelined ADC.
SPRUGE9 TMS320x2802x, 2803x Piccolo Enhanced Pulse Width Modulator (ePWM) Module
Reference Guide describes the main areas of the enhanced pulse width modulator that include
digital motor control, switch mode power supply control, UPS (uninterruptible power supplies), and
other forms of power conversion.
SPRUGE8 TMS320x2802x, 2803x Piccolo High-Resolution Pulse Width Modulator (HRPWM)
describes the operation of the high-resolution extension to the pulse width modulator (HRPWM).
SPRUGH1 TMS320x2802x, 2803x Piccolo Serial Communications Interface (SCI) Reference
Guide describes how to use the SCI.
SPRUFZ8 TMS320x2802x, 2803x Piccolo Enhanced Capture (eCAP) Module Reference Guide
describes the enhanced capture module. It includes the module description and registers.
SPRUG71 TMS320x2802x, 2803x Piccolo Serial Peripheral Interface (SPI) Reference Guide
describes the SPI - a high-speed synchronous serial input/output (I/O) port - that allows a serial bit
stream of programmed length (one to sixteen bits) to be shifted into and out of the device at a
programmed bit-transfer rate.
SPRUFZ9 TMS320x2802x, 2803x Piccolo Inter-Integrated Circuit (I2C) Reference Guide describes
the features and operation of the inter-integrated circuit (I2C) module.
Tools Guides
SPRU513 TMS320C28x Assembly Language Tools v5.0.0 User's Guide describes the assembly
language tools (assembler and other tools used to develop assembly language code), assembler
directives, macros, common object file format, and symbolic debugging directives for the
TMS320C28x device.
SPRU514 TMS320C28x Optimizing C/C++ Compiler v5.0.0 User's Guide describes the
TMS320C28x C/C++ compiler. This compiler accepts ANSI standard C/C++ source code and
produces TMS320 DSP assembly language source code for the TMS320C28x device.
SPRU608 TMS320C28x Instruction Set Simulator Technical Overview describes the simulator,
available within the Code Composer Studio for TMS320C2000 IDE, that simulates the instruction
set of the C28x core.
Reference Guide
SPRUFZ8A May 2009 Revised October 2009
Introduction
Uses for eCAP include:
Speed measurements of rotating machinery (e.g., toothed sprockets sensed via Hall sensors)
Elapsed time measurements between position sensor pulses
Period and duty cycle measurements of pulse train signals
Decoding current or voltage amplitude derived from duty cycle encoded current/voltage sensors
The eCAP module described in this guide includes the following features:
4-event time-stamp registers (each 32 bits)
Edge polarity selection for up to four sequenced time-stamp capture events
Interrupt on either of the four events
Single shot capture of up to four event time-stamps
Continuous mode capture of time-stamps in a four-deep circular buffer
Absolute time-stamp capture
Difference (Delta) mode time-stamp capture
All above resources dedicated to a single input pin
When not used in capture mode, the ECAP module can be configured as a single channel PWM output
Description
The eCAP module represents one complete capture channel that can be instantiated multiple times
depending on the target device. In the context of this guide, one eCAP channel has the following
independent key resources:
Dedicated input capture pin
32-bit time base (counter)
4 x 32-bit time-stamp capture registers (CAP1-CAP4)
4-stage sequencer (Modulo4 counter) that is synchronized to external events, ECAP pin rising/falling
edges.
Independent edge polarity (rising/falling edge) selection for all 4 events
Input capture signal prescaling (from 2-62)
One-shot compare register (2 bits) to freeze captures after 1 to 4 time-stamp events
Control for continuous time-stamp captures using a 4-deep circular buffer (CAP1-CAP4) scheme
Interrupt capabilities on any of the 4 capture events
www.ti.com
SyncIn
Capture
mode
Counter (timer)
32
Note:
Same pin
depends on
operating
mode
CAP1 reg
CAP2 reg
CAP3 reg
Sequencing
Edge detection
Edge polarity
Prescale
ECAPx
pin
CAP4 reg
ECAPxINT
Interrupt I/F
Or
SyncIn
APWM
mode
Counter (timer)
32
Syncout
Period reg
(active) (CAP1)
Compare reg
(active) (CAP2)
Period reg
(shadow) (CAP3)
PWM
Compare logic
APWMx
pin
Compare reg
(shadow) (CAP4)
ECAPxINT
Interrupt I/F
A single pin is shared between CAP and APWM functions. In capture mode, it is an input; in APWM mode, it is an
output.
In APWM mode, writing any value to CAP1/CAP2 active registers also writes the same value to the corresponding
shadow registers CAP3/CAP4. This emulates immediate mode. Writing to the shadow registers CAP3/CAP4 invokes
the shadow mode.
www.ti.com
SYNC
CTRPHS
(phase register32 bit)
SYNCIn
APWM mode
CTR_OVF
OVF
TSCTR
(counter32 bit)
SYNCOut
RST
CTR [031]
Deltamode
PRD [031]
PWM
compare
logic
CMP [031]
32
CTR=PRD
CTR [031]
CTR=CMP
32
PRD [031]
ECCTL1 [ CAPLDEN, CTRRSTx]
CAP1
(APRD active)
APRD
shadow
LD1
MODE SELECT
ECAPx
32
Polarity
select
LD
32
CMP [031]
32
32
CAP2
(ACMP active)
32
32
32
LD
LD2
Polarity
select
Event
qualifier
ACMP
shadow
CAP3
(APRD shadow)
LD
CAP4
(ACMP shadow)
LD
Event
Prescale
Polarity
select
LD3
LD4
ECCTL1[EVTPS]
Polarity
select
4
Capture events
CEVT[1:4]
to PIE
Interrupt
Trigger
and
Flag
control
CTR_OVF
Continuous /
Oneshot
Capture Control
CTR=PRD
CTR=CMP
ECCTL2 [ REARM, CONT/ONESHT, STOP_WRAP]
4.1
Event Prescaler
10
An input capture signal (pulse train) can be prescaled by N = 2-62 (in multiples of 2) or can bypass the
prescaler.
This is useful when very high frequency signals are used as inputs. Figure 3 shows a functional
diagram and Figure 4 shows the operation of the prescale function.
www.ti.com
Bypass
ECAPx pin
(from GPIO)
/n
5
ECCTL1[EVTPS]
prescaler [5 bits]
(counter)
When a prescale value of 1 is chosen (i.e. ECCTL1[13:9] = 0,0,0,0,0 ) the input capture signal by-passes the prescale
logic completely.
PSout
div 2
PSout
div 4
PSout
div 6
PSout
div 8
PSout
div 10
4.2
4.3
Four independent edge polarity (rising edge/falling edge) selection MUXes are used, one for each
capture event.
Each edge (up to 4) is event qualified by the Modulo4 sequencer.
The edge event is gated to its respective CAPx register by the Mod4 counter. The CAPx register is
loaded on the falling edge.
Continuous/One-Shot Control
The Mod4 (2 bit) counter is incremented via edge qualified events (CEVT1-CEVT4).
The Mod4 counter continues counting (0->1->2->3->0) and wraps around unless stopped.
A 2-bit stop register is used to compare the Mod4 counter output, and when equal stops the Mod4
counter and inhibits further loads of the CAP1-CAP4 registers. This occurs during one-shot operation.
11
www.ti.com
The continuous/one-shot block controls the start/stop and reset (zero) functions of the Mod4 counter via a
mono-shot type of action that can be triggered by the stop-value comparator and re-armed via software
control.
Once armed, the eCAP module waits for 1-4 (defined by stop-value) capture events before freezing both
the Mod4 counter and contents of CAP1-4 registers (i.e., time-stamps).
Re-arming prepares the eCAP module for another capture sequence. Also re-arming clears (to zero) the
Mod4 counter and permits loading of CAP1-4 registers again, providing the CAPLDEN bit is set.
In continuous mode, the Mod4 counter continues to run (0->1->2->3->0, the one-shot action is ignored,
and capture values continue to be written to CAP1-4 in a circular buffer sequence.
Figure 5. Details of the Continuous/One-shot Block
0 1 2 3
2:4 MUX
CEVT1
CEVT2
CEVT3
CEVT4
CLK
Modulo 4
counter Stop
RST
Mod_eq
Oneshot
control logic
ECCTL2[STOP_WRAP]
4.4
ECCTL2[REARM]
ECCTL2[CONT/ONESHT]
12
www.ti.com
ECCTL2[SYNCOSEL]
SYNCI
CTR=PRD
Disable
Disable
ECCTL2[SYNCI_EN]
SYNCO
Sync out
select
CTRPHS
LD_CTRPHS
RST
Deltamode
TSCTR
(counter 32b)
SYSCLK
CLK
OVF
CTROVF
CTR[310]
4.5
CAP1-CAP4 Registers
These 32-bit registers are fed by the 32-bit counter timer bus, CTR[0-31] and are loaded (i.e., capture a
time-stamp) when their respective LD inputs are strobed.
Loading of the capture registers can be inhibited via control bit CAPLDEN. During one-shot operation, this
bit is cleared (loading is inhibited) automatically when a stop condition occurs, i.e. StopValue = Mod4.
CAP1 and CAP2 registers become the active period and compare registers, respectively, in APWM mode.
CAP3 and CAP4 registers become the respective shadow registers (APRD and ACMP) for CAP1 and
CAP2 during APWM operation.
4.6
Interrupt Control
An Interrupt can be generated on capture events (CEVT1-CEVT4, CTROVF) or APWM events (CTR =
PRD, CTR = CMP).
A counter overflow event (FFFFFFFF->00000000) is also provided as an interrupt source (CTROVF).
The capture events are edge and sequencer qualified (i.e., ordered in time) by the polarity select and
Mod4 gating, respectively.
One of these events can be selected as the interrupt source (from the eCAPx module) going to the PIE.
Seven interrupt events (CEVT1, CEVT2, CEVT3, CEVT4, CNTOVF, CTR=PRD, CTR=CMP) can be
generated. The interrupt enable register (ECEINT) is used to enable/disable individual interrupt event
sources. The interrupt flag register (ECFLG) indicates if any interrupt event has been latched and contains
the global interrupt flag bit (INT). An interrupt pulse is generated to the PIE only if any of the interrupt
events are enabled, the flag bit is 1, and the INT flag bit is 0. The interrupt service routine must clear the
global interrupt flag bit and the serviced event via the interrupt clear register (ECCLR) before any other
interrupt pulses are generated. You can force an interrupt event via the interrupt force register (ECFRC).
This is useful for test purposes.
13
www.ti.com
Note: The CEVT1, CEVT2, CEVT3, CEVT4 flags are only active in capture mode (ECCTL2[CAP/APWM
== 0]). The CTR=PRD, CTR=CMP flags are only valid in APWM mode (ECCTL2[CAP/APWM == 1]).
CNTOVF flag is valid in both modes.
Figure 7. Interrupts in eCAP Module
ECFLG
Clear
ECCLR
ECFRC
Latch
ECEINT
Set
CEVT1
ECFLG
Clear
ECCLR
ECFRC
Latch
ECFLG
ECEINT
ECCLR
Set
ECFLG
Clear
Clear
Latch
ECEINT
Generate
interrupt
pulse when
input=1
ECCLR
ECFRC
Latch
Set
ECAPxINT
CEVT2
Set
CEVT3
ECFLG
Clear
0
ECCLR
ECFRC
Latch
ECEINT
Set
CEVT4
ECFLG
Clear
ECCLR
ECFRC
Latch
CTROVF
Set
ECEINT
ECFLG
Clear
ECCLR
ECFRC
Latch
ECEINT
PRDEQ
Set
ECFLG
Clear
Latch
ECEINT
4.7
Set
ECCLR
ECFRC
CMPEQ
14
www.ti.com
4.8
1000h
500h
ACMP
300h
0000000C
APWMx
(o/p pin)
On
time
Offtime
Period
15
www.ti.com
31
0
TSCTR
R/W-0
Field
Description
31:0
TSCTR
0
CTRPHS
R/W-0
Field
Description
31:0
CTRPHS
Counter phase value register that can be programmed for phase lag/lead. This register shadows
TSCTR and is loaded into TSCTR upon either a SYNCI event or S/W force via a control bit. Used
to achieve phase control synchronization with respect to other eCAP and EPWM time-bases.
0
CAP1
R/W-0
Field
Description
31:0
CAP1
This register can be loaded (written) by :) Time-Stamp (i.e., counter value TSCTR) during a capture
event) Software - may be useful for test purposes / initialization) APRD shadow register (i.e.,
CAP3) when used in APWM mode
0
CAP2
R/W-0
16
Bit(s)
Field
Description
31:0
CAP2
www.ti.com
NOTE:
In APWM mode, writing to CAP1/CAP2 active registers also writes the same value to the
corresponding shadow registers CAP3/CAP4. This emulates immediate mode. Writing to the
shadow registers CAP3/CAP4 invokes the shadow mode.
0
CAP3
R/W-0
Field
Description
31:0
CAP3
In CMP mode, this is a time-stamp capture register. In APWM mode, this is the period shadow
(APRD) register. You update the PWM period value through this register. In this mode, CAP3
(APRD) shadows CAP1.
0
CAP4
R/W-0
Field
Description
31:0
CAP4
In CMP mode, this is a time-stamp capture register. In APWM mode, this is the compare shadow
(ACMP) register. You update the PWM compare value via this register. In this mode, CAP4
(ACMP) shadows CAP2.
14
13
12
11
10
FREE/SOFT
PRESCALE
CAPLDEN
R/W-0
R/W-0
R/W-0
CTRRST4
CAP4POL
CTRRST3
CAP3POL
CTRRST2
CAP2POL
CTRRST1
CAP1POL
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
Field
15:14
FREE/SOFT
13:9
Value
Description
Emulation Control
00
01
1x
PRESCALE
00001
Divide by 2
00010
Divide by 4
00011
Divide by 6
00100
Divide by 8
17
www.ti.com
Field
Value
Description
00101
Divide by 10
...
11110
Divide by 60
11111
Divide by 62
CAPLDEN
CTRRST4
CAP4POL
CTRRST3
CAP3POL
CTRRST2
CAP2POL
CTRRST1
Reset counter after Event 1 time-stamp has been captured (used in difference mode
operation)
CAP1POL
11
10
Reserved
APWMPOL
CAP/APWM
SWSYNC
R-0
R/W-0
R/W-0
R/W-0
SYNCO_SEL
SYNCI_EN
TSCTRSTOP
REARM
R/W-0
R/W-0
R/W-0
R/W-0
STOP_WRAP
R/W-1
R/W-1
0
CONT/ONESH
T
R/W-0
18
www.ti.com
Field
Description
15:11
Reserved
Reserved
10
APWMPOL
APWM output polarity select. This is applicable only in APWM operating mode
0
CAP/APWM
ECAP module operates in capture mode. This mode forces the following
configuration:
Inhibits TSCTR resets via CTR = PRD event
Inhibits shadow loads on CAP1 and 2 registers
Permits user to enable CAP1-4 register load
CAPx/APWMx pin operates as a capture input
ECAP module operates in APWM mode. This mode forces the following
configuration:
Resets TSCTR on CTR = PRD event (period boundary
Permits shadow loading on CAP1 and 2 registers
Disables loading of time-stamps into CAP1-4 registers
CAPx/APWMx pin operates as a APWM output
SWSYNC
Writing a one forces a TSCTR shadow load of current ECAP module and any
ECAP modules down-stream providing the SYNCO_SEL bits are 0,0. After writing
a 1, this bit returns to a zero.
Note: Selection CTR = PRD is meaningful only in APWM mode; however, you can
choose it in CAP mode if you find doing so useful.
7:6
2:1
SYNCO_SEL
Sync-Out Select
00
01
10
11
SYNCI_EN
Enable counter (TSCTR) to be loaded from CTRPHS register upon either a SYNCI
signal or a S/W force event.
TSCTRSTOP
TSCTR stopped
TSCTR free-running
RE-ARM
One-Shot Re-Arming Control, i.e. wait for stop trigger. Note: The re-arm function is
valid in one shot or continuous mode.
0
STOP_WRAP
Stop value for one-shot mode. This is the number (between 1-4) of captures
allowed to occur before the CAP(1-4) registers are frozen, i.e., capture sequence is
stopped.
Wrap value for continuous mode. This is the number (between 1-4) of the capture
register in which the circular buffer wraps around and starts again.
00
01
19
www.ti.com
Field
Description
10
11
20
CONT/ONESHT
www.ti.com
8
Reserved
CTR=CMP
CTR=PRD
CTROVF
CEVT4
CEVT3
CEVT2
CETV1
Reserved
R/W
R/W
R/W
R/W
R/W
Field
15:8
Reserved
CTR=CMP
Value
Description
Counter Equal Compare Interrupt Enable
CTR=PRD
CTROVF
CEVT4
CEVT3
CEVT2
CEVT1
Reserved
The interrupt enable bits (CEVT1, ...) block any of the selected events from generating an interrupt.
Events will still be latched into the flag bit (ECFLG register) and can be forced/cleared via the
ECFRC/ECCLR registers.
The proper procedure for configuring peripheral modes and interrupts is as follows:
Disable global interrupts
Stop eCAP counter
Disable eCAP interrupts
Configure peripheral registers
Clear spurious eCAP interrupt flags
Enable eCAP interrupts
Start eCAP counter
Enable global interrupts
21
www.ti.com
8
Reserved
R-0
CTR=CMP
CTR=PRD
CTROVF
CEVT4
CETV3
CEVT2
CETV1
INT
R-0
R-0
R-0
R-0
R-0
R-0
R-0
R-0
Field
15:8
Reserved
CTR=CMP
Value
Description
Compare Equal Compare Status Flag. This flag is active only in APWM mode.
Indicates the counter (TSCTR) reached the compare register value (ACMP)
CTR=PRD
Counter Equal Period Status Flag. This flag is only active in APWM mode.
0
Indicates the counter (TSCTR) reached the period register value (APRD) and was reset.
CTROVF
Counter Overflow Status Flag. This flag is active in CAP and APWM mode.
0
Indicates the counter (TSCTR) has made the transition from FFFFFFFF " 00000000
CEVT4
Capture Event 4 Status Flag This flag is only active in CAP mode.
0
CEVT3
Capture Event 3 Status Flag. This flag is active only in CAP mode.
0
CEVT2
Capture Event 2 Status Flag. This flag is only active in CAP mode.
0
CEVT1
Capture Event 1 Status Flag. This flag is only active in CAP mode.
0
INT
8
Reserved
R-0
CTR=CMP
CTR=PRD
CTROVF
CEVT4
CETV3
CETV2
CETV1
INT
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
22
www.ti.com
Field
15:8
Reserved
CTR=CMP
Description
Counter Equal Compare Status Flag
0
CTR=PRD
CTROVF
CEVT4
CEVT3
CEVT2
CEVT1
INT
Writing a 1 clears the INT flag and enable further interrupts to be generated if any
of the event flags are set to 1.
14
13
12
11
10
Reserved
R-0
7
CTR=CMP
CTR=PRD
CTROVF
CEVT4
CETV3
CETV2
CETV1
reserved
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R-0
Field
15:8
Reserved
CTR=CMP
Value
Description
0
Force Counter Equal Compare Interrupt
0
CTR=PRD
CTROVF
23
Register Mapping
www.ti.com
Table 12. ECAP Interrupt Forcing Register (ECFRC) Field Descriptions (continued)
Bits
4
Field
Value
CEVT4
CEVT3
CEVT2
CEVT1
reserved
Description
Register Mapping
Table 13 shows the eCAP module control and status register set.
Table 13. Control and Status Register Set
Name
Offset
Size (x16)
Description
TSCTR
0x0000
Time-Stamp Counter
CTRPHS
0x0002
CAP1
0x0004
Capture 1 Register
CAP2
0x0006
Capture 2 Register
CAP3
0x0008
Capture 3 Register
CAP4
0x000A
Capture 4 Register
reserved
0x000C - 0x0013
ECCTL1
0x0014
ECCTL2
0x0015
ECEINT
0x0016
ECFLG
0x0017
ECCLR
0x0018
ECFRC
0x0019
Reserved
0x001A - 0x001F
24
www.ti.com
7.1
CEVT2
CEVT3
CEVT4
CEVT1
CAPx pin
t5
t4
FFFFFFFF
t3
t2
t1
CTR[031]
00000000
MOD4
CTR
CAP1
CAP2
XX
t5
t1
XX
t2
XX
CAP3
t3
XX
CAP4
t4
t
Polarity selection
Capture registers [14]
25
7.1.1
www.ti.com
Code snippet for CAP mode Absolute Time, Rising Edge Trigger
// Code snippet for CAP mode Absolute Time, Rising edge trigger // Initialization Time
//======================= // ECAP module 1 config ECap1Regs.ECCTL1.bit.CAP1POL = EC_RISING;
ECap1Regs.ECCTL1.bit.CAP2POL = EC_RISING; ECap1Regs.ECCTL1.bit.CAP3POL = EC_RISING;
ECap1Regs.ECCTL1.bit.CAP4POL = EC_RISING; ECap1Regs.ECCTL1.bit.CTRRST1 = EC_ABS_MODE;
ECap1Regs.ECCTL1.bit.CTRRST2 = EC_ABS_MODE; ECap1Regs.ECCTL1.bit.CTRRST3 = EC_ABS_MODE;
ECap1Regs.ECCTL1.bit.CTRRST4 = EC_ABS_MODE; ECap1Regs.ECCTL1.bit.CAPLDEN = EC_ENABLE;
ECap1Regs.ECCTL1.bit.PRESCALE = EC_DIV1; ECap1Regs.ECCTL2.bit.CAP_APWM = EC_CAP_MODE;
ECap1Regs.ECCTL2.bit.CONT_ONESHT = EC_CONTINUOUS; ECap1Regs.ECCTL2.bit.SYNCO_SEL = EC_SYNCO_DIS;
ECap1Regs.ECCTL2.bit.SYNCI_EN = EC_DISABLE; ECap1Regs.ECCTL2.bit.TSCTRSTOP = EC_RUN; // Allow
TSCTR to run // Run Time ( e.g. CEVT4 triggered ISR call)
//========================================== TSt1 = ECap1Regs.CAP1; // Fetch Time-Stamp captured
at t1 TSt2 = ECap1Regs.CAP2; // Fetch Time-Stamp captured at t2 TSt3 = ECap1Regs.CAP3; // Fetch
Time-Stamp captured at t3 TSt4 = ECap1Regs.CAP4; // Fetch Time-Stamp captured at t4 Period1 =
TSt2-TSt1; // Calculate 1st period Period2 = TSt3-TSt2; // Calculate 2nd period Period3 = TSt4TSt3; // Calculate 3rd period
26
www.ti.com
7.2
CEVT4
CEVT1
CEVT2
CEVT3
CEVT1
CEVT4
CEVT1
CEVT3
CAPx pin
FFFFFFFF
t6
t5
CTR[031]
t3
t9
t8
t7
t4
t2
t1
00000000
MOD4
CTR
CAP1
CAP2
CAP3
CAP4
XX
t1
XX
t5
t2
XX
t6
t3
XX
t7
t4
t8
tt
Polarity selection
Capture registers [14]
27
7.2.1
www.ti.com
Code snippet for CAP mode Absolute Time, Rising & Falling Edge Triggers
// Code snippet for CAP mode Absolute Time, Rising & Falling // edge triggers // Initialization
Time //======================= // ECAP module 1 config ECap1Regs.ECCTL1.bit.CAP1POL = EC_RISING;
ECap1Regs.ECCTL1.bit.CAP2POL = EC_FALLING; ECap1Regs.ECCTL1.bit.CAP3POL = EC_RISING;
ECap1Regs.ECCTL1.bit.CAP4POL = EC_FALLING; ECap1Regs.ECCTL1.bit.CTRRST1 = EC_ABS_MODE;
ECap1Regs.ECCTL1.bit.CTRRST2 = EC_ABS_MODE; ECap1Regs.ECCTL1.bit.CTRRST3 = EC_ABS_MODE;
ECap1Regs.ECCTL1.bit.CTRRST4 = EC_ABS_MODE; ECap1Regs.ECCTL1.bit.CAPLDEN = EC_ENABLE;
ECap1Regs.ECCTL1.bit.PRESCALE = EC_DIV1; ECap1Regs.ECCTL2.bit.CAP_APWM = EC_CAP_MODE;
ECap1Regs.ECCTL2.bit.CONT_ONESHT = EC_CONTINUOUS; ECap1Regs.ECCTL2.bit.SYNCO_SEL = EC_SYNCO_DIS;
ECap1Regs.ECCTL2.bit.SYNCI_EN = EC_DISABLE; ECap1Regs.ECCTL2.bit.TSCTRSTOP = EC_RUN; // Allow
TSCTR to run // Run Time ( e.g. CEVT4 triggered ISR call)
//========================================== TSt1 = ECap1Regs.CAP1; // Fetch Time-Stamp captured
at t1 TSt2 = ECap1Regs.CAP2; // Fetch Time-Stamp captured at t2 TSt3 = ECap1Regs.CAP3; // Fetch
Time-Stamp captured at t3 TSt4 = ECap1Regs.CAP4; // Fetch Time-Stamp captured at t4 Period1 =
TSt3-TSt1; // Calculate 1st period DutyOnTime1 = TSt2-TSt1; // Calculate On time DutyOffTime1 =
TSt3-TSt2; // Calculate Off time
28
www.ti.com
7.3
CEVT3
CEVT2
CEVT4
CEVT1
CAPx pin
T1
FFFFFFFF
T3
T2
T4
CTR[031]
00000000
MOD4
CTR
CAP1
CAP2
XX
t4
XX
t1
XX
CAP3
t2
XX
CAP4
t3
t
Polarity selection
Capture registers [14]
29
7.3.1
www.ti.com
Code snippet for CAP mode Delta Time, Rising Edge Trigger
// Code snippet for CAP mode Delta Time, Rising edge trigger // Initialization Time
//======================= // ECAP module 1 config ECap1Regs.ECCTL1.bit.CAP1POL = EC_RISING;
ECap1Regs.ECCTL1.bit.CAP2POL = EC_RISING; ECap1Regs.ECCTL1.bit.CAP3POL = EC_RISING;
ECap1Regs.ECCTL1.bit.CAP4POL = EC_RISING; ECap1Regs.ECCTL1.bit.CTRRST1 = EC_DELTA_MODE;
ECap1Regs.ECCTL1.bit.CTRRST2 = EC_DELTA_MODE; ECap1Regs.ECCTL1.bit.CTRRST3 = EC_DELTA_MODE;
ECap1Regs.ECCTL1.bit.CTRRST4 = EC_DELTA_MODE; ECap1Regs.ECCTL1.bit.CAPLDEN = EC_ENABLE;
ECap1Regs.ECCTL1.bit.PRESCALE = EC_DIV1; ECap1Regs.ECCTL2.bit.CAP_APWM = EC_CAP_MODE;
ECap1Regs.ECCTL2.bit.CONT_ONESHT = EC_CONTINUOUS; ECap1Regs.ECCTL2.bit.SYNCO_SEL = EC_SYNCO_DIS;
ECap1Regs.ECCTL2.bit.SYNCI_EN = EC_DISABLE; ECap1Regs.ECCTL2.bit.TSCTRSTOP = EC_RUN; // Allow
TSCTR to run // Run Time ( e.g. CEVT1 triggered ISR call)
//========================================== // Note: here Time-stamp directly represents the
Period value. Period4 = ECap1Regs.CAP1; // Fetch Time-Stamp captured at T1 Period1 =
ECap1Regs.CAP2; // Fetch Time-Stamp captured at T2 Period2 = ECap1Regs.CAP3; // Fetch Time-Stamp
captured at T3 Period3 = ECap1Regs.CAP4; // Fetch Time-Stamp captured at T4
30
www.ti.com
7.4
Example 4 - Time Difference (Delta) Operation Rising and Falling Edge Trigger
In Figure 24 the eCAP operating mode is almost the same as in previous section except Capture events
are qualified as either Rising or Falling edge, this now gives both Period and Duty cycle information, i.e:
Period1 = T1+T2, Period2 = T3+T4, etc Duty Cycle1 (on-time %) = T1 / Period1 x 100%, etc Duty Cycle1
(off-time %) = T2 / Period1 x 100%, etc
Figure 24. Capture Sequence for Delta Mode Time-stamp With Rising and Falling Edge Detect
CEVT4
CEVT2
CEVT2
CEVT3
CEVT1
CEVT4
CEVT5
CEVT3
CEVT1
CAPx pin
T1
FFFFFFFF
T3
T5
T8
T2
T6
T4
T7
CTR[031]
00000000
MOD4
CTR
CAP1
CAP2
CAP3
CAP4
XX
t5
t1
XX
t2
XX
t4
XX
t6
t3
t7
t
Polarity selection
Capture registers [14]
During initialization, you must write to the active registers for both period and compare. This will then
automatically copy the init values into the shadow values. For subsequent compare updates, i.e. during
run-time, only the shadow registers must be used.
31
7.4.1
www.ti.com
Code snippet for CAP mode Delta Time, Rising and Falling Edge Triggers
// Code snippet for CAP mode Delta Time, Rising and Falling // edge triggers // Initialization
Time //======================= // ECAP module 1 config ECap1Regs.ECCTL1.bit.CAP1POL = EC_RISING;
ECap1Regs.ECCTL1.bit.CAP2POL = EC_FALLING; ECap1Regs.ECCTL1.bit.CAP3POL = EC_RISING;
ECap1Regs.ECCTL1.bit.CAP4POL = EC_FALLING; ECap1Regs.ECCTL1.bit.CTRRST1 = EC_DELTA_MODE;
ECap1Regs.ECCTL1.bit.CTRRST2 = EC_DELTA_MODE; ECap1Regs.ECCTL1.bit.CTRRST3 = EC_DELTA_MODE;
ECap1Regs.ECCTL1.bit.CTRRST4 = EC_DELTA_MODE; ECap1Regs.ECCTL1.bit.CAPLDEN = EC_ENABLE;
ECap1Regs.ECCTL1.bit.PRESCALE = EC_DIV1; ECap1Regs.ECCTL2.bit.CAP_APWM = EC_CAP_MODE;
ECap1Regs.ECCTL2.bit.CONT_ONESHT = EC_CONTINUOUS; ECap1Regs.ECCTL2.bit.SYNCO_SEL = EC_SYNCO_DIS;
ECap1Regs.ECCTL2.bit.SYNCI_EN = EC_DISABLE; ECap1Regs.ECCTL2.bit.TSCTRSTOP = EC_RUN; // Allow
TSCTR to run // Run Time ( e.g. CEVT1 triggered ISR call)
//========================================== // Note: here Time-stamp directly represents the
Duty cycle values. DutyOnTime1 = ECap1Regs.CAP2; // Fetch Time-Stamp captured at T2 DutyOffTime1
= ECap1Regs.CAP3; // Fetch Time-Stamp captured at T3 DutyOnTime2 = ECap1Regs.CAP4; // Fetch TimeStamp captured at T4 DutyOffTime2 = ECap1Regs.CAP1; // Fetch Time-Stamp captured at T1 Period1 =
DutyOnTime1 + DutyOffTime1; Period2 = DutyOnTime2 + DutyOffTime2;
32
www.ti.com
8.1
1000h
500h
ACMP
300h
0000000C
APWMx
(o/p pin)
On
time
Offtime
Period
33
Appendix A
www.ti.com
34
Location
Global
Revision History
IMPORTANT NOTICE
Texas Instruments Incorporated and its subsidiaries (TI) reserve the right to make corrections, modifications, enhancements, improvements,
and other changes to its products and services at any time and to discontinue any product or service without notice. Customers should
obtain the latest relevant information before placing orders and should verify that such information is current and complete. All products are
sold subject to TIs terms and conditions of sale supplied at the time of order acknowledgment.
TI warrants performance of its hardware products to the specifications applicable at the time of sale in accordance with TIs standard
warranty. Testing and other quality control techniques are used to the extent TI deems necessary to support this warranty. Except where
mandated by government requirements, testing of all parameters of each product is not necessarily performed.
TI assumes no liability for applications assistance or customer product design. Customers are responsible for their products and
applications using TI components. To minimize the risks associated with customer products and applications, customers should provide
adequate design and operating safeguards.
TI does not warrant or represent that any license, either express or implied, is granted under any TI patent right, copyright, mask work right,
or other TI intellectual property right relating to any combination, machine, or process in which TI products or services are used. Information
published by TI regarding third-party products or services does not constitute a license from TI to use such products or services or a
warranty or endorsement thereof. Use of such information may require a license from a third party under the patents or other intellectual
property of the third party, or a license from TI under the patents or other intellectual property of TI.
Reproduction of TI information in TI data books or data sheets is permissible only if reproduction is without alteration and is accompanied
by all associated warranties, conditions, limitations, and notices. Reproduction of this information with alteration is an unfair and deceptive
business practice. TI is not responsible or liable for such altered documentation. Information of third parties may be subject to additional
restrictions.
Resale of TI products or services with statements different from or beyond the parameters stated by TI for that product or service voids all
express and any implied warranties for the associated TI product or service and is an unfair and deceptive business practice. TI is not
responsible or liable for any such statements.
TI products are not authorized for use in safety-critical applications (such as life support) where a failure of the TI product would reasonably
be expected to cause severe personal injury or death, unless officers of the parties have executed an agreement specifically governing
such use. Buyers represent that they have all necessary expertise in the safety and regulatory ramifications of their applications, and
acknowledge and agree that they are solely responsible for all legal, regulatory and safety-related requirements concerning their products
and any use of TI products in such safety-critical applications, notwithstanding any applications-related information or support that may be
provided by TI. Further, Buyers must fully indemnify TI and its representatives against any damages arising out of the use of TI products in
such safety-critical applications.
TI products are neither designed nor intended for use in military/aerospace applications or environments unless the TI products are
specifically designated by TI as military-grade or "enhanced plastic." Only products designated by TI as military-grade meet military
specifications. Buyers acknowledge and agree that any such use of TI products which TI has not designated as military-grade is solely at
the Buyer's risk, and that they are solely responsible for compliance with all legal and regulatory requirements in connection with such use.
TI products are neither designed nor intended for use in automotive applications or environments unless the specific TI products are
designated by TI as compliant with ISO/TS 16949 requirements. Buyers acknowledge and agree that, if they use any non-designated
products in automotive applications, TI will not be responsible for any failure to meet such requirements.
Following are URLs where you can obtain information on other Texas Instruments products and application solutions:
Products
Amplifiers
Data Converters
DLP Products
DSP
Clocks and Timers
Interface
Logic
Power Mgmt
Microcontrollers
RFID
RF/IF and ZigBee Solutions
amplifier.ti.com
dataconverter.ti.com
www.dlp.com
dsp.ti.com
www.ti.com/clocks
interface.ti.com
logic.ti.com
power.ti.com
microcontroller.ti.com
www.ti-rfid.com
www.ti.com/lprf
Applications
Audio
Automotive
Broadband
Digital Control
Medical
Military
Optical Networking
Security
Telephony
Video & Imaging
Wireless
www.ti.com/audio
www.ti.com/automotive
www.ti.com/broadband
www.ti.com/digitalcontrol
www.ti.com/medical
www.ti.com/military
www.ti.com/opticalnetwork
www.ti.com/security
www.ti.com/telephony
www.ti.com/video
www.ti.com/wireless
Mailing Address: Texas Instruments, Post Office Box 655303, Dallas, Texas 75265
Copyright 2009, Texas Instruments Incorporated