
This project implements a 32-bit quadrature motor controller and measurement unit operating at a 10 MHz master clock. It decodes 4X quadrature encoder signals (enc_a, enc_b) with a two-stage anti-metastability synchronizer, tracks signed 32-bit pulse counts, and calculates both rotational speed in RPM (over a 1-second measurement window) and angular position in degrees (0° to 359°, with sign).
The user selects the active measurement mode via uio[2] (0 = RPM velocity, 1 = angular position in degrees) and configures the encoder resolution from 1 to 255 pulses per revolution (PPR) using the 8-bit input ui[7:0] (with built-in division-by-zero protection when PPR = 0). The selected value is converted from 32-bit binary to BCD using a sequential Double Dabble state machine and driven onto a 6-digit multiplexed common-anode 7-segment display (5 numeric digits plus 1 negative sign indicator).
1 to 255) on the dedicated inputs ui[7:0] (for example, 100 PPR = 0x64, which yields 400 quadrature edges per revolution).uio[2]: set uio[2] = 1 to view angular position in degrees (00000 to 00359 or -00001 to -00359), or uio[2] = 0 to view rotational speed in RPM.rst_n = 0 then 1) to clear internal counters to zero.A leading B for forward rotation, B leading A for reverse rotation) on uio[0] (enc_a) and uio[1] (enc_b) at a frequency below 10 MHz, and observe the multiplexed 7-segment output on uo[6:0] and digit enables on uo[7] (an[0]) and uio[7:3] (an[5:1]).uio[0] and uio[1], operating at 3.3 V logic).ui[7:0] to configure the encoder PPR value).uio[2] to switch between RPM and angular position modes).a–g connected to uo[6:0] and digit anodes an[0..5] connected to uo[7] and uio[7:3] with current-limiting resistors).| # | Input | Output | Bidirectional |
|---|---|---|---|
| 0 | ppr[0] | seg[0] (g) | enc_a (in) |
| 1 | ppr[1] | seg[1] (f) | enc_b (in) |
| 2 | ppr[2] | seg[2] (e) | modo (in) |
| 3 | ppr[3] | seg[3] (d) | an[1] (out) |
| 4 | ppr[4] | seg[4] (c) | an[2] (out) |
| 5 | ppr[5] | seg[5] (b) | an[3] (out) |
| 6 | ppr[6] | seg[6] (a) | an[4] (out) |
| 7 | ppr[7] | an[0] (out) | an[5] (out) |