Does ADC in + PWM out = trouble?

Is there any issue with reading one analogue pin whilst outputting PWM on another?

An example of this would be making an analogue voltmeter. So you'd read the input analogue voltage on a pin with analogRead(). Map this value so that you represent it with analogWrite() on another pin that then drives an analogue voltmeter. I would only be interested in the highest 8 bits of the input signal, so I'd analogRead() >> 2. Simple stuff at first glance.

It's common practice to separate analogue and digital circuitry as they may cause interference /noise between them. I have to avoid extraneous noise on the analogue readings. I do not want to be reading in fractious parts out what I'm outputting. My concern is that simultaneously driving the voltmeter with a digital output may feed back to the ADC circuitry. Parasitic coupling, spikes and all the associated troubles.

Is this an issue? Can this be done reliably with a single Arduino, or do I need a separate ADC chip located remotely?

PS. This is not for a voltmeter, it's just a simplified example to save a lengthy explanation.

Parasitic coupling, spikes and all the associated troubles.

These could be problems, but you haven't provided enough information to know. Post a complete schematic and circuit layout plan of the actual project.

Most people do not have trouble mixing analogRead with PWM output.

The crucial thing is impedance - a high impedance analog circuit will easily pick up noise from any
signal source, a low impedance one won't (or rather will only be affected by induction from nearby
large currents, not stray capacitive coupling). 100 ohms is low enough to be pretty robust, 100k
will be quite sensitive, at 1M noise is always an issue to think about. This is an audio frequencies,
at RF stray capacitance becomes much more important.

It also depends how much noise you can tolerate - for instance for audio tiny amounts of noise
can be audible and unwanted, whereas on a temperature sensor output can be low-pass filtered out
very effectively.

Depends when in the PWM cycle the analog input samples it - it could be 0 or full scale.

You ought to know from the PWM value what proportion of the supply you're getting, so that's a help.

it'll be value /255 of the supply.

If you want an average by reading it with an analog input you'll have to fit a lowpass filter which will, of course, slow down the response considerably.

regards

Allan.

Allan, I probably wasn't clear in what my circuit is doing. It's not sampling the PWM. It's doing this:-

So cue lengthy explanation... The complete circuit is for a true random number generator that is accessible over Ethernet. The white noise source is buffered prior to sampling, and the volt meter is fed with buffered PWM. The purpose of the volt meter is to indicate the optimum noise signal level to avoid clipping the highs. I want sufficient headroom, perhaps 10 dBV. That way I can sample maximum entropy from the noise sub circuit. Entropy extraction will occur off Arduino so all that is output is noise signal samples. I'm hoping to achieve a 5kHz bandwidth if I can run the Arduino ADC at the full 10KS/s. The only processing that the Arduino will do is to monitor the peak ADC readings so that analogRead() >> 2 is less than 255. I may have to apply some statistic leniency to this as white noise peak levels are a stochastic event and not clearly defined. This level will then be indicated on the volt meter.

In architectural terms, the Arduino (+ Ethernet shield) is just an Ethernet bridge for the noise generator. I like networked thingies.

My concern is will I be indeed measuring the noise source (even if buffered)? Or will I get significant feedback /correlation from the outbound PWM signal? The PWM signal will go into a very high impedance buffer so not a great deal of spikey current, but I have little familiarity with the Arduino internals. My only experience with a similar situation was that it seems sending fast serial data + ADC sampling of a floating pin is problematic. You seriously skew the analogRead() if the serial rate goes much past 56kBaud. I won't have a floating pin. The noise source is a proper circuit.

Any thoughts?

Try it and see.

There are many methods for validating a random number stream and most should quickly reveal any problems.

:slightly_frowning_face: Yes thanks, but if we all just blindly built this stuff there'd be no point in having a forum...

I completely misunderstood your problem!

Any idea of the upper spectral limit of your noise source?
and is your required random number in the range 0..255?
and how often do you want a new random number?

there might be an easier way.........

regards

Allan

At the risk of going off topic:-

It's a Steampunk cryptographic true random number generator. Why? I don't know.

The noise source will be a valve voltage regulator running at approximately 100VDC. It's a QS92/10 which is the one used in Britain's first Premium Bond draw machine called ERNIE1. Upper limit is probably the quantum limit, but clearly that will reduce due to all the metal, wires and capacitance in my chassis. And the buffer circuit which will be more valves. It should be orders of magnitude above the 10kS/s rate of the Arduino nevertheless.

I really need the samples as octets for subsequent processing purposes.

The Arduino circuit will not output random numbers, but rather noise samples. It will output a block of noise samples perhaps 20KB in size. I expect to be able to extract 5KB from that as true randomness, but this will be done elsewhere.

I realise that there might be an easier way, but this way sounds fun as long as the Arduino can do it's stuff without trashing the noise sampling. If the voltage meter is a problem, I'll use some other form of visual indicator. Perhaps just simple "Threshold Exceeded" light bulbs a la VU meter.

So I ran this:-

void setup() {
 Serial.begin(19200);
 Serial.println("Running");
 analogWrite(3, 75);         <---  THIS STATEMENT TOGGLED ON /OFF
}

void loop() {
 Serial.println(analogRead(4));
}

on a Nano just floating on my bench. Nothing connected to any pins.

Serial Monitor shows analogue readings of 18X with the analogWrite() statement commented out, and 19X with the PWM running. X is a changing digit. This is less effect than I expected, but statistically visible. You can clearly see the 50Hz mains hum on Serial Plotter. Hmm. It may not be an issue then with buffered input and output.

You can expect a floating analog input pin to eventually return all possible values, between and including 0 and 1023.

You could try the appended circuit - use eg a 74HC14 as the schmidt trigger.

You'll get a random load of transitions. Feed them into a digital input used to counts pulses, time for a while, then take mod 255 of that count - which will be huge.

regards

Allan

pretty punk, eh?

edit.. not sure that ERNIE didn't use a similar technique....
-and with this spproach the amplitude of the signal doesn't matter much, so long as it's well above the hysteresis of the schmidt...

-and the digital inputs of the arduino can count at up to 8MHz, so you should get big numbers fast.

random.pdf (18 KB)

cossoft:
The noise source will be a valve voltage regulator running at approximately 100VDC. It's a QS92/10

What is the output impedance - as I said its all about impedance.

I remember those old tubes - probably a few hundred ohms.

But the noise output will quite be small, so will need a fair bit of gain to get the noise signal up to arduino levels

I don't know how much - I only used them as regulators so they were followed by a low-pass filter.

regards

Allan

allanhurst:
But the noise output will quite be small...

... I'm not so sure. I'm hoping that the noise will be huge (say 100mV peak). I've toyed with a 20V Zener diode. If you just add a simple voltage follower and shove it up a small tranny speaker, you can actually hear the hiss! It's quiet, but quite audible nevertheless. Pretty amazing to hear pure quantum mechanics going on atop your bench! The mechanism seems similar.

I can't just yet power up the tube as I need to build a buffer /safety circuit for my PC which I'm using as a rudimentary oscilloscope. I just know that I'm going to blow it up anyway.

ERNIE1 amplified the regulator noise via two pentode stages but they were probably running the rest of the gating hardware on higher voltages than 5. Assuming 50 x 50 gain, that is a lot though. I have the same pentodes to experiment with.

That was the point of the question. I was going to output a PWM signal to an analogue volt meter and use that to indicate if the noise signal was clipping the input range. You would then be able to adjust the level to a nominal setting. It's starting to look as if I was worried unnecessarily.

MarkT:
What is the output impedance - as I said its all about impedance.

I don't know, but the tube will run on about 2mA via a throttling resistor. The noise will be taken directly off the tube's anode and then amplified by other tubes. A pentode's grid impedance is pretty high. The biggest extraneous noise will be mains hum @ 50Hz but that will not effect the randomness extraction. RFI is irrelevant as the circuit can only sample frequencies at a maximum of 5kHz if I run the Arduino at full pelt. There's also a 100kHz SMPS for the 260V tube voltage but again that's above the sample limit.

I'm concerned about the 500Hz PWM output from the Arduino. That's right in the sample range and it might affect the analogue readings. I'd be creating my own auto correlation. Hence this question since I have scant experience of Arduinos (Arduinoes?)

allanhurst:
You'll get a random load of transitions...
... and the digital inputs of the arduino can count at up to 8MHz

To be honest I don't like thresholding. It automatically reduces the measured entropy rate by a decade as you down sample from 10 bits to 1 bit. You then just have to reassemble all the bits into bytes to transmit them over Ethernet, and you still have to process them again to make them truly random. Simply thresholding a noise source into bits won't make cryptographic strength random numbers.

Also, I'm not sure that 8MHz is anywhere near the practical bandwidth of the pentodes I have. I think that we're looking at audio frequencies. I can't easily test /trouble shoot 8MHz frequencies but I can hear audio. Plus I now have my super dooper PC oscilloscope to see it too :slight_smile:

If you coupled the output with a good quality high voltage capacitor you should be fairly safe....

  • any idea what pentodes they used? If 807's as in colossus, good for 10MHz easily.

  • I bet ERNIE didn't have any sort of A/D - they must have used thresholds. Not very random?

  • if you stick with your a/d idea I think you're worrying unduly about the effect of your pwm/meter output - the arduino analog input will be driven by quite a low impedance from your pentode amplifiers. Check the anode impedance of your pentodes - it'll be a few k ohms .

regards

Allan

allanhurst:
any idea what pentodes they used?

CV4002s are military wired versions of the pin based CV4014 that I'm using. I've consulted some valve aficionados but no one seems able to guess the operating frequency of this circuit. I'm concerned with the small 1nF inter stage coupling capacitors. They suggest frequencies above normal audio. The RC constant on the cathode resistor /bypass suggests perhaps a minimum of 16KHz. I'm hoping to re spec the bandwidth of the amplification stages but valve design is really hard :frowning: I think that I'll have to resort to the Monte Carlo methodology and just try some stuff. It's perhaps apt to use randomly chosen components for a random number machine...

I'd really really like to avoid MHz frequencies as I only have a PC and hammers. The Arduino can only sample 5kHz analogue anyway.

The arduino can COUNT at up to 8MHz - which, since 10 bits a/d is 1000:1, is equivalent to sampling to 10 bits at 8kHz.. I repoint you at my schmidt idea..

aha ! ...... it's an EF91.

check specs at EF91 @ The Valve Museum

it's good to 200MHz ... bit overkill for 5k arduino analog sampling, but should give plenty of rattle at 8Mhz +

regards

Allan.