FILE: eqep_ex5_speed_dir_motor.c
This example can be used to sense the speed and direction of motor using eQEP in quadrature encoder mode. ePWM1A is configured to simulate motor encoder signals with frequency of 5 kHz on both A and B pins with 90 degree phase shift (so as to run this example without motor). EQEP unit timeout is set which will generate an interrupt every UNIT_PERIOD microseconds and speed calculation occurs continuously based on the direction of motor
The configuration for this example is as follows
- PWM frequency is specified as 5000Hz
- UNIT_PERIOD is specified as 10000 us
- Simulated quadrature signal frequency is 20000Hz (4 * 5000)
- Encoder holes assumed as 1000
- Thus Simulated motor speed is 300rpm (5000 * (60 / 1000))
freq : Simulated quadrature signal frequency measured by counting the external input pulses for UNIT_PERIOD (unit timer set to 10 ms).
speed : Measure motor speed in rpm
dir : Indicates clockwise (1) or anticlockwise (-1)
External Connections (if motor encoder signals are simulated by ePWM)
For External connections, Control Card settings are used by default. To use launchpad pins for output select them in SysConfig.
- On controlCARD, Connect GPIO25/eQEP1A to GPIO0/ePWM1A
- On controlCARD, Connect GPIO29/eQEP1B to GPIO1/ePWM1B
- On LaunchPad, Connect GPIO40/eQEP1A to GPIO10/ePWM6A (simulates eQEP Phase A signal)
- On LaunchPad, Connect GPIO41/eQEP1B to GPIO11/ePWM6B (simulates eQEP Phase B signal)
- Comment in "MOTOR" in includes For External connections, Control Card settings are used by default. To use launchpad pins for output select them in SysConfig.
- On controlCARD, Connect GPIO25/eQEP1A to encoder A output
- On controlCARD, Connect GPIO29/eQEP1B to encoder B output
Watch Variables
- freq : Simulated motor frequency measurement is obtained by counting the external input pulses for UNIT_PERIOD (unit timer set to 10 ms).
- speed : Measure motor speed in rpm
- dir : Indicates clockwise (1) or anticlockwise (-1)
- pass - If measured qudrature frequency matches with i.e. input quadrature frequency (4 * PWM frequency) then pass = 1 else fail = 1 (** only when "MOTOR" is commented out)