Gambling with electronics… literally

Finally… I am done with my exams and there is time for some fun.

No, I didn’t spend a fortune in a casino. But I wanted to try some of the “games” that could be assembled with my Conrad kit which includes a breadboard and some basic elements. The binary die caught my eye (woah, a rhyme!) Most tabletop games require a die or two. It’s usually a plain old six-sided guy, although if you’ve played Dungeons & Dragons, you know there are some bizarre looking cousins of this die. The most famous being the d20, or a regular icosahedron if you prefer the geometric term. So there I was, dreaming of how spectacular it would be if I appeared at our next D&D session with a light show on a breadboard which is actually a 20-sided die.

However, I had to make the boring 6-sided one first. The idea is to use 3 LEDs of different colour, assigning the numbers 1, 2 and 4 to each colour. Then, while a button is pushed, the LEDs will change their condition quickly and make it impossible to recognise any number. After the button is released, the LEDs remain in a stable condition and the rolled number can be read. It is the sum of the LEDs that remain lit.

scheme

The circuit used, with NAND gate, binary counter, resistors, capacitor and the three LEDs

 

In theory this is great. The cycle for switching through the conditions is achieved with the NAND-gate. The resistor R1 and the capacitor C1 determine the cycle speed. The cycle is only applied to the binary counter (IC2) when the button is pushed. If the button is not pushed, the cycle input (CPU) is connected to ground across the pull-down resistor R2. So far so good… here’s the messy part:

From the Conrad manual:

The inputs D0 to D3 specify that the counter is to start at 1. For this, only the input D0 (pin 15) is connected to high. The inputs D1 to D3 are connected to ground (low level). The counter reading is always reset to 1 when the pin PL (11) is pulled to low level. This should be done after the number 6, since the number 7 is not permitted. Resetting to 1 takes place with the number 7; then all outputs (Q0 to Q3) have a high level. The three NAND-gates are switched to result in a NAND gate with three inputs. For three high levels at the inputs, a low level results at the output of IC1D (pin 11). The low level thus resets the counter reading to 1. Resetting is so fast that the counter reading 7 (all at high level) is not visible.

Alright, so I hooked up everything, I checked the circuit and here’s what happened:

OLYMPUS DIGITAL CAMERA

The circuit, ready to rock

OLYMPUS DIGITAL CAMERA

Pressing the button and…

Red and only red. Checked everything again – no change. Is red my lucky number, or I just messed up big time? Then I noticed the button was pretty wobbly, it actually jumped away from the board when I tried to push it harder and let it go. So… My plan for troubleshooting is: set it up without a button (I’ll use wires instead); check for other errors; check for errors in the circuit itself and find alternative ways for building dice.

This post and project is indeed a failure… For now. Hopefully, with some holidays coming, I’ll have the time for a follow-up and a fix. Meanwhile, if anyone who stumbles upon this has something to say, please do. Surely tabletop games will be perfectly fine without my clumsy circuit dice, but I still wanna do this. Maybe other gambling tools in the future too. The ways of achieving randomness via electronics fascinate me!

3 comments

  1. Oh this circuit smells like fun 🙂 It is a proof that with electronics (ah well, not only) many things can go wrong even if one is using the simplest possible circuits to achieve his goals. I have always been in favour of simple designs and such do breathe a lot of charm, however in some cases simplicity pushes us to sacrifice some qualities. I believe that here this is also the case.

    Having a look at the ripple-carry counter, everything around it seems quite ok, the count_up pin has its pull down, the initialization port D0,D1,D2 and D3 are connected so that the counter is reset in 0001 state – just as we want it to do. CPD is high, so our counter would count upwards and would be enabled. Master reset MR pin is low, and as you said we are ready to rock. There is however something fishy around this oscillator. It is the simplest possible form of relaxation oscillator and it should often work quite well, nice idea to use the last NAND gate from the second IC as a NOT element, however with this structure there are some details to have in mind. The timeconstant of the oscillator should be about 1ms, which sounds good, however there is a chance that the circuit becomes metastable and locks at some mid-point. For example when the voltage on C1 rises gradually at some point it would reach the threshold voltage of the NFET in the IC, in the same time however it would also reach the Vth levels of the PFET, depending on the process it could happen that both the NFET and PFET are in semi-conducting state and somehow balance-out, in this case, we get a stopped oscillator somewhere in-between a logic ‘1’ and ‘0’.

    Some debugging ideas that come to my mind.
    1) Check if everything with the counter is working as expected. Take a wire and connect and disconnect pin 5 to V+ a couple of times and see if the counter is actually counting. If yes and if it is resetting properly, we can definitely have a main suspect – the oscillator.
    2) The pull down R2 with its 3.3K seems a bit on the low side, remove it and connect the oscillator to pin 5 directly. If it works, then R2 had a too low impedance and the gate’s PFET transistors were struggling to pull-up at a high enough level so that the node on pin 5 passes the threshold voltage of the NAND gate inside the counter IC.
    3) If 2 does not work, change the value of R1 or C1, or flip R2 with R1 if you don’t have suitable resistors lying around.
    4) If you happen to have an oscilloscope skip 2) and 3) and see if that guy is actually oscillating. Maybe also try to connect an LED with a 10k resistor in series to the output of the oscillator and then nod your head quickly and observe if the LED is flickering.
    5) If it still does not oscillate, try to kick-start the oscillator by connecting the cap to V+ for a very short time.
    6) If all of the above still does not work, go to the nearest supermarket, buy a pack of beans, go back to your desk, close your eyes, start throwing beans around the bench and mumble “oh you mighty gods of dice, hear my inquiry for resurrection, it shall liiiivve, liiiive” 🙂

    The last one has worked quite well for me a number of times. Never be scared of failures… and beans. It is all about the failures that keep us excited to go forward and fight with our circuits until they start doing what we want them to do.

    Like

  2. Oh that was long… One last idea that pops on top of my head now, it would be really cool to have a dice, which looks like it behaves randomly but in fact follows a specific law about which only we know about, so you can easily cheat to your enemies. For this I propose one very fun circuit called a Linear Feedback Shift Register (LFSR). This circuit is used everywhere as a pseudo random number generator. It is exactly predictable and very simple to implement with just XOR gates and flip-flops for shifting the data. Here’s a general description of the principle: http://en.wikipedia.org/wiki/Linear_feedback_shift_register

    Like

Leave a comment