Introduction: DIY Digital Dice
This Instructable describes how to design Digital Dice, a true random number generator from 1 to 6. This device can be used instead of a commonly used dice. It has a 1-digit 7-segment LED display and two buttons: "Run" and "Display Previous". The Digital Dice can be powered from a single CR2032 battery. It has no power-on switch due to negligibly low power consumption when idle.
Below we described steps needed understand how the GreenPAK chip has been programmed to create the Digital Dice. However, if you just want to get the result of programming, download GreenPAK software to view the already completed GreenPAK Design File. Plug the GreenPAK Development Kit to your computer and hit program to create the custom IC to control your Digital Dice.
Step 1: Device Architecture
The design consists of the following blocks:
- Entropy Generator
- Linear Feedback Shift Register
- Binary to 7-Segment Decoder
- Control Unit
- Macrocell Settings
Step 2: Entropy Generator
The entropy generator is built of four asynchronous oscillators. Two of which are built using an inverted closed-loop LUT with delay (1 MHz and 6.5 MHz). Two others are GreenPAK's OSC1 (2.048 MHz along with a divide by 3) and OSC2 (25 MHz divided by 2).
Inputting a few asynchronous clock signals to XNOR gate is enough to get an unpredictable signal on its output (noise or entropy). But the macrocells within the SLG46826V allow making even more complicated solutions. Using one more oscillator and DFF we get a completely random signal.
Step 3: Linear Feedback Shift Register
The 3-bit LFSR is built using three DFFs and one XNOR gate. This block with each input clock generates a 3-bit pseudo-random number. Here, instead of a clock pulse, the noise signal goes into the LFSR's input, generating a true random 3-bit number.
Step 4: Binary to 7-Segment Decoder
In order to convert the 3-bit random number generated by the LSFR, the Binary to 7-segment decoder is used, see Figure 3. The decoder is built of 3-bit LUTs.
Step 5: Control Unit
The control unit is a part of the device designed to start it and stop after the 3-second period. Two pins are configured as inputs and two buttons must be connected from VDD to those pins. While the button "Run" is pressed, the device continuously generates random numbers. Right after the button is released, the generation stops and LFSR latches its outputs. The decoder subsequently drives a 7-segment display. After a 3 second period, the Digital Dice goes idle. The device is still powered on, but because all oscillations have been turned off, the current consumption is extremely low. This allows the device to "remember" the last generated random number. If the button "Display Previous" is pressed, the last generated random number will be displayed until the button is released. Because Digital Dice is designed to replace usual dice, the 3-bit LUT12 is used to restart it when "0" or "7" occurs. This ensures the device will generate a random number in the range of 1 to 6.
Step 6: Macrocell Settings
For each macrocell, settings refer to the tables above.
The Digital Dice can be used as a replacement of usual dice in casinos or when playing any other games where dice are needed. It has an entropy generator that is constantly generating 3-bit random numbers while the button "Run" is pressed. It stops and displays the result only when the button is released, so the human factor also affects the generated random number. Four asynchronous oscillators together with human button push variability make the device completely and desirably unpredictable.