AM62L FreeRTOS SDK  11.00.00
EQEP Position Speed

Introduction

Position and Speed Measurement Using eQEP

This example provides position and speed measurement using the capture unit and speed measurement using unit time out of the eQEP module. ePWM0 and a GPIO are configured to generate simulated eQEP signals. The ePWM module will interrupt once every period and call the position/speed calculation function. This example uses the IQMath library to simplify high-precision calculations.

The configuration for this example is as follows

  • Maximum speed is configured to 6000rpm (baseRPM)
  • Minimum speed is assumed at 10rpm for capture pre-scalar selection
  • Pole pair is configured to 2 (polePairs)
  • Encoder resolution is configured to 4000 counts/revolution (mechScaler)
  • Which means: 4000 / 4 = 1000 line/revolution quadrature encoder (simulated by ePWM0)
  • ePWM0 (simulating QEP encoder signals) is configured for a 5kHz frequency or 300 rpm (= 4 * 5000 cnts/sec * 60 sec/min) / 4000 cnts/rev)

SPEEDRPM_FR: High Speed Measurement is obtained by counting the QEP input pulses for 10ms (unit timer set to 100Hz).

SPEEDRPM_FR = (Position Delta / 10ms) * 60 rpm

SPEEDRPM_PR: Low Speed Measurement is obtained by measuring time period of QEP edges. Time measurement is averaged over 64 edges for better results and the capture unit performs the time measurement using pre-scaled SYSCLK.

Note that the pre-scaler for capture unit clock is selected such that the capture timer does not overflow at the required minimum frequency.

This example wait for 10 iterations of unit time out event and verifies the measured speed: 295 < posSpeed.speedRPMFR < 305

  • posSpeed.speedRPMFR - Speed meas. in rpm using QEP position counter
  • posSpeed.speedRPMPR - Speed meas. in rpm using capture unit
  • posSpeed.thetaMech - Motor mechanical angle (Q15)
  • posSpeed.thetaElec - Motor electrical angle (Q15)

External connections

AM62LX-EVM

  • This example uses the user expansion connector (J2) in the board for testing on AM62LX-SK.
  • All pin numbers are on the expansion connector in the board.
  • The pins configured for the example is enabled on user expansion connector based on the FET selection switch(FET_SEL0).
  • The SOC_VOUT0_DATAn are the input to FET switches. The pins that are configured for the example are pinmuxed with the FET switches.
  • The S0 select pin decides if the configured pins (which is pinmuxed with SOC_VOUT0_DATAn) map to HDMI or USER EXP connector.
  • The S0 pin is triggered to a high value in the software. When the S0 is high, the pin that is configured for the example (which is pinmuxed with SOC_VOUT0_DATAn) will be available on the user expansion connector.

The below diagram depicts the selection:

S2 S1 S0 IP(nA)/OP(nB1 (Or) nB2)
H H L nA=nB1 -> SOC - HDMI
H H H nA=nB2 -> SOC - GPIO EXP CONN

Below is the connection details.

  • Connect EQEP0A to EPWM0A (simulates EQEP Phase A signal)
  • Connect EQEP0B to EPWM0B (simulates EQEP Phase B signal)
  • Connect EQEP0I to GPIO0_21 (simulates EQEP Index Signal)
  • Connect J2 Pin 19 to J2 Pin 18
  • Connect J2 Pin 14 to J3 Pin 7
  • Connect J2 Pin 15 to J2 Pin 23

Supported Combinations

Parameter Value
CPU + OS a53ss0-0 nortos
a53ss0-0 freertos
Toolchain arm.gnu.aarch64-none
Board am62lx-evm
Example folder examples/drivers/eqep/eqep_position_speed/

Steps to Run the Example

  • When using CCS projects to build, import the CCS project for the required combination and build it using the CCS project menu (see Using SDK with CCS Projects).
  • When using makefiles to build, note the required combination and build using make command (see Using SDK with Makefiles)
  • Establish connections as mentioned in External Connections section
  • To Load and Run an example (see Application Run and debugging using CCS)
  • View the UART console logs for results

See Also

EQEP

Sample Output

Shown below is a sample output when the application is run,

EQEP Position Speed Test Started ...
Please ensure EPWM to EQEP loopback is connected...
Please wait few seconds ...
Expected speed = 300 RPM, Measured speed = 299 RPM
Electrical angle (Q15) = 32716
Mechanical angle (Q15) = 16358
Rotation direction = CW, forward
EQEP Position Speed Test Passed!!
All tests have passed!!