Zener Diode Noise Random Number Generator

From Makerpedia
Jump to navigation Jump to search

by Henry Sottrel

Project Overview

A simple electronic random number generator, using both analog and digital components. The generator I built was one-bit, so it generates a 1 or 0 with a 50% chance of each. However, the project could be extended to generate numbers in a larger range. The principle behind the generator is Zener Diode noise. A Zener diode does not allow current to flow through it opposite its bias until the voltage across it reaches the 'Zener Voltage'. Above this value, current can flow freely through the diode. However, at voltages very close to the Zener Voltage, the current through the diode is chaotic. Since the current is so unpredictable, we can generate a 1 or 0 randomly by checking whether the current is above or below its mean value.

Tools and Materials

  • Breadboard
  • Precision Adjustment power supply (+15V)
  • +5V/-5V Power Supply
  • Oscilloscope with voltage probe
  • Assorted Resistors (200Ω-1MΩ)
  • 15V Zener Diode
  • PN Junction Diode
  • Op-Amp x2
  • Capacitor (100 nF)
  • Shift Register Chip
  • Pushbutton
  • Parallel Register Chip
  • D-Type Flip-Flop x3
  • XOR Gate Chip
  • AND Gate Chip
  • LED x2

Project Files

Step-by-Step Instructions

Use the Zener diode to generate noise. Connect the Zener diode to the precision power supply and to a resistor with high resistance (I found 1MΩ works well) with the other side of the resistor at ground. The stripe on the diode which marks the forward bias direction should point towards the power supply. Use the oscilloscope and probe to measure the voltage at the ‘high’ end of the resistor. Experiment with different voltages around 15V to see what gives you a suitably random signal. These diodes have voltage ratings within a tolerance, so you will need to figure out what voltage works best for your diode. If the voltage is too low, the output signal will sit at 0 a lot of the time, and if it is too high it will sit at an some maximum value associated with the diode. You’re looking for the middle ground between these. Note that the signal will be very small and will have a very large frequency, so you will need to turn the volts/div and sec/div on your oscilloscope way down.

Amplify the noise signal with an Op-Amp. Use an op-amp designed for use in the 5V range, with the high Vcc input at ground and the low Vcc input at -5V. Connect the voltage you measured in the last step to the inverting (-) terminal with a 1kΩ resistor, and ground the non-inverting (+) terminal. Finally, connect the output to the inverting input using a 20kΩ resistor. Measuring the voltage at the output, this should be an inverting amplifier with a gain of 20. Since the input signal is positive, the output of this op-amp should be negative, and the amplitude should be 20x larger than the input. The ratio of the two resistors used determines the gain, so you can, for example, increase the amplification by replacing the 20kΩ resistor with a larger one. I found that a gain of 20 was large enough to work with the other components, so that’s what I used.

Remove DC offset. Connect a capacitor to the output of the op-amp from the previous step. Connect the other end to a resistor, and ground the other end of the resistor. Measure the voltage at the connection between the resistor and capacitor. This high pass filter should remove the DC offset of the amplified signal so it is centered at zero. Increasing R or C will increase the threshold frequency, allowing less and less of the low-frequency part of the signal. The challenge is that we want to keep the amplitude of the signal as large as possible while also ensuring it’s centered on zero. I used a 100nF capacitor and a 200Ω resistor, but you can test different values of RC to see what yields the best results for you by measuring the mean voltage using the oscilloscope and finding the lowest value of RC for which the mean is close to 0.

Convert the AC signal to DC using a Schmitt trigger. Using another op amp, with the high Vcc set to +5V and the low Vcc set to -5V, connect the output of the high pass filter Ωto the non-inverting (+) input with a 1kΩ resistor, and ground the inverting (-) input. Connect the output to the non-inverting input with a 20kΩ resistor, and finally connect a diode and 1kΩ resistor in series from the output to ground. This configuration of the op-amp will cause the output to be at +5V when the input is positive, and -5V when the input is negative. In theory, since the input signal is centered on 0, it should be negative about half the time and positive the other half, and the mean of the output should be zero. In practice, the signal will probably not have zero mean. Having zero mean is not essential, but it will help to generate bits more quickly later on. I found that the mean responded to small changes in the input voltages to the zener diode and the op-amps, so it might be worth varying these voltages to see how close to zero you can make the mean (Don’t turn the Vcc voltages on the op-amps too high or too low! If you change them by more than 1V in either direction there is a chance you will either fry the op-amp or that the digital part of the circuit will not recognize the high output of the schmitt trigger. It’s probably safer to mess with the voltage applied to the zener diode). The diode and resistor attached to the output are used to convert the analog high of +5V and low of -5V to a digital signal. When the output is 5V, the voltage on the other end should be about 4.4V, a digital high signal. When it is -5V, it should be 0V. Congratulate yourself on finishing the analog part of the circuit! The voltage on the ‘forward’ side of this diode should rapidly and unpredictably switch between 0V and 4.4V, which the digital part of the circuit will sample for random bits.

Set up a debounced pushbutton. Ground one side of a normally-closed debounced push button. Connect the other end to the +5V supply across a 10kΩ resistor. The non-grounded side of this pushbutton should be at 0V when it is not pushed, and about 5V when it is pushed. This pushbutton will act as the clock for the digital part of the circuit. The digital components are designed with a ‘CLK’ connection. When this input goes high, the component performs some simple operation. So pushing this button is what causes the circuit to perform operations.

Set up a 2-bit shift register. The output of the analog portion of the circuit should be either high or low, and the output should be random. However, it is not guaranteed that the odds of each are 1 in 2. So we will need to set up some digital logic to ensure that we generate 1 or 0 with exactly 50% odds. The way we can do this is to sample two bits from the analog portion, and if the two bits are different, then the first bit generated is our random bit. If they are the same, we throw both bits out and try again. This works because for a pair of events, the odds of ‘a, then b’ are always the same as the odds of ‘b, then a’, regardless of the individual probabilities of a and b. The first part of this digital circuit is a 2-bit shift register, so we can generate two bits and have other parts of the circuit reference them simultaneously. You can do this with a shift register chip or two D-type flip-flops. Either way, the CLK input(s) should be connected to the non-grounded end of the pushbutton. If using individual flip-flops, the input of the second flip flop should be connected to the first output. The input of the first flip flop or of the chip should be connected to the output of the analog part of the circuit, at the ‘forward’ end of the diode. When the button is pressed, the first output should go to the same value it read from its input, and the second output should go to the previous value of the first input. So pressing the button twice loads two new random bits into the shift register. Check that this works, both with the analog output and with manually set high and low voltages.

Build a digital frequency divider. Now that we have the ability to generate two bits, it makes sense to build in a way to compare them. But if we compare the bits in the shift register every single button press, then the second bit in a comparison will always be the first bit from the last comparison, so the bits we generate consecutively will not be independent of each other. Accordingly, we want to compare the bits every other button press so each comparison sees two brand new bits in the shift register. We also don’t want to compare bits on the very first two presses, since we don’t know what the shift register has in it at that point. We can do this by connecting three D-type flip-flops together input-to-output, with their clocks all connected to the same clock signal as the shift register. The input of the first flip-flop should be connected to its own ‘not Q’ inverted output. When all the outputs are 0, and the button starts to be pressed, the first two presses should not change the third output. On the third press onwards, every other press should send the third output high, and the next press should send it low again. This is a ‘frequency divider’ because if we press the button with a given frequency, the frequency with which the output of this block goes high will be ½ of the clock frequency.

Set up a parallel register and XOR gate. You’re almost there! A parallel register is a group of unconnected flip-flops with different inputs and a shared clock signal. Connect a d-type flip-flop to each output of the shift register, and connect their clocks to the frequency divider output from step 7. When the frequency divider output goes high, the outputs of these flip-flops should switch to be the same as the outputs of the shift register. These outputs should only change when the frequency divider signal goes high.

Comparing and displaying the generated bit. This is the last step! Connect the two parallel register outputs to an XOR gate. The output of an XOR gate is high only when the two inputs are different. So if this output is high, we know we have generated two different bits. Now connect the output of the XOR gate to an AND gate input, and connect the frequency divider input to the other AND gate input. So the AND gate input will go high when the frequency divider output goes high and there are two different bits in the parallel register. This is our signal that we have generated a bit successfully! Connect an LED-resistor pair in series between the AND gate output and ground. This is the ‘indicator’ LED. Connect another LED-resistor pair in series between one of the parallel register outputs and ground. This is the ‘bit’ LED. To generate a bit, press the pushbutton twice. If the indicator light turns on, the generated bit it 0 if the bit LED is off, and 1 if it is on. If the indicator light does not turn on, keep pressing the button until it does.