TRNG Tinkering - Page 1
Forum section: electronics / projects

author: Dabbot
author_rank: Regular Contributor
timestamp: July 08, 2020, 05:10:52 am
content: Here's my try at a TRNG. Note this is not for any larger endeavor. I'm merely pulling at the threads of entropy for further understanding.The majority of the circuit (attached) is an LM324 amplifying it's own noise, which is fed into a basic PIC micro for packaging and shipping. Initially I was simply collecting the LSB from each ADC sample, but it produced a fair amount of bias. I tried a chip with a 10 bit ADC and got similar results.So I wrote a program which generates each random bit by comparing the ADC sample to a pre-calculated threshold, effectively using the ADC as a comparator. But this on its own is not enough. So the program also keeps track of bias and adjusts a PWM accordingly, giving the noise circuit's virtual ground a very slight nudge until it's about balanced.The result is a bit stream which still has small localised bias, but tends toward a perfect 50/50 as more is collected. It's also important to note there is no post processing done on the bit stream (whitening / von Neumann etc.). I use a couple of Python scripts to do some very basic analysis on the output (tally bits & hex characters, basic patterns). Nothing approaching the diehard tests, which requires a few GB of sample data and me knowing where to start with them.

author: magic
author_rank: Super Contributor
timestamp: July 08, 2020, 06:18:35 am
content: Quote from: Dabbot on July 08, 2020, 05:10:52 amUse one opamp as comparator, lowpass-filter its output to drive the threshold, throw the PIC to trash

author: RoGeorge
author_rank: Super Contributor
timestamp: July 08, 2020, 06:18:51 am
content: If you need digital noise and have a microcontroller, you can use Von Neumann debiasing algorithm (Von Neumann Extractor) to make sure the ratio between the 0s and 1s is kept 50/50.From there, by integration you can get any shape you want for a custom probability distribution.

author: Dabbot
author_rank: Regular Contributor
timestamp: July 08, 2020, 06:42:04 am
content: Quote from: magic on July 08, 2020, 06:18:35 amI like your thinking. I'm going to try this.Edit: No good. The circuit oscillates. Decreasing the gain only causes it to oscillate less vigorously.

author: magic
author_rank: Super Contributor
timestamp: July 08, 2020, 02:40:12 pm
content: Well, an analog solution has the further disadvantage that you will never get it to output 50/50 unless you get offset voltages perfectly right.If you want to play with it, be sure to include some hysteresis (positive feedback) in the comparator. The threshold regulatorwillreact immediately to every bit from the comparator (with a slew rate dependent on the RC filter, but with zero delay). To avoid oscillation, the comparator needs to be prevented from reacting to that threshold correction before the analog input signal has a chance of toggling it a few times.At least that's how I feel about it.

author: Dabbot
author_rank: Regular Contributor
timestamp: July 08, 2020, 03:11:14 pm
content: Quote from: magic on July 08, 2020, 02:40:12 pmI realise that's not going to be possible, but I can always see how close I can get it.Quote from: magic on July 08, 2020, 02:40:12 pmI might give it a try using a separate comparator IC. Having the comparator thrashing about on the same silicon with all that gain present can't be helping either. Any hysteresis will need to be small, given the noise is only roughly 50mv RMS.

author: magic
author_rank: Super Contributor
timestamp: July 08, 2020, 04:04:53 pm
content: I doubt it oscillated due to inter-channel crosstalk. Some amount of hysteresis is necessary IMO, even if it's just 1/1000 of the output.A real comparator will have the advantage of much faster slew rate. Try TLC3702 or similar with a push-pull output stage (not open collector).A silly little simulation below. Looks a bit like a delta-sigma ADC but reacting to slope rather than absolute value.

author: Dabbot
author_rank: Regular Contributor
timestamp: July 09, 2020, 04:55:52 am
content: I just tried an open collector comparator with a 1K resistor (I don't have any push-pull types handy) and got respectable results.I didn't see any obvious difference by including hysteresis, according to observations on the oscilloscope. This might change once I start sending random samples to the PC.

author: RoGeorge
author_rank: Super Contributor
timestamp: July 09, 2020, 05:49:19 am
content: Again, why don't you apply a Von Neumann Debiaser to the ADC bit(s) you said they were unbalanced?Anyway, if you insist to keep the noise balanced in the analog domain, put a series capacitor. Also, a revese polarized BE junctions from a bipolar transistor makes a great noise generator, all those OpAmps are not needed.

author: Dabbot
author_rank: Regular Contributor
timestamp: July 09, 2020, 06:34:33 am
content: Quote from: RoGeorge on July 09, 2020, 05:49:19 amThat's part of the challenge. It's easy enough to do debiasing in software, but I wanted to have a good starting point.Quote from: RoGeorge on July 09, 2020, 05:49:19 amThis doesn't treat the ADC's bias.Quote from: RoGeorge on July 09, 2020, 05:49:19 amThe reason I came up with this circuit is it will run down to 3 volts. No charge pumps necessary to place BE junctions into avalanche. Besides, all those op amps are very cheap and come in a single package.