Silicon ChipBuild A Digital Audio Millivoltmeter - March 2009 SILICON CHIP
  1. Outer Front Cover
  2. Contents
  3. Publisher's Letter: Carbon trading may not be needed in Australia after all
  4. Feature: Reviving Old Laptops With Puppy Linux by Warrick Smith
  5. Feature: Digital Radio Is Coming, Pt.2 by Alan Hughes
  6. Project: A GPS-Synchronised Clock by Geoff Graham
  7. Project: New, Improved Theremin Mk.2 by John Clarke
  8. Project: Build A Digital Audio Millivoltmeter by Jim Rowe
  9. Project: Microcontrollers Can Be A Snap by Stan Swan
  10. Vintage Radio: The deadly and the difficult: when to say "no" by Rodney Champness
  11. Book Store
  12. Advertising Index
  13. Outer Back Cover

This is only a preview of the March 2009 issue of Silicon Chip.

You can view 32 of the 96 pages in the full issue, including the advertisments.

For full access, purchase the issue for $10.00 or subscribe for access to the latest issues.

Articles in this series:
  • Digital Radio Is Coming, Pt.1 (February 2009)
  • Digital Radio Is Coming, Pt.2 (March 2009)
  • Digital Radio Is Coming, Pt.3 (April 2009)
  • Digital Radio Is Coming, Pt.4 (June 2009)
  • Digital Radio Is Coming, Pt.5 (August 2009)
Items relevant to "A GPS-Synchronised Clock":
  • VK2828U7G5LF TTL GPS/GLONASS/GALILEO module with antenna and cable (Component, AUD $25.00)
  • GPS-Synchronised Clock PCB pattern (PDF download) [04203091] (Free)
  • PIC16LF88-I/P programmed for the GPS Synchronised Clock for stepping hands [0420309A.HEX] (Programmed Microcontroller, AUD $15.00)
  • VK2828U7G5LF TTL GPS/GLONASS/GALILEO module with antenna and cable (Component, AUD $25.00)
  • PIC18LF88 firmware and C source code for the GPS-Synchronised Clock with stepping hands [0420309A.HEX] (Software, Free)
Articles in this series:
  • A GPS-Synchronised Clock (March 2009)
  • GPS Synchronisation For Clocks With Sweep Hands (November 2009)
Items relevant to "New, Improved Theremin Mk.2":
  • Theremin Mk.2 PCB [01203091] (AUD $15.00)
  • Improved Theremin Mk.2 PCB pattern (PDF download) [01203091] (Free)
  • Improved Theremin Mk.2 front panel artwork (PDF download) (Free)
Items relevant to "Build A Digital Audio Millivoltmeter":
  • Digital Audio Millivoltmeter Input Attenuator front panel artwork (PDF download) (Free)
  • Input Attenuator PCB for Digital Audio Millivoltmeter [04205091] (AUD $7.50)
  • Digital Audio Millivoltmeter PCB [04103091] (AUD $20.00)
  • PIC16F88-I/P programmed for the Digital Audio Millivoltmeter [0410309A.HEX] (Programmed Microcontroller, AUD $15.00)
  • PIC16F88 firmware and source code for the Digital Audio Millivoltmeter [0410309A.HEX] (Software, Free)
  • Digital Audio Millivoltmeter PCB pattern (PDF download) [04103091] (Free)
  • Digital Audio Millivoltmeter front panel artwork (PDF download) (Free)
Articles in this series:
  • Build A Digital Audio Millivoltmeter (March 2009)
  • Input Attenuator For The Digital Audio Millivoltmeter (May 2009)

Purchase a printed copy of this issue for $10.00.

By JIM ROWE Low-Cost Digital Audio Millivoltmeter Versatile unit indicates signal levels in mV, dBv & dbm Want to measure small signals at audio frequencies? Here’s a low-cost digital audio millivoltmeter which will allow you to measure audio signals from below 5Hz to above 100kHz. As well as indicating the level in both millivolts and dBV, it also shows the corresponding dBm level into 600 ohms. 58  Silicon Chip siliconchip.com.au BAL INPUT INTERCEPT ADJUST 58.33mV/dB 20mV/dB VR2 1 2 + IC3c 3 5k S3 UNBAL INPUT INPUT SELECT IMPEDANCE TRANSFORMER (IC1) 16x2 LINE LCD MODULE 43.75mV/dB LOGARITHMIC AMP/DETECTOR (IC2) 5k Iout DIGITAL VOLTMETER (IC4) IC3a 10:1 (–20dB) ATTENUATOR SLOPE ADJUST (CAL) +  35mV/dB GAIN = 2.0 (+6dB)  IC3b  VR1 S1 SELECT RANGE RANGE INDICATOR LEDS Fig.1: block diagram of the Digital Audio Millivoltmeter. The audio signal is first fed to an impedance transformer stage (IC1) and then to a log amplifier/detector via a resistive attenuator. Its output is then fed to three different DC amplifiers which in turn feed a digital voltmeter stage based on PIC microcontroller IC4 and an LCD module. T HIS NEW AUDIO millivoltmeter design is an adaptation of the RF Level & Power Meter described in the October 2008 issue of SILICON CHIP. Like that design, it makes use of a logarithmic amplifier/detector IC (an AD8307) to provide a very sensitive detector. This has a DC output which is closely proportional to the logarithm of the audio input voltage. We have combined one of these Analog Devices AD8307 chips with an instrumentation amplifier to provide it with a high input impedance and also added an “intelligent” metering circuit based on a PIC microcontroller. In operation, the PIC processes the detector’s logarithmic DC output voltage to indicate signal level and the equivalent dBV and dBm levels. The PIC micro uses some fairly fancy maths routines to work out the signal level, which is then displayed on a standard 2-line LCD display. All the circuitry is on a single PC board and fits in a compact diecast aluminium case. The whole set-up works from an external 12V battery or plugpack, drawing less than 200mA (most of which is drawn by the backlighting in the LCD module). How it works The block diagram of Fig.1 shows how the new meter works. At far left are the two input sockets, one for a balanced input and the other for an unbalanced input. Switch S3 allows one of these inputs to be selected, with the desired input fed to an impedance transformer stage. This uses an AD623 siliconchip.com.au instrumentation amplifier (IC1) to provide a relatively high input impedance of 100kΩ and operates with a gain of two (+6dB). The output of the impedance transformer stage is then fed to the AD8307 log amplifier/detector (IC2) via a 10:1 resistive attenuator. This attenuator is formed by the 5kΩ resistors in series with each input and the AD8307’s own input resistance of 1100Ω. The output of the log amp/detector is essentially a DC voltage, with a value closely proportional to the logarithm of the AC input voltage. In fact, the slope of the detector’s output is very close to 25mV per decibel rise or fall in the input. By adjusting the log detector’s load resistance via trimpot VR1, we can set the slope to 20mV/dB (for calibration). Trimpot VR2 is used to adjust the DC voltage levels inside IC2 to adjust its effective zero-input setting. The output from the log detector is then fed to three DC amplifiers using IC3a, IC3c & IC3b. These are configured to provide three levels of voltage gain, to provide three measuring ranges. IC3b provides a gain of 1.75, scaling the detector output slope to 35mV/ dB (for the <0dBV range), while IC3a and IC3c provide gains of 2.1875 and 2.9165 respectively, giving output slopes of 43.75mV/dB and 58.33mV/ dB for the <-20dBV and <-40dBV ranges. Each of these scaled detector voltages is fed to a different analog input of the digital voltmeter, which uses a PIC16F88-I/P microcontroller (IC4). Switch S1 allows the user to select which of the three analog inputs is connected to IC4’s 10-bit ADC (analogto-digital converter). The firmware running in IC4 then directs the ADC to measure the scaled detector output, performs the necessary calculations to Specifications • Main Features: a low-cost audio millivoltmeter based on a logarithmic amplifier/detector coupled to a digital metering circuit using a programmed PIC microcontroller and an LCD readout. • • • • • • • Input Impedance: 100kΩ (balanced input can be changed to 600Ω) Measuring Frequency Range: from below 5Hz to above 100kHz Maximum Input Signal Level: 1.4V RMS (+3.0dBV, +5.2dBm/600Ω) Minimum Input Signal Level: 160μV RMS (-76dBV, -73.8dBm/600Ω) Measurement Linearity: approximately ±0.3dB Measurement Accuracy: approximately ±3% Power requirements: 12-15V DC at <200mA with backlit LCD March 2009  59 Parts List 1 PC board, code 04103091, 160 x 111mm 1 diecast aluminium box, 171 x 121 x 55mm 1 front panel label 1 16 x 2 LCD module, Jaycar Cat. QP-5516 or Altronics Cat. Z-7012 4 M3 x 25mm tapped spacers 4 M3 x 15mm tapped Nylon spacers 1 SPST momentary pushbutton switch (S1) 1 SPDT mini toggle switch (S2) 1 DPDT mini toggle switch (S3) 1 panel-mount XLR type balanced audio plug (CON1) 1 panel-mount BNC socket (CON2) 1 PC mount 2.5mm concentric DC socket(CON3) 1 7 x 2 length of DIL socket strip OR 14 x 1 length of SIL socket strip (half of 28-pin IC socket) 1 7 x 2 length of DIL terminal strip OR 14-way length of SIL terminal strip 1 18-pin IC socket 1 14-pin IC socket 2 8-pin IC sockets work out the equivalent AC input voltage and dB levels and then displays these on a 16-character by 2-line LCD module. Circuit details Fig.2 shows the complete circuit of the Audio Millivoltmeter. The 100kΩ resistors connected between the inputs (pins 2 & 3) of IC1 and the +5V half-supply rail provide a biasing path and also set the instrument’s input resistance. The 2.2μF input coupling capacitors set the instrument’s lowfrequency limit to below 5Hz. On the other hand, the 470Ω resistors in series with each input, together with the 10pF capacitor across the inputs, form a low-pass filter which rolls off RF signals which could disturb the operation of both IC1 & IC2. The 100kΩ resistor connected between pins 1 & 8 of IC1 sets its gain to 2.0. The pin 6 output of IC1 is fed to the inputs of IC2 via a 10:1 attenuator formed by four 10kΩ resistors and the input resistance of IC2. The output 60  Silicon Chip 4 M3 x 6mm machine screws, csk head 13 M3 x 6mm machine screws, pan head 1 M3 nut 1 M3 star lockwasher 1 M3 Nylon flat washer 8 PC board terminal pins, 1mm diameter 1 1.2-metre length of 0.8mm-dia. tinned copper wire Semiconductors 1 AD623AN instrumentation amplifier (IC1) 1 AD8307AN log amplifier/ detector (IC2) 1 LM324 quad op amp (IC3) 1 PIC16F88-I/P microcontroller (IC4) programmed with 0410309A.hex firmware 1 LM317T adjustable regulator (REG1) 1 12V 1W zener diode (ZD1) 1 1N4004 1A diode (D1) 1 3mm green LED (LED1) 1 3mm orange LED (LED2) 1 3mm red LED (LED3) Capacitors 1 470μF 16V RB electrolytic coupling capacitors have a value of 10μF, to maintain the low frequency response, while the 100pF capacitor across the inputs of IC2 provides a further measure of RF rejection. PIC microcontroller The rest of the circuit is straightforward, with most of the real work done by the firmware running inside PIC micro IC4. The PIC16F88-I/P device is well-suited to this application, because it includes an ADC module with 10-bit measuring resolution. The ADC is also flexible in terms of its operating mode, with a choice of positive and negative reference voltages and a 7-channel input multiplexer. We take advantage of these features by using our own positive reference voltage of 3.50V (fed into pin 2) and also by using three of the ADC input channels to allow firmware selection of the measuring range via pin 1 (AN2), pin 18 (AN1) & pin 17 (AN0). We select the ranges inside the PIC simply by selecting the appropriate 1 220μF 16V RB electrolytic 1 100μF 16V RB electrolytic 1 22μF 16V RB electrolytic 2 10μF 16V tantalum 1 10μF 16V RB electrolytic 2 2.2μF 35V tantalum 2 1μF 25V tantalum 1 220nF monolithic ceramic 5 100nF monolithic ceramic 1 100pF disc ceramic 1 10pF disc ceramic Trimpots 2 50kΩ linear horiz. trimpot (VR1, VR2) – code 503 1 200Ω linear horiz. trimpot (VR3) – code 201 1 10kΩ linear horiz. trimpot (VR4) – code 103 Resistors (0.25W, 1%) 2 220kΩ 1 2.4kΩ 3 100kΩ 1 2.2kΩ 1 68kΩ 3 2.0kΩ 1 51kΩ 1 1.5kΩ 1 33kΩ 2 470Ω 5 10kΩ 2 330Ω 1 6.8kΩ 1 200Ω 2 4.7kΩ 1 120Ω 1 3.9kΩ 1 100Ω 1 3.0kΩ 2 10Ω 1 18Ω 0.5W – RBL (used with Altronics LCD module only) ADC input channel (AN2, AN1 or AN0). The firmware does this input selection by stepping from one range to the next each time you press S1, the range select button. To indicate which range is currently selected, the firmware switches on LED1, LED2 or LED3. The firmware automatically changes the scaling factor used for each range, so that the displayed values are correct. Finally, the LCD module is driven directly by the PIC in standard “4-bit interface” fashion. Power supply Most of the circuit runs from 5V DC, derived from either a nominal 12V battery or a 12-15V plugpack supply. The only part of the circuit which runs directly from the 12V input voltage is IC1, which needs the higher voltage to handle the full input signal levels. The +5V rail is obtained using an LM317T adjustable regulator. This allows us to adjust the supply rail to accurately set the +3.50V reference siliconchip.com.au POWER BALANCED INPUT CON1 S2 1 2 10 +12V 3 100nF 4.7k K 10 F A BAL S3a 470 2.2 F 100k S3b UNBAL INPUT CON2 470 2 –IN 7 +Vs 1 –Rg 10pF 8 2.2 F IC1 AD623 OUT REF +Rg 3 +IN –Vs 4 2 x 10k IC2 AD8307 +6V 100pF 4.7k 22 F 2 x 10k 1 IN L REG1 LM317T 10 F COM 2 VR2 INTERCEPT 50k ADJUST 51k 1 F 14 IC3d 13 TP4 TPG +5.00V 100nF 330 2.2k 4 14 Vdd MCLR 3.0k +3.50V 6.8k 2 Vref+ TPG 200 RA4 A A K TP3 +5.00V A  LED1 16 RA7 13 RB7 12 RB6 TP1 100nF  LED2 K  LED3 TPG K 10k 3 SELECT RANGE S1 220 F 4 IC3c 17 8 3.9k IC3: LM324 RBL* (SEE TEXT) AN0 IC4 PIC16F88-I/P 220k RB5 2.0k IC3a 18 1 2.4k RB4 AN1 220k LCD CONTRAST +5.00V 1(2* ) 11 4 ABL* 68k Vdd RS 16 x 2 LCD MODULE 3 2 100 12 +5.00V 9 ADJ SET 3.50V AT TP1 VR3 200 LOG DETECTOR OUTPUT 10 IN OUT 120 3 OFS – 330 5 INT CON3 220nF 6 EN 4 OUT 7 VPS IN H 8 100nF 100 F 100nF 10 F 2x 100k UNBAL A 10 6 5 K ZD1 12V 1W 470 F 16V 12–15V DC INPUT + D1 1N4004 10 9 8 7 RB1 6 RB0 6 CONTRAST 3 VR4 10k EN D7 D6 D5 D4 D3 D2 D1 D0 14 13 12 11 10 9 8 7 GND R/W 2(1* ) 5 KBL* RB3 RB2 2.0k 5 SLOPE ADJUST VR1 50k 6 IC3b 11 7 1 1.5k Vss 5 1 F 33k CLKo AN2 15 * CONNECTIONS FOR ALTRONICS MODULE TP2 (2.0MHz) TPG 2.0k LM317T LEDS SC  2009 DIGITAL AUDIO MILLIVOLTMETER D1, ZD1 A K K A OUT ADJ OUT IN Fig.1: this is the complete circuit of the Digital Audio Millivoltmeter. The input impedance matching stage is based on IC1 which is an AD623AN instrumentation amplifier. IC2, an AD8307AN, is the log/amplifier detector and this feeds op amps IC3a-IC3c which operate with different gains to provide the three ranges. IC4, a PIC16F88-I/P microcontroller does the 10-bit analog-to-digital conversion (among other things) and drives the 16 x 2-line LCD module. siliconchip.com.au March 2009  61 ZD1 12V 1W JAYCAR QP-5516 LCD MODULE A < –20dBV LED3 CON3 POWER S2 V01+ A S1 + 2.0k 100nF 220k 3.9k 2.0k LM324 100 F 1 F TPG + RANGE SELECT IC3 TP4 (BUFFERED LOG DETECTOR OUTPUT) VR1 50k 22 F IC2 AD8307 INTERCEPT VR2 10 F 3 1 2 50k 100 CON2 CON1 2.2 F 2.2 F S3 10 F 330 10 F 10pF + + 1 + 100k 4.7k 100k 100nF 100k IC1 AD623 1 + 1 F 1 + + 470 2.4k 220k 1.5k + 33k 4.7k 470 SLOPE 100nF CONTRAST TPG TP3 VR3 200 220 F 10k 10k 10k 10k V0LCD 0.5+ 100pF 200 18  0.5W RBL* 68k 2.2k 10k 3.0k 6.8k 100nF 2.0k SEE TEXT* VR4 10k 3.50V TP1 TPG 5.00V 1 10 2MHz 120 14 51k TP2 470 F REG1 LM317T IC4 PIC16F88-I/P 330 < –40dBV TPG 220nF 4004 5.00V LED2 100nF 19030140 9002 © RETE M LEVEL FL LATI GID A 10 ADJUST LED1 < 0dBV D1 12-15V IN (ALTRONICS Z-7012 LCD MODULE) G UN/BAL INPUT Fig.3: follow this layout diagram to assemble the unit. Note that neither connectors CON1 & CON2 nor switches S1S3 are mounted directly on the board. Instead, they are first mounted on the case lid and fitted with tinned copper wire “extension leads”. The leads then pass through the relevant board holes when the board is mounted on the lid. voltage for the PIC’s ADC. This +3.50V reference is derived directly from the +5V rail via a resistive voltage divider consisting of 3.0kΩ, 6.8kΩ & 200Ω resistors. This reference voltage for the ADC is fed into pin 2 of the PIC, which is configured as the Vref+ input. Notice that there are a number of test points provided on the PC board, to allow more convenient set-up and calibration. TP1 allows you to measure the ADC reference voltage, so you can adjust trimpot VR3 to achieve exactly +3.50V at pin 2 of the PIC. TP3 also allows you to measure the +5.00V rail directly, if you wish, while TP2 allows you to check the PIC’s internal clock oscillator. In this project, we run the oscillator at 8MHz, which means that the signal available at TP2 should be very close to 2MHz (Fc/4). So if the PIC is running correctly, you will find a 2MHz square wave of 5V peak-to-peak at TP2. The fourth test point TP4 is provided to allow monitoring of the log detector’s DC output voltage with an external DMM. Op amp IC3d is 62  Silicon Chip configured as a unity gain voltage follower, making the voltage at IC2’s pin 4 output available at TP4 without any significant loading and disturbance to circuit operation. Construction As noted earlier, virtually all of the circuitry in the project is mounted on a single PC board which mounts inside a diecast aluminium case (171 x 121 x 55mm) for shielding. The PC board measures 160 x 111mm and is coded 04103091. As shown in the photos, the LCD module (Jaycar QP-5516 or Altronics Z-7011) mounts above the main board in the upper centre, while the complete assembly mounts behind the lid of the case on 25mm spacers. The switches and input connectors mount directly on the lid, which therefore forms the instrument’s front panel. Fig.3 shows the parts layout on the PC board. Note that DC input connector CON3 is the only connector mounted directly on the board. The three range indicator LEDs are also mounted directly on the board, with the underside of their bodies spaced up by about 24mm so that they just protrude through matching holes in the lid when the board is mounted behind it. Sockets are used for all four ICs, rather than soldering them directly to the board. There are 10 wire links on the board and it’s a good idea to fit these before any of the components, so they’re not forgotten. Note that two of the links are fitted under the footprint of the LCD module, at upper left. These two links are only required if you use the Altronics Z-7011 module, however. The test point terminal pins can also be fitted at this early stage, along with the IC sockets. Make sure you mount the latter with their orientation as shown in Fig.3, so they’ll guide you in plugging in the ICs later. Next fit DC input connector CON3, which goes in at upper right. It’s then a good idea to fit the connector for the LCD module you’re using. If you’re using the Jaycar LCD module, this means that a 7 x 2 piece of DIL socket siliconchip.com.au This view shows the fully-assembled PC board, just prior to mounting it in position on the case lid. Make sure that all polarised parts (including the three ICs) are correctly orientated and note that IC1 & IC2 face in opposite directions. strip must be fitted with a north-south orientation at the lefthand end of the module’s footprint – see Fig.3. Alternatively, if you’re using the Altronics module, this needs a 14 x 1 section of SIL socket strip (made from one side of a 28-pin IC socket). This strip is fitted with an east-west orientation at lower left within the module’s footprint (just above the position for trimpot VR4). Follow this by fitting the four trimpots (VR1-VR4). These are all horizontal mounting types and the board allows either the small open type or the even smaller sealed type. Note that the two 50kΩ trimpots go in the VR1 and VR2 positions, while the 200Ω trimpot is used for VR3. A 10kΩ trimpot is used for VR4 and is the LCD module’s contrast adjustment. Once all four trimpots are fitted you can fit the resistors, making sure that you fit each one in its correction position as shown in Fig.3. Note that the resistor labelled “RBL” (18Ω 0.5W) is the current-setting resistor for the Altronics LCD module’s back lighting. siliconchip.com.au It’s not needed if you use the Jaycar module. The disc ceramic and monolithic capacitors should be fitted next. These are then followed by the tantalum and electrolytic capacitors which are polarised – so take care to fit them with the orientation shown in Fig.3. Now fit diode D1 and zener diode ZD1, followed by regulator REG1. Note that the latter is a TO-220 device and is mounted with its body flat against the top of the board. To do this, you will first have to bend its three leads down by 90° about 6mm from its body. That done, secure it to the board using an M3 x 6mm machine screw and nut before soldering its leads. The LCD module can now be prepared for mounting on the main board, by fitting it with either a 7 x 2 DIL pin header in the case of the Jaycar module or a 14 x 1 SIL pin header in the case of the Altronics module. In both cases, the header pins are passed up through the matching connection holes in the module from below, until the upper ends of their pins are just protruding The LCD module is fitted with header pins and plugged into a matching socket on the PC board – see text. This photo shows the arrangement for the Jaycar module (7 x 2 DIL header). from the top of the LCD module board. All 14 pins are then carefully soldered to the pads on the top of the board using a fine-tipped iron and just enough solder to make a good joint. The next step is to mount four M3 x 12mm tapped Nylon spacers on the main board to support the LCD module. These spacers must go in the correct positions to match the module March 2009  63 76.25 G 76.25 G A A C 8 A LCD WINDOW 8 42 42 65 x 16.5mm 30 22 65.0 16.75 59.5 14 B CL B 5.25 13.25 E 17.25 39 42 B 10.25 42 A 16.5 D C B F 11.5 39.5 G 11.5 G 10.25 CL ALL DIMENSIONS IN MILLIMETRES Fig.4: this full-size diagram shows the drilling details for the case lid and can be used as a drilling template. The large cutouts can be made by drilling a series of holes around the inside perimeter, then knocking out the centre piece and filing the job to a smooth finish. HOLES A: HOLES B: HOLES C: HOLE D: 3.0mm DIAMETER 4.0mm DIAMETER 6.5mm DIAMETER 7.0mm DIAMETER A HOLE E: 9.5mm DIAMETER HOLE F: 24.0mm DIAMETER HOLES G: 3.0mm DIAMETER (COUNTERSUNK) 29 11 HOLE 11mm DIAMETER FOR ACCESS TO DC INPUT SOCKET Fig.5: an 11mm-dia. hole is required in the righthand end of the case to provide access to the DC power socket on the PC board. (RIGHT HAND END OF BOX) you are using and are attached using four M3 x 6mm machine screws. The LCD module is then mounted on top of these spacers, with its 14-pin “plug” mating with the matching socket on the main board. Four more M3 x 6mm screws are then used to hold the LCD module in place. Note that if you are using the Al64  Silicon Chip tronics Z-7012 LCD module, you will also have to connect its “A” & “K” terminals (for the backlight LEDs) to the corresponding pads immediately below on the PC board. This can be done using short lengths of tinned copper wire. These connections are not necessary for the Jaycar QP-5516 module. The last components to mount on the board are the three range indicator LEDs. These all mount vertically with their longer anode leads to the right, towards the LCD module. The leads are all left at their full lengths, so the bottom of each LED’s body is very close to 24mm above the board. Note that the green LED goes in the siliconchip.com.au Table 1: Resistor Colour Codes o o o o o o o o o o o o o o o o o o o o o No. 2 3 1 1 1 5 1 2 1 1 1 1 3 1 2 2 1 1 1 2 Value 220kΩ 100kΩ 68kΩ 51kΩ 33kΩ 10kΩ 6.8kΩ 4.7kΩ 3.9kΩ 3.0kΩ 2.4kΩ 2.2kΩ 2.0kΩ 1.5kΩ 470Ω 330Ω 200Ω 120Ω 100Ω 10Ω uppermost position as LED1, with the orange LED in the centre (LED2) and the red LED at the bottom (LED3). After the LEDs have been mounted, it’s time to plug the four ICs into their sockets. Take special care to orientate each IC correctly, as shown in Fig.3. In addition, take care to ensure that all the pins go into the sockets and that none go down the outside of the socket or are folded back under the IC. Take your time here – the AD623 and AD8307 devices are fairly pricey and PIC micro isn’t exactly cheap either. Preparing the case Your board assembly will now be complete and can be placed aside while you prepare the meter’s front panel. This involves drilling and cutting quite a few holes in the case lid as shown in Fig.4. Most are easily drilled, the two exceptions being the rectangular cutout for the LCD viewing window and the 24mm main hole for the XLR balanced input connector. These are best cut by drilling many 3mm holes around the inside of the cutout outline and then using a small needle file to join the holes and allow the centre piece to be removed. A small file is then used to smooth the inside of the cutouts. It’s tedious but if you take your time, this method gives a good result. You also have to drill a single hole siliconchip.com.au 4-Band Code (1%) red red yellow brown brown black yellow brown blue grey orange brown green brown orange brown orange orange orange brown brown black orange brown blue grey red brown yellow violet red brown orange white red brown orange black red brown red yellow red brown red red red brown red black red brown brown green red brown yellow violet brown brown orange orange brown brown red black brown brown brown red brown brown brown black brown brown brown black black brown in the righthand end of the box itself, to give access to the DC input socket. The location and diameter of this hole is shown in Fig.5. Once all of the holes have been cut in the lid, de-burred and countersunk where appropriate (eg, holes “G” in Fig.4), you’re ready to apply the front panel label. This can be made by photocopying the artwork shown in Fig.7 onto an adhesive-backed A4 sheet label, then applying a protective film (such as “Contac”). It’s then just a matter of cutting it to shape before peeling off the backing and applying it to the carefully cleaned lid. Then when it has been smoothed down, you can cut out the holes in the label using a sharp hobby knife. With the front panel now complete, you can mount switches S1, S2 & S3 in position, followed by input connectors CON1 and CON2. Note that connector CON 1 mounts with its flange on the underside of the lid (see photo). It may be necessary to file away one corner of the flange in order to do this. Extension wires You now have to fit each of the connection lugs on the rear of these switches and connectors with short “extension leads”, long enough to pass through their matching holes in the PC board when it’s mounted behind the panel. 5-Band Code (1%) red red black orange brown brown black black orange brown blue grey black red brown green brown black red brown orange orange black red brown brown black black red brown blue grey black brown brown yellow violet black brown brown orange white black brown brown orange black black brown brown red yellow black brown brown red red black brown brown red black black brown brown brown green black brown brown yellow violet black black brown orange orange black black brown red black black black brown brown red black black brown brown black black black brown brown black black gold brown Table 2: Capacitor Codes Value 220nF 100nF 100pF 10pF mF Code IEC Code EIA Code 0.22μF 220n 224 0.1μF 100n 104       NA    100p 100   NA   10p   10 The best approach here is to use 4060mm lengths of tinned copper wire for these extensions. Each of these is soldered at one end of a switch or connector contact lug and orientated vertically, ready to be passed through the board holes. Make each extension wire a different length, as this will make it easier to get them through the board holes. Note that you will also have to shorten the existing earth lug on the 3-pin XLR socket before fitting its extension lead, to prevent it later fouling the PC board. Now you should be ready to mount the board to the rear of the front panel. To do this, first attach four M3 x 25mm tapped spacers to the front panel, using four M3 x 6mm countersunk-head screws to secure them (these pass through “G” in Fig.5). That done, carefully offer up the PC board assembly to the rear of the front panel, taking care to ensure that the wire extension leads from the switches and input connectors all pass through their matching March 2009  65 Connectors CON1 & CON2 and switches S1-S3 are mounted on the lid of the case and fitted with tinned copper wire extension leads before fitting the PC board in place. M3 x 6mm COUNTERSINK HEAD SCREWS LCD VIEWING WINDOW LEDS 7x2 DIL PIN HEADER IC4 S2 LCD MODULE 7x2 DIL SOCKET STRIP M3 TAPPED x 12mm LONG NYLON SPACERS REG1 CON3 MAIN PC BOARD M3 TAPPED x 25mm LONG SPACERS M3 x 6mm MACHINE SCREWS Fig.6: the PC board is attached to the lid of the case via four M3 x 25mm tapped spacers as shown here. Four M3 x 6mm countersink-head screws secure the lid to the spacers, while four M3 x 6mm pan-head secure the PC board. This photo shows how the tinned copper wire extension leads soldered to the switches and connectors pass down through the PC board. Use a pair of long-nose pliers to guide each lead through its hole as the board is placed in position. holes in the board. At the same time, you also need to ensure that LEDs 1-3 each pass through their respective holes in the upper left of the panel. Once the board is in position against 66  Silicon Chip the spacers, secure it in place using four M3 x 6mm pan-head screws – see Fig.6. Note that it’s a good idea to place a star lockwasher under the head of the screw nearest to CON1, to ensure a good connection between the board’s input earth copper and the metal of the case lid. Having secured the board in place, the assembly can be upended and all the switch and input connector extension wires soldered to their corsiliconchip.com.au SILICON CHIP POWER 12–15V DC INPUT <0dBV <–20dBV <–40dBV DIGITAL AUDIO MILLIVOLTMETER SET 5.00V LCD CONTRAST UNBAL INPUT SLOPE (Rin=100k) SELECT RANGE BALANCED BAL INPUT INTERCEPT INPUT SELECT UNBALANCED www.siliconchip.com.au Fig.7: this full-size artwork can be copied and used to make the front panel. Alternatively, it can be downloaded from the SILICON CHIP website and printed out. Cover it with a protective film before attaching it to the case lid. responding board pads. The board and front panel assembly will now be complete and ready for its initial checkout. Initial checkout Your Digital Audio Millivoltmeter should now be given a preliminary functional checkout, as this is best done before the front panel/board assembly is attached to the case. To begin, use a small screwdriver or alignment tool (passing down through holes “B” in the front panel) to set trimpots VR1-VR4 to their centre positions. After this, use a suitable DC cable to connect CON3 to a suitable source of 12-15V DC, which can be either a 12V battery or a nominal 12V DC plugpack. Next, apply power and check that LED1 lights. There should also be an announcement message reading “Silicon Chip AF Millivoltmeter” on the LCD, although you may have to adjust trimpot VR4 before this message siliconchip.com.au is displayed with good contrast. Note that this greeting message only lasts for a few seconds, after which it is replaced by the meter’s normal display of readings. If all is well so far, now is the time to set the voltage regulator so that the PIC’s ADC reference voltage sits at exactly +3.50V. This is easy to do: just connect your DMM to TP1 and to its nearby TPG pin and adjust trimpot VR3 until you get a reading as close as possible to 3.500V. Use your most accurate DMM for this, because to a large extent the accuracy of this setting will determine the accuracy of your millivoltmeter. That basically completes the initial set-up, although if you have access to a scope or a frequency counter you may want to check the PIC’s clock signal at TP2. You should find a 5V peakto-peak squarewave with a frequency very close to 2MHz. After this initial checkout, you are ready to mount the front panel/board assembly in the case. Secure it using the six M4 countersink-head screws supplied. Note that although a length of neoprene rubber is supplied for use as a seal between the case and its lid, there’s no need to use this seal here. In fact, the box will provide better shielding if the seal is left out. Final adjustment Your Digital Audio Millivoltmeter is now ready for the final step, which is adjustment and calibration. To do this, you’ll need an audio signal generator of some kind, able to supply an audio sinewave signal of known level. If you don’t have access to a calibrated generator, an alternative is to use an uncalibrated oscillator with another audio measuring instrument of some kind, so that you can adjust its output to a convenient level (eg, 1.0V or 100mV RMS). The calibration process is straightforward. Here’s the step-by-step procedure: March 2009  67 What The Meter’s PIC Firmware Does As we explain in the main text, the AD8307 chip in the Digital Audio Millivoltmeter detects the incoming audio signals and converts them into a DC voltage according to a logarithmic conversion scale. It is this log-scale DC voltage which the PIC micro then measures and converts into the equivalent voltage and dB readings, under the control of the author’s firmware program “0410309A.hex”. As you can imagine, the program directs the PIC to perform a number of maths calculations. To do this, it makes use of a suite of maths routines made available to PIC programmers by Microchip Technology Inc, the manufacturers of the PIC family of micros. These routines are used to perform 24-bit and 32-bit floating point (FP) addition, subtraction, multiplication and division, base-10 exponentiation, fixed-point multiplication and division, and floating-point to ASCII conversion. In essence, the PIC firmware program works through the following sequence in making each measurement: First, it directs the PIC’s 10-bit analogto-digital converter (ADC) module to take a measurement of the DC output voltage from the AD8307 chip. It then takes that measurement and converts it into 24bit floating point form, after which it is multiplied with a pre-calculated scaling factor (24-bit also) for the currently chosen measurement range. The resulting product is then divided by the ADC’s full-scale 10-bit value of 3FF (in 24-bit FP form), to give the measurement value in what I call “raw dB” form. This is essentially a 24-bit number varying between 0 and 100. This raw dB value is then used to calculate the equivalent dBV value, by subtracting decimal 96.4782 (in 24-bit FP form), and also the equivalent dBm value (for a 600Ω impedance level) by subtracting decimal 94.2602 (again in 24-bit form). These values are then saved for display. The dBV value is also used to calculate the actual voltage level. This is done by first dividing it by decimal 20 (in 24-bit FP form) and then raising decimal 10 to that power using “EXP1024”, Microchip’s 24bit floating point base-10 exponentiation routine. This is equivalent to calculating the antilogarithm, so we end up with the equivalent voltage value in 24-bit FP form. This is then saved for display. Once the three parameters have been All About Volts, dBV and dBm The Audio Millivoltmeter described in this article gives three indications for every measurement: the audio input level in volts or millivolts and the corresponding values in dBV and dBm. The voltage level needs no explanation but we should explain the significance of the two decibel figures. For many years, electronics engineers have found it convenient to describe signal amplitude in decibels, because of the very wide ranges involved – from microvolts (μV) to kilovolts (kV). Because decibel scales are logarithmic, they make it easier to work with signals varying over such wide ranges. For example, to describe the voltage gain of an audio amplifier in decibels, we take the base-10 logarithm of the voltage gain (Vout/Vin) and multiply this figure by 20. So a voltage gain of 10 corresponds to +20dB, a gain of 100 corresponds to +40dB, a gain of 1000 corresponds to +60dB and so on. Similarly an attenuator which reduces 68  Silicon Chip the voltage level by a factor of 10:1 can be described as having a “gain” of -20dB. DBV & dBm But what’s the difference between the “dBV” and “dBm” figures? These are both decibel scales but they are used to compare a specific voltage level with a known reference value, rather than to compare two specific values. So the contractions dBV and dBm indicate that the figures they accompany are absolute, rather than relative. A reading in “dBV” is a voltage expressed in decibels with reference to 1.0V. So +6dBV means a voltage that is 6dB greater than 1.0V (ie, 2.00V), while -20dBV means a voltage that is 20dB smaller than 1.0V (ie, 100mV) and so on. Similarly, ”dBm” means that a signal level is being expressed in decibels with reference to a specific power level of 1mW (milliwatt) – in other words, on a decibel scale where 1mW corresponds to calculated, the final steps of the measurement sequence involve taking each 24-bit parameter and processing it for display on the LCD module. For the dBV and dBm figures, this means working out the correct polarity indication (+ or -) and then using a Microchip routine called “Float_ASCII” to convert the numbers themselves into ASCII digits for display. Things are a little more complicated for the voltage value, because this must first have its 24-bit binary exponent analysed to work out the scaling, the position of the decimal point and the most convenient multiplier to give it (eg, volts or millivolts). After this is done, it is again converted into the equivalent ASCII digits using Float_ASCII. As you can see, there’s a bit of mathematical jiggery-pokery involved but most of this is performed by Microchip’s fancy maths routines. By the way, the full source code for the firmware will be available on the SILICON CHIP website, along with the source code for the floating point maths routines it uses (in a file called “FPRF24. TXT”). The assembled hex code of the complete firmware will also be available, ready to burn into a PIC. 0dB. So +10dBm corresponds to 10mW, +20dBm to 100mW and -30dBm to 1μW (microwatt). Since the dBV and dBm scales are “absolute”, can they be related to each other? Yes they can but to work this out you need to know the impedance level, because this is what relates voltage and power in any circuit. In traditional audio work, the impedance level is 600Ω. At this level, a voltage of 1V corresponds to a power level of 1.667mW (12/600), so 0dBV equals +2.218dBm. So at this impedance level, there’s a fixed 2.2dB difference between dBm and dBV. Older audio level meters often indicated in just dBm or perhaps in dBV as well. If the user wanted to know the actual voltage level, they had to refer to a chart or grab a calculator and work it out. This could be pretty tedious and that’s why we’ve given this new Digital Audio Millivoltmeter the ability to calculate and display not just dBV and dBm (for 600Ω circuits) but the equivalent voltage level as well, for every measurement. siliconchip.com.au +INP SIX 14.3dB GAIN, 900MHz BW AMPLIFIER/LIMITER STAGES INTERC. SET –INP 3x PASSIVE ATTENUATOR CELLS MIRROR Iout NINE FULL-WAVE DETECTOR CELLS WITH DIFFERENTIAL OUTPUT CURRENTS – ALL SUMMED ENB BAND-GAP REFERENCE AND BIASING INPUT OFFSET COMPENSATION LOOP Fig.8: block diagram of the AD8307AN IC. It includes six cascaded amplifier/limiter stages with a total gain of 86dB. OUT 25mV/dB 12.5k COM The AD8307 Log Amplifier/Detector You may not be too familiar with logarithmic amplifier/detector ICs because they are fairly specialised devices. But you can get an idea of how they work from Fig.8, which gives a simplified view of what’s inside the AD8307AN device. The incoming AC signals are passed through six cascaded wideband differential amplifier/limiter stages, each of which has a gain of 14.3dB (about 5.2 times) before it Step 1: set switch S3 to select unbalanced input connector CON2, then fit a 50Ω termination load plug to CON2 so that the meter has a nominal audio input of “zero”. Step 2: apply power and monitor the LCD readout after the greeting message has been replaced by the normal readings. In particular, look at the dBV reading, because initially you’ll probably find that it shows a figure rather higher than it should. Step 3: leave it for a few minutes to allow the circuit to stabilise, then adjust the “Intercept” trimpot (VR2) carefully using a small screwdriver or alignment tool to reduce the reading down to the lowest figure you can – ideally -76dBV or less, corresponding to about 0.160mV (160μV) and -73.8dBm. Step 4: remove the 50Ω termination plug from CON2 and instead connect the output of your audio generator. The latter should be set to some convenient frequency (say 1kHz) and to a known audio level – say 1.00V. Step 5: adjust the “Slope” trimpot (VR1) until you get a reading of +00.0dBV on the LCD. Step 6: reduce the generator output siliconchip.com.au enters limiting. This gives a total amplifier gain of about 86dB or about 20,000 times. The outputs of each amplifier/limiter stage are then fed to a series of nine full-wave detector cells, along with similar outputs from three cascaded passive 14.3dB attenuator cells connected to the input of the first amplifier/limiter. The differential current-mode outputs of all nine detector cells are added together and to 10mV and check the dBV reading on the LCD again. It should now read -40dBV and if you press the unit’s Range Select button (S1) so that the micro switches down to the <-20dBV range (ie, orange LED glowing), this reading should remain very close to -40dBV. In fact, if you press S1 again to switch down to the <-40dBV range (red LED glowing), the reading should still remain very close to -40dBV. If it changes up or down by a significant amount, you should try adjusting either the Intercept or Slope trimpots (or both) very carefully to bring it back to the correct reading. Step 7: to make sure that you have found the correct settings for the two trimpots, try changing the generator output back to 1.00V and also press S1 again to switch the meter back to its top range (<0dBV, green LED glowing). The LCD reading should again be 0.00dBV but if it has changed slightly you’ll need to tweak VR1 and/or VR2 again to bring it back. The basic idea is to repeat this process a few times until the millivoltmeter is giving the correct readings fed to a “current mirror” output stage, which effectively converts them into a single-sided DC output current. And because of the combination of cascaded gain and limiting in the amplifiers (plus an internal offset compensation loop), the amplitude of this output current turns out to be quite closely proportional to the logarithm of the AC input voltage, over an input range of just on 100dB – ie, from about -93dBV (22.4μV) up to +7.0dBV (2.24V). In fact, this “logarithmic law” relationship is linear to within ±0.3dB over most of the range. The output current Iout increases at a slope of very close to 2μA per dB increase in AC input level and when this current passes through a 12.5kΩ load resistor inside the chip, this results in a DC output voltage which increases at the rate of 25mV/dB. This slope can be fine-tuned using an adjustable external resistor in parallel with the internal 12.5kΩ resistor. The “intercept set” input allows us to adjust the DC offset in the output current mirror, which adjusts the effective “zero level” point of the chip’s output current and voltage – ie, the “origin” from which the output slope rises. You can think of it as setting the detector’s zero point. Fig.9: the display at top shows the message that appears on the LCD when the unit is switch­ed on, while directly above is a typical readout. for both of the known audio levels: 00.0dBV for 1.00V input and -40.0dBV for 10.0mV input. Once this is done, your Digital Audio Millivoltmeter is calibrated and ready for use. By the way, the maximum audio level that the Audio Millivoltmeter can measure by itself is 1.4V RMS, corresponding to +3.0dBV or +5.2dBm. To use it to make measurements of higher audio voltages, you’ll need to connect an audio attenuator/divider ahead of its input. If there’s enough interest, we’ll describe such an add-on divider in a SC future edition of SILICON CHIP. March 2009  69