Issue 266: EQ Answers

The answers to the Circuit Cellar 266 (July 2012) Engineering Quotient are now available. The problems and answers are listed below.

Problem 1—What’s the key difference between infinite impulse response (IIR) and finite impulse response (FIR) digital filters?

Answer 1—An infinite impulse response (IIR) filter incorporates feedback in its datapath, which means that any particular input sample can affect the output for an indefinite (infinite) time into the future. In contrast, a finite impulse response (FIR) filter uses only feedforward in its datapath, which means that any given input sample can only affect the output for a time corresponding to the number of storage (delay) stages in the filter.

Problem 2—Does the fact that the finite resolution of digital arithmetic effectively truncates the impulse response of an IIR filter turn it into an FIR filter?

Answer 2—While it’s technically true that the impulse response of an IIR filter implemented, say, with fixed-point arithmetic is effectively finite, this has no real bearing on its classification in terms of either its design or application. It’s still an IIR filter for all practical purposes.

Problem 3—The following pseudocode represents an implementation of a single-pole low-pass IIR filter, using 16-bit input and output values and a 24-bit internal accumulator and a filter coefficient of 1/256:


  # The 32-bit accumulator holds 16 integer
  # and 16 fractional bits
  $acc = 0x00000000;

  # The input value is a 16-bit integer.
  $input = 0xFFFF;

  # Offset used for rounding the accumulator
  # to 24 bits.
  $offset = 0x80;

  while (1) {
    # acc = (255*acc + input)/256
    $acc -= ($acc >> 8);
    $acc += ($input << 8) + $offset;
    # limit acc to 24 bits
    $acc &= 0xFFFFFF00;
    # output is integer part of acc
    $output = $acc >> 16;
  }

An implementor of this filter complained that “the output never reaches 0xFFFF.” What was the flaw in his reasoning?

Answer 3—The accumulator in this filter eventually settles at the value 0xFFFE8100. If you simply take the upper 16 bits of this, then the output value appears to be 0xFFFE. But if you properly round the accumulator by adding 0×00008000 before dropping the LSBs, then the output value is the correct value of 0xFFFF.

Problem 4—The original implementor’s solution was to change the $offset value to 0xFF. Why did this work?

Answer 4—Changing the $offset value to 0xFF effectively adds a bias to each input sample, which averages out to 0x00007F00 in the accumulator. The effect of this is to add the required rounding offset to the accumulator so that truncating the LSBs to create the 16-bit output value comes up with the correct answer.

.

Implement a Tilt and Interference-Compensated Electronic Compass

Would you like to incorporate an electronic compass in a consumer product you’re designing or a personal device you’re constructing? If so, you’ll do well to understand as much as possible about the differences between various sensors and how certain forms of interference can affect their accuracies.

Mark Pedley of Freescale Semiconductor has an article in Circuit Cellar 265 (August 2012) on these topics. An abridged version of his article follows. Pedley writes:

 Whenever a new high-volume consumer electronics market develops, the semiconductor companies are never far behind, providing excellent components at surprisingly low prices. The market for sensors in consumer products is a recent example. It all started with an accelerometer used to select between portrait and landscape display orientations and then, with the addition of a magnetometer, evolved into the electronic compass (eCompass) used to align street maps to the smartphone’s geographic heading or to enable augmented reality overlays. As a result, high-volume pricing for smartphone accelerometer and magnetometer sensors is now less than $1 each.

A magnetometer sensor alone cannot provide an accurate compass heading for two reasons. First, the magnetic field measured at the magnetometer varies significantly with tilt angle. Second, the magnetometer requires calibrating not only for its own offset but also against spurious magnetic fields resulting from any nearby ferromagnetic components on the circuit board. This article describes how the accelerometer is used to compensate the magnetometer for tilt and includes a simple technique for calibrating the magnetometer.

SENSOR SELECTION

The accelerometer should be three axis and capable of operating in the ±2-g range with a minimum of 10 bits of resolution. The output of a 10-bit accelerometer operating in the ±2-g range will change by 512 counts as the accelerometer is rotated 180° from pointing downward to upward, giving an average sensitivity of one count per 0.35° change in tilt. This is more than adequate for tilt-compensation purposes.

It is important to check the accelerometer datasheet for the “0-g offset accuracy” which is the output when the accelerometer is in 0-g freefall. Since this value is a constant additive error on each accelerometer channel, it adds a bias in the calculated tilt angles, so look for accelerometers where this parameter does not exceed 50 mg.

The magnitude of the earth’s geomagnetic field is typically about 50 µT with a horizontal component that varies over the earth’s surface, from a maximum of about 40 µT down to 0 at the geomagnetic poles. If an eCompass is required to operate in horizontal geomagnetic fields down to 10 µT (in arctic Canada, for example) with a noise jitter of ±3°, then a back-of-the-envelope calculation indicates that a magnetometer with a maximum noise level of 0.5 µT is needed.

Most of my projects have used Freescale’s MMA8451Q Xtrinsic three-axis, 14-bit accelerometer and MAG3110 three-axis magnetometer. The MMA8451Q is supplied in a 3-mm × 3-mm × 1-mm, 16-pin QFN package and provides a 14-bit data output with ±30-mg, 0-g offset accuracy. The MAG3110 magnetometer is supplied in a 2-mm × 2-mm × 0.85 mm, 10-pin DFN package and provides a measurement range of ±1,000 µT with 0.1-µT resolution and a noise level down to 0.25 µT. Both parts operate with a supply voltage between 1.95 V and 3.6 V.

Similar sensors are supplied by Asahi Kasei (AKM), Kionix, STMicroelectronics, and other manufacturers. Your best strategy is to go to the manufacturers’ websites and make a list of those that provide samples in single units or low-volume packs of up to five devices. With a bit of luck, you may be able to get both the accelerometer and magnetometer sensors for free. Add a handful of decoupling capacitors and pull-up resistors and you should be well within the $5 component cost.

Each reader has a preferred microcontroller to read the raw data from the two sensors and implement the eCompass. This article assumes the microcontroller provides an I2C bus to interface to the sensors, supports floating-point operations whether natively or through software emulation libraries, and has a few spare bytes of program and data memory…

LAYOUT & BOARD BRING-UP

Once you’ve selected your sensors, the next step is to design the accelerometer and magnetometer daughterboard with I2C bus connection to the microcontroller. Reference schematics for the MMA8451Q and MAG3110 are provided in the sensor datasheets and reproduced in Figure 1.

Figure 1: Schematics for (a) MMA8451Q and (b) MAG3110 sensors (Source: M. Pedley, Circuit Cellar 265)

Don’t waste any time rotating the accelerometer or magnetometer packages to align their x-, y-, and z-sensing directions to each other since this will be  fixed later in software. But do ensure the sensor board will not be mounted in the immediate vicinity of any ferromagnetic materials since these will produce a constant additive magnetic field termed the “hard-iron field.” The most common ferromagnetic materials are iron, steel, ferrite, nickel, and cobalt. Non-ferromagnetic materials are all safe to use (e.g., aluminum, copper, brass, tin, silver, and gold).

The calibration process described later enables the estimation and software subtraction of any hard-iron field, but it’s good practice to minimize hard iron interference at the design stage. Remember, a current trace will create a cylindrical magnetic field that falls off relatively slowly with the inverse of distance, so place the magnetometer as far away from high current traces as possible. A 0.1-A current trace at 10-mm distance will produce a 2-µT magnetic field, four times our 0.5-µT error budget, only reducing to 0.5 µT at a 40-mm distance. More detailed layout guidance is provided in Freescale Semiconductor’s application note AN4247: “Layout Recommendations for PCBs Using a Magnetometer Sensor.”

You’ll be surprised at the number of features implemented in the latest consumer sensors (i.e., freefall detection, high- and low-pass filtering options, automatic portrait and landscape detection, etc.), but disable all these since you simply want the raw accelerometer and magnetometer data. Configure the accelerometer into a 2-g range and check that you can read the x, y, and z accelerometer and magnetometer data (in units of bit counts) from the sensors’ internal registers at a sampling rate of between 10 Hz and 50 Hz. Smartphones commonly use IDH3 to minimize power consumption while anything above 50 Hz is overkill. Check the accelerometer datasheet for the conversion factor between counts and g (4,096 counts per g for the MMA8451Q in ±2-g mode) and use this to scale the x, y, z accelerometer readings into units of g. Do the same for the x, y, z magnetometer data again taking the conversion factor from the magnetometer datasheet (10 counts per µT for the MAG3110).

COORDINATE SYSTEM

The equations and C software in Listing 1 use the “aerospace,” or “x-North y-East z-Down,” coordinate system depicted in Photo 1.

Listing 1: C source code for the tilt-compensated eCompass (Source: M. Pedley, Circuit Cellar 265)

This defines the initial eCompass orientation to be where the x-axis points north, the y-axis points east, and the z-axis points downwards. The three orientation angles, roll (ϕ), pitch (θ), and compass heading, or yaw (ψ)—are defined as clockwise rotations about the positive x, y, and z axes— respectively. Photo 1 also shows the earth’s gravitational vector which points downward with magnitude of 1 g or 9.81 ms-2 and the earth’s geomagnetic field vector, which points downward from horizontal (in the northern hemisphere) by the inclination angle δ to give a horizontal component B0cosδ and a downward component B0sinδ.

Photo 1: The aerospace noth-east-down coordinate system (Source: M. Pedley, Circuit Cellar 265)

Based on how your eCompass housing will be held, you should be able to assign the compass-pointing direction or x-axis, the downward or z-axis, and the y-axis, which should point to the right to complete a right-handed coordinate system.

AXIS ALIGNMENT & MAGNETIC CALIBRATION

You now need to align the sensor data to the aerospace coordinate system. As with all work with magnetometers, this should be performed on a wooden table well away from any laboratory power supplies or steel furniture. Place the eCompass flat and upright so the z-axis points downward and is aligned with gravity. Check that the accelerometer z-axis reads approximately 1 g and the x- and y-axes are near 0. Invert the eCompass so its z-axis points upward and check that the z-axis now reads approximately –1 g. Repeat with the x- and y-axes pointing downward and then upward and check that the x- and  y-axis accelerometer readings are near 1 g and –1 g, respectively. It’s not important if the accelerometer readings are a few tens of mg away from the required reading since all you’re doing here is correcting for gross rotations of the sensor packages and the sensor daughterboard in multiples of 90°. Any needed correction will be unique for your board layout and mounting orientation but will be no more complicated than “swap the x- and y-accelerometer channels and negate the z-channel reading.” Code this accelerometer axis mapping into your software and don’t touch it again.

Figure 2 may help explain this visually. The accelerometer sensor measures both gravity and linear acceleration and, in the absence of any linear acceleration (as is the case when sitting on a desk), the magnitude of the accelerometer reading will always equal 1 g, and therefore, lie on the surface of a 1-g sphere, irrespective of the orientation.

Figure 2: Accelerometer axis alignment points (Source: M. Pedley, Circuit Cellar 265)

The six measurements  lie on the vertices of an octahedron inscribed within the 1-g sphere and the axis mapping simply rotates and reflects the octahedron as needed until the accelerometer channels are correctly aligned.

The magnetometer axis alignment is similar to that of the accelerometer, but makes use of the geomagnetic field vector. Place the eCompass flat, upright, and pointing northward and then rotate in yaw angle by 270° to the east, south, and finally west. The x-channel magnetometer reading should be a maximum when the eCompass is pointed north and a minimum when pointed south. The y-channel magnetometer reading should be a minimum when the eCompass is pointed east and a maximum when pointed west. The z-channel reading should be approximately constant since the vertical component of the geomagnetic field is constant irrespective of rotation in yaw.

Then invert the eCompass on the desk and repeat the process. As before, the magnetometer x-axis reading should be a maximum when the eCompass is pointed north and a minimum when pointed south. But now, because of the inverted position, the magnetometer y-axis should be a maximum when the eCompass is pointed east and a minimum when pointed west. The magnetometer z-axis reading should still be constant but, in the northern hemisphere, lower than the previous upright readings since the magnetometer z-axis is now aligned against the downward component of the geomagnetic field vector.

Figure 3 shows upright and inverted magnetometer measurements taken in the northern hemisphere with a 270o compass rotation.

Figure 3: The upright (a) and inverted (b) magnetometer measurements (Source: M. Pedley, Circuit Cellar 265)

The maximum and minimum of the x- and y-axis magnetometer measurements occur at the expected angles and the z-axis measurement is less when inverted than when upright. These magnetometer axes are therefore correctly aligned but, as with the accelerometer correction, swap and negate the measurements from your three magnetometer channels as needed until correctly aligned and then lock down this part of your code.

A lot can be learned by closely looking at the measurements in Figure 3. The x- and y-magnetometer measurements lie on a circle with radius of approximately 25 µT enabling us to deduce that the horizontal geomagnetic field is approximately 25 µT. But the measurements are offset from zero by the magnetic “hard iron” interfering field, which results from both permanently magnetized ferromagnetic materials on the circuit board and from a zero-field offset in the magnetometer sensor itself. Consumer sensor manufacturers long ago realized it was pointless to accurately calibrate their magnetometers when their target market is smartphones, each with a different hard-iron interfering field. The magnetometer sensor offset is, therefore, calibrated together with the circuit board hard-iron magnetic field. For now, simply note that the x and y components of the hard iron offset have values of approximately 215 µT and 185 µT. A simple method to determine all three hard-iron components is described later.

Refer to the complete article for information about calculating the roll and pitch angles and determining the compass heading angle.

Mark Pedley has a Physics degree from Oxford University and now works on sensor fusion algorithms for Freescale Semiconductor in Tempe, Arizona.

The Basics of Thermocouples

Whether you’re looking to build a temperature-sensing device or you need to add sensing capabilities to a larger system, you should familiarize yourself with thermocouples and understand how to design thermocouple interfaces. Bob Perrin covered these topics and more in 1999 Circuit Cellar Online article , “The Basics of Thermocouples.” The article appears below in its entirety.

A mathematician, a physicist, and an engineer were at lunch. The bartender asked the three gentlemen, “what is this pi I hear so much about?”

The mathematician replied, “pi is the ratio of a circle’s circumference to its diameter.”

The physicist answered, “pi is 3.14159265359.”

The engineer looked up, flatly stated, “Oh, pi’s about three,” then promptly went back to doodling on the back of his napkin.

The point is not that engineers are sloppy, careless, or socially inept. The point is that we are eminently practical. We are solvers of problems in a non-ideal world. This means we must be able to apply concepts to real problems and know when certain effects are negligible in our application.

For example, when designing first- or second-order filters, 3 is often a close enough approximation for pi, given the tolerance and temperature dependence of affordable components.

But, before we can run off and make gross approximations, we must understand the physical principles involved in the system we’re designing. One topic that seems to suffer from gross approximations without a firm understanding of the issues involved is temperature measurement with thermocouples.

Thermocouples are simple temperature sensors consisting of two wires made from dissimilar alloys. These devices are simple in construction and easy to use. But, like any electronic component, they require a certain amount of explanation. The intent of this paper is to present and explain how to use thermocouples and how to design thermocouple interfaces.

A TAIL OF TWO METALS

Figure 1a shows a thermocouple. One junction is designated the hot junction. The other junction is designated as the cold or reference junction. The current developed in the loop is proportional to the difference in temperature between the hot and cold junctions. Thermocouples measure differences in temperature, not absolute temperature.

Figure 1a: Two wires are all that are required to form a thermocouple.

To understand why a current is formed, we must revert to physics. Unfortunately, I’m not a physicist, so this explanation may bend a concept or two, but I’ll proceed nonetheless.

Consider a homogenous metallic wire. If heat is applied at one end, the electrons at that end become more energetic. They absorb energy and move out of their normal energy states and into higher ones. Some will be liberated from their atoms entirely. These newly freed highly energetic electrons move toward the cool end of the wire. As these electrons speed down the wire, they transfer their energy to other atoms. This is how energy (heat) is transferred from the hot end to the cool end of the wire.

As these electrons build up at the cool end of the wire, they experience an electrostatic repulsion. The not-so-energetic electrons at the cool end move toward the hot end of the wire, which is how charge neutrality is maintained in the conductor.

The electrons moving from the cold end toward the hot end move slower than the energetic electrons moving from the hot end move toward the cool end. But, on a macroscopic level, a charge balance is maintained.

When two dissimilar metals are used to form a thermocouple loop, as in Figure 1a, the difference in the two metal’s affinity for electrons enables a current to develop when a temperature differential is set up between the two junctions.

As electrons move from the cold junction to the hot junction, these not-so-energetic electrons are able to move easier in one metal than the other. The electrons that are moving from the hot end to the cold end have already absorbed a lot of energy, and are free to move almost equally well in both wires. This is why an electric current is developed in the loop.

I may have missed some finer points of the physics, but I think I hit the highlights. If anyone can offer a more in-depth or detailed explanation, please e-mail me. One of the best things about writing for a technical audience is learning from my readers.

BREAKING THE LOOP

If you use thermocouples, you must insert a measurement device in the loop to acquire information about the temperature difference between the hot and cold junctions. Figure 1b shows a typical setup. The thermocouple wires are brought to a terminal block and an electric circuit measures the open circuit voltage.

Figure 1b: To use a thermocouple, you must have a measurement system.

When the thermocouple wires are connected to the terminal block, an additional pair of thermocouples is formed (one at each screw terminal). This is true if the screw-terminals are a different alloy from the thermocouple wires. Figure 1c shows an alternate representation of Figure 1b. Junction 2 and junction 3 are undesired artifacts of the connection to the measurement circuitry. These two junctions are commonly called parasitic thermocouples.

Figure 1c: The act of connecting a measurement system made of copper introduces two parasitic thermocouples.

In a physical circuit, parasitic thermocouples are formed at every solder joint, connector, and even every internal IC bond wire. If it weren’t for something called the Law of Intermediate Metals, these parasitic junctions would cause us endless trouble.

The Law of Intermediate Metals states that a third metal may be inserted into a thermocouple system without affecting the system if, and only if, the junctions with the third metal are kept isothermal (at the same temperature).

In Figure 1c, if junction 2 and junction 3 are at the same temperature, they will have no effect on the current in the loop. The voltage seen by the voltmeter in Figure 1b will be proportional to the difference in temperature between Junction 1 and Junctions 2 and 3.

Junction 1 is the hot junction. The isothermal terminal block is effectively removed electrically from the circuit, so the temperature of the cold junction is the temperature of the terminal block.

MEASURING TEMPERATURE

Thermocouples produce a voltage (or loop current) that is proportional to the difference in temperature between the hot junction and the reference junction. If you want to know the absolute temperature at the hot junction, you must know the absolute temperature of the reference junction.

There are three ways to find out the temperature of the reference junction. The simplest method is to measure the temperature at the reference junction with a thermistor or semiconductor temperature sensor such as Analog Devices’ TMP03/04. Then, in software, add the measured thermocouple temperature (the difference between the hot junction and the reference junction) to the measured temperature of the reference junction. This calculation will yield the absolute temperature of the hot junction.

The second method involves holding the reference junction at a fixed and known temperature. An ice bath, or an ice slushy, is one of the most common methods used in laboratory settings. Figure 2 shows how this is accomplished.

Figure 2: By inserting a short pigtail of Metal A onto the terminal block where Metal B would normally connect, we move the cold junction.

Alternately, we could have omitted the pigtail of Metal A and just immersed the terminal block in the ice. This would work fine, but it would be much messier than the method shown in Figure 2.

Sometimes, the temperature of the cold junction (terminal block) in Figure 1c is allowed to float to ambient. Then ambient is assumed to be “about 25°C,” or some other “close enough” temperature. This method is usually found in systems where knowing the temperature of the hot junction is not overly critical.

The third method used to nail down the cold junction temperature is to use a cold junction compensation IC such as the Analog Devices AD594 or Linear Technology LT1025. This method sort of combines the first two methods.

These ICs have a temperature sensor in them that detects the temperature of the cold junction. This is presumably the same temperature as the circuit board on which the IC is mounted. The IC then produces a voltage that is proportional to the voltage produced by a thermocouple with its hot junction at ambient and its cold junction at 0°C. This voltage is added to the EMF produced by the thermocouple. The net effect is the same as if the cold junction were physically held at 0°C.

The act of knowing (or approximating) the cold junction temperature and taking this information in to account in the overall measurement is referred to as cold junction compensation. The three techniques I discussed are each methods of cold junction compensation.

The ice bath is probably the most accurate method. An ice slushy can maintain a uniformity of about 0.1°C without much difficulty. I’ve read that an ice bath can maintain a uniformity of 0.01°C, but I’ve never been able to achieve that level of uniformity. Ice baths are physically awkward and therefore usually impractical for industrial measurements.

The off-the-shelf cold junction compensation ICs can be expensive and generally are only accurate to a few degrees Celsius, but many systems use these devices.

Using a thermistor, or even the PN junction on a diode or BJT, to measure the cold junction temperature can be fairly inexpensive and quite accurate. The most common difficulty encountered with this system is calibration. Prudent positioning of the sensor near, or on the terminal block is important.

If the terminal block is to be used as the cold junction (see Figure 1b), the terminal block must be kept isothermal. In practice, keeping the terminal block truly isothermal is almost impossible. So, compromises must be made. This is the stock and trade of engineers. Knowing what is isothermal “enough” for your application is the trick.

Lots of money can be wasted on precision electronics if the terminal block’s screw terminals are allowed to develop a significant thermal gradient. This condition generally happens when power components are placed near the terminal blocks. You must pay careful attention to keeping the temperature stable around the terminal blocks.

There are two broad classes of temperature-measurement applications. The first class involves measuring absolute temperature. For example, you may want to know the temperature of the inside of an oven relative to a standard temperature scale (like the Celsius scale). This type of application requires that you know precisely the absolute temperature of the reference junction.

The second type of measurement involves measuring differences in temperature. For example, in a microcalorimeter, you may want to measure the temperature of the system, then start some chemical reaction and measure the temperature as the reaction proceeds. The information of value is the difference between first measurement and the subsequent ones.

Systems that measure temperature differences are generally easier to construct because control or precise measurement of the reference junction isn’t required. What is required is that the reference junction remain at a constant temperature while the two measurements occur. Whether the reference junction is at 25.0°C or 30.0°C isn’t relevant because the subtraction of consecutive measurements will remove the reference junction temperature from the computed answer.

You can use thermocouples to make precise differential temperature measurements, but you must ensure the terminal block forming the cold junction is “close enough” to isothermal. You must also ensure that the cold junction has enough thermal mass so it will not change temperature over the time you have between measurements.

PRACTICAL MATTERS

Thermocouples are given a letter designation that indicates the materials they are fabricated from. This letter designation is called the thermocouples “type.” Table 1 shows the common thermocouples available and their usable temperature ranges.

Table 1: There are a wide variety of industry-standard alloy combinations that form standard thermocouples. The most commonly used are J, K, T, and E.

Each thermocouple type will produce a different open-circuit voltage (Seebeck voltage) for a given set of temperature conditions. None of these devices are linear over a full range of temperatures. There are standard tables available that tabulate Seebeck voltages as a function of temperature.[1] There are also standard polynomial models available for thermocouples.

Thermocouples produce a small Seebeck voltage. For example, a type K thermocouple produces about 40 µV per degree Celsius when both junctions are near room temperature. The most sensitive of the thermocouples, type E, produces about 60 µV per degree Celsius when both junctions are near room temperature.

In many applications, the range of temperatures being measured is sufficiently small that the Seebeck voltage is assumed to be linear over the range of interest. This eliminates the need for lookup tables or polynomial computation in the system. Often the loss of absolute accuracy is negligible, but this tradeoff is one the design engineer must weigh carefully.

CIRCUITS

When designing a thermocouple interface, there are only a few pieces of information you need to know:

  • what type of thermocouple will be used
  • what is the full range of temperatures the hot junction will be exposed to
  • what is the full range of temperatures the cold junction will be exposed to
  • what is the temperature resolution required for your application
  • does your system require galvanic isolation
  • what type of cold junction compensation will be used

If the answer to the last question requires the analog addition of a voltage from a commercial cold junction compensation IC, then the manufacturer of the IC will probably supply you with an adequate reference design. If you plan to do the cold-junction compensation either physically (by an ice bath) or in software (by measuring the cold junction’s temperature with another device), then you must build or buy a data-acquisition system.

Galvanic isolation is an important feature in many industrial applications. Because thermocouples are really just long loops of wire, they will often pick up high levels of common-mode noise. In some applications, the thermocouples may be bonded to equipment that is at line voltage (or higher).

In this case, galvanic isolation is required to keep high-voltage AC out of your data acquisition system. This type of isolation is usually accomplished in one of two ways—using either an opto-isolator or a transformer. Both systems require the thermocouple signal conditioner to allow its ground to float with respect to earth ground. Figure 3a and 3b outlines these schemes.

Figure 3: Galvanic isolation to a few thousand volts is easy (but a little expensive) using opto-isolation (a) and inexpensive (but a bit more challenging) using a VFC and a transformer (b).

Because the focus of this article is on the interface to the thermocouple, I’ll have to leave the details of implementing galvanic isolation to another article.

Given the tiny voltage levels produced by a thermocouple, the designer of the signal-conditioning module should focus carefully on noise rejection. Using the common-mode rejection (CMR) characteristics of a differential amplifier is a good place to start. Figure 4 shows a simple yet effective thermocouple interface

Figure 4: The common-mode filter and common-mode rejection characteristics pay off in thermocouple amplifiers.

The monolithic instrumentation amplifier (in-amp) is a $2–$5 part (depending on grade and manufacturer). These are usually 8-pin DIP or SOIC devices. In-amps are simple differential amplifiers. The gain is set with a single external resistor. The input impedance of an in-amp is typically 10 gigaohms.

Certainly you can use op-amps, or even discrete parts to build a signal conditioner. However, all the active components on a monolithic in-amp are on the same dice and are kept more-or-less isothermal. This means in-amp characteristics behave nicely over temperature. Good CMR, controllable gain, small size, and high input impedance make in-amps perfect as the heart of a thermocouple conditioning circuit.

Temperature tends to change relatively slowly. So, if you find your system has noise, you can usually install supplementary low-pass filters. These can be implemented in hardware or software. In many systems, it’s not uncommon to take 128 measurements over 1 s and then average the results. Digital filters are big cost reducers in production systems.

Another problem often faced when designing thermocouple circuits is nulling amplifier offset. You can null the amplifier offset in a variety of ways [2], but my favorite is by chopping the input. Figure 5 shows how this process can be accomplished.

Figure 5: An input chopper like a CD4052 is all that is necessary to null signal conditioner offsets.

Thermocouples have such small signal levels, gains on the order of 1000 V/V are not uncommon, which means an op-amp or in-amp with a voltage offset of even 1 mV will have an offset at the output on the order of volts.

The chopper in Figure 5 allows the microcontroller to reverse the polarity of the thermocouple. To null the circuit, the microcontroller will take two measurements then subtract them.

First, set the chopper so the ADC measures GAIN (Vsensor + Voffset). Second, set the chopper so the ADC measures GAIN (–Vsensor + Voffset).

Subtract the second measurement from the first and divide by two. The result is GAIN*Vsensor. As you can see, this is exactly the quantity we are interested in. The in-amp’s offset has been removed from the measurement.

CLOSING TIME

In 1821, Thomas J. Seebeck discovered that if a junction of two dissimilar metals is heated, a voltage is produced. This voltage has since been dubbed the Seebeck voltage.

Thermocouples are found in everything from industrial furnaces to medical devices. At first glance, thermocouples may seem fraught with mystery. They are not. After all, how can a device that’s built from two wires and has been around for 180 years be all that tough to figure out?

When designing with thermocouples, just keep these four concepts in mind and the project will go much smoother. First, thermocouples produce a voltage that is proportional to the difference in temperature between the hot junction and the reference junction.

Second, because thermocouples measure relative temperature differences, cold junction compensation is required if the system is to report absolute temperatures. Cold-junction compensation simply means knowing the absolute temperature of the cold junction and adjusting the reparted temperature value accordingly.

The third thing to remember is that thermocouples have a small Seebeck voltage coefficient, typically on the order of tens of microvolts per degree Celsius. And last, thermocouples are non-linear across their temperature range. Linearization, if needed, is best done in software.

Armed with these concepts, the circuits in this article, and a bit of time, you should have a good start on being able to design a thermocouple into your next project.

Bob Perrin has designed instrumentation for agronomy, soil physics, and water activity research. He has also designed embedded controllers for a variety of other applications.

REFERENCES

[1] www.omega.com/pdf/temperature/z/zsection.asp

[2] B.Perrin, “Practical Analog Design,” Circuit Cellar, #94, May 1998.

SOURCES

AD594, TMP03/04
Analog Devices
www.analog.com

INA118
Texas Instruments (Burr-Brown Corp.)
www.ti.com/ww/analog/index.html

LT1025
Linear Technology
www.linear-tech.com

This article was originally published in Circuit Cellar Online in 1999. Posted with permission. Circuit Cellar and CircuitCellar.com are Elektor International Media publications.

 

Modify & Test a Phase Meter Calibrator

Charles Hansen described a DIY phase meter calibrator using all-pass, phase-shift filters in a November 2006 article published in audioXpress magazine. Being able to measure phase angle is often helpful, so I’ll begin by quoting from the beginning of his article:

“A phase angle meter is useful in audio work to determine the phase angle between a reference signal and a phase shifted signal, both having identical time periods. Typical uses include: Finding the phase angle between voltage and current to determine the phase shift and impedance of a loudspeaker over its frequency range. Finding the phase shift between the input and output of a tube amplifier to establish the HF (high frequency) and LF (low frequency) cutoff points needed to avoid instability in feedback amplifiers.”

In addition to these, there are other uses—for example, measuring the phase shift through any active or passive filter which includes equalization networks.

In his design, he chose a set of five calibrations frequencies: 10 Hz, 100 Hz, 1000 Hz, 10 kHz, and 100 kHz. He relied on an external oscillator to drive the calibrator at these input frequencies. I first built the calibrator as described, and then I made some modifications that better suited my needs. But first I will describe how the calibrator works. I think it’s best to just provide a bit more  from Hansen’s article:

“The Phase Angle Calibrator makes use of an op amp filter circuit called the all-pass circuit, which takes a sine-wave input and produces a constant amplitude phase-shifted sine wave output. The lag output version was used in Fig. 1. The theory behind the all-pass filter is available in many reference books and texts, but I found one by Walt Jung [1] that I believe is the easiest for a novice to understand. The phase shift angle is varied by the parallel combination of R3 and R9 through R19 with C3 through C7 in accordance with the formula:

θ = -2 arctan (2ΠRC)

where θ is the phase angle, and f is the frequency. After selecting a suitable value for C, you can solve for R by rearranging the formula:

R = tan(-θ/2) / 2ΠfC

This is hardly a linear relationship. Large changes in resistor value produce very little change in phase angle as you approach 0 or 180 degrees. It’s much easier to apply the input signal to both inputs of the phase angle meter for zero degrees, and use an op-amp inverter to generate the 180 degree signal.”

MODIFY THE CALIBRATOR

I added an internal Wein-bridge oscillator to simplify using the calibrator and I changed the set of frequencies to cover just the audio range: 20 Hz, 100 Hz, 1000 Hz, 10 kHz, and 20 kHz. (This range is also easier to cover with a single-range oscillator, the capacitor values stay reasonable.) The actual frequencies, shown in Table 1, vary somewhat from the ideal frequencies because I used standard 1% resistors and 5% capacitors.

Table 1: These are phase calibrator phase-shift measurements. The column labeled “305” refers to the Dranetz model 305 phase meter with 305-PA-3007 plug-in. The column labeled “5245L” refers to the Hewlett-Packard model 5245L frequency counter with a model 5262A time interval unit plug-in. Phase shift measurements at 19.6 kHz are not useful from the HP-5245L counter because the 10-MHz timebase does not provide enough significant figures.

Selecting and matching the capacitors would give closer results, but it’s more important to know what the frequencies are. Because I had already built a circuit board for the calibrator circuit, I used a second circuit board for the oscillator. Figure 1 and Figure 2 are the two circuit diagrams.

Figure 1: Phase angle calibrator using all-pass phase-shift filters. This is a Charles Hansen design, 2005, with circuit board design by the author (PHASECAL.PCB).

Figure 2: Wein-bridge oscillator with lamp amplitude stabilization. Adjust R6 for minimum harmonic distortion. (MAIN115.PCB)

Tables 2 and Table 3 are the parts lists. Please note that the calibrator circuit is unchanged from Hansen’s design, except for the values of the capacitors C3 and C7. In the original, C3 was 470 nF (for 10 Hz) and C7 was 47 pF (for 100 kHz). I put both circuit boards and a ±15-VDC power supply (any regulated supply will suffice) in a Wolgram MC-9 enclosure.

Table 2: Calibrator parts list

Table 3: Wein-bridge oscillator parts list

The completed calibrator is shown in Photo 1 with a Dranetz Phase meter. (More about this later.) The unlabeled knob, lower left in the photo, is an oscillator output level control (R8 in Figure 2), which I added after making the front panel label.

Photo 1: A Dranetz automatic phase meter, model 305, is at the top. The phase meter calibrator is below. The calibrator, a Charles Hansen design, is not a TDL product, but construction details are included in this article.

Wein-bridge oscillator theory is discussed in many textbooks and is rather mathematical. I will describe it as simply as possible. In Figure 2 the oscillation frequency is set by the value of R and C connected between the op-amp non-inverting input (pin 3), the op-amp output (pin 6), and common. For a frequency of 1,000 Hz, C = 22 nF (C3 and C10) and R = 7235 Ω (the series combination of R1 + R2 and R3 + R4). The equation is:

f = 1/(2ΠRC) = 1/(2Π(22 x 10-9) (7235)) = 1000 Hz

For amplitude-stable oscillation to occur, the gain of the op-amp circuit must be 1/3. This is set by the impedance of the RC network and resistors R5, R6 and R7 and the incandescent lamp. The lamp is important because it stabilizes the gain at 1/3. If the output voltage (pin 6) tries to increase, the lamp’s resistance decreases and the output voltage decreases. This works very well, but it takes the output amplitude a small of amount of time to stabilize, especially at low frequencies. The CM6833 lamp is very small, so its thermal time constant is very low and stability happens very quickly. The trimmer pot, R6, is adjusted for minimum distortion in the output signal. You can get rather close by looking at the waveform with a scope, but it’s better to use a distortion analyzer or spectrum analyzer. Spectrum analysis software on a PC is fine, just adjust R6 to minimize the height of the sidebands or use a program that directly displays harmonic distortion.

At 1000 Hz, TrueRTA shows the second harmonic (2000 Hz) down 80 dB (0.01% distortion) with the higher harmonics even lower. AudioTester shows a total harmonic distortion of 0.0105% using the first ten harmonics.

TrueRTA is a spectrum analysis program available from True Audio. Demo versions and a free version (level 1) are available on its website. AudioTester is another spectrum analysis program.

TEST THE CALIBRATOR

The calibrator should be reasonably accurate when built using the 1% resistors and 5% capacitors in the parts list. But as with any other piece of test equipment, it would be satisfying to make some measurements to be sure. I will describe two methods that I used: all the measured values are presented in Table 1. As you can see, the calibrator is very satisfactory.

One method is to use a calibrated phase meter with an accuracy better than the calibrator. I used a Dranetz model 305 (five-digit phase angle display) with a model 305-PA-3007 plug-in.(The Dranetz phase meter is no longer manufactured but used units may be found on eBay or from used electronic instrument dealers.) This plug-in provides automatic operation for input amplitudes of 50 mV RMS to 50 V RMS and frequencies from 2 Hz to 70 kHz. Automatic operation means there are no operating controls. The plug-in scales the input voltage to the mainframe and provides the correct frequency compensation.

Another method is to use a time interval counter to measure the time between an amplitude zero crossing of the reference signal to the amplitude zero crossing of the phase shifted signal. Phase shift can be calculated from the time interval as:

θ = 360τf/1000

where θ is the phase shift in degrees, time delay τ is in milliseconds, and f is the frequency in hertz.

I used a Hewlett-Packard (HP) model 5245L frequency counter with a model 5262A time interval unit plug-in (see Photo 2).

Photo 2: Hewlett-Packard model 5245L frequency counter with a time interval plug-in unit below and my dual zero-crossing detector above.

The 10-MHz counter timebase gives a time resolution of 0.1 ms. The time interval plug-in has trigger-level controls for each channel but they are not calibrated and can’t accurately set the zero crossing with a sine wave input. The smaller “box” above the counter in the photo is a two-channel zero crossing detector. I designed and built this detector to output a pulse whose leading edge coincides in time with the input zero crossing. The counter measures the time between the leading edges of the two pulses: the reference and the phase shifted signal. The detector circuit diagram (see Figure 3) and parts list (see Table 4) are included. I packaged the Detector circuit board with a simple ±5-V regulated power supply in a Wolgram MC-7A enclosure.

Figure 3: The ual zero-crossing detector circuit board

Table 4: The two-channel zero crossing detector's parts list

Looking at one of the detector’s channels in Figure 3, U1 is an input buffer. Resistors R5, R6, and D1 clip the negative-going half of the input sine wave. The comparator circuit (U2) outputs a very short pulse at the input zero crossing. This pulse is “stretched” by the monostable multivibrator in U3 to about 12 ms as set by the time-constant of C1 and R19. Two front panel toggle switches select either the positive-going or negative-going output pulses. The reference and shifted pulses—45° at 10 kHz—are shown in Photo 3.

Photo 3: The digital storage scope display of reference pulse (above) and phase shifted pulse (below) for 45 degrees of shift at 10 kHz. The pulse width is 12 us. The pulse amplitude is 5 V. Pulse baselines are shifted for clarity.

FINDING A PHASE METER

New phase meters are expensive but used models can sometimes be found on eBay or from used electronic test equipment dealers, just try a Google search. In addition to the Dranetz 305 (which I found on eBay), other useful models include:

  • Aerometrics model PM720 phase meter, 5 Hz to 500 kHz, analog meter display. Aerometrics  denies any association with this unit but it is often listed under this name.
  • Hewlett-Packard model 3575A gain-phase meter, 1 Hz to 13 MHz, four-digit display
  • Wavetek model 750 phase meter, 10 Hz to 2 MHz, four-digit display

In addition, you can find application notes and magazine articles that describe how to build your own phase meter. These are usually fairly simple designs. The following appear to be useful: Intersil Application Note AN9637 (This is identical to Design Idea #1890 that was published in the July 4, 1996 issue of EDN); Elliott Sound Products Project 135; and Salvati, M. J., “Phase Meter Profits From Improvements,” Design Idea, Electronic Design magazine, April 11, 1991.

TAILOR THE DESIGN

I sent a copy of this article to Hansen for comments. He agreed that having the oscillator built-in is a good feature. He also commented as follows:

“A problem with my phase meter calibrator design is that the distortion increases with phase shift, and the amplitude drops as well. It might be possible that the zero-crossing detector might be fooled by the higher order distortion harmonics. I’d be interested in what you find out in this regard.”

So, I measured the amplitude drop and distortion at 150°, which should be worst case. I set the 20-Hz variable output to an arbitrary 2.00 V. Keeping the output level control unchanged, I measured what you see in Table 5. This amount of drop seems acceptable.

Table 5: I set the 20-Hz variable output to 2 V, and I kept the output level control unchanges as I measured these.

I used a Hewlett-Packard model 3581A wave analyzer to measure the harmonics. Refer to Table 6. These numbers look acceptable and the zero-crossing detector output at 20 kHz and 150 degrees measures 22 ms on an oscilloscope with a calculated 21.5 ms at the actual frequency of 19.61 kHz.

Table 6: I used a Hewlett-Packard 3581A wave analyzer to measure the harmonics. These numbers are acceptable and the zero-crossing detector output at 20 kHz and 150 degrees measures 22 ms on an oscilloscope with a calculated 21.5 ms at the actual frequency of 19.61 kHz.

I am very satisfied that the calibrator is suitable to troubleshoot and calibrate any phase meter you are likely to find, either new or used. Without overdoing the math, there is enough design information here to allow you to tailor the design to a specific frequency range, keeping in mind the 1000:1 practical frequency range of the Wein-bridge oscillator, without using range switching.

The circuit board designs listed in the parts lists are available in CIRCAD format and are posted on the TDL website. (CIRCAD is a circuit board design program available from Holophase. The boards in the pmcalpcb.zip file were designed with Version 4, a free download of which is available on the Holophase website.) The physical boards are not available.

Ron Tipton lives in Las Cruces, NM. Visit the TDL Technology website for more information about his audio designs and services.

REFERENCE

[1] Jung, W. and Sams, H., Audio IC Op-Amp Applications, 2nd Edition, Sams Publishing, 1978.

Editor’s note: audioXpress, like CircuitCellar.com, is an Elektor International Media publication.

A Workspace for Radio & Metrology Projects

Ralph Berres, a television technician in Germany, created an exemplary design space in his house for working on projects relating to his two main technical interests: amateur radio and metrology (the science of measurement). He even builds his own measurement equipment for his bench.

Ralph Berres built this workspace for his radio and metrology projects

“I am a licensed radio amateur with the call sign DF6WU… My hobby is high-frequency and low-frequency metrology,” Berres wrote in his submission.

Amateur radio is popular among Circuit Cellar readers. Countless electrical engineers and technical DIYers I’ve met or worked with during the past few years are amateur radio operators. Some got involved in radio during childhood. Others obtained radio licenses more recently. For instance, Rebecca Yang of Tymkrs.com chronicled the process in late 2011. Check it out: http://youtu.be/9HfmyiHTWZI and http://tymkrs.tumblr.com/.

Do you want to share images of your workspace, hackspace, or “circuit cellar” with the world? Click here to email us your images and workspace info.