RTL Studio Open IDE

Edge, Debounce & Pulse

Quadrature Decoder x4 — L2 Upgrade

Quadrature Decoder x4 with windowed sticky inactivity flag.

About this block

Simulate it in the Verilog IDE

Mediumverilogsimsyn

Quadrature Decoder x4 — L2 Upgrade is a Verilog reference block in the Edge, Debounce & Pulse catalog. Edge detectors, debouncers, pulse stretchers, and one-shot generators. Marked Medium: more state or a wider datapath, still one workspace in the IDE.

This IP implements a high-performance quadrature decoder with x4 frequency multiplication. It accurately detects rotation direction (CW/CCW) from standard A/B phase inputs and includes a configurable windowed inactivity detector to identify when the encoder has stopped moving.

The design is synchronous, robust against noise via double-registering, and suitable for L2 integration in embedded systems.

This IP provides a robust, synchronous quadrature decoder with x4 resolution and inactivity detection. It is designed for easy integration into L2 systems, featuring metastability protection and configurable timeout thresholds. The included testbench ensures reliable operation for both CW and CCW rotation detection, as well as proper handling of inactivity flags and system resets.

  1. Choose Open in IDE. RTL Studio loads the packaged workspace for Quadrature Decoder x4 — L2 Upgrade.
  2. Read the Verilog module in the editor. The catalog line for this block: Quadrature Decoder x4 with windowed sticky inactivity flag.
  3. Run the packaged testbench with the in-browser Verilator simulator, then open the VCD in the waveform viewer.
  4. Run Yosys in the same IDE for a generic netlist. Sky130 liberty mapping is a separate Pro library option.

RTL Studio is the Verilog simulator and IDE around this block: Slang lint, Verilator, VCD waveforms, and Yosys, in the browser. Simulation guide · Yosys guide.

Features

  • x4 Resolution: Detects transitions on all edges of A and B phases.
  • Direction Detection: Identifies Clockwise (CW) and Counter-Clockwise (CCW) rotation.
  • Inactivity Detection: Configurable window counter to detect stationary encoders.
  • Sticky Flag: Maintains inactivity status until explicitly cleared.
  • Metastability Protection: Double-registering of inputs.

Architecture

  1. Input Synchronization: The a_b inputs are registered twice (a_b_d1, a_b_d2) to mitigate metastability and ensure clean edge detection.
  2. Transition Detection: The logic compares the current state with the previous state to identify valid quadrature transitions.
  3. Direction Logic: Based on the Gray code sequence of transitions, the direction (dir) is determined:

* 1'b1: Clockwise (CW) * 1'b0: Counter-Clockwise (CCW)

  1. Window Counter: A counter increments on every clock cycle where no valid transition is detected. It resets to zero on any valid transition.
  2. Sticky Flag: When the window counter reaches the window_cnt threshold, window_expired is set, which asserts sticky_flag. The flag remains set until explicitly cleared.

Ports

Port NameDirectionWidthDescription
clkInput1Clock input
rst_nInput1Active-low asynchronous reset
a_bInput2Quadrature A/B inputs
clear_stickyInput1Active-high clear for sticky flag
window_cntInput8Window counter threshold (0-255)
dirOutput1Detected direction (1=CW, 0=CCW)
sticky_flagOutput1Inactivity flag (sticky)

Verification

The testbench verifies five key scenarios:

  1. TC1: Basic CW rotation detection.
  2. TC2: Basic CCW rotation detection.
  3. TC3: Window expiry setting the sticky flag.
  4. TC4: Clearing the sticky flag.
  5. TC5: System reset functionality.

All tests passed successfully in simulation.

Test CaseDescriptionResult
TC1Basic CW rotationPASS
TC2Basic CCW rotationPASS
TC3Window sticky flagPASS
TC4Clear sticky flagPASS
TC5Reset functionalityPASS

More in Edge, Debounce & Pulse

All Edge, Debounce & Pulse blocks