Monday, June 16, 2014

The Solution to My Gain Problem - Goofy Op Amps

If you remember,
http://jazz-disassemblies.blogspot.com/2014/06/toying-with-gain-peek-at-differential.html
I had a problem with an operational amplifier. My circuit for multiplying by a fractional gain was successful. 1/2 gain, 1/3 gain, no problem. But when I wanted to increase gain by 2, the output voltage was much too high; exactly +5v too high in all cases. The problem was how to reduce my output by 5v in all cases, but how?

The op amp circuit that we used was a differential amplifier, which means the difference between two input voltages is amplified, and not any one voltage input. I finally found this web site with a much simpler equation:
http://electronics.stackexchange.com/questions/94043/op-amp-design-resistor-values-vs-actual-values-gain-calculation



The equation, Vout = -(R2/R1)(V1-V2)
I knew that the gain was determined by R2/R1
and that the Vin would be 0 to 5v
and Vout should be -5v to +5v

Since the gain I wanted was 2 and I knew my in and out signals, I needed to find V1, which would become my reference voltage. I thought my reference would be 0, because I want my output signal centered at 0v BUT, it is not in fact the center point of our output. It turns out that the reference voltage is also multiplied by the gain and then added to the output. If my output is 5v too high in all cases, then we need to add (-5v/2).
Therefore my range would be:

-(gain)*(V1-V2) = Vout
so,
(-2) * (2.5-5) = -2*-2.5 = +5v
and,
(-2) * (2.5-0) = -2*2.5 = -5v

There is my range! And there is my reference voltage!

R2 = 100K ohms
R1 = 50K ohms
Vref = 2.5v
so,
Gain = 2
Vin = 0/5v
Vout = -5/+5v (10vpp)

If I connect my supply voltages to +5v and -5v, then any voltages outside of that range will be clipped off, protecting any other devices this may be connected to along the line. Success!

Monday, June 9, 2014

Arduino - Cast Int to Byte - What happens?

For a project I need to spread a 16-bit unsigned integer across one byte variable and two 1-bit variables, all of which will be written to pins. The reason is not important, but I needed to know what happens to the byte value when I cast it to the byte variable. I understand that it will be truncated, but what will? The higher 8-bits or the lower 8-bits?

To find out, I wrote a quick program with a lot of clear text output.


// cast test by Jordan
// Test truncation of variables from one type to another
// most importatntly: int to byte

unsigned int intVar = 0x4080; // will it truncate to 01000000 or 10000000?
byte byteVar = 0x33;
void setup(){
  Serial.begin(9600);
  Serial.print("hello world.");
  Serial.println();
  Serial.println();

}

void loop(){
  Serial.println("integer variable equals: ");
  Serial.println(intVar, BIN); // print variable in binary
  Serial.println();
  Serial.println("byte variable equals: ");
  Serial.println(byteVar, BIN);
  Serial.println(".");
  Serial.println("..");
  Serial.println("...");
  byteVar = (byte)intVar;
  Serial.println("byte variable now equals: ");
  Serial.println(byteVar, BIN);
  while(1){} // loop forever
}

Then I uploaded it to my Arduino Nano and opened the serial monitor. I then uploaded it to my Teensy 2.0 to double check the code across platforms. Teensy is a little different in some aspects, so I had to make sure. They both output exactly the same thing:

Serial monitor output:

"hello world.
integer variable equals:
100000010000000
byte variable equals:
110011
.
..
...
byte variable now equals:
10000000"

These are the exact results that I wanted to see. I may continue on with more programming now...

EDIT: Further testing proves that the same theory does NOT hold true with booleans. (get it? "true") I had hoped that the boolean could be used to store a 1-bit number, but it turns out they are actually some sort of integer in disguise! I will have to figure out some fast way to manipulate individual bits...

Toying with Gain - A Peek at the Differential Amplifier

Op Amps have many uses and functions, even more so than a massive wikipedia page can cover. Today I will introduce the Differential Amplifier; one such function. I will also offer some real-life instances in which to use it and then discuss some issues that I found in testing.

Differential Amplifier

With some simple algebra, one may calculate a wide range of gain to apply to an input signal. According to wikipedia, the differential amplifier amplifies the difference in voltage between its inputs. The two inputs are shown as minus (-) and plus (+) or inverting and non-inverting respectively. Depending on the location of Rf, or the feedback resistor the output signal will be inverted or not. With feedback from Vout to minus, the signal will not be inverted. With feedback from Vout to plus, the output will be inverted. I only have a use for a non-inverted signal right now, so Rf will remain from Vout to minus, as shown below:


The image is borrowed from wikipedia, and is how they show a non-inverting differential amplifier. Now for the math behind it.


Not a terrible equation by any means, and it can be reorganized to calculate any of the variables other than Vout if need be. It is probably in the user's best interest to do so since they most likely already know what Vout they want and what the input voltages are.

Applying your own 1/3 or 1/2 Gain

I do have one problem with this though and that is Rg which is connected to 0v. This voltage is not taken into consideration of the equation, but could potentially be any other voltage! Lets say I want to connect V1 to 0v so this functions like an ordinary gain amplifier. According to this guy:
http://www.cnblogs.com/shangdawei/p/3190899.html
If R4 (Rg) is connected to another voltage, that voltage becomes the reference voltage that the output signal centers on. His example illustrates a -5/+5v (10vpp) voltage being multiplied by a fractional gain to output a 0/3v3 siganl. (3.3 - 0)/2 = 1.65, which becomes his reference voltage. This is excellent news since I need to work with a 10vpp signal as well. I however need to apply a 1/2 gain to get 0/5v instead of 0/3v3. Since 33K/100K = 1/3, then 50K/100K - 1/2. All i have to do is replace the 33K resistors with 50K resistors and change the refrence voltage to (5-0)/2 = 2.5v.

Exploitation

Just a note that seems never to be shared is that the power supplies to your op amp must exceed the range of your gain. If you want to amplify (lets say) a 0/5v signal up to 0/10v, then you must have a power supply at or above +10v at the positive voltage input and at most a 0v signal at the negative power pin. If you do not use a supply higher than your what your output could potentially reach, then you will see "clipping" where the signal gets cut off at the levels of the supply.

Another note is that your power supply connections may be less than the input signal if in fact you are applying a fractional gain (1/2 gain, 1/3 gain, etc.). If you have a input signal of 0/5v and want an output of 0/3.3v, then you may happily use a 3.3v input as the positive supply voltage.

Clipping sounds like a bad thing, but at the same time you may exploit it in your advantage. I need to send Vout to a microcontroller, which has a 5v tolerance. If this tolerance is exceeded, then the mC could be damaged which we don't want! Since the 10vpp signal is coming from an outside source, I have no control of how precise it is. It coul be high than +5v or lower than -5v potentially. So I can use clipping to my advantage to protect the mC. How? By applying a voltage supply the same as my Vout limits: 0/5v.
With ground and +5v, any other voltages will be clipped off! Genius. :P

Applying a Gain of 2 - Problematic ...

Within the same project, I have the need to apply another gain to another signal. I need to boost a 0/5v signal into a 10vpp signal. Since this is the exact opposite of my calculation above, I can say with confidence taht we just swap the resistors values. 50K and 100K values are swapped to produce a 2 times gain. I also want my output to be centered on 0v, so I should connect my reference voltage to 0v. It all sounds correct and I set it all up on my breadboard:



Yes, its a mess but I have three voltage supplies (+12, -12, 0 and +5) and a pot (off screen) connected to 5v and 0 as a voltage divider for my input. I also have more resistors than I should because I don't have any 50K ohm resistors, so the 100Ks are in parallel to make 50K. At one point I even had a -5v regulator connected on the board...

The problem is that when I measure my Vout with an input signal of 0/5v I am reading a range from 0 to +10v. Now, this is perfect for my gain calculations, but bad because of my reference voltage. It is referenced at +5v. Clearly, this is wrong or I am wrong, or something...

I want to assume that the reference voltage works only if it is a positive value. 0 and negative do not work as references because of some multiplication in the equations that I am missing. Everyone knows what happens when you multiply by negative numbers or by 0. I believe the fix may be a second op amp, but with a different configuration. A configuration not to apply a gain, but to shift the level down by 5v. By changing the reference and not the gain, I should be able to get the voltages I want to see. I will get back to you all once I do some further reading and testing. Let me know if you have a solution before I find it.

Until then however, I designed a simple board in Eagle that allows the user to configure it in different ways. Gain can be calculated, reference(s) voltage can be chosen Vp and Vn and it even has the option to add some DC clocking capacitors if you are working with audio signals. I call it devGain. It too has the same problem as I am having, but any fractional gain should work accordingly. I designed it sort of as a daughter card to stand upright with 90 degree header pins and take up very little room on a breadboard. What do you think?




As you can see, there are many components not on my breadboard, but like I said it can be configured for multiple purposes. The two lower Ceramic caps can be bridged for non-audio as can the electrolytic caps on the sides. RC can be either a resistor or ceramic capacitor. As a resistors it is used to define a ground reference for the next device to accept the signal. As a cap, it is used to clean up random noise that you might see on the signal if it going to a microcontroller or similar. Ignore the values below each resistor on the schematic. They were set that way for each of the two op amps found in the 8-pin DIP. TL062, 072, 082 or similar may be used.

Let me know what you think or if you have a solution to my 2x gain-reference voltage problem.

Cheers,
Jordan

THE SOLUTION!
http://jazz-disassemblies.blogspot.com/2014/06/the-solution-to-my-gain-problem-goofy.html

Wednesday, June 4, 2014

Repairing an LCD Monitor

I am damn cheap, and this isn't the first time I have gotten a broken monitor to use as my own. By broken, I do not mean that the LCD is cracked, but that it comes on and goes off immediately. Some even went black and had a buzzing noise. More often than not, this means some capacitors on the power board are swollen or popped. This is just a detailing of one monitor in particular, but the method is nearly identical to other modern screens. The other problem that could occur seems less common, so I will not cover it here. The less common problem is the wires connecting to the CCLF tubes coming loose.

Step 1. Open the screen.
Unplug the monitor and press the power button a few times to (mostly) discharge any good capacitors.
Find all of the screws that are visible including VGA/DVI mounting screws and remove them, keeping a good idea of which holes they came from.

Now pry apart the plastic shell carefully. I use an expansion slot cover found on the back of a PC because they are wider than a screwdriver and leave less cosmetic damage (if any at all). Once you have the plastic bevel popped all around the edges, place the screen on your surface area, or lap, face down and lift the plastic off the back. This may not be the exact way for all monitors, but it has been for the last four I repaired.

Step 2. Take note of the orientation of the wires leading from the metal shielding. THese connecto to the high voltage CCFL tubes and may or may not be polarized. Don't screw this up! Take a photo if it helps.



Remove the metal shielding from the power and logic boards. Be very careful of any ribbon cables.
You should find the power board which is suspect.



Step 3. Inspect the power board. If you find swollen capacitors, you probably found the culprit. In our case, there are two swollen capacitors. From my experience, they normally go out in pairs, but I cannot prove that. Can you see the two fatties?




Step 4. Replace the capacitors with a "good" brand. Nichicon is my favorite. Make sure that the Farads are matched exactly and that the voltage is either the same or higher. Higher is better in this case, but normally the caps become larger with a higher voltage tolerance.



Step 5. Put it back together and power it up. ta-da! Although this is not 100% to work for you, it is a common problem and an easy fix. Good luck and good modding.

-Jordan

 ps. The monitor in this example was the Westinghouse L1975NW. I replaced two 220uF 25v capacitors with two 220uF 35v capacitors.
I also repaired an Acer x193w+ with new caps and some other Acer I no longer have.
One time I found that a Dell E2K-SE198WFPF(B) by reconnecting the CCFL tube with its wire which was difficult and apparently dangerous. To do so I had to disassemble the screen itself, LCD, polarizing film, and other layers just to get at the tubes...which were well encased in rubber. It was very difficult and I don't think that I would attempt it again.

Exploring the Miracle Piano Teaching System

A few years back, still living at my parent's house; I visited a small dirty yard sale hosted by a previously incarcerated criminal (or so he liked to brag). Oddly enough it was a combination of baby toys and power tools, but with one gem. Probably the best yard-sadly-deal I have ever found is my $5 Miracle Piano!

The sounds that it produces are pretty basic and common to other digital keyboards, but with a few more interesting ones. The keyboard has a "synth" option which sounds pretty cool and a bunch of drum samples, dog barking, ducks quacking and car screeching. Not only that, but it has MIDI input, MIDI output, RCA audio out, headphone out and internal stereo speakers.  The last two things to mention are the footpedal input which I have yet to use and the data port connection which connects to wither the NES, Sega Genesis, PC, or whatever other game console/computer it was designed for. All I would need is a special cable and the software, but I can't be happier with the keyboard itself.

I can't necessarily play any instruments, but my goal is to incorporate this keyboard into my modular kit. I hope to modify the audio output to be compatible with the "eurorack" parameters such as 10vpp (+/-5v) audio output, maybe a 0/5v gate or trigger output for when a key is pressed. I started by opening it up and tracing the speaker audio back to the source. I started probing from resistor to capacitor to op amp ... and a few hours later I still saw no end to JUST the left audio! This thing is overly complex it seems, so I took a break since then. I would like to not only take the audio signal itself, but also to mod the MIDI out signal with some sort of MIDI-to-CV converter which I am sure there are many different options for.

In any case, here are some photos to tide people over until I make some real progress:




Above is the board covered in what I assume is a ground plane to reduce noise. The screw terminals connect it to ground. Nothing but a pretty blue shielding.



And here is the bottom of the board. On this side you can see the external connectors, audio outputs and voltage regulation components.



And here is the good stuff. Several proprietary "Software Toolworks" ICs, some sort of microcontroller (maybe) ROM, RAM, and some other unidentified IC.



Above you can see the top right corner which has several op amps. The TDA connects most closely to the RCA outputs and speaker and if I recall correctly, the headphone too. The 5532 IC seems to connect only to one of the audio channels though which confuses me since there is only one 5532.



A closeup of the buttons, some LEDs and the key connectors at the bottom. This also shows one of the post-production modifications at the left. There are several modifications that they made the the final board before sale. MOre shown below.



This is a wide shot of several of the jumper wires that they added before sale, but after production. There seems to be a lot of them... It also shows the larger ICs which need identifying.



Yet more ICs and resistor arrays.



Here is a closeup of the ROM and RAM. It also clearly shows the text on some of the unknown ICs.



Above is the same photo, but with the sticker on the ROM removed. I will dump this ROM as soon as I get the chance and release the binary. Speculating, I bet it is some program and some sound samples. If we can figure out what is program and what is a sample, then the samples should be able to be replaced which could prove very interesting!

More soon. Thanks for reading,
Jordan