
Quadrature x4 decoder with 15-bit up/down count and last-step direction.
A=ui_in[0], B=ui_in[1] (two-stage sync to clk)00→01→11→10→00 = +1 per edge; reverse = −1uo_out[7] — DIR (1 = forward, 0 = backward)uo_out[6:0] — COUNT [6:0]uio_out[7:0] — COUNT [14:7]Notes:
uio_out and uo_out[6:0].On hardware
ui[0] and ui[1].uo[7] → DIR (1 = forward, 0 = backward)uo[6:0] → count[6:0]uio[7:0] → count[14:7]uo[7]=1. Reverse: count decreases and uo[7]=0.Simulation (local)
make -C test clean testgtkwave test/tb.vcdui[0:1].| # | Input | Output | Bidirectional |
|---|---|---|---|
| 0 | A | COUNT0 | COUNT7 |
| 1 | B | COUNT1 | COUNT8 |
| 2 | COUNT2 | COUNT9 | |
| 3 | COUNT3 | COUNT10 | |
| 4 | COUNT4 | COUNT11 | |
| 5 | COUNT5 | COUNT12 | |
| 6 | COUNT6 | COUNT13 | |
| 7 | DIR | COUNT14 |