Encoder Interface Ug
Encoder Interface Ug
2 User Guide
Clockwise
Counter-Clockwise
The following figure shows the edge detection of encoder pulses for higher resolution.
Figure 2. Edge Detection of Encoder Pulses for Higher Resolution
Edge
Detect
The following figure shows the Theta output for the positive direction.
Figure 3. Theta Output for Positive Direction
A
The following figure shows the Theta output for the negative direction.
Important:
1. The data in this table is captured using typical synthesis and layout settings. CDR reference clock
source was set to Dedicated with other configurator values unchanged.
2. Clock is constrained to 200 MHz while running the timing analysis to achieve the performance
numbers.
1. Functional Description.............................................................................................................................6
3. Timing Diagrams..................................................................................................................................... 8
4. Testbench................................................................................................................................................9
4.1. Simulation.....................................................................................................................................9
5. Revision History.....................................................................................................................................11
Microchip Information................................................................................................................................... 12
The Microchip Website..........................................................................................................................12
Product Change Notification Service.................................................................................................... 12
Customer Support................................................................................................................................. 12
Microchip Devices Code Protection Feature.........................................................................................12
Legal Notice.......................................................................................................................................... 13
Trademarks........................................................................................................................................... 13
Quality Management System................................................................................................................ 14
Worldwide Sales and Service................................................................................................................15
reset_i
sys_clk_i
fil_trig_i
direction_config_i
clear_buffer_i
dir_o
sensor_reset_i
omega_out_o
qa_i encoder_interface
angle_out_o
qb_i
line_count_o
speed_factor_i
angle_factor_i
angle_count_max_i
speed_window_i
filter_factor_i
The encoder interface block converts signals received from QA, QB into its corresponding angle and speed. The
block counts encoder edges till the angle_count_max_i value is attained and then starts counting from zero again.
The angle generated is scaled to 262144 by multiplying it with the angle_factor_i. Speed is measured by counting
the number of encoder events in a constant time period defined by speed_window_i input. A filter is used to filter the
quantization noise from speed measurement. The filter time constant can be configured using the filter_factor_i value
using the following equation:
The sensor_reset_i input is used to find motor electrical angle by injecting constant current for a small duration.
When the motor has aligned to the injected angle, the encoder output is initialized with 90° or 270° based on initial
direction of rotation. The encoder edge counting is expected to start after the falling edge of the sensor_reset_i input
is detected.
The clear_buffer_i input can be used to reset the filter buffer, as the filter buffer is expected to be reset when the
motor stops.
The direction_config_i input is used to initially detect the motor direction. Once the motor starts running, the motor
direction is detected from the encoder signals and used in generating the angle.
qa_i
qb_i
angle_out_o 0 1 2 3 65
omega_out_o 0 45 300
Important: If you do not see the Catalog tab, click View, open Windows menu, and then click
Catalog to make it visible.
3. On the Stimulus Hierarchy tab, click the testbench (encoder_interface_tb.v), point to Simulate Pre-
Synth Design, and then click Open Interactively.
Important: If you do not see the Stimulus Hierarchy tab, click View, open Windows menu, and
then click Stimulus Hierarchy to make it visible.
ModelSim opens with the testbench file as shown in the following figure.
Figure 4-3. ModelSim Simulation Window
Important: If the simulation is interrupted due to the runtime limit specified in the .do file, use the run
-all command to complete the simulation.