Path: Home => AVR-EN => Applications => Random ATtiny13 =&t; Random noise   Diese Seite in Deutsch: Flag DE Logo
Random colors 250*250 AVR applications

Random number generation with ATtiny13
Noise generation for random numbers in assembler

3 To generate noise for random numbers in assembler

The calculation of random numbers, while very effective and reliable, is rather boring: depending from the starters all the same row of numbers is generated, even if this row is very long. We try to use an electronic noise generator here, for which some additional components are necessary.

3.1 Failures to construct the hardware for a random noise generator

It has also to be possible here, to report on complete failures: that does not work as designed. My tries were not very succesful.

Random noise sources The standard approach is simple: Zener diode, resistor and done. Or: transistor with reversed (non-conducting) emitter-base, and done. I tried that standard approaches:
  1. The Zener diode with a pre-resistor, here with 1 kΩ, to have relevant current flow through the diode.
  2. A few NPN transistors from the spare part box, with the emitter-base in non-conducting direction, I tried 1 kΩ,10 kΩ, then 100 kΩ and even with 10 MΩ.
  3. A PNP transistor from the spare part box, also with different resistors.
The oscillograph in its most sensitive mode showed: nothing. A clean line, even when sharpend, nothing else but a clean line. Neither low nor high frequency noise on that line, simply nothing.

Noise amplifier Now, probably it is too small for my oscillograph to show, and it needs some amplification. To being able to work with small amplitudes, a FET opamp would be the right approach. CA3140s were still in my spare part box, so I used one of these.

Neither 10- nor 100-fold amplification showed and any difference. Only the 50 Hz from the 230V supply net showed up, if I used higher resistances of 100 kΩ and more. So I decided to add an RC filter for 500 Hz and below between the noise source and the amplifier. This reduced to 50 Hz, but did not bring any noise to the light of the day. Again: simply nothing showed up.

With a 10 MΩ in the back-coupling part of the CA3140 I increased the amplification to 1,000. And my oscillograph showed these pictures.

Random noise with BC547B This was the picture with 10 MΩ in the noise source, a BC547B NPN transistor, filtered with a 330 pF-10 MΩ high pass filter and an amplification of one. Based on the 50 Hz signal from my electricity supply net, rapid swings on top of the amplitude showed up. Those were so fast and so different from swing to swing that my oscillograph showed only a gray field on top. That would be random, I thought, even if that only happened on top of the 50 Hz swing for less than 20% of the complete time. Only the amplitude of the wild swings was a bit small.

An elevated gain of 10 in the CA3140 washed away those bellies completely and ended with a 50 Hz rectangle. Nothing you want to drive an ADC with.

If it does not work with an NPN, probably a PNP would be better? I found only three exemplars of BC557B in my spare part box, but those three didn't work either.

Probably a HF transistor would be better? A circuit from the internet used a BF199, so I tried that, too. As the circuit in the internet used a very small resistor of 1 k, I tried 10 kΩ. And changed the RC filter to 1 nF and 10 kΩ, which corresponds to 15 kHz.

And: the 50 Hz moved away completely due to the low resistance, replaced by a higher frequency swing, which was not very clear and somehow looked washed. Not of a high enough amplitude, but looked nice and noisy. Now some more gain (1.000) and the noise generator is complete.

Generator with BF199 This looked like a noise source with large enough amplitude and a noisy swing.

Generator without interfering pulses But: after I switched off the energy-saving lamp on my desktop, the swing did not show up any longer. It was simple interference from the lamp that caused the swing. Instead, at a higher oscillograph sensitivity though, this random noise showed up. Nice noise, but very small in amplitude.

The contribution of the base-emitter of the BF199 to that noise showed not much influence, when I removed it. Probably it was more the entry stages of the CA3140 or the resistors than the BF199 that produced that noise.

Note that the strange property of the circuit is that if you decrease the 10 ,kΩ on the negative input of the CA3140 to increase the gain, the noise does not increase but the 50 Hz from the electricity net comes through. Also if you increase that resistor, the noise disappears. It works only with the 10 kΩ resistor!

Here is my complete circuit.

Random noise generator with BF199 The RC filter of 33 kΩ and 1 nF on the output has the function of reducing higher frequent noise. That higher frequent noise would disable the ADC in the ATtiny13 because the sample+hold would not work. Because the ADC works with a clock signal of ca. 10 kHz, the RC filter is designed for half of that frequency. Most of the generated noise is removed by that filter, but the 50 Hz passes that. To not bring a voltage of more than 1.1 V to the AD converter input pin, a 10 kΩ resistor functions as limiter.

That output signal is attached to the noise generator input on the ATtiny13. The program measures this input, checks if the result is 0 or 0x03FF, and, if not, rotates the least significant bit of the result into the 24 already collected bits. No matter how good the amplitude of the noise generator is or if it is the 50 Hz only, this process produces extra noise. The last bit of the result corresponds to the following voltage sensitivity:
  1. Internal reference: 1.100 mV
  2. 10 bits resolution = 1024,
  3. corresponds to 1.07 mV for the last bit.

Noise generator version 2 Here a further try. As noise source serves a 2N2222 (NPN). The emitter-base diode is in reverse direction. The 150 pF capacitor suppresses higher frequent noise (fT=1/2/Π/R/C = 10 kHz), the second RC combination of 3,3 nF and 100 kΩ filters noise below 500 Hz. The resistor combination of 10 MΩ and 1 kΩ amplifies this noise band by a factor of 10,000.

Noise generator 2 - signal Also, this delivers not a really good noise signal. In the depth of the signal even this very high-frequent portion is visible (here with a gain of 50 mV/cm). How this high frequency passes the 33 kΩ/1 nF filter on the output is not rational. The signal is already seen on the output of the CA3140, prior to the RC filter on the output. This should not be there, but it is. A myterious artefact.

Noise generator 2 - Mounting And that is the noise generator 2 on the breadboard.

My final conclusion: I am not very proud of this design. It is more than nonsense and I do not recommend it for others that want to build a noise generator. I did not find a way to do it better, sorry for this.

But: practice has shown that it works, even though it should not. To find out why it works, even though it shouldn't, I tried a simple sine wave for randomness. See Chapter 4 that demonstrates that even a completely-free-of-noise-source works as noise generator!

Page top Main page Calculation Display Analysis sine wave

Praise, error reports, scolding and spam please via the comment page to me.

©2020 by