Turn my laptop into an oscilloscope/THD meter?


SLS BATTERY AUCTIONS are now live at www.batteryhookup.com EV, Lithium, LifePo4, Inverters & More
Joined
May 25, 2017
Messages
472
Lots of companies tell you what the total harmonic displacement of their products are, but how can we be sure they're telling the truth? I mean, companies also say their 18650 cells have 9000000mAh too. But actual testing reveals more like 500mAh. So I like to test things.

Now, I've never seen an appliance or electronic device blow up from too much THD, but I'd like to know what's going on anyway. So I've been looking for some kind of THD meter that doesn't cost hundreds of dollars. I came upon this interesting discussion that among other things, talks about an application that can be used to turn a PC into an oscilloscope, and it calculates THD too. I tried it out on my laptop, and it "sees" the sound from my integrated microphone. So the principal seems sound. (No pun intended.)

To see what's happening in an electrical circuit though, some kind of device has to reduce the voltage down to something like 0.7V, according to the discussion, to avoid melting the PC. Maybe 0.5V to be safe. It was suggested a transformer and Voltage divider be used. I dug around my many piles of junk and found an old Ni-Cad drill battery charger. Last time I tried it, either the battery was bad, or the charger was bad. I don't intend to replace either one, so I opened the charger up and discovered a lovely low frequency transformer.

20230224_194150.jpg


After liberating it from the circuit board, I poked around it, looking for continuity and Voltage output. It appears to have two separate secondary windings which are isolated from each other and the primary. Well I made a picture with labels to help keep track of things:

Transformer.jpg


On the primary side, there are 3 pins. A is hot, B is neutral, C is unused.
On the secondary side, pins 1 and 2 show 2.6V, and pins 3 and 4 show 9.2V. The 1,2 coil has no continuity with the 3,4 coil.

When it was still on the circuit board, pins 2 and 3 were soldered together. I suppose that would give a total voltage of 11.8V. I made a modified version of the diagram discussed in the other forum:
VoltDivider.jpg


I have a bunch of 10k potentiometers that I bought for fine-tuning TP4056 boards' current output. I figure one of them could be used as R1, and then the output Voltage could be fine-tuned to whatever the PC oscilloscope can read well. If I did the Voltage divider math right, I'll need somewhere around 2,260 Ohms for R1. I should be able to find a 100 Ohm resistor around somewhere. The current through the Voltage divider should be very small. Like 0.005A. I don't know how much current would be going through the TRS jack. I'm guessing another tiny amount.

Since I'll be getting a split-phase generator and inverter, it would be nice to be able to plug either 120V or 240V into the device, and adjust it for the PC. Another reason to use a pot. for R1. Maybe a switch to toggle between two different R1s? I wonder if pin C on the primary side could be used for anything. I'm thinking that the primary coil goes from pin A to pin C, with pin B being a center tap. I suppose this transformer was designed for many different applications, and not just this particular charger. Well, I'm getting ahead of myself here. Let's see if the basic device works first.

Anyway, I thought this would make a pretty cool project. Hopefully I'll have some progress to share soon.
 

Redpacket

Active member
Joined
Feb 28, 2018
Messages
1,507
When running on a generator, it's more likely for things to get damaged from voltage surges, eg when another load is switched off, the generator takes a few cycles to settle to the lesser load. Might be less of a problem on the "inverter generator" models?

There's also free s/w called REW "Room Equalization Wizard" which has all sorts of fabulous features & distortion graphs are in there.

To save your PC/laptop input from overload you can use a bridge rectifier. Connect the rectifier's two AC points across the audio & solder the + & - together. This makes a two diode drop (approx 1.4V) limiter that's bidirectional.
You could just use the potentiometer with one end to the input voltage, other end to ground & wiper to PC input (via above limiter)?
If you needed better range control, I'd put eg a 4.7k resistor in series with the input voltage.
 
Joined
May 25, 2017
Messages
472
I hadn't thought about surges from appliances being switched off. I plan to use an inverter generator. I'm not an expert in any of this stuff, but I think and inverter gen would react faster, as it's Voltage and frequency output is controlled electronically rather than from the RPMs of the engine. There is a "whole house" surge suppressor that can be installed on say, a breaker panel, that takes large-ish Voltage spikes and somehow shunts them to ground.

The REW program looks interesting. I wonder what it would make of a 60Hz sine wave.

I'm not sure I followed your ideas to modify the Voltage divider. But here's what I came up with:
VoltDividerMod.jpg


I'm way closer to being a noob than an expert at electronics, so there are big gaps in my understanding of how this all works.
 
Joined
May 25, 2017
Messages
472
I found all the parts and soldered them together in a very temporary fashion today.
20230226_202807.jpg


I used the empty charger box to house the transformer. Keeps things safer from the high Voltage side that way. My 100 Ohm resistor turned out to be more like 186 Ohms, but that's ok, because the potentiometer worked perfectly to reduce the output signal to 0.5V. I have an ultra cheap pocket oscilloscope that isn't very accurate, but gives a general idea of what's going on. I've got it set up to 0.5 Volts and some number of ms. Got a nice sine wave coming from the wall.

Well, I can't find my old laptop which I was going to use to try this out. I do have an external USB sound card though that I might try with my current laptop. If I can find it. I might have a 1VAC meter somewhere I might add to this too, to make sure I'm always below a Volt.

I was watching some You Tube videos today, and saw a lot of people building general purpose probe adapters for REW and the soundcard scope software. The parts they used look like they might be what Redpacket was describing to me. I think the design I'm using has a single application, to measure signal and THD from a 120V source. The other type is designed for studying electronics, and is much more versatile. At least I think that's what's going on. If this works out, I may try to build one of those also. Though I'm mostly just interested in the wave form coming from inverters, UPSs, and generators. Never-the-less, I appreciate the suggestion.
 

Redpacket

Active member
Joined
Feb 28, 2018
Messages
1,507
Good idea with the box :)
That diagram looks almost right!
Just move the bridge over to the right side just before the TRS jack, & turn the 10k "vertical" so the wiper (center) goes towards the TRS jack, top of 10k to 4.7k, bottom of 10k to 100ohm or just remove 100ohm & replace with wire link.
Otherwise, with the bridge rectifier as now, it'll be likely to be close to clipping already.

If the transformer is intended for 120V, it's likely to get unhappy & do magic smoke with 240...!!

Maybe like this:
divider for THD measurement.jpg
 
Last edited:
Joined
May 25, 2017
Messages
472
I was thinking that with so little current used, 240V shouldn't be a problem. But there's also the iron core to consider. It can only convert so much... something... into a magnetic field before the coil becomes a short. So yeah, better keep it at 120V.

I also measured pin C on the primary side while I had it plugged in. There's 120V between A and C, and 0V between B and C. Unfortunately, I don't know enough about transformers to understand what that means, or why there is an unused pin C. Doesn't really matter anyway. It works the way it is.

I never did find my old laptop. I did find the external USB sound card, so I plugged that into my newer laptop. Unfortunately, the external sound card seams to clip the wave form and did some other odd things. But it didn't pop or smoke, so I plugged the divider into the laptop directly and got a perfect signal:
PowerGridWave.png


Turns out the tip of the TRS jack is read as channel 1, and the ring is read as channel 2. So I got a red line for the graph. But I was able to measure the THD of the mains. It seems to average at about 2.9%. I've read that mains Voltage typically has around 3%, so this is as expected.
PowerGridTHD.png


Now that I verified that it works, I took it all apart and clean it up. The box was a mess from many years of paint and grime. Plus the labels are all wrong now, so I removed them. I also pulled a few more components off the circuit board. It got put back together with longer wires, shrink wrap where I could fit it, and I hot glued the bridge rectifier and heat sink into the box.
20230228_074332.jpg


I soldered the rectifier to the transformer and got 10.72VDC out from the 12.6VAC that's across pins 1 and 4. At least I think it was 12.6V. I don't remember for sure. Anyway, you can see the DC ripple coming out of the rectifier on the oscilloscope. I don't know where the weird lines on the screen are coming from. Must be some artifact from the camera. The circuit board had a single capacitor on it which I figured was a smoothing capacitor for the rectifier. It's a 25V capacitor, so safe to use here. Sure enough, the ripple smoothed way down, and the Voltage ended up at 15.8V.
20230228_075223.jpg


I hot glued the red LED from the circuit board into it's original spot in the box, and did some LED math. I needed a resistor around 934 Ohms to run the LED at 15.8V. Well, I found a 996 Ohm resistor from the circuit board. I tested all these components with my little parts tester.
20230228_075810.jpg


I can't actually read all those ring codes on resistors. Plus this way I can verify that all the parts are working before I try to reuse them. Probably no coincidence that these parts have all worked out. I attempted to do some cable management, but that mostly failed. I did cover all the exposed circuitry with hot glue.
20230228_081347.jpg


That rectifier is good for up to 4A, so I may add a DC output and a regulator at some point. Here it is all buttoned up.
20230228_081632.jpg


The LED is a reminder that it is still plugged in, and I glued the potentiometer to the outside so it can be adjusted without having to open the box. Shouldn't really need to though. I'd still like to add a 1VAC meter to the output. I think I have one somewhere.

Well now I have a couple UPSs, some inverters, and eventually a generator that I can test for THD. And I built the thing with junk I had lying around, so it was free.
 

Oberfail

Member
Joined
Jun 22, 2021
Messages
298
Keep in mind that the ADC (analog to digital converter or also called sound card) of your Laptop has probably a good amount of THD and other noise issues itself. Apple's USB-C Audio Dongle costs 10usd and is the best DAC / ADC in its price class for a computer but may still need a USB to USB-C Adapter.

But still, a great project :)
I'm looking forward for all the measurements you are going to collect!
 
Joined
May 25, 2017
Messages
472
I collected 3 UPSs today and made some measurements. Not very scientific, but my understanding is that THD can change depending on the type of load an inverter has, and even if it has a load or not. So I found an inductive load (fan), a resistive load (light bulb) a non-linear load (my laptop's switch mode power supply) and a ballast load (a CFL)

I didn't find any patterns in the numbers I got. Maybe because these weren't particularly heavy loads. I also found that the THDs were listed on the back stickers of each device, so I added that into the table too.
THD.png

The one listed as Power Box is the UPS I turned into a portable power supply. I don't use the inverter part much since the battery is limited to 30W. I've found the DC 12V and 5V ports I added are much more useful while traveling.

My big UPS has a bad battery, so its out at the moment. I also have a WZRELB that is a "pure" sine inverter. That's the one I got for the trailer project. I'm very interested to compare that to these really bad inverters.

Just for fun, I took some screen shots of the wave forms. They are mostly just regular modified sine waves, but with a couple interesting variations:
Screenshot 2023-03-06 12.49.21.png

Power Box with no load.

Screenshot 2023-03-06 12.49.21.png

The APC 350, also no load.

Screenshot 2023-03-06 12.55.01.png

The APC 350 with a load. It didn't matter which one.

Screenshot 2023-03-06 12.57.33.png

The APC 750 with no load. It turned into a "normal" modified sine wave under load.

I had to look really hard for a CFL and an incandescent light bulb. I had to raid the fridge for its 40W incandescent, and I found an old lamp with a CFL that was still working. Pretty much everything in my house is LED now.
 
Joined
May 25, 2017
Messages
472
You're looking at a different UPS than the one I have. Mine is the BE750G. I suspect the SMT750C has a much nicer wave and lower THD. All my APCs have a THD listing on the back. 40-50% THD. I haven't measured my APC 1300 yet since it has a bad battery, but I'm sure it will look terrible also.

I got my WZRELB pure sine inverter setup with a power supply. It has a much nicer wave form:
WZRELB.png


The THD with no load was an astonishing 0.86%. Under the various loads it went up to 1.01-1.76%. I'm only using a few Watts for these loads, so I suspect the THD would increase as the loads get closer to the device's maximum. The advertised THD is <5%. True so far.

This is the only source of pure sine power that I have apart from the grid. I bought it to run an air conditioner and mini fridge in the trailer I haven't built yet. I think those would both be considered inductive loads. I should look at the THD next time I have all those things together.
 
Joined
May 25, 2017
Messages
472
Hey all,
I thought you might like to see a chart of what 40% THD looks like:
40PercentTHD.png

The tallest peak on the left represents the regular 60Hz sine wave. The smaller peaks are occurring at various harmonic points, which is where THD gets the harmonic term from. I don't totally get what those are, but apparently they're some sort of multiple of the main signal. In fact, the x-axis on the chart is Hz, with the main signal being at 60. I don't know what the y-axis is measured in. Some kind of signal strength I guess.

Anyway, the weaker signals are not supposed to be there. These lower peaks represent the distortion in the perfect wave form. What the app does is to add up all these distortions to make a total to display as a percentage. Here's what the graph looks like at 0.83% THD:
0dot83PercentTHD.png

See, pretty much no extra peaks.

I also made a final "as built" diagram for the Voltage divider:
VoltageDivider.png

I was bored, so I prettied it up a little. It's a bit modified so I can use the rectified DC to power a small buck converter. Should be good for 60W.

I have a 1,500W conventional generator I want to measure, but that won't be until later when the weather improves. Other ideas I have are comparing DC power supply outputs to see how a really bad input sine wave might affect the output.
 

Redpacket

Active member
Joined
Feb 28, 2018
Messages
1,507
Awesome measurements, nice work :)
Some thoughts:
Yeah putting 240V into the 120V transformer is likely to "saturate" the iron core because the stronger magnetic field is now too much, this makes the current in the winding rise a lot = magic smoke soon!
If the transformer has multiple connections on the primary (120 side) there might be "taps" (connection points) for 0V (the neutral), 120V & 240V
or other international variations like 100V (Japan), 220V (Europe), but I doubt that charger is that fancy :)
So the circuit you're using just above here could put 12V AC into the soundcard/laptop if you turned the potentiometer to the end
It also has no overvoltage limiting at the TRS jack like suggested above. You might blow the sound input?
Also, if you draw any significant current from the 15V DC output, this will load the transformer & cause a nice clean sinewave to get clipped at the tops a bit & distortion to rise.
The 15VDC out will likely drop a volt or two with a "modified sine" input.
 
Joined
May 25, 2017
Messages
472
I've decided to just leave the primary side be, and use it only for 120V input. In addition to not having to worry about misusing the transformer, it also keeps the output the same all the time. This means that once the potentiometer is set, there's no need to ever change it. So I'm looking at the potentiometer as the voltage limiter. It's one of those tiny blue boxes that is really meant to set it an leave it. Wouldn't hurt to double check the output voltage before I plug it into the laptop after not using it for a while. Just to be sure.

I'm thinking of the AC signal output, and the DC power output as either/or. I don't plan to use them both at the same time. In fact, once I've measured the THD of some 120VAC source, I have no further use for it. I see it setting on a shelf collecting dust for months or years if that's all I use it for. It would get a lot more use as a second benchtop power supply. I have one of those typical 30V 10A adjustable power supplies, but its often busy doing other things.

It would be interesting though, to see what happens to the signal output when a load is on the DC. I might try that some time just for fun. :)
 
Top