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. MCPWM1A is configured to simulate
motor encoder signals with frequency of 5kHz 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µs
- 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 10ms).
speed : Measure motor speed in rpm
dir : Indicates clockwise (1) or anticlockwise (-1)
External Connections (if motor encoder signals are simulated by MCPWM)
With motor
- Comment in "MOTOR" in includes
- Connect GPIO6/eQEP1A to GPIO0/MCPWM1A (simulates eQEP Phase A signal)
- Connect GPIO7/eQEP1B to GPIO1/MCPWM1B (simulates eQEP Phase B signal)
Watch Variables
- freq : Simulated motor frequency
measurement is obtained by counting the external input pulses for UNIT_PERIOD (unit
timer set to 10ms).
- speed : Measure motor speed in rpm
- dir : Indicates clockwise (1) or anticlockwise (-1)
- pass - If measured quadrature frequency
matches with input quadrature frequency (4 * PWM frequency) then pass = 1 else fail = 1
(** only when "MOTOR" is commented out)