Monday, December 28, 2009

When not to use a clamp meter

Was just wondering whether my hardly-used Sanwa DCM 60L clamp meter would be able to measure the current draw of an incandescent lamp. I tried it out on a 60Watt bulb, and to my surprise the meter reading remained at 0.0A. Odd, I thought. I then tested a 100Watt. The meter budged by one count and read 0.1A. Obviously the meter was incorrect in the first case, since the bulb was shining brightly. And unless the lamp was way out of spec, the meter was wrong in the second case as well.

To find out the real deal, I decided to determine current using the Sanwa CD771 multimeter. I placed a 10-ohm, 5%, 1-Watt resistor in series with the bulb (the lamp socket, that is, in my test rig) via a terminal block onto which I screwed in the resistor leads and the wires to make a good and safe connection. The ohmmeter measured the actual resistance to be 9.5 ohms.

I would've wanted a smaller resistor value so that it would be insignificant compared to the lamps' filament resistance. Unfortunately I don't have any resistor smaller than 10 ohms and I don't have any other 10-ohm resistor (which I could connect in parallel). So I had to make do with this one resistor even if according to my calculations it would burn out if I used a 100-Watt lamp in the circuit: [(100W/220V)2]10Ω = 2.1Watts.

What's with the resistor anyway? I want to find out the actual current going through the circuit. To accomplish that I would measure the voltage drop across the resistor. It would then be trivial to compute for the current through the resistor and, because this is a series circuit, that would be the same current through the lamp as well.

The results are in the table below. Measured voltage of the mains at the time of testing was 232 Volts. This is the value used for calculations in the last column.

Lamp TypeClamp meter reading (without resistor)Voltage Drop across Resistor (V)Computed Current (A)Computed Total Power Dissipation (W)
Philips Softone 60Watts0.02.590.2762.6
Philips Spotline R80 60Watts0.02.570.2762.6
Philips Superlux 100Watts0.14.310.45104.4

As can be seen above, the lamps are in fact very close to their specified output and it was the clamp meter that was way, way off the mark. But why? I read the manual again and it turns out that at 50-60Hz the meter's accuracy is +/-(2% + 5 counts) and at 60-500Hz it's +/-(2.9% + 5 counts). These are for currents <200A.

Since the reading can be off by 5 digits (in this case that translates to +/- 0.5A), this clamp meter is absolutely useless for measuring currents less than 1A. Even for a current of 1A this meter will show anywhere from 0.4 to 1.5A. Thus the reading can be off from the true value by -60% to +50%. For 10A, reading will be in the range of 9.2 to 10.7A, which translates to -8% to +7% accuracy. Tolerable. In the 200A range, the meter reaches its highest accuracy of +/- 2 to 2.9% when measuring currents just below 200A. At over 100A the +/-0.5A (which is what the +/- 5 counts means in this range) becomes negligible.

So now I must remind myself that with this particular meter I have to take with a grain of salt any reading below 10A. Given the 220VAC mains voltage here, finding out the current draw of a load less than 2000W simply isn't worth checking with this meter.

Saturday, December 26, 2009

Twinkle, twinkle little bulbs, how I wonder how you're powered

Been meaning to find out the design of commercial Christmas lights control units. Obviously a microcontroller takes care of the various flashing patterns, frequency, fading in and out, etc. I was at a loss, however, at how they power the MCU--a low voltage DC device--and what they use to power the lamps--AC or DC.

Got the chance to do that when I fortuitously came across some old strings of lights that my brother had left here about a year or so ago. I didn't even know he had left them. I was clearing some stuff and stumbled upon them.

This particular set has three wires coming out of the control box. It was evident that one was a common and the two other were strings of bulbs. A momentary contact switch allows the user to cycle through the six or eight lighting/flashing patterns.

I was smiling when I saw two screws on the small control case. That meant I could actually open the thing up without cracking the case to bits. I would've been rather reluctant to ruin the plastic enclosure had it been glued shut.

I promptly opened the case and to my surprise the board contained very few parts. Take a look (click to see a larger version):

Seeing the four diodes immediately told me that the circuit uses a bridge rectifier. The electrolytic capacitor must be for filtering, I mused. And the two TO-92 parts just had to be transistors to switch the two lines of bulbs. The MCU is on the vertical daughterboard, the die sealed in a blob of black epoxy.

What intrigued me was how the MCU was being powered. At first I thought that the two resistors might be forming a voltage divider and feeding the MCU with a low voltage DC which is then filtered by the cap. But when I took the multimeter, traced the connections, and actually drew out the circuit, it turns out this simply was not so.

I now believe that the MCU has an integral shunt regulator or a voltage regulator of some sort which automatically delivers the required MCU voltage, probably 5V. The 180K resistor is necessary in order to drop practically all 200VDC across it (VACrms × √2 × 0.636 = VDC average). The 10uF capacitor filters the pulsating DC. Its 63V rating implies that voltage at the MCU's VDD pin is well below the raw rectified voltage of 200VDC (with a peak of >300V). That the resistor value is 180K means that average current going through is tiny--200V/180K = 1.1mA. The MCU has to be using a relatively low clock frequency and the load--the two transistors--have to be drawing a miniscule current.

Since I see no crystal, resonator, or resistor-capacitor to serve as clock, the MCU is probably using an internal oscillator. Stands to reason since this is a low-priced product. The board has provisions for 4 transistors and thus 4 branches of lights but only two are installed. Counting all the connections to the MCU including the provision for two more transistors, I surmise that this is an 8-pin type. Since the lighting pattern chosen by the user via the tactile switch is remembered even after the unit had been turned off, the MCU must be storing the value in nonvolatile memory, probably EEPROM.

Interestingly the 2-Mohm resistor is connected to the 220VAC line. The other end meanwhile goes directly to one of the MCU's pins. This must imply that the zero crossing of the AC wave is being sensed. Why would the circuit be doing that? It probably uses zero crossing for pulse width modulation timing purposes. Among the patterns available in this set of lights is a gradual fade in/out. Given the components, without a doubt PWM is being used to achieve this. I imagine that the PWM frequency is 120Hz--synchronized to the power line--while the duty cycle is varied from 100 to % (and back to 100%) when the lights are being dimmed and brought back to full brightness. Whenever a zero crossing is detected, the transistor is switched on. For how long depends on the duty cycle as determined by the firmware. How fast the duty cycle is incremented/decremented is variable--again as determined by firmware.

Since the load is being powered by full-wave rectified and unfiltered AC, the PWM system is analogous to AC phase control. Had this been an AC system, the MCU would, upon detection of zero crossing, begin timing. After a computed delay time, it would pulse the triac briefly to turn it on. The triac would then conduct until the next zero crossing upon which it automatically turns off and switches to high impedance state.

In this all-DC system, transistors are used for switching. Although I drew NPN BJTs in the above schematic, there is a good chance that MOSFETs are being used since they draw very little current. And as you may have noticed there are no current limiting resistors to the base of the transistors. I googled the printed part number "1225 A868" but couldn't find any useful information on it. What we do know is that these transistors are high voltage types since >300V peak will be across their output terminals.

Saturday, December 19, 2009

ATX in AT's clothing

I was going to use a very old AT power supply and convert it into a bench power supply, the reason being that it has a much larger case than an ATX which means there would be ample space for the seven binding posts I intend to install (five voltages and two ground). Moreover, it has an integral AC power switch right on the case--something you no longer get in current power supplies (and in some AT's the switch is not on the case but on the front panel of the computer). So this enclosure is perfect.

Alas, a check of the voltage outputs revealed that while the +5VDC line was fine, its +12VDC was only delivering 10.8V even when two hard drives were plugged in and whirring away. This was rather disappointing since a 10% deviation is simply unacceptable. But I really want this enclosure.

To cut to the chase I found an ATX power supply from a discarded Pentium 3 computer which showed output (positive) voltages within 5% of their stated values. After mulling it over I decided to disembowel the AT and transplant the ATX board into it.

Testing the ATX I discovered that while even without a load the PS starts (fan spins) and outputs were live, without any load the outputs were not too good: +5.25VDC and +11.5VDC. These two voltages are the most important to me so they're the ones I use as benchmark. I further discovered that loading the 12VDC line did not improve its output. But loading the 5VDC line not only pushed that output down toward 5.0VDC, but also pulled up the 12VDC line toward 12.0V.

My main reference for this project is How to Convert a Computer ATX Power Supply to a Lab Power Supply. In that article it advises using a power resistor to load the output. I thought, Why waste all that good power? Why not put it to some use? As in lighting up a bank of LEDs. I initially thought of using white LEDs that would be configured into some sort of a lamp to illuminate whatever circuit the PS was powering. However, I decided to illuminate the interior of the enclosure instead, using colored LEDs to bathe the components inside in theatrical lighting.

The AT has a 110/220VAC switch. Right above that is the socket into which the computer monitor's power cable is plugged. This area would be perfect and large enough for a small prototyping board with all the LEDs mounted on it. So I removed both the switch and socket. I cut a board down to a size that would fit that space. I then populated it with a total of 8 red and 10 blue LEDs. Supply is 5VDC and resistors were chosen such that current is about 15mA per branch. Measured forward voltage of the red LEDs were 1.8 and so two reds are in series per branch with a 100-ohm resistor as current limiter. Blues have a forward voltage of 3.0V and so there's only one LED per branch in line a 150-ohm resistor. There are 14 branches and so total current is around 210mA, for a total power dissipation of around 1000mW. Test shows that with this load, output voltages are as follows:

Ideal output (volts)Actual output (volts)

The green and a black wire are connected to a switch at the back. When green is not connected to ground PS is virtually off including the cooling fan. When green wire is grounded PS supplies power to the outputs. The AC power switch has to be closed of course. Purple and gray wires ("standby" and "power-good", respectively) are not used and not connected to anything.

Here's the ATX board and its fan already installed in the AT enclosure. The connectors to the motherboard and drives have all been snipped off and I've bundled and temporarily taped the wires by color (voltage). The bunch of red-black-yellow wires on the right is for the LEDs. I initially was going to use the +12V (yellow) but then as I said above tests showed that using it does not contribute to +12V output regulation. This yellow wire eventually joined its siblings.

Here it is after the case cover had been drilled and the binding posts installed. I couldn't find any other colors besides red and black so I used red binding posts for the negative voltages as well. Notice there are two posts for ground.

Back view showing the AC power switch and the PS-ON switch. The reason for the latter's location is that there already was a 1/8" hole on that spot. I just made it larger. The "AMAX" plastic sticker nameplate is from the ATX. You can see that the power supply was made in 2000. The neat thing about this PS is that it actually lists the wire color codes.

A look inside the connections to the binding posts. All wires were terminated with ring lugs. Even if the nuts come loose the wires won't fall onto the board and possibly cause disaster.

A view from the fan side. You can see the rectangular holes where the the monitor power socket and 220/110V selector switch once were. Because the copper side of the prototyping board will be exposed and accessible through these holes, I mounted an aluminum sheet to seal them. The sheet is sandwiched between the casing the two standoffs for the board.

The prototyping board is clearly visible. The top two rows are red LEDs. The rest are blue. I ran out of diffused epoxy blue LEDs so most of them are the clear type.

And the LEDs are shining!

The following were taken in complete darkness. Even with 18 LEDs the total output is nowhere close to bright.

Wednesday, December 16, 2009

It's the season ... to automate

I don't celebrate Christmas but when there's an electronics design opportunity in it I don't complain. There are these Christmas lights which I have to switch on at night and then switch off before midnight. This is a nightly task which will go on till the end of the year. Well, as can be expected there are times when I'm not around to turn the lights on and there are days when I simply forget. And there has been at least one occasion when I forgot to unplug the lights from the outlet (that's what serves as the switch).

Got fed up so I decided to automate it. What I needed was for the circuit to know it's dusk, turn the lights on, keep them lit for several hours, and then have them off until dusk the next day. This is a temporary circuit--one month and it won't be used anymore--so I decided to just keep everything on a breadboard. I also decided that it would be best to keep the main electronics indoors with only the "dusk sensor" somewhere outdoors.

In a nutshell this is how the circuit works. The dusk sensor outputs an analog voltage proportional to the ambient light level. This is fed to a microntroller which switches the load when light level falls below a value determined by the user. After a preset time duration the MCU turns off the load.

The sensor is a simple voltage divider using an LDR and a 300K resistor. Its output is fed to an op amp configured as a voltage follower. The ultra high impedance of this buffer prevents any loading of the signal. The op amp output is then sent to one of the MCU's analog input channels. The analog signal gets digitized by its ADC. The MCU compares this value with the trip level selected by the user. The trip level is adjusted using a 10K potentiometer whose output is connected to another of the MCU's analog channel.

I've chosen an 8-pin Microchip PIC12F615 because the circuit needs only two inputs and one output and I need those inputs to be analog channels. I could've picked one from the PIC10F series but I don't have software to program those in C. I'm just not in the mood right now for assembly language. I have about half a dozen models of single-supply, rail-to-rail Microchip op amps around here. I just opted for the MCP6273.

Because there may be abrupt and transient changes in ambient light level (lightning flash, car headlamp glare, prankster shining a flashlight, etc.) it is necessary to make sure that the sensor/circuit ignores these changes, else intermittent switching of the load occurs. This can be done via hardware by adding a few components--a capacitor, diode, and maybe a resistor. It can also be effected in firmware. The latter is what I opted for--why put to waste all that MCU computing power and memory?

I developed an algorithm for this two years ago and is based on moving averages. Readings are taken at fixed intervals (one to several seconds apart--the longer the interval the more immune to transient changes in light level). Each reading is compared to the previous average. If it exceeds the average by a predetermined amount (meaning there has been an abrupt change in light level) this reading is replaced with the average plus or minus the maximum allowed change (added or subtracted depending on whether the light level has increased or decreased). Thereafter, the last eight readings are averaged and compared to the trip level. If this new average is below the trip level then the MCU turns the load on. A hysteresis value (deadband) is incorporated such that the average light reading must increase beyond the trip level + hysteresis before the firmware resets a flag bit which keeps track of the transition from light to dark and dark to light (analogous to the rising/falling edges of a square wave). If the light level is between the trip level and trip level + hysteresis, then no action is taken.

Power supply is an adapter from my collection of old chargers, adapters, and the like. The one I found suitable is an Ericsson phone charger. It's probably a linear supply--cubelike and heavy, implying a bulky transformer. Its output is around 5.3VDC which drops to around 4.5V when the gas guzzling DC relay (40-ohm coil) is connected. I didn't even bother using an oscilloscope to check ripple voltage. I just used the multimeter to see what the DC voltage was with and without the load. To help Ericsson along I added a 1000uF 10V filter cap. This pulled up the with-load DC to 4.8V. Fortunately the relay still functions at barely 5VDC this adapter outputs. A diode (D1 in the schematic) was placed in series to drop the supply to the chips to <5VDC just to make sure they'll be operating within their supply limits.

The MOSFET transistor I used to switch the relay is a 2N7000. Relay is an Idec 4PDT. Coil: 6VDC, 40-ohms. Contacts: 250VAC 6A. It's plugged into a socket so all the AC and DC wires can be conveniently screwed in and safely secured. I added LEDs to provide visual indicators for the status of the load. A high efficiency blue LED that requires only a couple of milliamps to be visible was used to indicate "on." This choice was made in order to reduce the total current load on the power supply when the relay is on.

The main breadboard and relay were plunked into a plastic box. The sensor was also put in its own small translucent box and situated outdoors some 10 meters from the main electronics. So far so good. I adjusted the potentiometer so the load turns on when the streetlights have already been on for some 15 to 30minutes. The circuit works as required and the MCU timer is right on the money, turning the load off in almost exactly 5 hours even if it's only using its internal clock oscillator.

I love these tiny microcontrollers.

Click on the schematic.

Thursday, December 10, 2009

Telephone signals

Took the Rigol DS1102E scope and connected the probe to my home telephone line. I obtained the following readings. Click on the image to see a more legible version. Do keep in mind that dial tone, ringing, busy tone, and off-hook warning frequencies (and cadences) vary from country to country. So do voltages and other parameters. Seems like a free for all.

1. On-hook, telephone on standby. When the phone is not being used, the line is at 48 volts DC.

2. On-hook, phone ringing.

In the screen shot above the cursors are on and I've adjusted them to measure the DC voltage right before the ringing signal. You can see at the top right inset (delta Y) that the voltage has jumped to 54 Volts right before ringing.

The amplitude of the ringing signal itself is shown below measured. The value (delta Y) is 132 Volts peak to peak. That's around 47 Volts RMS (132/2/√2) riding on top of the 50 or so Volts DC.

I switched to split screen mode and both ringing signal and its frequency spectrum as obtained through the fast Fourier transform (FFT) function are shown below.

The same in full screen mode:

As you can see cursor A reads 20.8Hz. That's the ringing signal frequency

3. Off-hook, dial tone:

Like the ringing signal the dial tone is also a sine wave, but this one has high frequency noise riding on it. The cursors are on and you can read off the peak-to-peak amplitude which is around 350mV. The FFT function was turned on when I took the above reading and it is shown below.

I changed the resolution from 500Hz to 50Hz per division to get a better view of the peak frequency:

The dial tone is basically a single tone at 420Hz, although during other times I've measured it at 440 to 450Hz. The drift could be at the telephone company's end or somewhere along the transmission.

4. Off-hook, busy signal. I picked up the phone and just waited until the dial tone gave way to the busy signal. That took several seconds. Here's the waveform I got.

The low level high frequency noise to the left of the busy signal is the lull between the busy tone pulses. The purple curve at the bottom half is the frequency spectrum provided by the FFT. You can already see three or four significant blips there. Below are measurements of those frequencies using the cursors.

And a more detailed look at those:

So what I got were prominent signals at 480Hz and 620Hz with smaller signals at 1.9KHz and 2.0KHz. The latter two may or may not be actual components of the busy signal.

5. Off-hook alert. After several more seconds the busy signal gives way to the loud off-hook warning tone, which is screaming, "Hang up, you idiot!"

As you can see the maximum peak-to-peak voltage is approximately 460mV. The waveform along with the frequency spectrum:

Frequency spectrum measurements:

A closer look at those frequencies:

The most significant frequencies are 1.4KHz and 1.8KHz. The amplitudes of the 2.0, 3.2 and 3.6KHz are rather small. These may or may not be part of the off-hook alert signal.

Wednesday, December 9, 2009