C2000™ Position Manager PTO API Reference Guide: Application Report
C2000™ Position Manager PTO API Reference Guide: Application Report
Application Report
C2000™ Position Manager PTO API Reference Guide
Table of Contents
1 Introduction.............................................................................................................................................................................2
2 PTO – PulseGen...................................................................................................................................................................... 3
3 PTO – QepDiv.......................................................................................................................................................................... 5
4 PTO – Abs2Qep.....................................................................................................................................................................10
5 PTO Example Projects..........................................................................................................................................................21
6 PTO Library Source and Projects........................................................................................................................................25
7 Using the PTO Reference APIs in Projects........................................................................................................................ 34
8 References............................................................................................................................................................................ 37
Revision History.......................................................................................................................................................................37
List of Figures
Figure 2-1. PulseGen Output Diagram........................................................................................................................................ 3
Figure 2-2. PulseGen Implementation Diagram.......................................................................................................................... 3
Figure 2-3. PulseGen CLB Tile Diagram..................................................................................................................................... 4
Figure 3-1. QepDiv Input and Output Diagram............................................................................................................................ 5
Figure 3-2. QepDiv Interconnect Diagram................................................................................................................................... 6
Figure 3-3. Implementation Diagram........................................................................................................................................... 6
Figure 3-4. QepDiv CLB Tile Diagram......................................................................................................................................... 7
Figure 4-1. Abs2Qep Implementation Diagram......................................................................................................................... 10
Figure 4-2. Absolute Position Encoder...................................................................................................................................... 10
Figure 4-3. Incremental Position Encoder..................................................................................................................................11
Figure 4-4. Abs2Qep Zero-Cross in the Forward Direction....................................................................................................... 14
Figure 4-5. Abs2Qep Zero-Cross in the Reverse Direction....................................................................................................... 14
Figure 4-6. Abs2Qep Example System Waveform.................................................................................................................... 15
Figure 4-7. Abs2Qep CLB Tile Block Diagram.......................................................................................................................... 16
Figure 4-8. Abs2Qep PTO State Diagrams............................................................................................................................... 18
Figure 4-9. Simulation QEP-A and QEP-B Generation............................................................................................................. 19
Figure 4-10. Simulation of Halt Latch........................................................................................................................................ 20
Figure 6-1. Abs2Qep Translate Function...................................................................................................................................33
Figure 7-1. Compiler Include Options for Projects Using PTO Reference APIs........................................................................ 35
Figure 7-2. C2000™ Linker Options – PulseGen....................................................................................................................... 35
Figure 7-3. C2000 Linker Options – QepDiv..............................................................................................................................36
List of Tables
Table 2-1. PulseGen CLB Tile 1...................................................................................................................................................4
Table 3-1. QepDiv CLB Tile 1...................................................................................................................................................... 8
Table 3-2. QepDiv CLB Tile 2...................................................................................................................................................... 9
Table 4-1. Abs2Qep Relationship Between Lines and QCLK (Forward Direction).................................................................... 11
Table 4-2. Abs2Qep Example Calculations............................................................................................................................... 13
Table 4-3. Abs2Qep CLB Tile 1................................................................................................................................................. 16
Table 4-4. QEP-A (s0) Signal Generation Karnaugh Maps ...................................................................................................... 18
Table 4-5. QEP-B (s1) Signal Generation Karnaugh Maps ...................................................................................................... 18
Table 4-6. RUN/HALT Output.....................................................................................................................................................19
SPRAC77C – MARCH 2020 – REVISED MAY 2021 C2000™ Position Manager PTO API Reference Guide 1
Submit Document Feedback
Copyright © 2021 Texas Instruments Incorporated
Trademarks www.ti.com
Trademarks
Code Composer Studio™ and C2000™ are trademarks of Texas Instruments.
All trademarks are the property of their respective owners.
1 Introduction
The C2000 Real-Time MCU Pulse Train Output (PTO) APIs assist in generating various pulse patterns. These
APIs leverage the Configurable Logic Block (CLB), Type 1 or later, to generate the specified PTO.
This document describes the implementation and associated software for each PTO module.
The patterns included are:
PulseGen: Output a simple pulse and a direction-indication signal.
QepDiv: Scale Quadrature Encoded Pulse inputs (QEP-A, QEP-B and QEP-Index) to output reduced frequency
PTO signals.
Abs2Qep: Translate a change in absolute position into equivalent QEP-A/B and QEP-I signals.
There are two categories of software provided:
Example Application Projects: Small applications which configure a C2000 Real-Time MCU, incorporates the
appropriate reference library, and demonstrates the PTO functionality. Section 5 describes how to access the
source code, import the project into CCS, and then build and run the example.
PTO Reference API Libraries: Software implementation of the PTO. Section 6 includes a description of each
API, how to access the source code, and how to rebuild the libraries. Section 7 explains how to incorporate the
API into your own project.
Note
You will need the appropriate development tools installed to build the CLB-based projects. For more
information, see the CLB Tool User’s Guide.
2 C2000™ Position Manager PTO API Reference Guide SPRAC77C – MARCH 2020 – REVISED MAY 2021
Submit Document Feedback
Copyright © 2021 Texas Instruments Incorporated
www.ti.com PTO – PulseGen
2 PTO – PulseGen
The PTO-PulseGen function can be used to generate pulse and direction outputs as required by the application.
Figure 2-1 shows the PulseGen output and Figure 2-2 shows the implementation diagram.
Pulse
(Output)
PulseGen
Direction
(Output)
GPIO14
Pulse - Output
CLB
OUTPUT GPIO15
Direction - Output
XBAR
C28xCPU
TMS320F28379D
Note
Interconnect between the CLB and the MCU boundary may differ between devices or between
examples. For specific interconnect routing information, see Section 5.
SPRAC77C – MARCH 2020 – REVISED MAY 2021 C2000™ Position Manager PTO API Reference Guide 3
Submit Document Feedback
Copyright © 2021 Texas Instruments Incorporated
PTO – PulseGen www.ti.com
e0 TILE1_FSM_2
e1 s0
s0 = ((~s0) & (e0 & e1)) | (s0 & (e0 | (~e1)))
xe0 s1 = s1 s1
xe1 out = s0 out
Note
Section 6 describes how to build the library project in Code Composer Studio™. By building the
project, CCS will regenerate the CLB tile diagram (clb.svg or clb.html). and object (.lib). The CLB tile
diagram will be located in the RELEASE/syscfg directory.
4 C2000™ Position Manager PTO API Reference Guide SPRAC77C – MARCH 2020 – REVISED MAY 2021
Submit Document Feedback
Copyright © 2021 Texas Instruments Incorporated
www.ti.com PTO – PulseGen
QEPB QEPB
(Input) (Output)
QepDiv
QEPI QEPI
(Input) (Output)
SPRAC77C – MARCH 2020 – REVISED MAY 2021 C2000™ Position Manager PTO API Reference Guide 5
Submit Document Feedback
Copyright © 2021 Texas Instruments Incorporated
PTO – QepDiv www.ti.com
IN7:,QGH[ ,QSXW
Pos Edge detect
OUT5: WR *3,2
Via O/P-XBAR
GPIO2
QEPA - Output
GPIO3
QEPB - Output
OUTPUT GPIO14
QEPI - Output
XBAR
OUTPUT3
CLB
C28xCPU
TMS320F28379D
Note
Interconnect between the CLB and the MCU boundary may differ between devices or between
examples. For specific interconnect routing information, see Section 5.
6 C2000™ Position Manager PTO API Reference Guide SPRAC77C – MARCH 2020 – REVISED MAY 2021
Submit Document Feedback
Copyright © 2021 Texas Instruments Incorporated
www.ti.com PTO – QepDiv
uint16_t
pto_qepdiv_config(uint16_t divider, uint16_t indexWidth)
{
CLB_writeInterface(CLB2_BASE, CLB_ADDR_COUNTER_0_MATCH2, divider * 4);
CLB_writeInterface(CLB2_BASE, CLB_ADDR_COUNTER_0_MATCH1, divider * 2);
CLB_writeInterface(CLB1_BASE, CLB_ADDR_COUNTER_2_MATCH1, indexWidth - 1);
return(divider);
}
TILE2_BOUNDARY i0
TILE2_OUTLUT_4
squareWave in0 : i1 out
out i0 out = i0
squareWave in1 : i2
Period = 500, Duty = 250
out in2 = i1 TILE2_LUT_0 out
Period = 500, Duty = 250
in3 : i2 out = i0 & (i1 | i2)
in4 = i3
squareWave
squareWave TILE1_BOUNDARY out in5 :
Period = 500, Duty = 250
out in0 : in6 :
Period = 500, Duty = 250
in1 : in7 :
e0 TILE1_FSM_0 i0
in2 =
e1 s0 i1 TILE1_LUT_1 out TILE1_BOUNDARY
squareWave in3 : s0 = e0
xe0 s1 = e1 s1 i2 out = (((~i0) & (~i1)) & i3) | (((~i0) & i1) & i2) | ((i0 & (~i1)) & i2) | ((i0 & i1) & i3) out0
out in4 : e0 TILE1_FSM_1 e0 TILE2_FSM_0
Period = 500, Duty = 250 xe1 out = s0 | s1 out i3 out1
in5 = e1 s0 i0 e1 s0
s0 = ((~s0) & e0 & e1) | (s0 & (~e1) | e0) TILE1_OUTLUT_4 out2
xe0 s1 i1 out s0 = e0
in6 : s1 = s1 xe0 s1 = s1 s1
out = s0 & s1 out = i0 & i1 out3 i0
in7 9 xe1 out i2 xe1 out = (~s0) & e0 out
squareWave out4 i1 TILE2_LUT_1 out e0
out TILE2_FSM_1
out5 reset zero TILE2_BOUNDARY
Period = 500, Duty = 250 i2 out = (i2 & i1) | ((~i2) & i0) e1 s0 i0
event TILE2_COUNTER_0 match1 s0 = ((~s0) & (e0)) | (s0 & (~e0)) TILE2_OUTLUT_0
out6 i3 xe0 s1 i1 out out0
s1 = s0
i0 out7 mode0 evAction = None match2 out = s0 | s1 out = i0
TILE1_OUTLUT_5 xe1 out i2 out1
e0 TILE1_FSM_2 i1 out mode1
squareWave out2
e1 s0 out = i0
out i2
Period = 3000, Duty = 1500 s0 = ((~s0) & e0) | (s0 & (~e1)) i0 out3
xe0 s1 = s1 s1 TILE2_LUT_2
out = ~s0 i1 out e0 TILE2_FSM_2 out4
reset zero xe1 out i0
i2 out = (i2 & i0) | ((~i2) & i1) e1 s0 TILE2_OUTLUT_2 out5
event TILE1_COUNTER_2 match1 s0 = ((~s0) & (e0)) | (s0 & (~e0)) i1 out
i3 xe0 s1 = s1 s1 out = i0 out6
mode0 evAction = None match2 out = s0 i2
xe1 out out7
mode1
reset zero
event TILE1_COUNTER_0 match1
mode0 evAction = None match2
1
mode1
reset zero
event TILE1_COUNTER_1 match1
mode0 evAction = None match2
mode1
SPRAC77C – MARCH 2020 – REVISED MAY 2021 C2000™ Position Manager PTO API Reference Guide 7
Submit Document Feedback
Copyright © 2021 Texas Instruments Incorporated
PTO – QepDiv www.ti.com
Note
You can import and build the QepDiv API reference project for each respective device, located
in [C2000Ware_MotorControl_SDK]\libraries\position_sensing\pto\ccs. By rebuilding
the compiled object, it will regenerate the CLB tile diagram (clb.svg or clb.html). and object (.lib) The
CLB tile diagram will be located in the RELEASE/syscfg directory.
8 C2000™ Position Manager PTO API Reference Guide SPRAC77C – MARCH 2020 – REVISED MAY 2021
Submit Document Feedback
Copyright © 2021 Texas Instruments Incorporated
www.ti.com PTO – QepDiv
SPRAC77C – MARCH 2020 – REVISED MAY 2021 C2000™ Position Manager PTO API Reference Guide 9
Submit Document Feedback
Copyright © 2021 Texas Instruments Incorporated
PTO – Abs2Qep www.ti.com
4 PTO – Abs2Qep
The PTO-Abs2Qep function translates a change in absolute position into a quadrature encoder pulse train
output. Figure 4-1 shows the implementation diagram of the PTO-Abs2Qep interface.
C28x CPU
PTO-QEPA
CLB PTO-QEPB
Absolute Position
Encoder
PTO-QEPI
eQEP
Loop-back to eQEP
for testing only
An absolute encoder output represents the exact position of a rotating shaft. If Qmax is the resolution of a single
rotation, then the position will range from 0 to Qmax. Resolutions in the range Q17 = 217 or Q20 = 2 20 are
common. The absolute position increases when the direction is forward (clockwise) and decreases when the
direction is reverse (counter-clockwise).
10 C2000™ Position Manager PTO API Reference Guide SPRAC77C – MARCH 2020 – REVISED MAY 2021
Submit Document Feedback
Copyright © 2021 Texas Instruments Incorporated
www.ti.com PTO – Abs2Qep
Forward Reverse
Lines per
Revolution Forward QEP-A
0 QEP-A Leads
Reverse QEP-B
QEP-A Lags
QEP-B QEP-B
Index
QEP-I
Incremental
Encoder Disk
QCLK
(Internal
Each Line Signal)
Generates 2 Edges:
One on QEP-A and
One on QEP-B
An incremental encoder output is a quadrature encoder pulse (QEP). This pulse train consists of the following
outputs: QEP-A, QEP-B and QEP-I with the following characteristics:
• The phase between QEP-A and QEP-B indicates the direction of movement. If QEP-A leads by 90°, then
the direction is forward (clockwise). If QEP-A lags by 90° degrees, then the direction is reverse (counter-
clockwise).
• The QEP-A/B frequency is proportional to the disk's velocity.
• The index signal, QEP-I, indicates crossing over absolute zero.
The resolution of the incremental encoder is specified by the number of lines around the disk. As each line
passes a sensor, an edge (falling or rising) is generated on QEP-A as shown in Figure 4-3. A second channel
can be added by second ring of lines, inside and offset from the outer ring. In such a case, this inner ring of lines
generates QEP-B. For example, a 1024 line encoder would have 1024 QEP-A lines and 1024 QEP-B lines for a
total of 2048 QEP state changes in a full rotation.
In Abs2Qep, a configurable parameter in the header file defines how many QEP state transitions are generated
per line. The QEP state transition is controlled by an internal CLB signal called QCLK as shown in Figure 4-3.
The default setting is each line corresponds to two QCLK pulses.
The example in Table 4-1 further clarifies this point.
Table 4-1. Abs2Qep Relationship Between Lines and QCLK (Forward Direction)
Line QCLK QEP-A QEP-B
Line 1 Outer Ring QCLK 1 Rising Edge
Line 1 Inner Ring QCLK 2 Rising Edge
Line 2 Outer Ring QCLK 3 Falling Edge
Line 2 Inner Ring QCLK 4 Falling Edge
Note
The parameters used in the translation equations are configurable in the Abs2Qep library header file.
This includes: absolute encoder resolution, incremental encoder lines per revolution, drive maximum
revolutions per minute.
SPRAC77C – MARCH 2020 – REVISED MAY 2021 C2000™ Position Manager PTO API Reference Guide 11
Submit Document Feedback
Copyright © 2021 Texas Instruments Incorporated
PTO – Abs2Qep www.ti.com
The Abs2Qep translation uses the ratio ABS_TO_INCR to map a change in absolute position to a corresponding
number of QEP edges. Any fraction of an edge is tracked. If the fractional edge accumulation reaches 1, then an
additional edge is generated.
where
• LINES_PER_REV is the incremental encoder resolution.
• QCLK_PER_LINE is typically 2. One for QEP-A and one for QEP-B.
• ABS_MAX_POSITION = 2ABS_ENCODER_RESOLUTION. For example 220.
The number of QCLKs, or QEP edges, that represent a change in position is:
where:
• DELTA_ABS_POSITION = ABS_POSITION(n) - ABS_POSITION(n-1) the change in absolute position
between the current sample (n) and the previous sample (n-1).
• QCLK is the total number of QEP-A + QEP-B edges required to represent the change in position.
Note
This simple translation in Equation 2 assumes absolute zero was not crossed. For zero-cross
detection, see Section 4.2.3
For a given position change, the frequency of QCLK is such that the edges are equally divided across the
position sampling period. This frequency is expressed in terms of CLB clock cycles.
4.2.2 Abs2Qep Translation Example
Given the following parameters:
• CLB clock = 10 nanoseconds
• Position sampling period = 100 microseconds or 10,000 CLB clocks
• Absolute encoder resolution = ABS_MAX_POSITION = Q20 = 1048576
• Incremental encoder resolution = 1024 lines. Therefore QCLK_PER_REV = 2 x 1024 = 2048
The ABS_TO_INCR ratio is:
2 x Lines 2048
ABS_TO_INCR = = = .00195313 (3)
Qmax 1048576
12 C2000™ Position Manager PTO API Reference Guide SPRAC77C – MARCH 2020 – REVISED MAY 2021
Submit Document Feedback
Copyright © 2021 Texas Instruments Incorporated
www.ti.com PTO – Abs2Qep
Table 4-2 shows example translations from a change in absolute position to QCLKs generated.
Notice at sample 2 and sample 3, the fractional edge accumulation is greater than 1. When this occurs, an
additional QCLK is generated and one is subtracted from the fractional edge accumulation.
Note
The absolute position samples shown are for illustration only. Actual position change values may be
much larger than shown or may be in the reverse direction.
(1) Position(n) - Position(n-1). In this example all changes are in the forward direction and zero is not crossed. If this value were negative,
the direction would be reverse.
(2) Number of CLB clocks betweeen each QCLK pulse. This is based on the sampling frequency expressed in CLB clocks. For this
example: 10,000 CLB clocks / QCLKs generated
(3) An additional QCLK is generated and the fractional portion is adjusted by 1.
Therefore any position change where the magnitude is greater than .05 x Qmax is assumed to be a zero
crossing.
SPRAC77C – MARCH 2020 – REVISED MAY 2021 C2000™ Position Manager PTO API Reference Guide 13
Submit Document Feedback
Copyright © 2021 Texas Instruments Incorporated
PTO – Abs2Qep www.ti.com
Figure 4-4 illustrates crossing zero in the forward direction. Position(n) is a relatively small number and
Position(n-1) is a very large number. Position(n) - Position(n-1) is, therefore, a negative number with a
magnitude greater than ABS_MAX_POSITION.
In this case, Abs2Qep uses the sum of two measurements to determine the equivalent QEP pulses:
• (A) delta between Position(n-1) and Qmax
• (B) delta between 0 and Position(n)
A+B
A B
Qmax - Posion(n-1) Posi on(n)
PTO-QEP-A
Qmax 0
A B PTO-QEP-B
Qmax – Posion(n-1) Posion(n)
A+B
Position(n-1) PTO-QEP-I
Position(n)
Figure 4-5 illustrates zero crossed in the reverse direction. Position(n) is a large value and Position(n-1)
is relatively small. Therefore Position(n) - Position(n-1) will be positive and have a magnitude >
ABS_MAX_POSITION.
In this case, Abs2Qep uses the sum of measurements:
• (A) delta between Position(n-1) and zero
• (B) delta between Qmax and Position(n)
Notice, in the resulting PTO, QEP-B leads by 90° indicating a reverse direction.
A+B
A B
Posion(n-1) Qmax - Posi on(n)
PTO-QEP-A
Qmax 0
PTO-QEP-B
B A
Qmax – Posion(n) Posion(n-1)
A+B
PTO-QEP-I
Position(n) Position(n-1)
14 C2000™ Position Manager PTO API Reference Guide SPRAC77C – MARCH 2020 – REVISED MAY 2021
Submit Document Feedback
Copyright © 2021 Texas Instruments Incorporated
www.ti.com PTO – Abs2Qep
Figure 4-6 shows PTO-QEP waveforms and their tie to CLB components. In this example, the position sampling
period is controlled by an ePWM ISR on the C28x.
PTO for: Movement from Position (0) to Position (1) Position (1) to Position (2)
...
PTO-QCLK Edge
(COUNTER 0 match1) *
... ...
...
Position Sampling Period 1 Position Sampling Period 2 etc...
A. Counter 0 match 1 is initialized to a fixed value and is not changed. This match generates the QCLK pulse. This places QCLK toggle at
the beginning of the count, reducing the time between the previous PTO halt and the next PTO start.
B. The time between QCLK pulses is controlled by the COUNTER 0 match 2. This match resets COUNTER 0.
C. P(n) stands for Absolute Position at sample n.
SPRAC77C – MARCH 2020 – REVISED MAY 2021 C2000™ Position Manager PTO API Reference Guide 15
Submit Document Feedback
Copyright © 2021 Texas Instruments Incorporated
PTO – Abs2Qep www.ti.com
The CLB Tile block diagram is shown in Figure 4-7 and Table 4-3 describes the functionality of each CLB
component in detail.
out0 For Testing Only
DIRECTION
0: Reverse
WIDTH_CONTROL in1 (GPREG) 1: Forward
PTO_DONE
PTO_DONE
reset zero
TILE1_COUNTER_2
QCLK PTO_QEP-I_HIGH PTO_QEP-I
event match1 e0 s0 out2
QEP-I Control
Count Sent Edges PTO_QEP-I_LOW TILE1_FSM_2
mode0 match2 e1 s1
Add 1 on Event QEP-I Generation
mode1 xe0 out
xe1
16 C2000™ Position Manager PTO API Reference Guide SPRAC77C – MARCH 2020 – REVISED MAY 2021
Submit Document Feedback
Copyright © 2021 Texas Instruments Incorporated
www.ti.com PTO – Abs2Qep
FSM2 Generate PTO_QEP-I signal Force PTO_QEP-I high and low based on the QEP-I control. Enables
the user to configure QEP-I to stay high for more than one QCLK if
desired.
CNT0 Generate QCLK (PTO width control) signal Counts up by 1 each CLB clock.
• match1: fixed value. Generates the QCLK signal near the start of
the count. This placement reduces the time between the last PTO
halt and the next PTO start.
• match2: number of CLB clocks between QEP edges. The counter
is reset every match2 event.
CNT1 PTO edge-count control Increments by 1 every QCLK event to count the total QEP-A + QEP-B
edges sent during a PTO.
• match1: manipulated by the HLC in order to clear a halt latch
condition and start the PTO.
• match2: number of edges to be sent. Once reached, the
PTO_DONE signal is asserted. This latches a halt state and resets
the edge count and resets QEP-I control.
CNT2 PTO_QEP-I control Increments by 1 every QCLK event to count the total QEP-A + QEP-B
edges sent during a PTO.
• match1: Edge where PTO_QEP-I will go high
• match2: Edge where PTO_QEP-I will go low
Note
If PTO-QEP-I should remain low for the whole PTO, then
configure match1 and match2 to be a large number to
avoid a match. (i.e. 0xFFFFFFFF).
SPRAC77C – MARCH 2020 – REVISED MAY 2021 C2000™ Position Manager PTO API Reference Guide 17
Submit Document Feedback
Copyright © 2021 Texas Instruments Incorporated
PTO – Abs2Qep www.ti.com
Table 4-4 and Table 4-5 are the corresponding Karnaugh Maps. The resulting equations are determined by
inspecting each "1" within the map or by using a Karnaugh Map solver. x is used to indicate states which are
not valid. Note that there is no need to further simplify the equations; they can be entered into the CLB tool
as shown. Use the OR operator to build up the full equation from the parts as shown in the simulation results
(Figure 4-9).
Table 4-4. QEP-A (s0) Signal Generation Karnaugh Maps
DIRECTION (e0) = 1 (Forward) DIRECTION (e0) = 0 (Reverse)
Next State Next State
QCLK, QEP-B (e1, s1) QCLK, QEP-B (e1, s1)
00 01 11 10 00 01 11 10
00 0 0 x (2) 1 (2) 00 0 0 0 x
Current State
Current State
(QEP-A, B)
(QEP-A, B)
01 0 0 x 0 01 0 0 1 (3) x (3)
s0, s1
s0, s1
(1) s0_1 = (e0 & s0 & !e1) | (!e0 & s0 & !e1) = s0 & !e1
(2) s0_2 = e0 & !s1 & e1
(3) s0_3 = !e0 & s1 & e1
Current State
(QEP-A, B)
(QEP-A, B)
s0, s1
(1) s1_1 = (e0 & s1 & !e1) | (!e0 & s1 & e1) = s1 & !e1
(2) s1_2 = e0 & s0 & e1
(3) s1_3 = !e0 & !s0 & e1
18 C2000™ Position Manager PTO API Reference Guide SPRAC77C – MARCH 2020 – REVISED MAY 2021
Submit Document Feedback
Copyright © 2021 Texas Instruments Incorporated
www.ti.com PTO – Abs2Qep
HALT_LATCH is set on the rising edge of PTO_DONE. It will remain set until cleared by a a rising edge on the
HALT/CLEAR_LATCH signal from the CPU.
Table 4-7. HALT_LATCH Karnaugh Map
PTO_DONE, CLEAR_LATCH (e0, e1)
00 01 11 10
0 0 0 0 1 (2)
(LATCH)
s0
1 1 (1) 0 0 1 (1),(2)
SPRAC77C – MARCH 2020 – REVISED MAY 2021 C2000™ Position Manager PTO API Reference Guide 19
Submit Document Feedback
Copyright © 2021 Texas Instruments Incorporated
PTO – Abs2Qep www.ti.com
20 C2000™ Position Manager PTO API Reference Guide SPRAC77C – MARCH 2020 – REVISED MAY 2021
Submit Document Feedback
Copyright © 2021 Texas Instruments Incorporated
www.ti.com PTO – Abs2Qep
SPRAC77C – MARCH 2020 – REVISED MAY 2021 C2000™ Position Manager PTO API Reference Guide 21
Submit Document Feedback
Copyright © 2021 Texas Instruments Incorporated
PTO Example Projects www.ti.com
Note
To build the examples, only the above software is required. To re-build the CLB-based libraries,
the CLB Tool is also required. This tool is included in Code Composer Studio (sysconfig) and the
C2000Ware sub-component of the SDK (support utilities). To run CLB-based simulations requires
installation of additional tools which are documented in the CLB Tool User's Guide.
22 C2000™ Position Manager PTO API Reference Guide SPRAC77C – MARCH 2020 – REVISED MAY 2021
Submit Document Feedback
Copyright © 2021 Texas Instruments Incorporated
www.ti.com PTO Example Projects
Table 5-5. F28004x, F2837x and F2838x QepDiv Output GPIO Mapping
QepDiv Input QepDiv Output
Input Signal Connect to for Routing to CLB Output Signal Routing From the GPIO Pin
Demo (1) CLB
QEP-A: GPIO10 EPWM4A/GPIO6 INPUTXBAR4 → PTO_QEP-A Override PWM2A GPIO2
or External Signal AUXSIG0 →
Tile1 in1, in2 and
Tile2 in1, in2
QEP-B: GPIO11 EPWM5A/GPIO8 INPUTXBAR5 → PTO_QEP-B Override PWM2B GPIO3
or External Signal AUXSIG1 →
Tile1 in4, in5 and
Tile2 in4
QEP-I: GPIO9 EPWM4B/GPIO7 INPUTXBAR6 → PTO_QEP-I Tile1 out5 → GPIO5
or External Signal AUXSIG2 → OUTPUTXBAR3
Tile1 in7
(1) In the example, spare EPWMs are used to provide QEP inputs. These are for test purposes and do not correspond to real-time usage.
You can choose to connect these EPWM outputs to the QepDiv input signals or you can choose to connect other external signals.
Table 5-6 lists the connections that need to be made to use the EPWMs as inputs to QepDiv.
Table 5-6. QepDiv Test Input Connections
Board EPWM4A to QEP-A EPWM5A to QEP-B EPWM4B to QEP-I
LAUNCHXL-F280049C 78 to 40 38 to 39 77 to 37
LAUNCHXL-F28379D 80 to 76 78 to 75 79 to 77
TMDSCNCD28388D 54 to 61 57 to 63 56 to 59
SPRAC77C – MARCH 2020 – REVISED MAY 2021 C2000™ Position Manager PTO API Reference Guide 23
Submit Document Feedback
Copyright © 2021 Texas Instruments Incorporated
PTO Example Projects www.ti.com
(1) J8 and J6 are swapped on the silkscreen of RevA F28004x LaunchPad. J8 and J6 Pin numbers in this table refer to the silkscreen on
Rev A. To confirm whether this applies to your board, see the "known issues" in the revision section of C2000™ Piccolo™ F28004x
Series LaunchPad™ Development Kit.
24 C2000™ Position Manager PTO API Reference Guide SPRAC77C – MARCH 2020 – REVISED MAY 2021
Submit Document Feedback
Copyright © 2021 Texas Instruments Incorporated
www.ti.com PTO Library Source and Projects
SPRAC77C – MARCH 2020 – REVISED MAY 2021 C2000™ Position Manager PTO API Reference Guide 25
Submit Document Feedback
Copyright © 2021 Texas Instruments Incorporated
PTO Library Source and Projects www.ti.com
6.3.1 pto_pulsegen_runPulseGen
Description
A runtime function to be called periodically for dynamically configuring and changing the pulse generation
requirements as required by the application. This function must be called periodically with appropriate
parameters like the number of pulses, period, duration, and more.
Definition
uint16_t pto_pulsegen_runPulseGen(
uint32_t pulseLo,
uint32_t pulseHi,
uint32_t ptoActivePeriod,
uint32_t ptoFullPeriod,
uint32_t ptoInterruptTime,
uint16_t ptoDirection,
uint16_t run
);
Parameters
Input:
• pulseLo – Low pulse width
• pulseHi – High pulse width
• ptoActivePeriod – Period the pulses are sent out; less than ptoFullPeriod
• ptoFullPeriod – Full PTO period
• ptoInterruptTime – Time when that the interrupt is generated to the CPU
• ptoDirection – Direction output; latched as it is on direction output at the beginning of new period
• run – Value indicting 1-run and 0-stop. Sampled at the beginning of the new period to determine to continue
or halt the pulse generation
Return:
• Val – If the function is executed successfully, the function will return ptoFullPeriod as the return value
26 C2000™ Position Manager PTO API Reference Guide SPRAC77C – MARCH 2020 – REVISED MAY 2021
Submit Document Feedback
Copyright © 2021 Texas Instruments Incorporated
www.ti.com PTO Library Source and Projects
Usage
In pto_pulsegen.c, a sample configuration function called pto_setOptions is provided as an example to assist
with the pto_pulsegen_runPulseGen function and to perform the intermediate calculations. See the following
code sample calculation that illustrates how various parameters for this function can be generated. For more
details, see the pto_pulsegen.c and pto_pulsegen.h files.
uint32_t pto_setOptions(
uint32_t numPulses, //number of pulses needed to be generated in next period
uint32_t Period, // PTO period in clock cycles
uint32_t ptoInterruptTime, // Interrupt generation time
uint16_t ptoDirection, // Direction output
uint16_t run) //run-stop condition.
{
uint32_t pulseFreq, reminder;
uint32_t pulseLo;
uint32_t pulseHi;
uint32_t ptoActivePeriod;
uint32_t ptoFullPeriod;
pulseFreq = Period / numPulses;
reminder = Period - (pulseFreq * numPulses);
pulseLo = (pulseFreq/2 );
pulseHi = pulseFreq;
ptoActivePeriod = (pulseFreq * numPulses);
ptoFullPeriod = Period;
pto_pulsegen_runPulseGen(
pulseLo,
pulseHi,
ptoActivePeriod,
ptoFullPeriod,
ptoInterruptTime,
ptoDirection,
run);
return(reminder);
}
6.3.2 pto_startOperation
Description
This function initiates the pulse generation. This function must be called after pto_pulsegen_setupPeriph. Hence,
the pto_pulsegen_startOperation kick starts the pulse generation that was set up earlier.
Note
The setup and start operations are separate function calls. Users can set up the transfer and start the
pulse generation by using this function call, as required, at a different time.
Definition
void pto_pulsegen_startOperation(void);
Parameters
Input: none
Return: none
Usage
Example code:
pto_initPulsegen ();
SysCtl_delay (800L);
pto_pulsegen_startOperation ();
retval1 = pto_pulsegen_runPulseGen (7, 15, 960, 990, 500, 1, 1);
SPRAC77C – MARCH 2020 – REVISED MAY 2021 C2000™ Position Manager PTO API Reference Guide 27
Submit Document Feedback
Copyright © 2021 Texas Instruments Incorporated
PTO Library Source and Projects www.ti.com
6.3.3 pto_pulsegen_setupPeriph
Description
This function performs the setup for the CLB and other interconnect XBARs during system initialization. This
function must be called after every system reset. No transactions will be performed until the setup peripheral
function is called.
Definition
Parameters
Input: none
Return: none
Usage
Example code:
pto_pulsegen_setupPeriph();
6.3.4 pto_pulsegen_reset
Description
This function resets the pulsegen parameters set by the earlier configuration (PulseGen function calls) and starts
a new setup. This function must be called in case the pulse generation must be reset and started again at a later
stage.
Definition
Parameters
Input: none
Return: none
Usage
Example code:
pto_pulsegen_reset();
28 C2000™ Position Manager PTO API Reference Guide SPRAC77C – MARCH 2020 – REVISED MAY 2021
Submit Document Feedback
Copyright © 2021 Texas Instruments Incorporated
www.ti.com PTO Library Source and Projects
6.4.1 pto_qepdiv_config
Description
This function configures the divider. The divider value cannot be changed dynamically. Users must reset the
module using pto_qepdiv_reset before reconfiguring the functionality.
Definition
Parameters
Input:
• Divider – Value of the divider
• Index width – Number of cycles for which the index pulse output is kept on
Return:
• Val – If the function is executed successfully, it will return ptoFullPeriod as the return value
Usage
Example code:
SPRAC77C – MARCH 2020 – REVISED MAY 2021 C2000™ Position Manager PTO API Reference Guide 29
Submit Document Feedback
Copyright © 2021 Texas Instruments Incorporated
PTO Library Source and Projects www.ti.com
6.4.2 pto_startOperation
Description
This function initiates the pulse generation. This function must only be called after pto_qepdiv_setupPeriph.
Hence, the pto_qepdiv_startOperation function kick starts the pulse generation that was set up earlier.
Note
The setup and start operations are separate function calls. Users can set up the transfer and start the
pulse generation by using this function call, as required, at a different time.
Definition
Parameters
Input (parameters to be passed to start or stop the function):
• Start = 1
• Stop = 0
Return: none
Usage
Example code:
6.4.3 pto_qepdiv_setupPeriph
Description
Setup for the CLB and other interconnect XBARs is performed with the pto_qepdiv_setupPeriph function during
system initialization. This function must be called after every system reset. No transactions will be performed
until the setup peripheral function is called.
Definition
Parameters
Input: none
Return: none
Usage
Example code:
pto_qepdiv_setupPeriph();
30 C2000™ Position Manager PTO API Reference Guide SPRAC77C – MARCH 2020 – REVISED MAY 2021
Submit Document Feedback
Copyright © 2021 Texas Instruments Incorporated
www.ti.com PTO Library Source and Projects
6.4.4 pto_qepdiv_reset
Description
Used to reset the qepdiv parameters set by earlier configurations and to begin a fresh setup. This function must
be called in case the pulse generation must be reset and started again at a later stage.
Definition
Parameters
Input: none
Return: none
Usage
Example code:
pto_qepdiv_reset();
SPRAC77C – MARCH 2020 – REVISED MAY 2021 C2000™ Position Manager PTO API Reference Guide 31
Submit Document Feedback
Copyright © 2021 Texas Instruments Incorporated
PTO Library Source and Projects www.ti.com
6.5.2 pto_abs2qep_runPulseGen
Description
Function called during runtime to start a new PTO. This function checks that the previous PTO has completed
before starting a new PTO.
Note
The setup and start operations are separate function calls. The setup (pto_abs2qep_translatePosition)
must be called before this function. You can set up the transfer and start the pulse generation by using
this function call, as required, at a different time.
Definition
void
pto_abs2qep_runPulseGen(
uint16_t ptoDirection
);
Parameters
Input:
• ptoDirection: Direction of the PTO. This determines which signal leads QEP-A or QEP-B.
Return: none
Usage
6.5.3 pto_abs2qep_setupPeriph
Description
This function performs the setup for the CLB and XBAR interconnect during system initialization. This function
must be called after every system reset. No transactions will be performed until the setup peripheral function is
called.
Definition
void pto_abs2qep_setupPeriph(void);
Parameters
Input: none
Return: none
Usage
pto_abs2qep_setupPeriph();
...
//
// GPIO and other system peripheral configuration
//
32 C2000™ Position Manager PTO API Reference Guide SPRAC77C – MARCH 2020 – REVISED MAY 2021
Submit Document Feedback
Copyright © 2021 Texas Instruments Incorporated
www.ti.com PTO Library Source and Projects
6.5.4 pto_abs2qep_translatePosition
Description
This function translates a change in absolute position into an equivalent PTO configuration to be loaded into the
CLB FIFO. The information includes:
• Number of QCLKs required to generate the QEP-A and QEP-B pulses
• If crossing zero, the QCLK edge where QEP-I should be driven high and low
• The number of CLB clocks between each QCLK
• The direction of the position change.
No No
Total
Determine total
fraconal QCLK Yes Adjust QCLK edges to be Adjust the fraconal carry-
accumulated fraconal
>= 1 sent by 1 over by 1
QCLK pulses to carry over
or <= -1?
No
Definition
uint16_t
pto_abs2qep_translatePosition(
uint32_t positionNew
);
SPRAC77C – MARCH 2020 – REVISED MAY 2021 C2000™ Position Manager PTO API Reference Guide 33
Submit Document Feedback
Copyright © 2021 Texas Instruments Incorporated
Using the PTO Reference APIs in Projects www.ti.com
Parameters
Input:
• positionNew - The new absolute position as sampled by the system. The translate function compares this
value to the previous sample to determine the change in position.
Return: ptoDirection - Indicates the direction of the PTO.
• PTO_ABS2QEP_CLOCKWISE_PTO
• PTO_ABS2QEP_COUNTERCLOCKWISE_PTO
Note
This function loads the PTO configuration directly into the HLC PULL FIFO.
Usage
Note
The exact location may vary depending on where C2000Ware_MotorControl_SDK is installed and
which other libraries the project is using.
#include "pto_pulsegen.h"
#include "pto_qepdiv.h"
#include "pto_abs2qep.h"
2. In Code Composer Studio (CCS), right click on the project and navigate to Project Properties → Build →
C2000 Compiler → Include Options
a. Add the header file directory to the '#include search path' (see Figure 7-1)
The path for PTO header files is ${SDK_ROOT}\libraries\position_sensing\pto\include.
Note
${SDK_ROOT} is a varaible used by CCS to indicate the install location of the SDK. Its
definition can be viewed under Project Properties → Resource → Linked Resources.
34 C2000™ Position Manager PTO API Reference Guide SPRAC77C – MARCH 2020 – REVISED MAY 2021
Submit Document Feedback
Copyright © 2021 Texas Instruments Incorporated
www.ti.com Using the PTO Reference APIs in Projects
Figure 7-1. Compiler Include Options for Projects Using PTO Reference APIs
3. Add the compiled library file to the project:
a. Right click on the project name in the Project Explorer window
b. Navigate to 'Project Properties → Build → C2000 Linker → File Search Path'
c. Add the library directory to the 'library search path'
d. Add the name of the library to the 'Include library file'
e. Click 'Apply and Close'
The PTO compiled library object files are located at: [C2000Ware_MotorControl_SDK]
\libraries\position_sensing\pto\lib.
An example is shown in Figure 7-2 and Figure 7-3 show the changes to the linker options that are required to
include the PTO APIs compiled object file.
SPRAC77C – MARCH 2020 – REVISED MAY 2021 C2000™ Position Manager PTO API Reference Guide 35
Submit Document Feedback
Copyright © 2021 Texas Instruments Incorporated
Using the PTO Reference APIs in Projects www.ti.com
Note
The exact location may vary depending on where C2000Ware_MotorControl_SDK is installed and
which other libraries the project is using.
36 C2000™ Position Manager PTO API Reference Guide SPRAC77C – MARCH 2020 – REVISED MAY 2021
Submit Document Feedback
Copyright © 2021 Texas Instruments Incorporated
www.ti.com Using the PTO Reference APIs in Projects
pto_abs2qep_translatePosition(0);
pto_abs2qep_runPulseGen(PTO_ABS2QEP_CLOCKWISE_PTO);
4. Configure a timer to start an ISR when the absolute position is to be sampled. The example uses ePWM3.
5. In the sampling ISR do the following (see pto_EPWM3ISR):
a. Start the previous PTO translation: pto_abs2qep_runPulseGen(ptoDirection)
b. Sample a new absolute position AbsolutePositionNext = <application dependent
function>()
c. Translate the next PTO. ptoDirection =
pto_abs2qep_translatePosition(absolutePositionNext) This translation will be run the next
time the ISR is run.
8 References
• Texas Instruments: CLB Tool User’s Guide
• Texas Instruments: C2000™ Piccolo™ F28004x Series LaunchPad™ Development Kit
Revision History
NOTE: Page numbers for previous revisions may differ from page numbers in the current version.
Changes from Revision B (March 2020) to Revision C (May 2021) Page
• Updated the numbering format for tables, figures and cross-references throughout the document. .................2
• Added new Section 4........................................................................................................................................10
• Added Abs2Qep information to Section 5 ........................................................................................................21
• Added Abs2Qep information to the Section 6...................................................................................................25
SPRAC77C – MARCH 2020 – REVISED MAY 2021 C2000™ Position Manager PTO API Reference Guide 37
Submit Document Feedback
Copyright © 2021 Texas Instruments Incorporated
IMPORTANT NOTICE AND DISCLAIMER
TI PROVIDES TECHNICAL AND RELIABILITY DATA (INCLUDING DATASHEETS), DESIGN RESOURCES (INCLUDING REFERENCE
DESIGNS), APPLICATION OR OTHER DESIGN ADVICE, WEB TOOLS, SAFETY INFORMATION, AND OTHER RESOURCES “AS IS”
AND WITH ALL FAULTS, AND DISCLAIMS ALL WARRANTIES, EXPRESS AND IMPLIED, INCLUDING WITHOUT LIMITATION ANY
IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT OF THIRD
PARTY INTELLECTUAL PROPERTY RIGHTS.
These resources are intended for skilled developers designing with TI products. You are solely responsible for (1) selecting the appropriate
TI products for your application, (2) designing, validating and testing your application, and (3) ensuring your application meets applicable
standards, and any other safety, security, or other requirements. These resources are subject to change without notice. TI grants you
permission to use these resources only for development of an application that uses the TI products described in the resource. Other
reproduction and display of these resources is prohibited. No license is granted to any other TI intellectual property right or to any third party
intellectual property right. TI disclaims responsibility for, and you will fully indemnify TI and its representatives against, any claims, damages,
costs, losses, and liabilities arising out of your use of these resources.
TI’s products are provided subject to TI’s Terms of Sale (https:www.ti.com/legal/termsofsale.html) or other applicable terms available either
on ti.com or provided in conjunction with such TI products. TI’s provision of these resources does not expand or otherwise alter TI’s
applicable warranties or warranty disclaimers for TI products.IMPORTANT NOTICE
Mailing Address: Texas Instruments, Post Office Box 655303, Dallas, Texas 75265
Copyright © 2021, Texas Instruments Incorporated