Tuesday, September 1, 2015

Potentiometer as a voltage divider, when does the value of the pot make a difference?

Knowing what you can and cannot change about a circuit can make projects much easier  There have been several times in the past, in which I've found a circuit I liked, but been annoyed because it had bizarre potentiometer values, and I've wondered, "can I just use whatever pots I want?"

For example, the yu synth oscillator has 22kΩ potentiometers as well as some other, what I would consider harder to find trimpot values.  When I breadboarded the circuit, I decided to just use more common values for the pots (I used 100k) and trim pots and it all seemed to work just fine.

Then, this last term in my circuits class, I made the blanket statement that for pretty much any voltage divider, the pot values don't really matter because of the voltage division rule...

We show that Vout is really just a ratio of Vin based on the position of the pot. Unfortunately this is not always true as I found out when I started considering the voltage divider as part of the various circuits it is usually implemented in.

Consider the case when a voltage divider pot is used to scale the voltage of an incoming signal to a simple op amp inverting amplifier/mixer....

If you do the node voltage method to solve this function for Vout, you will find that....

This equation right above tells the whole story. RB (and therefor RP) must be considered with respect to Rin.  To understand the equation, lets consider a few cases...

The simplest case is when RB << Rin (note: << reads as "much less than" and allows us to do some mathematical magic to simplify our equation; basically we are going to say that Rin = ∞ with respect to RB).

We can say that RB << Rin when Rin is at least twice as large as RP(the pot value).  This math is hardly a "proof" as I skip steps like taking limits. It is only meant to give a feel for what is going on.

From the above, we can say that when Rin is at least twice as large as RP, the circuit works as a classic linear voltage divider (we're gonna show that with a graph in a minute).

Now lets consider another case when Rin = RB. When Rin is larger that Rp, like in the above example, this can never be true. So, now we must assume that RP is larger than Rin

So, this is just a snap shot of when the pot is in a position such that RB = Rin, but we can see that it isn't the same equation as the simple voltage divider.  Vout will be smaller at this pot position that it would have been when RP << Rin.

I decided to graph a few different values in wolfram alpha to express this idea.  I choose to evaluate this with Vin=5, Rin = 1000, x represents RB,

This first graph is the case when RP is 10 times smaller than Rin.  as you can see, the output is very linear.

How about Rp being just half the size of Rin (as we defined in some of the math above). As RB approaches 500, you can see the transition becomes less linear and more exponential (I guess we were a bit liberal with our assumptions.)

Now lets look at a graph where Rin = RP.  This exponential response kicks in sooner.

Finally, lets look at the case when Rp is 10 times greater than Rin
Wow,  totally un-linear now and it appears to no longer reach 5 volts at the output.

In summation.  If you are looking for a linear response, Potentiometer voltage divider values should be chosen such that their value is at least the same if not less than the value of the Rin resistor. So for the Potentiometers in the yu synth oscillator, replacing a 22k pots, it would be better to use 20k or even 10k rather than 50k.

One last thing to consider is the amount of current you are allowing through your pot. replacing a 100k pot with a 100Ω will probably mean much higher power consumption and should probably be avoided.  Replacing a 22k pot with a 10k pot should be fine.

Wednesday, July 1, 2015

Sound activated LED PWM circuit

Although I've doing a lot of electronics, I haven't written about it in a while.  I'm in school for electrical engineering and most of my projects have taken place over 2 or 3 months, so by the time they are finished, it is hard to remember my thought process through the whole project.  This project was pretty quick and so it was easy to write about.

This is a simple Sound/voltage Sensitive LED circuit.  LEDs are dimmed most efficiently with pulse width modulation.  For LEDs, this means turning the LED on and off faster than our eyes perceive while varying the ratio of "on time" to "off time" to change the perceived brightness of the LED.  unlike lightbulbs, LEDs have a fixed voltage drop and changing the voltage across an LED does not directly effect the LEDs brightness.

I designed this simple circuit to convert changes in voltage at the input to changes in PWM on LEDs. I achieved this with a 555 and a few op amps. Once I built a the basic Voltage to PWM circuit, it was easy to add a sound input, mic, and "afterglow"(slew circuit).  I designed the system but each of the elements were simple circuits that I've encounter in a lot of different analog projects.

Voltage controlled PWM basics: 
simple voltage controlled PWM shows up a lot in modular synthesizers.  If you have access to a triangle wave (or can create one), you use an op amp to compare a triangle wave to some input voltage(this could be a mic signal).  This will create a square wave and the duty cycle (on vs off time) will be dependent on that voltage signal.

Virtual Ground
Because my circuit uses 5 op amps and a simple 12vdc supply (6 op amps including the virtual ground circuit), I opted to build a virtual ground circuit rather than just a voltage divider at each of the non-inverting input.  Speaking of all this ground/virtual ground stuff.  I spent an few minutes the other day with some 9v batteries and my arduino and a DC adapter and the basic question "when am I allowed(electrically) to connect the grounds of two separate systems. We take for granted that when we plug our headphones output into other circuits, that we are doing just that...connecting the grounds so that the voltage potential between the systems has the same reference. Through my experiments with the batteries, it seemed safe, so long as neither circuit has a reference to the other (electrically isolated through transformers or by being battery powered), you can choose any point in either circuit to equalize as ground reference. For this circuit, incoming signals are reference to the virtual ground.

Getting a triangle wave from a 555: 
If you probe around a basic astable 555 setup, you can find that a triangle (or triangle-ish) wave is available from the charging capacitor on the 555. Because we are using PWM in a more qualitative way, it is not necessary for the wave to be a precise triangle wave.  If we were really picky, we could use 2 op amps to create a very nice triangle wave oscillator without the 555.

I calculated my frequency using this 555 calculator.  In order to get a reasonable triangle wave from the capacitor on the 555, you should shoot for a 50% duty cycle on the 555.

555 calculator

This is a slew-limiter circuit.  The diode allows the circuit to only control fall time.  When the potentiometer is set to a low resistance state, the capacitor is allowed to fill and empty at a reasonably fast rate. This filling and emptying only happens on the potentiometer side of the circuit because the non-inverting input doesn't sync any current. When the potentiometer is in a high resistive state, the diode allows the capacitor to fill very fast but drain at whatever rate is determined by the resistance of the pot.  This essentially creates a controlled "fall time". For the LEDs, it basically means "after glow".

Electret Mic circuit: 
This is about the simplest electret mic circuit you can find. The 1M resistor is working as a feedback resistor.  Because we are not particularly interested in precision or supplying power, we are using capacitors to separate the DC from AC signal and so we don't need to bias the transistor.

Input Mixer/Offset:
This is the input buffer/amplifier section of the circuit.  It takes my incoming signal and adjust it to a reasonable magnitude and voltage range such that it can be compared to the 555 triangle wave. If you've ever worked with op amps as summing amplifiers, you kinda take for granted that the non-inverting input is usually held to ground. One of the best upsides to having the non-inverting input tied to ground, is that you can calculate each arm (or channel) of the mixing amplifier separately and the voltages at the output will add. This is still basically true for the op amp when the non-inverting input is tied to some other voltage but the math is a little trickier. For example, when the non-inverting input is tied to ground, unconnected inputs to the mixer act pretty much like 0v and "fall out" of the node voltage equations. This will become more clear if you sit around doing node voltage on some op amps for an afternoon.

*note that the "kill all positive voltage diode" actually only kills voltage above the voltage drop of the diode, around .7v. We do this because we want our voltage swing to be 0 to -3v and AC signals, depending on our offset value, can end up greater than 0v after the inversion of the op amp.

555 triangle conditioner: 
This circuit adjusts our 555 triangle signal into a range and magnitude that will easily be comparable to our adjusted input voltage. I made a note that the original waveform (pictured in the box) has a magnitude of around 5v and is off center from our virtual ground.  Again, I did node voltage to calculate my resistor values.  I used a 270k resistor instead of the 280k shown in the diagram.

This is the final comparator circuit before which creates our PWM wave.  One thing of note is the LED and resistor after the op amp and before the 2n2222 transistor.  Because the op amp does not swing "rail to rail", the output from the comparator would never actually turn out because its emitter is tied to -6v and the maximum negative voltage for the op amp is around -5v.  The LED greats a voltage drop which eliminates this problem.  The resistor which isn't labeled was a 1k. 

The node labeled "L" represents the cathode of some series of LEDs (plus a resistor).  my LEDs had a 3.2v drop, so I used 3 in series with a 68Ω resistor.  Because the 2n2222 can handle 800mA of current and each set of 3 LEDs only draws 20mA of current, I designed my light to use 90 LEDs(30 sets of 3).

Basically, thats it.