
This chip is a referee for a two-player game of rock-paper-scissors. Each player sets a 2-bit move on the input pins (00 = rock, 01 = paper, 10 = scissors, 11 = invalid). When the play input goes from low to high, the chip judges the round, shows the result, and adds a point to the winner's score. Ties show a tie result without changing either score.
The scores are 3-bit counters, so each one can go up to 7 and then stops there. A round with an invalid move does not change the scores and sets the result to 00 (no result). The clear input resets both scores and the result to zero, and holds them there as long as it stays high.
Edge detection on the play input means holding the button down only counts as one round. The play and clear inputs each go through two flip-flops (a synchronizer) so a button press that lands right on a clock edge can't cause a glitch. A real switch also "bounces" for a few milliseconds when pressed, which could count as several rounds. Setting ui[7] high turns on a debounce filter: play only changes after it has stayed the same for 262,144 clock cycles (about 5 ms at 50 MHz). With ui[7] low the filter is off.
The chip also has a ring oscillator: a NAND gate followed by a chain of 70 inverters, with the loop closed from one of four points. That gives 15, 31, 51 or 71 inverting stages, picked with uio[1:0] (00 = 15, 01 = 31, 10 = 51, 11 = 71). Because the number of stages is always odd, the loop can never settle and oscillates on its own. How fast it runs depends only on the real delay of the gates on the silicon.
Measuring all four lengths separates two things. The period grows by the same amount for every extra inverter, so plotting period against number of stages gives a straight line. Each edge has to travel around the loop twice per period (once rising, once falling), so the slope is twice the delay of one inverter, and the offset is twice the fixed delay of the NAND, the selector and the wiring. Comparing that measured inverter delay with what the open-source timing models predict is the experiment.
ui[6] turns the oscillator on. Its output is too fast to measure directly on a pin, so it drives a 24-bit ripple counter that divides it down. uio[3] shows the oscillator frequency divided by 2^8, uio[4] by 2^12, uio[5] by 2^16, uio[6] by 2^20 and uio[7] by 2^24.
Setting uio[2] high is a test mode: the counter runs from the normal clock instead of the ring, so the divider can be checked with a known input.
Example: rock (00) vs scissors (10) gives uo[1:0] = 01 and player 1's score goes up by one.
To test the ring oscillator:
The slowest outputs blink slowly enough to see on an LED.
None. The inputs can be set with the DIP switches on the demo board and the outputs read as raw bits on the LEDs or the individual segments of the 7-segment display.
| # | Input | Output | Bidirectional |
|---|---|---|---|
| 0 | P1 move bit 0 | result bit 0 | ring length select bit 0 |
| 1 | P1 move bit 1 | result bit 1 | ring length select bit 1 |
| 2 | P2 move bit 0 | P1 score bit 0 | test mode (divider runs from clk) |
| 3 | P2 move bit 1 | P1 score bit 1 | oscillator / 2^8 |
| 4 | play | P1 score bit 2 | oscillator / 2^12 |
| 5 | clear | P2 score bit 0 | oscillator / 2^16 |
| 6 | oscillator enable | P2 score bit 1 | oscillator / 2^20 |
| 7 | debounce enable | P2 score bit 2 | oscillator / 2^24 |