"Probability Meter" - use output from a PC program to drive voltmeter

Thread Starter

MikeMee

Joined Sep 3, 2019
12
What would it take to hook up an old voltmeter to a PC (Mac actually) to respond to the output data from a program/database?

Objective:
Use the output of a computer program that calculates the number of coin flips to drive a voltmeter via the USB port.

Based on an algorithm, as the output deviates from normal probability distribution (over a big data set), the voltage will increase correspondingly and swing the needle on the voltmeter. Fun!

Student project. Any suggestions?
Thanks

il_794xN.1783550723_8a7f.jpg
 

Alec_t

Joined Sep 17, 2013
14,314
Welcome to AAC!
We don't do your homework/project for you, but can offer guidance. You are expected first to submit your best effort at solving the problem.
 

Thread Starter

MikeMee

Joined Sep 3, 2019
12
What are your thoughts about how to convert a digital result into an analog voltage?
At this point I am scoping out this project to assess if I have the know-how to do it, as well as the time it will take. I don't have any methodology in mind yet.

It is a "student project" - not because it has been assigned by a teacher. There is no supervisor. It would be a personal project. I would like to see how feasible it is for me (no electronics experience). So I am simply trying to assess if it is a feasible project by getting an outline of what might be involved.

If there is a "black box" (DAC) that can be bought off the shelf, and with just some simple connections to assemble it, that would work well enough for me too.

Thanks
 

jpanhalt

Joined Jan 18, 2008
11,087
There is lots of stuff on the Internet about sound card v. stand-alone DAC's. Similar functions, but access to output may vary.
 

MisterBill2

Joined Jan 23, 2018
18,506
To drive an analog meter from a computer without using additional active components such as a D/A converter and amplifier, and an external power source would require a sound card, or equivalent with a speaker output connection. The speaker output from the sound card would feed a rectifier of some kind, which would then feed a filter circuit and finally provide a direct current to the meter being driven.
I will provide a more detailed description of the circuit if this sounds like the answer you are seeping.
 

Sensacell

Joined Jun 19, 2012
3,448
It's easy to drive meters with PWM, they respond rather slowly so you do not need a very high frequency.

You could use a micro-controller kit board that has USB and a PWM output.

Just a single adjustable series resistor is all you need, set the PWM to 100% and adjust the resistor for full-scale deflection and you are good to go.
 

Thread Starter

MikeMee

Joined Sep 3, 2019
12
To drive an analog meter from a computer without using additional active components such as a D/A converter and amplifier, and an external power source would require a sound card, or equivalent with a speaker output connection. The speaker output from the sound card would feed a rectifier of some kind, which would then feed a filter circuit and finally provide a direct current to the meter being driven.
I will provide a more detailed description of the circuit if this sounds like the answer you are seeping.
This sounds like an interesting approach. It keeps the requirement of external parts to a minimum. I would like to explore this further. Thanks.

Early questions:
In my program, the PRNG (random generator) tosses about 10 million coins in just over 40 seconds. And so, I am aiming to see the meter movement during those 40 seconds. The needle will move as the probability varies from the norm. It might be a dumb question, but would the sound card respond to such a blistering torrent of data? I don't imagine they are designed to do that for audio applications (but I might be wrong)?
 

Thread Starter

MikeMee

Joined Sep 3, 2019
12
It's easy to drive meters with PWM, they respond rather slowly so you do not need a very high frequency.

You could use a micro-controller kit board that has USB and a PWM output.

Just a single adjustable series resistor is all you need, set the PWM to 100% and adjust the resistor for full-scale deflection and you are good to go.
This also sounds like a viable option. Definitely. Thanks.
(I will look into what PWM is about)
 

Thread Starter

MikeMee

Joined Sep 3, 2019
12
Got it --- Pulse-width modulation (PWM) is used for controlling the amplitude of digital signals in order to control devices and applications requiring power or electricity. It works as a method for generating an analog signal using a digital source.
 

MrChips

Joined Oct 2, 2009
30,807
The number of possible solutions is almost limitless. Since you are a student, let us cover all the possibilities for different makes and models of PC.

Parallel/Printer Port
If your computer has a printer port:
1) Interface a DAC to the parallel data port
2) Use a single output pin, data or control, to output PWM signal
3) Use one or more pins to output serial data to a serial input DAC
4) Use one or more pins to output serial data to an external MCU (micro-controller unit)

Serial/COM port
As above, solutions 2, 3, 4.

USB port
As above, solution 4.

Sound Output
1) Output AM (amplitude modulation) signal
2) Output PWM signal
3) Output variable frequency to a FVC (frequency to voltage converter)

For any PWM solution, you can also send PPM (pulse position modulation) which is a variation of PWM.
With two digital output pins you can send phase shift modulation.
 

MrChips

Joined Oct 2, 2009
30,807
Got it --- Pulse-width modulation (PWM) is used for controlling the amplitude of digital signals in order to control devices and applications requiring power or electricity. It works as a method for generating an analog signal using a digital source.
Not amplitude of digital signal.
PWM controls the duty cycle (ratio of pulse width over pulse period).




PPM is a variation of PWM:


 

MisterBill2

Joined Jan 23, 2018
18,506
Generation of a PWM signal with an average speaker port may be beyond the capabilities of the average sound card, while sending out a tone with the amplitude controlled by the software would be a lot simpler, and within the capability of most sound cards. And the code needed to create that PWM signal will not be simple, certainly not as simple as looking up a volume setting would be.
Unless the meter has a built in rectifier, which probably the one in the picture does not have, you will certainly require a rectifier and probably a small filter capacitor.
 

Thread Starter

MikeMee

Joined Sep 3, 2019
12
The number of possible solutions is almost limitless. Since you are a student, let us cover all the possibilities for different makes and models of PC.

Parallel/Printer Port
If your computer has a printer port:
1) Interface a DAC to the parallel data port
2) Use a single output pin, data or control, to output PWM signal
3) Use one or more pins to output serial data to a serial input DAC
4) Use one or more pins to output serial data to an external MCU (micro-controller unit)

Serial/COM port
As above, solutions 2, 3, 4.

USB port
As above, solution 4.

Sound Output
1) Output AM (amplitude modulation) signal
2) Output PWM signal
3) Output variable frequency to a FVC (frequency to voltage converter)

For any PWM solution, you can also send PPM (pulse position modulation) which is a variation of PWM.
With two digital output pins you can send phase shift modulation.
SIMPLE SCHEMATIC 1.jpg

Does this represent the basic idea?
 

Thread Starter

MikeMee

Joined Sep 3, 2019
12
Generation of a PWM signal with an average speaker port may be beyond the capabilities of the average sound card, while sending out a tone with the amplitude controlled by the software would be a lot simpler, and within the capability of most sound cards. And the code needed to create that PWM signal will not be simple, certainly not as simple as looking up a volume setting would be.
Unless the meter has a built in rectifier, which probably the one in the picture does not have, you will certainly require a rectifier and probably a small filter capacitor.
.... "the code needed to create that PWM signal will not be simple, certainly not as simple as looking up a volume setting would be" <--- this concerns me. I'm not an advanced programmer.

The picture of the meter is not the actual one. Just a representation of a retro industrial meter I will get. The ones from the USSR in the 50s look pretty cool. So you are probably right, it will not have a rectifier etc
 

DickCappels

Joined Aug 21, 2008
10,179
IF your plan includes a sound card you can just have the sound card produce a steady tone, use the tone to drive the meter through a rectifier (filtering to smooth is optional but probably not needed) and just adjust the amplitude of the tone.

Bigger question =>Can you program you Mac?
 

MaxHeadRoom

Joined Jul 18, 2013
28,687
PWM output on using a printer port pin is the way the DIY CNC programs such as Mach3 do it, then then use a external PWM to analogue (0v-10v) convertor to drive a motor controller.
Max.
 

bogosort

Joined Sep 24, 2011
696
In my program, the PRNG (random generator) tosses about 10 million coins in just over 40 seconds. And so, I am aiming to see the meter movement during those 40 seconds. The needle will move as the probability varies from the norm. It might be a dumb question, but would the sound card respond to such a blistering torrent of data? I don't imagine they are designed to do that for audio applications (but I might be wrong)?
Does it need to be a "real-time" system? You can control the data output rate in your program, tailoring it to the optimal meter movement speed. Which brings us to the more important question:

How will you indicate that the "probability varies from the norm"? In other words, what specifically does the meter's needle position represent?

One possibility: associate the maximum needle position with HEADs and the minimum with TAILs. In your program, associate HEADs with 1.0 and TAILs with 0.0, and then calculate the mean result over a block of simulated coin flips. You can start with a small block -- say, 1 flip -- increasing the block size as you go. As the block size gets larger, the mean will converge to the expected value. The meter's visual behavior will depend on how you time the output and how quickly you increase the block size.

Note that, using this method, your meter will soon point toward the middle of the scale and barely move, which is pretty boring. A digital readout of, say, 5 decimal points of the mean value is perhaps a bit more interesting to look at. If you want to stay analog, you could drive 5 identical analog meters, each representing a digit of the expected value: 0.50000. Then, as your program runs, the leftmost meter will quickly reach its zero deviation point, the next will converge a bit more slowly, and so on, with the rightmost meter swinging about for most of the run.

In any case, I think you can better choose your implementation details after you've worked out exactly how you want the meter(s) to behave.
 

Thread Starter

MikeMee

Joined Sep 3, 2019
12
Does it need to be a "real-time" system? You can control the data output rate in your program, tailoring it to the optimal meter movement speed. Which brings us to the more important question:

How will you indicate that the "probability varies from the norm"? In other words, what specifically does the meter's needle position represent?

One possibility: associate the maximum needle position with HEADs and the minimum with TAILs. In your program, associate HEADs with 1.0 and TAILs with 0.0, and then calculate the mean result over a block of simulated coin flips. You can start with a small block -- say, 1 flip -- increasing the block size as you go. As the block size gets larger, the mean will converge to the expected value. The meter's visual behavior will depend on how you time the output and how quickly you increase the block size.

Note that, using this method, your meter will soon point toward the middle of the scale and barely move, which is pretty boring. A digital readout of, say, 5 decimal points of the mean value is perhaps a bit more interesting to look at. If you want to stay analog, you could drive 5 identical analog meters, each representing a digit of the expected value: 0.50000. Then, as your program runs, the leftmost meter will quickly reach its zero deviation point, the next will converge a bit more slowly, and so on, with the rightmost meter swinging about for most of the run.

In any case, I think you can better choose your implementation details after you've worked out exactly how you want the meter(s) to behave.
Thanks for that feedback on meter behaviour and what we can expect in practice. I hadn't thought too much about this aspect. If the needle is hardly moving after a short period, it will not be fun at all. Furthermore, calibrating (configuring) the analog meter to display something meaningful is another challenge.

The use of 5 meters would be more of an interesting "journey", visually speaking. It would resemble the action of a poker machine with each spinning dial coming to rest (sort of).

Thinking aloud...
All of which brings me to thinking that a panel of digital meters would not only vastly simply the build (no need for a DAC, PWM etc), but display truly meaningful numerical results while the coin toss is in progress. This is a real-time test.

I guess the meters would display negative results when more tails than heads come up, where the probability perspective is whether the occurrence of heads will be more than 0.50000
 

MisterBill2

Joined Jan 23, 2018
18,506
First, there is nothing simple about using a USB interface as far as the circuit part goes. And the software is not trivial either.
If digital displays are an option then how about on-screen digital displays, and avoid the hardware part completely? A display could show the difference between the counts of heads and tails, and that could be a very educational thing, as it might vary a lot in a hurry.
 
Top