Go Down

Topic: Does ADC in + PWM out = trouble? (Read 6671 times) previous topic - next topic

cossoft

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.

jremington

#1
Aug 17, 2016, 04:15 pm Last Edit: Aug 17, 2016, 04:16 pm by jremington
Quote
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.

MarkT

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.
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

allanhurst

#3
Aug 17, 2016, 04:52 pm Last Edit: Aug 17, 2016, 08:56 pm by allanhurst
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.

cossoft

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?

jremington

Try it and see.

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

cossoft

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

allanhurst

#7
Aug 18, 2016, 02:47 am Last Edit: Aug 18, 2016, 02:59 am by allanhurst
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

cossoft

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.

cossoft

#9
Aug 18, 2016, 02:14 pm Last Edit: Aug 20, 2016, 03:30 pm by cossoft Reason: Code tags utilised
So I ran this:-
Code: [Select]

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.

jremington

#10
Aug 18, 2016, 03:53 pm Last Edit: Aug 18, 2016, 03:55 pm by jremington
You can expect a floating analog input pin to eventually return all possible values, between and including 0 and 1023.

allanhurst

#11
Aug 18, 2016, 07:56 pm Last Edit: Aug 18, 2016, 11:17 pm by allanhurst
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.

MarkT

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 will NOT respond to personal messages, I WILL delete them, use the forum please ]

allanhurst

#13
Aug 19, 2016, 09:13 pm Last Edit: Aug 20, 2016, 12:11 am by allanhurst
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

cossoft


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.

Go Up