Design Ideas
-- EDN, 4/29/1999
Make a simple PC-based frequency meter Radovan Stojanovic, University of Patras, Patras, Greece A simple, low cost, and precision frequency meter uses only two pins of a pc parallel port (Figure 1). The TTL-level periodic input signal with frequency fIN connects to the ACK pin of LPT1. This input produces an IRQ7 hardware in- terrupt on every rising edge (Figure 2). The software counts the number of IRQ7 interrupts in the time unit of timebase T. If this timebase is 1 sec, the frequency of the input signal equals the number of IRQ7 interrupts in 1 sec. You can use many ways to precisely generate the timebase, T, such as using the delay() or sleep() functions in C. You can also use software calibration loops. Unfortunately, these techniques are unreliable because they are based on polling. The best choice is to use a second interrupt, such as IRQ0 (software 0x1C). This interrupt is related to the internal PC timer and occurs 18.2 times/sec. For precise measurements, you can use proportional constants. For example, if your timebase equals the 18 IRQ0, you must correct the result by a factor of 18.2/18. The software in Listing 1 is simple and interrupt-based, which allows for resident operation in an MS-DOS environment and for multitasking mode under Windows. For a timebase of 1 sec and using a 100-MHz Pentium PC, the frequency meter gives good results in the range of 10 Hz to 10 kHz with errors less than 0.26% for DOS and 0.94% for Windows (Figure 3). This design uses a Listing 1 is written in Borland C++ compiler, and you can use the same program for DOS-based C compilers, such as Turbo C. Also, you can use the second parallel port LPT2, with interrupt IRQ5, to perform this same frequency-meter function. If you add one voltage-to-frequency, current-to-frequency, or temperature-to-frequency converter, the frequency meter can also perform simple, low-cost, and high-resolution measurements of analog values. (DI #2342) Simple circuit safely deep-discharges NiCd battery Jim Hagerman, Science & Technology International, Honolulu, HI Nickel-cadmium (NiCd) batteries can possess an undesirable memory effect due to partial discharges. The remedy is a complete discharge before charging again. Figure 1a shows a simple circuit that performs this feat. Although relatively straightforward in concept, the circuit has three redeeming features: It receives its power from the battery undergoing the discharge; after the battery is fully discharged, the current drain is only approximately 4 µA, which is usually well below the self-discharge level of a battery alone; and an LED flashes at end-of-charge. Ignoring LED current, RD determines the rate at which the circuit discharges the battery, as follows:
A NiCd or nickel-metal-hydride (NiMH) battery has a nominal cell voltage of approximately 1.2V at midcharge and approximately 1V at end of charge. Do not discharge past the end-of-charge voltage, because you may damage the battery. The values in Figure 1a are for a four-cell battery. R1 and R2 determine the end-of-voltage limit referenced to the built-in 1.182V bandgap reference. When battery voltage is high, comparator IC1 turns on Q1 , a power n-channel MOSFET, which discharges the battery through RD . When the battery reaches the end-of-charge voltage, the circuit's behavior gets interesting. R3 and C1 provide positive ac feedback to ensure that the comparator fully switches and prevents the circuit from becoming a linear regulator. However, the intrinsic internal resistance of the battery also causes negative dc feedback. As the MOSFET turns off the battery terminal voltage, the comparator turns the MOSFET back on. The positive ac feedback overwhelms the negative feedback, thus ensuring switching, but only for a short time, and the circuit oscillates. The frequency is roughly
Oscillation eventually stops when the battery voltage stays below the hysteresis threshold, which the intrinsic resistance of the battery determines. The higher the resistance, the longer the LED will flash. The circuit takes advantage of the fact that this resistance is greatest at the end of charge. When the discharge cycle stops, the LED stays off, and the only current drain is from IC1 and the R1 /R2 divider. Both of these values are small enough to leave the battery connected indefinitely. (DI #2348) Algorithm extracts roots of decimal numbers Frank Vitaljic, Bellingham, WA "Algorithm extracts cube root" (EDN, Jan 15, 1998, pg 100) covers only the one-third power (cube root). In contrast, the C routine in Listing 1 calculates the Kth root (X1/K) of positive decimal numbers X. Both K and X can vary widely. You type in X, K, and an estimate of the root; the routine then calls the calcRoot function in the software program. Upon calculating the root, the routine prints on screen the number of iterations performed and the root result X1/K. The routine raises this result to the Kth power and displays the result so you can make a comparison with the original X. The algorithm applies a Newton-Raphson approach to the equation Y=X1/K. If you differentiate the equation and express it in recursive form, you obtain This recursion monotonically converges toward the Kth root of the number. The routine terminates the iteration when The error in the calculation is Table 1 shows cube-root errors for numbers 0.001 to 1000. The number of iterations varies from six to 14. Table 2 compares the number of iterations inherent in the algorithm with the number of iterations of the earlier Design Idea. For increased accuracy, you can set the maximum ERROR define to 1.0e–14 at the expense of increasing the number of iterations. (DI #2339). Reset circuit provides snappy action Steve Kelley, Protobyte Inc, Liberty, MO The circuit in Figure 1 provides a 1-sec reset, using multiple AND gates for increased fanout. Intended for breadboarding or prototyping, the circuit generates a "snappy" master reset that remains active long enough to eliminate questionable start-ups. When you apply power to the circuit, the timing capacitor begins charging through the 1-Mwresistor, turning on the npn transistor. The AND-gate inputs go low, generating the reset signal and turning on the reset LED. When the timing capacitor brings the transistor's base nearer to ground, the transistor turns off, and the 2.2-kwresistor pulls the AND gates' inputs high. The transistor isolates the capacitor from the AND gates' internal pull-up resistors and provides a smooth transition through the logic threshold. Upon removal of power, the 1N4001 diode discharges the timing capacitor. (DI #2351). Diodes improve inverter efficiency Jeff Witt, Linear Technology Corp, Milpitas, CA In "Switched-capacitor regulator provides gain" (EDN, March 13, 1998, pg 80) a switched-capacitor voltage inverter wired as a supply splitter steps a positive voltage down to an output voltage equal to half the supply voltage. The input current to such a circuit is one-half the output current; thus, you obtain higher efficiency and lower power loss than you would from a linear regulator performing the same function. You can obtain the same benefits while inverting the input voltage. Figure 1 shows the principles of operation. Typical switched-capacitor inverters contain four internal switches. Two switches charge a flying capacitor from the input voltage to ground; the other two switches discharge the capacitor, pulling the positive side to ground and generating a negative output voltage. By adding three diodes to steer the current, you can use the switches to charge two capacitors in series and then discharge them in parallel to an output capacitor. Figure 1 shows the current paths. The absolute value of the output voltage equals half the input voltage minus some loss from the switches and diodes. Figure 2 shows a practical circuit, which converts 12V to –4V at 100 mA. IC1 modulates the voltage drop across Switch 1 to regulate the output, maintaining –4V from an input of 11 to 15V. Many negative supplies power loads that can pull the output above ground (op-amp circuits in particular). Q1 prevents such a load from pulling IC1 's output pin above the voltage on the op amp's ground pin. Because most of IC1 's operating current flows from its ground pin, the input current to this circuit is slightly more than half the output current. When the circuit delivers 100-mA load current, measurements show that the 12V input delivers 64 mA. The circuit dissipates only 350 mW, so an all-surface-mount configuration runs cool. (DI #2352). | |||||||||||||||||||||||||||||||||||||||||||||

















