Simple NiCd chargers have been around for a long time: these simply charge the battery at a low constant current. It is common to find 1-Ah AA-size cells or similar in devices such as electric pepper grinders or handheld vacuum cleaners with a plug-in charger that initially charges at 0.1 C, falling back to a continuous charge at perhaps 50 mA. The NiCd chemistry can withstand this overcharging for quite a while, but eventually the cells will be damaged. For this reason, and to improve charging time, a technique known as ‘delta-V’ charging is used. This technique exploits the fact that a fully-charged battery will turn excess charging power into heat, and the increase in cell temperature leads to a small drop in the cell voltage: see Figure 9. The charging circuit thus simply has to detect the point at which the voltage starts to drop.
This type of charger is also capable of fast charging. A charge current of 0.5 C or higher can easily be used with cells that are designed to support it. Note also that NiCd cells do not like to be deeply discharged, and should be recharged when their terminal voltage reaches 0.9 V.
One particular aspect of NiCd chemistry is the memory effect mentioned above. If a NiCd cell is repeatedly partially discharged and then fully recharged it starts to notice that only a fraction of its capacity is being used and then its maximum usable capacity starts to fall: this is a result of the formation of cadmium microcrystals. It is possible to reverse this process by repeatedly discharging the cell to below 0.9 V. The better microprocessor-controlled chargers take this into account and start each charging cycle by completely discharging the cell.
Sometimes circuits need to be isolated from each other for safety reasons, noise reduction or even to simplify a circuit function. An early classic example is e photoresistor that Gibson and Fender used to add a tremolo effect in early guitar amplifiers. This photoresistor was an early form of an optical coupler (optocoupler) that varied the resistance of a cadmium sulphide (CdS) cell using a light source to modulate the amplifier bias to create the tremolo effect. They were simple to make from discrete components and eventually companies like Vac-Tec integrated them into a single component in the 1960’s.
In general an optocoupler uses light to connect a circuit across an isolation gap instead of a straight electrical connection. The isolation gap allows the circuit to withstand very high voltages (kV), surges and noise that would normally destroy sensitive electronic components. But isolating a circuit isn’t very useful without being able to send a signal across the isolation gap so an optocoupler also includes a light source and detector on opposite
sides of the gap like in Figure 1. This arrangement works well for signals but is impractical for transmitting power like an isolation transformer. The isolation gap also means that both sides of the circuit will always be isolated even if the optocoupler fails making them suitable as protection devices.
The amount of gap between the light source and the receiver defines the isolation voltage rating with a larger gap increasing the isolation voltage. Devices that only need a few kV of isolation will typically use a planar construction like the top device in Figure 1. The bottom device shows a silicone dome construction where the light shines horizontally to allow for the larger gaps necessary for higher voltage ratings.
Optocouplers originally used incandescent or neon lamps as a light source but that quickly changed in the 1970’s when LEDs became available. The LEDs are a vast improvement over lamps because they are more linear, faster and have fewer temperature effects. The detectors have also changed over time from CdS cells to photodiodes and phototransistors. Photodiodes are used for high speed logic interfaces and phototransistors are slower and output a current based on the LED current.
A photoresistor is an example of a linear optocoupler because varying the light bulb (transmitter) current has a corresponding equal change to the CdS cell (receiver) resistance. Digital optocouplers on the other hand are meant to transmit digital on/off signals and are therefore optimized for speed. In fact, some optocouplers like the HP 6N137/ HPCL2601 family even contain extra circuitry to drive their LED to increase their operating speed even further. Optocouplers have been used for a long time and continue to be useful today, although magnetic and capacitive coupled isolators are also now available. Hopefully this has given you some insight into these humble parts.
In the case of sealed gel lead-acid batteries as well as the so-called ‘maintenance-free’ starter batteries it is important to ensure that they are not overcharged, as otherwise they can outgas. This can lead to a loss of electrolyte, which it is not a straightforward job to replace, and consequently to a shortening of service life and a reduction in capacity. In non-sealed lead-acid batteries, as used, for example, in fork-lift trucks, this is less of a problem as they can be topped up with distilled water. Lead-acid batteries should also not be subjected to deep discharge: the cell voltage should not be allowed to fall below 1.75 V. Relevant for storage is the self-discharge rate of 2% per month or more: for example, a starter battery on a petrol lawnmower may well not make it through the winter without some attention in January. The normal charging procedure is to begin with a constant current until the cell voltage reaches 2.35 V and then switch to constant voltage charging until a minimum current threshold is reached. Unless indicated otherwise the charge current should be at most 0.1 C (that is, 10% of the rated capacity in Ah/h). The current threshold when charging stops is typically 0.01 C.
In the case of a typical 12 V starter battery rated at 60 Ah this means that charging begins at a constant current of at most 6 A, and then, when the battery voltage reaches 14.1 V, the charging voltage should be kept constant.
The current will then fall and when it reaches 0.6 A charging can stop. Continuing to charge at this point (‘trickle charging’) does not cause any problems. Figure 8 shows a typical charging curve for this type of battery using the CC/CV strategy (‘constant current/constant voltage’).
A feature of lead-acid batteries is that over time they can lose capacity owing to a process called sulfation. To mitigate this special chargers are available that as well as providing a maintenance charging current, also provide regular millisecond-long pulses of current at over 100 A. This acts to prevent the formation of crystals in the battery and even help to break them down.
Most of what we said above for NiCd batteries goes equally well for their NiMH successors. NiMH batteries can also be charged using the delta-V method, although the voltage drop is less significant, especially at lower charging currents. For this reason higher charge currents are used, and this works well because the internal resistance of the NiMH battery is lower and hence it can be charged more quickly: up to 1 C is possible. In the interests of safety fast chargers also contain temperature monitors in case the fall in voltage is not detected. Since NiMH batteries do not suffer from the memory effect, there is no need to start each charge cycle with a discharge phase. NiMH-compatible chargers therefore allow the user to choose whether the discharge phase should be included in the cycle. Also, with the newer NiMH cells that have a very low self-discharge, it is possible to dispense completely with trickle charging at the end of the cycle. Looking at Figure 9, only the part of the cycle between the two vertical dotted lines is required. Figure 10 shows a universal NiCd and NiMH quick charger for four AAA or AA cells.
Figure 1 shows the modest schematic of our ultrasonic sound generator. The heart of the circuit is formed by — and how could it be otherwise — a microcontroller, in this case a small one: the ATtiny25-20. But let’s start from the beginning: the power supply. The input voltage, in the range from 9 to 12 VDC (derived from a 9-V battery, a line power adapter or a car battery), enters through the two-way header K1 and continues via on/off switch SW1 to a well-known, low-drop voltage regulator, the LP2950 in its 5-V variant. Capacitors C1 and C2 are part of the standard configuration and ensure the stability of the output voltage. The microcontroller is powered from the regulated 5-V output voltage that is generated by this regulator; for the output stage this is not necessary of course, for this the ‘raw’ battery voltage is used.
IC2 is the heart of the generator — an ATtiny25 with an absolute minimum of ancillary components. Trimpot P1 serves for setting the output frequency (with a range of about 20 kHz to about 43 kHz). The firmware has been developed such that the generator supplies an intermittent signal. We have done this to prevent the battery from being drained too quickly, and to avoid the scared animals from becoming habituated. We chose to generate a burst of roughly 1 second every 10 seconds. Since we cannot hear whether the circuit is active (that is, makes noise), we have added LED1 (in combination with a series resistor R2), which makes to operation of the circuit visible.
The output of the microcontroller (Pin 6) is nowhere near capable of delivering enough current to drive a loudspeaker oscillodirectly, so for this purpose we have added a driver stage around T1 (the well-known MOSFET BS170).
In order to send the amplified output signal from the controller (bursts of a frequency that is (far) above our range of hearing into the world with a substantial amount of decibels, it is best to use a piezo horn tweeter with a high efficiency. After some searching and experimenting we selected the MPT-001 from Monacor (Figure 2). Although this tweeter is not specifically intended for ultrasonic applications, it combines a reasonable efficiency with modest dimensions and, above all, a pleasant price of not even a tenner. In any case, good enough for our purpose. But if you happen to have another U/S tweeter or would prefer to use a different model, then go ahead! In this aspect the circuit invites experimenting.
The RV-8523 is a real-time clock (RTC) with 20 registers each eight bits wide. The registers, numbered from 00H to 13H inclusive, are listed on the right in Figure 4. The RTC has an internal supply voltage monitor and can switch itself automatically over to battery power. As the lead photograph shows, the device is available in module form complete with battery holder.
After the register number (from 0x00 to 0x13) has been sent, the register can be accessed. In contrast to the LM75 this device automatically increments the register pointer, wrapping round from 0x13 to 0x00. It is therefore possible to read from or write to all twenty registers in a single operation.
Suppose for example that we wish to read just the date and time. We set the register pointer to 3 and read seven bytes. Using the Arduino Wire library the code might look like the following.
Wire.write(byte(0x03)); // set register number to
Wire.requestFrom(0x68, 7); // read time and date
seconds = Wire.read();
tenseconds = (seconds >> 4) & 0x07; seconds &= 0x0f;
minutes = Wire.read();
tenminutes = (minutes >> 4) & 0x07; minutes &= 0x0f;
The resulting values are BCD-encoded, and so conversion to binary may be required.
Besides the clock itself, the RV-8523 also has an alarm function that can produce an interrupt at a specified point in time. The only wrinkle is that although the INT_1 output goes low at the appointed hour, it does not automatically go high again: it is necessary to reset the alarm interrupt explicitly with a write to AF in control register 2.
Some operating systems, including Raspbian, already have a driver for this device built in (rtc_pcf8523). In such cases there is no need for any programming if you are only interested in the current date and time, as the hwclock command will talk to the RTC and read or set the clock. An rc script run at boot time can be used to run this command to set the system clock automatically, and at power down the updated system time (which may have been adjusted either manually or over the network) can be written back to the RTC. This arrangement allows a Raspberry Pi, even without a network connection, to maintain its clock across a power failure with minimal additional hardware. However, if you wish to use the alarm feature of the RTC, then you will need to get involved in some programming. Once the RTC has been set using a Raspberry Pi, it can then be connected to an ATmega or Arduino. The back-up battery on the module ensures that the clock continues to keep time. Then it is just a matter of a few lines of code to read the time into the ATmega or Arduino.
The LM75 is the de facto standard temperature sensor with an I2C connection. Of the seven bits of its address only the upper four are fixed (at 1001); the other three bits can be set using external circuitry. Up to eight LM75s can therefore be connected to a single I2C bus, with addresses ranging from 0x48 to 0x4F. So if, for example, LM75s are to be used in a temperature monitoring application in a desktop PC, it is possible to measure the temperature at up to eight different places within the case.
Internally the LM75 has four registers, which are addressed using two bits (see Figure 1):
• 00H: a 16-bit temperature register, which can only be read from;
• 01H: an 8-bit configuration register;
• 02H: a 16-bit hysteresis register;
• 03H: a 16-bit threshold register.
At power up the temperature register is selected by default, but even if that is the only register you wish to access it is always a good idea to write the register’s address before reading it. When writing to a register the address must be given: the first byte after the write command is always interpreted by the LM75 as a register number.
After the register number come the data. In the case of a 16-bit register the more significant byte is transferred first, followed by the less significant byte.
In contrast to some other I2C devices the LM75 does not automatically increment the register number after each access: the register pointer remains fixed. If there is only one bus master and only the temperature reading is of interest, it is therefore unnecessary to reset the register pointer to zero before each access. All you need to do in the read operation is simply transfer the two data bytes representing the temperature. The accuracy of the LM75 does leave a little to be desired. According to the datasheet the reading can be in error by up to 2 °C. However, there are alternative devices, such as the TMP275, which are more accurate and in general protocol- and register-compatible with the LM75.
The LM75 is also rather sensitive to interference on its power supply lines. To avoid collecting garbage instead of temperature readings, it is wise to stick to the ‘one 100 nF capacitor per package’ rule of thumb.
The PCF8574 is a ‘remote 8-bit I/O expander’, a parallel I/O chip controlled over an I2C bus interface: see Figure 2. It comes in two variants, which differ only in their I2C slave address. In the case of the PCF8574 the upper four bits of the address are 0100, while in the case of the PCF8574A they are 0111. This means that it is possible to connect up to sixteen PCF8574-series devices to a single I2C bus.
Internally there is just one register, which is directly connected to the port. When a bit pattern is written to the register, the port pins change state; if a bit is set to ‘1’, then the pin can also be used as an input. When the register is read the device returns the logic levels on the external I/O pins. Figure 3 shows how to connect a PCF8574 with an LED wired to port pin P0 to a Raspberry Pi. If a ‘1’ is written to the PCF8574:
i2cset -y 1 0x40 0x01
the LED will light. If a ‘0’ is written:
i2cset -y 1 0x40 0x00
the LED will extinguish. Strictly speaking we are here setting the register number to 0x01 or 0x00, since, according to the manual and online guides the i2cset command expects a register number after the device address. However, the port expander interprets the number as a data value representing the desired bit pattern on its outputs.
It is sometimes desirable to use a device like this to provide a degree of isolation between a computer and a peripheral: if an output pin should accidentally be shorted to 12 V, for example, then it is only the PCF8574 that is likely to suffer any harm. The PCF8574 is also used on simple LCD interface boards, allowing an I2C bus to drive the common one- or two-line LCD panels that employ the HD44780 controller IC. The LCD is operated in four-bit mode, and three further pins on the PCF8574 are connected to the LCD panel’s E, RS and R/W signals. The one remaining port bit is sometimes used to control the LCD backlight. Some of these boards include pull-up resistors on the bus lines to 5 V. These should normally be removed, or not fitted in the first place.
Bluetooth is a protocol where a Master communicates with one or more Slaves; the Slaves cannot talk to each other. The Master is often a smartphone or computer, but this isn’t always desirable. A Bluetooth Master module will work very well instead.
The basic circuit of the remote control is fairly simple (see Figure 1). In fact, because the BL620 can do everything itself, there’s no need for much extra besides. Two push-buttons and a two project color LED are enough; a reset button, programming connector, and switch for selecting the operation mode (debugging or run) complete the picture. The complications arise when we add the power supply.
Remote control implies battery. Remote controls are usually wireless and hence battery powered. Ours is the same, we’ll even be using a 12 V battery. So why this voltage, when the BLE module operates at 3 volts? It’s the result
of a compromise. The problem was to find a small standard case suitable for a remote control with a battery holder, two push-buttons, and LED, and of course with room for the BL620 (which measures 19 × 12.5 mm). The only case that met our criteria was intended for 12-V batteries (in fact, it is a case for a garage door-style remote control) – that’s why! We’re going to drop the voltage using a little bit of electronics, and for this task we’ve chosen the LTC3632 from Linear Technology (now Analog Devices).
For the longest battery life, the circuit’s consumption must remain as low as possible. There’s no problem in terms of the BL620, it draws only 0.5 μA in sleep mode, but the converter/dropper also has to be fed. Now believe it or not, it’s quite greedy: it draws 12 μA! This might not seem like very much to you, but in reality it’s much too much, as the 12-V batteries (in 23A format) usually have a capacity of only 55 mAh. So it’s out of the question to leave it powered continuously, which is why we’ve added an electronic on/off switch, with the help of a few transistors and diodes. Figure 2 shows the final circuit.