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
Supported Combinations
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
Launch a CCS debug session and run the executable, see CCS Launch, Load and Run
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!!