Show Posts
Pages: 1 2 [3] 4 5 ... 59
31  Using Arduino / General Electronics / Re: Which Handheld Oscilloscope? on: June 02, 2014, 01:29:22 pm
But no trouble at all learning how to use a bus pirate?

No learning to use any digital tool seems to be much easier than learning to properly use an analog tool like an oscilliscope.  Personally, I find the bus pirate quite easy to use, certainly easier than what I would originally use, a microcontroller I would program for a specific test I needed.  Having a tool I can plug into my USB port and perform two-way communication over UART, SPI, I2C, etc... is very helpful for debugging.  Add in a couple of channels as a logic analyzer, and you might be suprised how easy and helpful it is.

DSO Quad $200 plus shipping.

Sorry you country inflates the true costs so much.

The cost for the DSO Quad I provided was straight from the chinese suppliers web site...  It was also for the new model which is the one with the specs you cited earlier as opposed to the previous generation which is being sold for about 40% less.  Of course that previous generation has specifications about half what you cited (36Msps / channel when both channels used).

Given that the same supplier can provide me the 1Gsps Scope I mentioned for $400, I suspect the differences in the costs your quoting must be locally (to you) inspired or perhaps that I was quoting an actual retail source as opposed to ebay...

Either way, I stand by my opinion that these toy 'oscilliscopes' are a bad investment for most hobbyists.
32  Using Arduino / General Electronics / Re: Problem reading random noise generator on: June 02, 2014, 01:19:18 pm
Without having kept detailed records of what my median is, having run it ~100 times over the past day or so, the calculated median is always between 50 and 60, inclusive. Is this a problem?

Your seeing about a quarter of the typical variation I see in my circuits.  I suspect that this may be because your not getting enough range in either your noise or perhaps in the A2D conversion.   The next step I would do is run a program to capture about 50,000 raw a2d values.  With any luck you can either use the internal 1.1V AREF or pick up an external AREF to maximize the range your A2D is capturing the noise.  Personally, I have found adjusting the AREF to be easier to do than small amplifications (say 1.2-2.6...) to get a full range (or nearly so).

BTW, good notes can help considerably with identifying an fixing problems.

Thank you for your patience and your exemplary assistance! You're really helping me to slowly understand every aspect of the problem. Thanks!

Your welcome!

I have posted a scope capture for a sample of my 2N3904 noise circuit which you can use as a basis of comparison.  You can see the output at https://sites.google.com/site/astudyofentropy/project-definition/avalanche-noise

Using all of the whitening I apply, that circuit can generate a little over 40MB of random bytes per day.  So far one particular implementation has generated about 18Gb of random data.
33  Using Arduino / General Electronics / Re: Problem reading random noise generator on: June 02, 2014, 11:56:10 am
Thank you. My median is always roughly 54, so I should be fine.

BTW, depending upon your definition of roughly, this could be another indicator of a problem.  Not counting the extremes my circuit has exhibited over time, the median (which I recalculate every 10,000,000 bytes) varies considerably from about 80 up to about 120.  If your not seeing a decent amount of variation in your median you probably have either a circuit problem or a software one.
34  Using Arduino / General Electronics / Re: Problem reading random noise generator on: June 02, 2014, 11:53:45 am
Yes that is the code.  In order to correctly 'slice' a random number to a smaller range you need the ability to get an additional random number so the first can be discarded if it doesn't 'slice' up properly, which occurs somewhat rarely depending upon the random size and the divisor.

So you don't need to have a pool, you just need to have your maping calls call whatever function you want to generate random numbers.  That way, if the particular 8-bit value doesn't slice properly (this is a relatively rare condition) you can try with the next 8-bit random value.  You can get away with a straight modulus operation, but only if the divisor is a power of two.


BTW, what is the variance or standard deviation on your raw analog reads (8-bit adjusted)?  A median of 56 isn't bad at all, but if the standard deviation is small you may not have enough range in your noise levels to work well.  I am concerned that may be the case since your only running 9V.  Granted my tests were with the 2N3904, but I needed at least 10V with that transistor to get decent range of noise.  In my circuits I was getting a vmin of about 40mV and a vmax of about 2.3V (I adjusted input voltage to get this range), I then used a Aref of 2.5V to maximize the initial resolution of the A2D. 

If you max voltage is below 1.1 you could use that internal reference, and maximize the resolution of the A2D.  This by itself will help eliminate some of the bias you generator is experiencing.
35  Using Arduino / General Electronics / Re: Which Handheld Oscilloscope? on: June 02, 2014, 09:30:19 am
Yep. It's the perfect blend for Arduino work.

Not in my opinion, and most certainly not for beginners who would not likely know how to use a scope and will have a harder time learning with such a limited device.

I agree that the DSO Quad is imperfect. The bandwidth is rubbish, the buttons are far too fiddly, a bigger screen would be nice, but what "real" 'scope can give me the same functionality? How much does it cost?

Costs are relative to where you live.  I posted the costs for both devices in my country.  DSO Quad $200 plus shipping.  New Scope Abt $400.  Used scopes < $100

Logic analyzer functions, bus pirate about $40...  This one device can do most of what a beginner needs, and add in a good used analog scope and they are sitting pretty (IMO).

The nearest thing I know of would be the Rigol DS1052D. That's over $600.

Sorry your country inflates the true costs so much.  What is the used market like for scopes?
36  Using Arduino / General Electronics / Re: Problem reading random noise generator on: June 02, 2014, 09:18:11 am
1) Do not filter the data you are getting from the noise circuit.  It is not needed, and it can severely affect bias.

2)  You basic mapping is flawed.  You are using a modulus operator which by itself is introducing additional bias.  To prove it to yourself, produce a fake data set with a perfect uniform distribution say 0-255, 100 times each.  Then apply your mapping using the modulus operator to that data set.  Since the input data set has a perfect uniform distribution, you would expect your mapped distribution to be perfectly equal.  It will not be.  If you look at the library code in my sig you can find code that maps the input data set to a smaller range while preserving the uniformity of the original.

3) Get down to the basics in your code.  First, just capture the pure analog readings after right shiting the analog read twice (to turn the 1024 bit read into an 8 bit value) by dropping the two least significant bit.s  Take say 50,000 samples and manually calculate the median.  For my circuits, it averages between 80-90.  YMMV, however, as long as it is above say 50 or so and you have a standard deviation of at least 10-20, you don't need any additional amplification to work with your circuit as is.

4) Only after 1-3 are done and working, should you start adding code one step at a time to first turn analog readings into bits, then bytes.  Then start adding whitening as needed to get a uniform distribution.

When testing how much whitening is needed, here is the order I add whitening.

First Von Neumann.

Then XOR on byte, then 32-bit level

If the XOR doesn't cut it, I replace the XOR step with a linear shift register.  I like the jenkins one at a time hash.

P.S.  I posted working code for both the Von Neuman and the Jenkins hashing function in http://forum.arduino.cc/index.php?topic=244024.msg1748064#msg1748064 of this thread.
37  Using Arduino / General Electronics / Re: How to calculate voltage drop ? on: June 01, 2014, 03:52:05 pm
And if it's a 30K resistance ?

The analog inputs on the Arduino are reasonably high impedance, so your straight voltage divider isn't going to be much of an issue.  Of course, that is unless you are doing all of the other hoop jumping required to get a accurate voltage reading from the ADC.  Most folks who use the ADC are happy with 'close enough', which is what you see implemented in nearly all Arduino examples.

What would be the 30k resistance you are asking about?

My suggestion is to build your circuit and compare the values you are getting from the Arduino with what you read from a voltmeter, and what you 'think' you should be getting--for instance measuring the voltage being divided and doing the math for the voltage divider. If your measurements (either Arduino or Voltmeter) don't match come back with specific vallues if you have any questions.
38  Using Arduino / General Electronics / Re: Which Handheld Oscilloscope? on: June 01, 2014, 03:46:31 pm
Considering that 100MHz DSO scopes with sample rates of 1Gsps are available for not much more money...

For example...?

AS far as I can tell a bottom of the range two channel scope will cost at least twice as much.

And ... 2 channels really isn't enough. I could probably get by with 3 channels* but I don't think I'd pay $400+ for something with only 2 channels, not when I know I regularly use more than that.

A "real" 4 channel DSO is going to cost way more than $400.

(*Do they make 3-channel 'scopes?)



The DSO Quad is a two channel scope and a separate two channel logic analyzer, not a four channel scope.
39  Using Arduino / General Electronics / Re: Which Handheld Oscilloscope? on: June 01, 2014, 03:42:45 pm
Considering that 100MHz DSO scopes with sample rates of 1Gsps are available for not much more money, people would be better off buying a real scope than spending money on something of dubious performance.

My DSO Quad is costing £115 with free delivery. My research suggested that the cheapest better alternative would have cost about twice that - and I don't think it was anywhere near 1Gsps.

I couldn't justify the extra money for something I will only use occasionally. I would prefer to spend the money on other Arduino hardware.

...R

If you don't mind I'll make my argument in dollars (not good at equivalent).  I can but the DSO quad for $199 plus shipping from Seed Studio.  I can get a Rigol 1052E 1Gsps scope from Amazon for $388 (w free shipping), so a cost difference of roughly $188.  Your mileage may vary.   So yes, brought new a scope is nearly twice the price (though well worth it).  However, there are a nearly unlimited supply of $50-$100 analog scopes out there on the used market, nearly any of which is more effective then the DSO quad as a scope.  The quad's one useful function (and why 4-chalnnels are useful) is as a logic analyzer..  However, as a scope its functions are very limiting.

I am an amateur, and I spent years avoiding spending money on a scope. Including buying a variety of products similar to the DSO quad but was never very happy with any of them.  For me the purchase of my first scope and later my first digital scope were eye opening experiences.  It isn't until you use a real scope, without the inherrent limitations in things like the DSO quad that you realize what your missing.

In my opinion, if you can't spend $400 on a scope, then don't spend $200 on a toy scope--I don't believe the difference is significant.  Learn to work around the limitations (very doable for hobbyists).  The cheaper item will (in my opinion) disappoint most people.  Curiously, the OP with experience with real scopes may be the besr type of hobbyist to be happy with the DSO Quad. Knowing how to use a real scope can make working the toy scopes easier and more productive; however, learning to use a scope with just the toy is much harder.    For instance, are you square waves looking like sine waves because of a problem with your circuit, or because the bandwidth limitation on your 'scope' is filtering out the harmonics?
40  Using Arduino / General Electronics / Re: Hot to calculate voltage drop ? on: June 01, 2014, 03:00:52 pm
It is the impedance/load of what you connect to Out, not the supply voltage from the Arduino.

As a rule, with resistances around 10K (like your example) you are fine with the theorectical value (no need to include load) when connecting the voltage divider to an analog in.  If there is any concern, you can connect an op amp buffer to your out, which presents the out with that ideal high impedance, and provides an ideal 'low impedance' out to whatever device you need to measure the out.

Here is a schematic for a buffer;
41  Using Arduino / General Electronics / Re: Hot to calculate voltage drop ? on: June 01, 2014, 02:22:40 pm
To expand upon the two previous answers.

If your 'load' at that point has a high impedance (resistance), you get a good approximation of the voltage as Vout = (R2 / (R1+R2) * Vin.  Or using your values Vout = (16000 / (25000) * 5 = 3.2V

However, if your 'load' at that point has a low impedance (resistance), say 1000 ohms the numbers change quite a bit since the load is in parallel with R2 (16k).

Two resistors in parallel have a resistence is Rnew = 1 / (1/R1 + 1/R2) = 1 / (0.001 + 0.0000625) = 941 ohms

So your out voltage would be 5V * (941 / 9941) or about 0.5V..   Think I did that math correctly...

'Corrected my error with R1/R1 in the voltage divider formula!
42  Using Arduino / General Electronics / Re: Problem reading random noise generator on: June 01, 2014, 02:03:35 pm
yep, but with lm393 replacing 2nd xistor stage, op pulled up to give what I hoped was a random stream of digits, which I could count 8 off at a time to give me a series of random 8bit numbers, or so I naively thought....but hey im a,relative newbie to amps n volts, so I forgave myself. it seemd like a good idea. it taught me how to bias a transistor, at least...so it was worthwhile for my hobby needs. my main aim in all this is to learn learn learn not make millions designing a better microwidget.

the "zener" was a ZXRE4041 OR 1004 cant remember which and the peak noise current was something like 7 or 8 uA I think, which is bang in line with what the other far more knowledgeable posters have said. I shall drop out now in the presence of such greatness, my 2c has been spent! these blokes know whst they are on about, im just a nosey amateur.

Sounds like you use this circuit as a basis; https://mywebspace.wisc.edu/lnmaurer/web/minirng/minirng.html  Which uses a ZXRE1004 voltage reference (kindof a zener) as the noise source.  The key to that circuit is the use of a high slew rate single sided rail to rail op amp.  The author used a OPA2340 (or a MCP6282), I don't think a LM393 would be up to the job.  I implemented the circuit with the original OPA2340 as well as my go to MCP629x series, and both worked great.  Even though the circuit produced a good balance of 1's and 0's (near 50/50) it still required a fair bit of whitening to produce a uniform distribution.  Attached are two graphs.  The first shows the distribution with no whitening, the second shows a two tiered whitening approach; Von Neumann followed by a Jenkins one at a time hash. 

Here are the ent results for the first test; followed by the results for the second
Code:
Entropy = 7.655314 bits per byte.

Optimum compression would reduce the size
of this 22124796 byte file by 4 percent.

Chi square distribution for 22124796 samples is 12926784.31, and randomly
would exceed this value less than 0.01 percent of the times.

Arithmetic mean value of data bytes is 126.1181 (127.5 = random).
Monte Carlo value for Pi is 3.375643870 (error 7.45 percent).
Serial correlation coefficient is -0.000318 (totally uncorrelated = 0.0).

Code:
Entropy = 7.999928 bits per byte.

Optimum compression would reduce the size
of this 2679092 byte file by 0 percent.

Chi square distribution for 2679092 samples is 266.62, and randomly
would exceed this value 29.59 percent of the times.

Arithmetic mean value of data bytes is 127.5069 (127.5 = random).
Monte Carlo value for Pi is 3.143365844 (error 0.06 percent).
Serial correlation coefficient is -0.000298 (totally uncorrelated = 0.0).

Which just goes to show how nescessary whitening is for any TRNG.

Here is Arduino functions to implement the two whitening algorithms I used:

Code:
uint8_t pool[POOL_SIZE];
uint8_t pool_position;

uint32_t jenkins_one_at_a_time_hash(uint8_t *key, size_t len)
{
    uint32_t hash, i;
    for(hash = i = 0; i < len; ++i)
    {
        hash += key[i];
        hash += (hash << 10);
        hash ^= (hash >> 6);
    }
    hash += (hash << 3);
    hash ^= (hash >> 11);
    hash += (hash << 15);
    return hash;
}

// This routine takes the bit stream from the first phase of bias removal and then
// adds a second stage of bias removal by xor'ng two consequetive bytes. 
// Depending upon the current operating mode, will dictate how the resulting byte
// is processed
void buildNum(byte input)
{
  static uint8_t tmp = 0;
  static int num_counter = 0;
  uint32_t out;

  if (input == 1)
  {
    tmp = (tmp << 1) | 0x01;
  } else {
    tmp = (tmp << 1);
  }
  num_counter++;
  num_counter %= 8;
  if(num_counter == 0)
  {
    pool_position++;
    pool[pool_position - 1] = tmp;
    if (pool_position == POOL_SIZE)
    {
      // Ok, we have filled the pool up.  Time to hash the values for an output
      out = jenkins_one_at_a_time_hash(pool, POOL_SIZE);
      Serial.println(out);
      pool_position = 0;
      tmp = 0; 
    }
  }
}

// This routine implements the von Neumann algorithm for removing bias from a bit stream
void vonNeumann(byte input)
{
  static int count = 1;
  static boolean previous = 0;
  static boolean flip_flop = 0;
 
  flip_flop = !flip_flop;

  if(flip_flop)
  {
    if(input == 1 && previous == 0)
    {
      buildNum(0);
    } else if (input == 0 && previous == 1) {
      buildNum(1);
    }
  }
  previous = input;
}

I feed the bits to the VonNeumann function which starts the whitening process.  The BuildNum function takes the preliminary whitened output from the VonNeumann function and builds a queue of 16-bytes, which are then fed to the Jenkins hash function, which produces a 32-bit (uint32_t) value which is then output as the random number.  It was these processed numbers which produced the second set of results above.  The last is an image of the circuit I breadboarded for testing this ZXRE1004 noise source.
43  Using Arduino / General Electronics / Re: Problem reading random noise generator on: June 01, 2014, 01:03:13 pm
So you're using a Zener diode to generate avalanche noise as opposed to transistor breakdown? Does your circuit look something like this, getting the noise from the zener and then using the two transistors to amplify that?

The reverse biased transistor used in the original circuit you cited, as well as my original circuit, not to mention the typical circuit floating around the web for 30+ years is behaving in the exact same manner as a zener diode.  This app note might help you:

http://www.maximintegrated.com/en/app-notes/index.mvp/id/3469

I have also made some suggested changes to your circuit.  First, since you are using a capacitor to isolate the noise voltage/current from the op-amp (ac-coupling) you can use a single sided rail to rail op amp supplied by 5V to perform your later amplification and buffering.  I use the MCP629x family but any similar opamp should work.  BTW, you may want to try a larger capacitor, say 0.1 - 0.22 uF

I also didn't show it, but adding a buffer (similar to what you have on the first op amp following the transistor) to your voltage divider would be beneficial, particularly if you keep the resistors your using to connect the divider to the + input of the op amps. 

I
44  Using Arduino / General Electronics / Re: Problem reading random noise generator on: June 01, 2014, 11:08:33 am
The author of the HRNG link you posted claims to have gone to some effort to reach his goal, namely
Quote
trying to design a circuit that could produce a symmetrical, zero-average noise signal from a reverse biased p-n junction in avalanche breakdown
but it really isn't clear how he achieved and verified the output of the hardware other than with software. Your circuit has no provision for adjustments and can't produce a zero mean signal. Also, he used a digital input to generate "1"s and "0"s -- your use of the ADC throws in an additional complication. So you may be fighting an uphill battle.

The original author of the circuit the OP is using believed that a relatively even balance between 0's and 1's produce a non-biased output (it doesn't), but they didn't appear to actually test that asuumption since they used 'whitening' techniques from the start:

Quote
This time there is no need to minimize bias inherent in the operation of the generator, if all went well we should get a probability of 1s and 0s very close to 50%. Of course I'm going to assume that the bit-stream still contain bias and correlation, so a de-skewing technique for reducing bias and correlation will be used anyway.
On the software side I have basically used the same code I had written for the Chua random generator: at the beginning GPIO4 is configured as input, then one bit is read (and its value is optionally printed), next we wait for a delay and repeat. This delay has been set to 500μs, producing a 2000bit/s stream.
45  Using Arduino / General Electronics / Re: Problem reading random noise generator on: June 01, 2014, 10:59:02 am
Just to reinforce what Coding Badly pointed out, I made a circuit based on that type of design using 2n2222 and I found that a supply of 5V and 9V didn't work well. It needed at least 12V.


I disagree. my original circuit was stolen from a 12v design. I dropped it to 5v, changed the NPN bias to get 2.5 ish midpoint and enough gain to exceed the upper and lower hystersis points of the 393. it didnt work...until I realised that the key point is the current through the noise source is quite critical. i guess most mfrs try to reruce noise and though zeners are inherently noisy there is a point on their curve where they are most noisy. we are talking nanocurrents here, any help you can get to boost the starting point is a bonus...I rebiased the zener to get the exact datasheet current point for peak noise and it burst into life....

albeit with the nyquist sample rate problem, so im not cel3brating yet, just my 2c that 5v circuits can be made noisy with a bit of care,a datasheet and a calculator

Avalanche noise is generally an order of magnitude lower for 5V and below sources (typically zeners') when compared to 12V+ sources, even when current is adjusted for.  Further the reverse bias transistor used in the OP example doesn't enter the breakdown zone until about 8-9V, though I have found a few examples of the 2N3904 (the transistor typically specified) that entered breakdown at lower voltages, the mean tends to be around 9V, with noise peaking near 12V.

The 'best' current for maximum noise varies with the device; however, the ones I have tested have generally been 5-50 uA.

Further, there have been several people who have tested a variety of such transistors, and the 2N3904 tend to produce the most noise.
Pages: 1 2 [3] 4 5 ... 59