Main Content

C28x eQEP

Quadrature encoder pulse block used to derive position, direction, and speed

  • C28x eQEP block

Libraries:
C2000 Microcontroller Blockset / C2803x
C2000 Microcontroller Blockset / C2805x
C2000 Microcontroller Blockset / C2806x
C2000 Microcontroller Blockset / C280x
C2000 Microcontroller Blockset / C2833x
C2000 Microcontroller Blockset / C2834x
C2000 Microcontroller Blockset / F280013x
C2000 Microcontroller Blockset / F280015x
C2000 Microcontroller Blockset / F28002x
C2000 Microcontroller Blockset / F28003x
C2000 Microcontroller Blockset / F28004x
C2000 Microcontroller Blockset / F2807x
C2000 Microcontroller Blockset / F2837xD
C2000 Microcontroller Blockset / F2837xS
C2000 Microcontroller Blockset / F2838x / C28x
C2000 Microcontroller Blockset / F28M35x / C28x
C2000 Microcontroller Blockset / F28M36x / C28x
C2000 Microcontroller Blockset / F28p65x
C2000 Microcontroller Blockset / F28p55x

Description

The enhanced quadrature encoder pulse (eQEP) block is used along with a linear or rotary incremental encoder to get position, direction, and speed information from a rotating machine.

The eQEP peripheral module inputs include QEPA, QEPB, QEPI (index), and QEPS (strobe).

To configure your device to work with the block, navigate to Model Configuration Parameters > Hardware Implementation, select your device at Hardware board, and expand Target hardware resources.

Examples

Ports

Input

expand all

If the input is true, the position counter is initialized to the value in the Initialization value (0~4294967295) parameter.

Dependencies

This port appears only when, in the Position counter tab, you select Enable software initialization and set Software initialization source to Input port.

Data Types: Boolean

Input value that generates the position compare sync signal.

Dependencies

This port appears only when, in the Compare output tab, you select Enable position-compare sync signal output and set Compare value source to Input port.

Data Types: int8 | uint8 | int16 | uint16 | int32 | uint32 | single | double | Boolean

Software index event marker for latching the position counter.

Dependencies

This port appears only when, in the Position counter tab:

  • You set Position counter reset mode to Reset on the maximum position or Reset on the first index event.

  • You select Output latch position counter on index event.

  • You set Index event latch of position counter to Software index marker via input port.

Note

In Compare output tab, if Sync output pin selection is set to Index pin is used for sync output, then the Index event latch of position counter parameter cannot be set to Software index marker via input port.

Data Types: Boolean

Output

expand all

Position counter signal (PCSOUT) received from the position counter and control unit (PCCU).

Dependencies

This port appears only when, in the Position counter tab, you select Output position counter.

Data Types: int8 | uint8 | int16 | uint16 | int32 | uint32 | single | double | Boolean

Outputs the position counter error flag on an error.

  • 0 — No error occurred during the last index transition.

  • 1 — Position counter error.

Dependencies

This port appears only when, in the Position counter tab:

  • You set Position counter reset mode to Reset on an index event.

  • You select Output position counter error flag.

Data Types: int8 | uint8 | int16 | uint16 | int32 | uint32 | single | double | Boolean

Direction flag of the quadrature module.

  • 0 — counterclockwise rotation (or reverse movement).

  • 1 — clockwise rotation (or forward movement).

Dependencies

This port appears only when, in the General tab, you select Quadrature direction flag output port.

Data Types: int8 | uint8 | int16 | uint16 | int32 | uint32 | single | double | Boolean

Outputs the eQEP capture timer signal.

Dependencies

This port appears only when, in the Speed calculation tab, you select Enable eQEP capture and Output capture timer.

Data Types: int8 | uint8 | int16 | uint16 | int32 | uint32 | single | double | Boolean

Outputs the capture period signal, which holds the period count value between the last successive eQEP position events.

Dependencies

This port appears only when, in the Speed calculation tab, you select Enable eQEP capture and Output capture period timer.

Data Types: int8 | uint8 | int16 | uint16 | int32 | uint32 | single | double | Boolean

Outputs overflow error flag (COEF flag) in the event of capture timer overflow between unit position events.

  • 0 — Overflow has not occurred.

  • 1 — Overflow occurred in the eQEP capture timer register (QEPCTMR).

Dependencies

This port appears only when, in the Speed calculation tab, you select Enable eQEP capture and Enable and output overflow error flag.

Data Types: int8 | uint8 | int16 | uint16 | int32 | uint32 | single | double | Boolean

Outputs the direction change error flag.

  • 0 — Capture direction error has not occurred.

  • 1 — Direction change occurred between two capture position events.

Dependencies

This port appears only when, in the Speed calculation tab, you select Enable eQEP capture and Enable and output direction change error flag.

Data Types: int8 | uint8 | int16 | uint16 | int32 | uint32 | single | double | Boolean

Outputs the capture timer latched value from the QCTMRLAT register.

Dependencies

This port appears only when, in the Speed calculation tab, you select Enable eQEP capture and Output capture timer latched value.

Data Types: int8 | uint8 | int16 | uint16 | int32 | uint32 | single | double | Boolean

Outputs the capture timer period latched value from the QCPRDLAT register.

Dependencies

This port appears only when, in the Speed calculation tab, you select Enable eQEP capture and Output capture timer period latched value.

Data Types: int8 | uint8 | int16 | uint16 | int32 | uint32 | single | double | Boolean

Outputs position counter latched value from the QPOSLAT register.

Dependencies

This port appears only when, in the Speed calculation tab, you select Enable eQEP capture and Output position counter latched value.

Data Types: int8 | uint8 | int16 | uint16 | int32 | uint32 | single | double | Boolean

eQEP index input can be configured to latch the position counter register (QPOSCNT) as output on the occurrence of a definite event on this pin.

Dependencies

This port appears only when, in the Position counter tab:

  • You set Position counter reset mode to Reset on the maximum position or Reset on the first index event.

  • You select Output latch position counter on index event.

Data Types: int8 | uint8 | int16 | uint16 | int32 | uint32 | single | double | Boolean

eQEP strobe input can be configured to latch the position counter register (QPOSCNT) as output on the occurrence of a definite event on this pin.

Dependencies

This port appears only when, in the Position counter tab:

  • You set Position counter reset mode to Reset on the maximum position or Reset on the first index event.

  • You select Output latch position counter on strobe event.

Data Types: int8 | uint8 | int16 | uint16 | int32 | uint32 | single | double | Boolean

Parameters

expand all

General

The eQEP peripheral module used to obtain position, direction, and speed information. The number of eQEP modules supported varies for different C2000™ processors.

The eQEP peripheral inputs are QEPA, QEPB, QEPI, and QEPS. Configure the GPIO pins for these inputs by navigating to Configuration Parameters > Hardware Implementation > Target hardware resources > eQEP.

Input signals QEPA and QEPB to the eQEP peripheral are processed by the quadrature decoder unit (QDU) in the eQEP peripheral to produce clock (QCLK) and direction (QDIR) signals. Choose the position counter mode that matches the way the input to the eQEP module is encoded:

  • Quadrature-count — Two square signals (A and B) 90 degrees out of phase are sent to the eQEP peripheral. The QDU uses the phase relationship of these two inputs to generate quadrature clock and direction signals.

  • Direction-count — Direction and clock signals are directly sent to the eQEP peripheral. The QEPA pin provides the clock input, and the QEPB pin provides the direction input.

  • Up-count — The position counter is used to measure the frequency of the signal in the QEPA pin. The direction is hard-wired for up count in this mode.

  • Down-count — The position counter is used to measure the frequency of the signal in the QEPA pin. The direction is hard-wired for down count in this mode.

Set the direction of rotation.

If Clockwise is selected, the quadrature count operation is performed without swapping the quadrature clock inputs fed to the QDU.

If Counterclockwise is selected, reverse counting is performed by swapping the quadrature clock inputs fed to the QDU. The quadrature decoder reverses the counting direction.

Dependencies

This parameter appears only when you set Position counter mode to Quadrature-count on the General tab.

Select the resolution of the clock generator that the position counter uses as input so that the counting occurs on both rising and falling edges of the QEPA input or on the rising edge only. Choosing the former increases the measurement resolution by a factor of 2.

Dependencies

This parameter appears only when you set Position counter mode to Direction-count, Up-count, or Down-count.

Creates a port (qdf) on the block that gives the direction flag of the quadrature module.

Dependencies

This parameter appears only when, in the General tab, Position counter mode is set to Quadrature-count.

Inverts the polarity of the eQEP peripheral inputs. The Invert input QEPxA polarity checkbox corresponds to QEPA, Invert input QEPxB polairty corresponds to QEPB, and so on.

Enables the gating of the peripheral input index signal with the peripheral input strobe signal. In this case, the internal index signal is high only when both the peripheral input signals eQEPxI and eQEPxS are high.

Sample time for the block in seconds. To execute this block asynchronously, set this parameter to -1.

Position counter

Outputs the position counter signal PCSOUT from the position counter and control unit (PCCU). The position counter register counts up or down on every eQEP pulse based on the direction of the input. The count value is proportional to the position from a given reference point.

Enter a maximum value (QPOSMAX) for the position counter. If the position counter reaches QPOSMAX, the position counter is set to 0 on the next increment of the counter. If the position counter is 0, the position counter is set to QPOSMAX on the next decrement of the counter.

Enables option to set the position counter to its initialization value on an index event.

Sets the position counter to its initialization value on the rising edge or falling edge of the index event.

Dependencies

This parameter appears only when, in the Position counter tab, you select Enable set to init value on index event.

Enables option to set the position counter to its initialization value on a strobe event.

The Rising edge option sets the position counter to its initialization value on the rising edge of the strobe input. The Depending on direction option sets the position counter to its initialization value on the:

  • rising edge of the strobe input, in the forward direction.

  • falling edge of the strobe input, in the reverse direction.

Dependencies

This parameter appears only when, in the Position counter tab, you select Enable set to init value on strobe event.

Allows the position counter to be set to its initialization value using the software.

Choose the Set to init value at start up option to initialize the position counter to the value entered in Initialization value at the start of the execution of the program. Choose the Input port option to update the initialization value dynamically based on an input initialization signal (input port swi). If the input swi is true, the position counter is initialized to the Initialization value.

Dependencies

This parameter appears only when, in the Position counter tab, you select Enable software initialization.

Enter the initialization value for the position counter.

Dependencies

This parameter appears only when you select Enable set to init value on index event, Enable set to init value on strobe event, or Enable software initialization.

Position counter reset mode, depending on the nature of the system the eQEP module is working with.

  • Reset on an index event — If the index event occurs during the forward direction, then the position counter is reset to 0 on the next eQEP clock. If the index event occurs during the reverse direction, then the position counter is reset to the value in the QPOSMAX register on the next eQEP clock.

  • Reset on the maximum position — During the forward direction, when the position counter is equal to QPOSMAX, the position counter is reset to 0 on the next eQEP clock, and the position counter overflow flag is set. During the reverse direction, when the position counter is equal to 0, the position counter is reset to QPOSMAX on the next QEP clock, and the position counter underflow flag is set.

  • Reset on the first index event — If the index event occurs during the forward direction, the position counter is reset to 0 on the next eQEP clock. If the index event occurs during the reverse direction, the position counter is reset to the value in the QPOSMAX register on the next eQEP clock. The position counter is reset using the Reset on the first index event option only on the first index event occurrence. After the first index event occurrence, the position counter is reset based on the maximum position.

  • Reset on a unit time event — The QPOSCNT value is latched to the QPOSLAT register on a unit time event. The QPOSCNT register is then reset to 0 for the forward direction and QPOSMAX for the reverse direction. You can use this option for frequency measurement.

Outputs the position counter error flag on error. When you select this option, the output port pcef is created.

Dependencies

This parameter appears only when, in the Position counter tab, you set Position counter reset mode to Reset on an index event.

When this option is enabled, the position counter QPOSCNT latches into QPOSLAT on the occurrence of an event on the strobe pin.

Dependencies

This parameter appears only when, in the Position counter tab, you set Position counter reset mode to Reset on the maximum position or Reset on the first index event.

Configures the eQEP position counter to latch on the index event selected.

Dependencies

This parameter appears only when, in the Position counter tab:

  • You set Position counter reset mode to Reset on the maximum position or Reset on the first index event.

  • You select Output latch position counter on index event.

The eQEP strobe input can be configured to latch the position counter (QPOSCNT) into QPOSSLAT on occurrence of a definite event on this pin. This option latches the position counter on each strobe event.

Dependencies

This parameter appears only when, in the Position counter tab, you set Position counter reset mode to Reset on the maximum position or Reset on the first index event.

Rising edge latches on the rising edge of the strobe event input. Depending on direction latches on the rising edge in the forward direction and the falling edge in the reverse direction.

Dependencies

This parameter appears only when, in the Position counter tab:

  • You set Position counter reset mode to Reset on the maximum position or Reset on the first index event.

  • You select Output latch position counter on strobe event.

Speed calculation

To view the other parameters of this tab, select the Enable QEP capture option.

The eQEP peripheral includes an integrated edge capture unit to measure the elapsed time between the unit position events. This option enables the edge capture unit.

Outputs the capture timer value from the QCTMR register.

Outputs the period count value between the last successive eQEP position events from the QCPRD register.

The eQEP capture timer runs from prescaled SYSCLKOUT. The capture timer clock frequency is the frequency of SYSCLKOUT divided by the value you choose for this parameter.

The timing of the unit position event is determined by prescaling the quadrature clock (QCLK). QCLK is divided by the prescalar value you choose for this parameter.

Enables and outputs the eQEP overflow error flag (COEF) in the event of capture timer overflow between unit position events.

Enables and outputs the direction change error flag (CDEF) when direction change occurs between the unit position events.

Event that triggers the latching of the capture timer and capture period register:

  • On position counter read — Latch on position counter read by the processor. The capture timer and capture period values are latched into the QCTMRLAT and QCPRDLAT registers when the processor reads the QPOSCNT register.

  • On unit time-out event — Latch on unit time-out. The position counter, capture timer, and capture period values are latched into the QPOSLAT, QCTMRLAT, and QCPRDLAT registers on unit time-out.

Set the unit timer period.

Dependencies

This parameter appears only when you set Capture timer and position to On unit time-out event.

Outputs the capture timer latched value from the QCTMRLAT register at the output port qctmrlat.

Outputs the capture timer period latched value from the QCPRDLAT register at the output port qcprdlat.

Outputs the position counter latched value from the QPOSLAT register at the output port qposlat.

Compare output

To view the other parameters of this tab, select the Enable position-compare sync signal output option.

The eQEP peripheral includes a position compare unit that generates the position compare sync signal when the position counter register (QPOSCNT) and the position compare register (QPOSCMP) values match. This option enables the position compare sync signal output. The sync signal can be output using an index pin or strobe pin of the eQEP peripheral.

The GPIO pin used for the sync signal output. Use the index pin or strobe pin of the eQEP peripheral to output the position compare sync signal.

Source of the value to be used for the position compare register (QPOSCMP). When this parameter is set to Input port the input port cmp is created.

This parameter lets you enable or disable shadow mode for updating the position compare (QPOSCMP) register. When shadow mode is enabled, you can also choose an event to trigger the loading of the shadow register value into the active register. When shadow mode is disabled, the processor directly loads the value into the active register.

Load on QPOSCNT=0 loads on a position counter zero event, and Load on QPOSCNT=QPOSCMP loads when the QPOSCNT and QPOSCMP values match. When you select these options, shadow mode is enabled.

This value is loaded into the position compare register (QPOSCMP).

Dependencies

This parameter appears only when you set Compare value source to Specify via dialog.

The pulse stretcher logic in the position compare unit generates a programmable position compare sync pulse output on the position compare match.

A value from 1 to 4096 that determines the pulse width of the position compare sync output signal. The width of the output pulse, measured in SYSCKOUT cycles, is four times the entered value.

Select the polarity of the sync output signal generated.

Watchdog unit

The eQEP peripheral contains a watchdog timer that monitors the quadrature clock to indicate that the motion-control system is operating. The timer is reset on an edge transition of the quadrature clock. The watchdog unit generates an interrupt, which you can enable in the Interrupt tab.

The time period after which the watchdog unit generates an interrupt.

Dependencies

This parameter appears only when you select Watchdog timer enable.

Signal Data Types

When you select signals as output in the other tabs, the corresponding signals appear in this tab. For example, when you select the Output position counter option on the Position counter tab, the Position counter value data type option appears on this tab. Using this tab, you can select the data types of the signals.

The valid data types are auto, double, single, int8, uint8, int16, uint16, int32, uint32, and boolean.

The following table summarizes the options for which you can set the data type in the Signal data types tab:

PaneOption
GeneralQuadrature direction flag output port
Position counterOutput position counter (selected by default)
Output position counter error flag
Output latch position counter on index event
Output latch position counter on strobe event
Speed calculationOutput capture timer
Output capture period timer
Enable and output overflow error flag
Enable and output direction change error flag
Output capture timer latched value
Output capture timer period latched value
Output position counter latched value

Interrupt

Interrupts corresponding to specific events are enabled or disabled based on the settings in this tab. The generated interrupts are used with the C28x Hardware Interrupt.

Enables position counter error interrupts. The position counter interrupt is generated only in index event reset mode. When eQEP is configured in this mode, the position counter value is latched to the QPOSILAT register, and the direction information is recorded on every index event marker. If the latched value is not equal to 0 or QPOSMAX, the position counter error interrupt is generated.

Enables quadrature phase error interrupts. In quadrature count mode, the quadrature inputs QEPA and QEPB are expected to be 90 degrees out of phase. The quadrature phase error interrupt is generated when edge transition is detected simultaneously on the QEPA and QEPB signals.

When the direction of counting changes, the quadrature direction change interrupt is generated.

The eQEP peripheral contains a watchdog timer that monitors the quadrature clock. If no quadrature clock event is detected until the watchdog timer matches the watchdog period, time-out occurs and the watchdog timeout interrupt is generated.

Enables position counter underflow interrupts. In the reverse direction, if the position counter reaches 0, then the position counter is reset to QPOSMAX on the next QEP clock and the position counter underflow interrupt is generated.

Enables position counter overflow interrupts. In the forward direction, if the position counter reaches QPOSMAX, the position counter is reset to 0 on the next QEP clock, and the position counter overflow interrupt is generated.

Enables position compare ready interrupts. When the position compare register is configured for shadow mode, the position compare ready interrupt is generated after the shadow register value is loaded into the active register.

Enables position compare match interrupts. The position compare match interrupt is generated when the position counter value QPOSCNT matches with the active position compare register QPOSCMP.

Enables strobe event latch interrupts. The strobe event latch interrupt is generated when the position counter is latched to the QPOSSLAT register during a strobe event latch.

Enables index event latch interrupts. The strobe event latch interrupt is generated when the position counter is latched to the QPOSILAT register during an index event latch.

Enables unit timeout interrupts. The unit time-out interrupt is generated when the unit timer matches the unit period.