Tuesday, 4 February 2014

Practical AVR Microcontrollers


Book Description
If you've heard of Arduino or even used it in your own projects, you probably know that the AVR microcontroller is the brain of the Arduino. In Practical AVR Microcontrollers, you'll learn how to use the AVR microcontroller to make your own nifty projects and gadgets.

You'll start off with the basics in part one: setting up your development environment and learning how the "naked" AVR differs from the Arduino. Then you'll gain experience by building a few simple gizmos and learning how everything can be interconnected.
Book Details
Publisher: Apress
By: Alan Trevennor
ISBN: 978-1-4302-4446-2
Year: 2012
Pages: 416
Language: English
File size: 18.6 MB
File format: PDF

Small Personal Alarm

Small, portable, anti-bag-snatching unit. Also suitable for doors and windows control

This circuit, enclosed in a small plastic box, can be placed into a bag or handbag. A small magnet is placed close to the reed switch and connected to the hand or the clothes of the person carrying the bag by means of a tiny cord. If the bag is snatched abruptly, the magnet looses its contact with the reed switch, SW1 opens, thecircuit starts oscillating and the loudspeaker emits a loud alarm sound.

The device can be reverse connected, i.e. the box can be placed in a pocket and the cord connected to the bag. This device can be very useful in signalling the opening of a door or window: place the box on the frame and the magnet on the movable part in a way that magnet and reed switch are very close when the door or window is closed.
Circuit operation:
A complementary transistor-pair is wired as a high efficiency oscillator, directly driving a small loudspeaker. Low part count and 3V battery supply allow a very compact construction. 
Parts:
R1____________330K   1/4W Resistor
R2____________100R   1/4W Resistor

C1_____________10nF   63V Polyester or Ceramic Capacitor
C2____________100µF   25V Electrolytic Capacitor

Q1____________BC547   45V 100mA NPN Transistor
Q2____________BC327   45V 800mA PNP Transistor

SW1____________Reed Switch and small magnet (See Notes)

SPKR___________8 Ohm Loudspeaker (See Notes)

B1_____________3V Battery (two A or AA cells wired in series etc.)
 
 Notes:
  • The loudspeaker can be any type, its dimensions are limited only by the box that will enclose it.
  • An on-off switch is unnecessary because the stand-by current drawing is less than 20µA.
  • Current consumption when the alarm is sounding is about 100mA.
  • If the circuit is used as anti-bag-snatching, SW1 can be replaced by a 3.5mm mono Jack socket and the magnet by a 3.5mm. mono Jack plug having its internal leads shorted. The Jack plug will be connected to the tiny cord etc.
  • Do not supply this circuit at voltages exceeding 4.5V: it will not work and Q2 could be damaged. In any case a 3V supply is the best compromise.

Converter 12 Vdc to 230 Vac or Inverter

As shown in the Inverter circuit diagram obove , Its used as the oscillator stage astable multivibrator contained in IC1, a CMOS 4047 (this cult series 40xx series) by varying the resistance value of R1 trimmer (220 k total resistance) can vary the oscillation frequency of 40 Hz to 70 Hz square wave, phase shifted by 180 °,  Output pin 10-11 will drives two NPN transistors TR1-TR3, which in turn is fed to the TR2-TR4. 
Converter 12 Vdc to 230 Vac or Inverter Schematic 
The diodes DS2-DS3, mounted on the output transistors TR2-TR4 are used to protect against voltage surges appearing across the windings V 9 + 9 V transformer T1. For the transformer T1, I used an ordinary mains transformer (primary 230 V so) with a secondary dual 2 x 9 V. 
Parts List: 
R1 ……. 220 k trimmer 
R2 ……. 330 k 
R3 ……. 680 
R4 ……. 2.2 k 
R5 ……. 2.2 k 
C1 ……. 4.7 nF polyester 
C2 ……. 220 uF electrolytic 
DS1 ….. 1N4004 
DS2 ….. 1N4004 
DS3 ….. 1N4004 
DL1 ….. LED 
TR1 ….. BC184 NPN 
TR2 ….. NPN BDX53C 
TR3 ….. BC184 NPN 
TR4 ….. NPN BDX53C 
IC1 …… 4047 CMOS 
T1 …….. transformer sector 80 VA primary 230 V 0.35 A / Secondary 2 x 9 V 3.5 A 
S1 ……. switch 
Note : 
  • Two final power TR2-TR4 should be mounted on the right size heatsink, otherwise they will overheat. You can choose from MJ4033 – MJ3007 or more, provided that the NPN.
  • The maximum power output that can be used depending on the size of the core of the transformer T1, the VA is: with 50 VA can be taken in the secondary 230 V 0.2 A (current consumed by the end will be 4 A) with 90 VA can be taken on the secondary 230 V 0.4 a (current consumed by the end will be 7 A).
  • To power the circuit from the 12V battery, it will take over at least 1.8 millimeters in diameter, to avoid loss by Joule effect.

Voltage Inverter using IC NE555

In many circuits we need to generate an internal adjustable voltage. This circuit shows how it is possible to use a trusty old NE555 timer IC and a bit of external circuitry to create a voltage inverter and doubler. The input voltage to be doubled is fed in at connector K1. To generate the stepped-up output at connector K2 the timer IC drives a two-stage inverting charge pump circuit.

The NE555 is configured as an astable multivibrator and produces a rectangular wave at its output, with variable mark-space ratio and variable frequency. This results in timing capacitor C3 (see circuit diagram) being alternately charged and discharged; the voltage at pin 2 (THR) of the NE555 swings between one-third of the supply voltage and two-thirds of the supply voltage.
The output of the NE555 is connected to two voltage inverters. The first inverter comprises C1, C2, D1 and D2. These components convert the rectangular wave signal into a nega-tive DC level at the upper pin of K2. The second inverter, comprising C4, C5, D3 and D4, is also driven from the output of IC1, but uses the negative output voltage present on diode D3 as its reference potential. The consequence is that at the lower pin of output connector K2 we obtain a negative volt-age double that on the upper pin.
Now let us look at the voltage feedback arrangement, which lets us adjust this doubled negative output voltage down to the level we want. The NE555 has a control voltage input on pin 5 (CV). Normally the voltage level on this pin is maintained at two-thirds of the supply voltage by internal circuitry. The voltage provides a reference for one of the comparators inside the device. If the reference voltage on the CV pin is raised towards the supply voltage by an external circuit, the timing capacitor C3 in the astable multivibrator will take longer to charge and to discharge. As a result the frequency of the rectangle wave output from IC1 will fall, and its mark-space ratio will also fall.

The source for the CV reference voltage in this circuit is the base-emitter junction of PNP transistor T1. If the base volt-age of T1 is approximately 500 mV lower than its emitter voltage, T1 will start to conduct and thus pull the voltage on the CV pin towards the positive supply.

In the feedback path NPN transistor T2 has the function of a voltage level shifter, being wired in common-base configuration. The threshold is set by the resistance of the feedback chain comprising resistor R3 and potentiometer P1. When the emitter voltage of transistor T2 is more than approximately 500 mV lower than its base voltage it will start to conduct. Its collector then acts as a current sink. Potentiometer P1 can be used to adjust the sensitivity of the negative feedback circuit and hence the final output voltage level.Using T1 as a voltage reference means that the circuit will adjust itself to compensate not only for changes in load at K2, but also for changes in the input supply voltage. If K2 is disconnected from the load the desired output voltage will be maintained, with the oscillation frequency falling to around 150 Hz.

A particular feature of this circuit is the somewhat unconventional way that the NE555’s discharge pin (pin 7) is connected to its output (pin 3). To understand how this trick works we need to inspect the innards of the IC. Both pins are outputs, driven by internal transistors with bases both connected (via separate base resistors) to the emitter of a further transistor. The collectors of the output transistors are thus isolated from one another [1].

The external wiring connecting pins 3 and 7 together means that the two transistors are operating in parallel: this roughly doubles the current that can be switched to ground.The two oscilloscope traces show how the output voltage behaves under different circumstances. The left-hand figure shows the behaviour of the circuit with an input voltage of 9 V and a resistive load of 470 Ω connected to the lower pin of outputconnector K2. The figure on the right shows the situation with an input voltage of 10 V and a load of 1 kΩ on the lower pin of output connector K2. The pulse width and frequency of the rectangle wave at the output of IC1 are automatically adjusted to compensate for the differing conditions by the feedback mechanism built around T1 and T2.

Because of the voltage drops across the Darlington out-put stage in the IC (2.5 V maximum) and the four diodes (700 mV each) the circuit achieves an efficiency at full load (470 Ω between the output and ground) of approximately 50 %; at lower loads (1 kΩ) the efficiency is about 65 %.

Power LED Driver

If you want to operate power LEDS with a truly constant current which significantly prolongs the lifetime of the lamp and avoid the power loss resulting from using a constant voltage supply with a series resistor, you need a suit-able constant current source. However, the only way to achieve really good efficiency is to use a switching regulator. Altogether, this means that you need a switching regulator designed to generate a constant current instead of a constant voltage.

With this in mind, the author started working on the development of a LED pocket torch with especially high efficiency. Along with using high-capacity rechargeable batteries to maximise operating life, it’s worthwhile to be able to reduce the brightness, and therefore the operating current of the LEDs, when you don’t need full power. Accordingly, the author incorporated a dimming function in the design, based on operation in PWM mode in to reduce power losses to an absolute minimum.

Power LED Driver Circuit Diagram

As you can see from the circuit diagram, the author chose an LT3518 switching regulator IC, which is a buck/boost converter optimised for LED operation. Here it is used as a down converter (buck mode). This IC can achieve better than 90% efficiency in this mode, depending on the input voltage. According to the typical application circuit on the data sheet [1], its switching frequency can be set to approximately 170 kHz by selecting a value of 82 kΩ for R1. To maximise overall efficiency with this type of IC, the volt-age drop over the sense resistor used to measure the current flowing through the LED should be as low as possible. This particular device operates with a voltage drop of 100 mV, corresponding to a current of just under 1.5 A with the specified value of 68 mΩ for R2. This value proved to be suitable for the Cree LED used by the author. At this current level, a diode with a power rating of at least 6 W should be used for D1.

IC1 has an additional property that is ideal for this application: the connect-ed LED can be dimmed by applying a PWM signal to pin 7 of the IC, with the brightness depending on the duty cycle. Obviously, the PWM frequency must be lower than the switching frequency. The PWM signal is provided by IC2, a special voltage-controlled PWM generator (type LTC6992 [2]). The duty cycle is controlled by the volt-age applied to the MOD input on pin1 (range 0–1 V). The resistor connected to pin 3 determines the internal clock frequency of the IC according to the formula f= 1 MHz × (50 kΩ/R3). This yields a frequency of approximately 73.5 kHz with R3 set to 680 kΩ, which is much too high for controlling IC1.

However, the PWM IC has an internal frequency divider with a division factor controlled by the voltage applied to pin 4, which in this circuit is taken from voltage divider R4/R5. The division factor can be adjusted over the range of 1 to 16,384. The division factor with the specified component values is 64, resulting in a PWM frequency of around 1,150 Hz. If you want to be able to generate a PWM signal with an adjust-able duty cycle over the full range of 0 to 100%, you must use the LTC6992-1 option. The -4 option, which provides a range from 5 to 100%, might be an acceptable alternative.To prevent the duty cycle (and thus the brightness of the LED) from depending on the battery voltage, which gradually drops as the battery discharges, IC3 generates a stabilised 1.24 V control voltage for potentiometer P1. Series resistor R7 reduces the voltage over P1 to 1V, which exactly matches the input voltage range of the LTC6992.

All capacitors should preferably be ceramic types, in particular due to their low effective series resistance (ESR) as well as other favourable characteristics. However, only capacitors with X5R or X7R dielectric should be used; capacitors with type Y dielectric have very poor temperature characteristics.The supply voltage is limited to 5.5V by the maximum rated supply voltage of IC2. The author used four NiMH re-chargeable cells connected in series, which yields a voltage that is just within spec. With an operating voltage in the range of 4.5 V to 5.5 V, you must use an LED that can operate at less than 4V.

This eliminates devices with several chips connected in series on a carrier, which is very often the case with power LEDS rated at over 5 W. These devices require a correspondingly higher supply voltage, which means more cells connected in series. This is only possible if the supply voltage for IC2 is reduced by a 5 V voltage regulator or other means, and of course R4 must also be connected to this lower supply voltage.

Finally, a few words about soldering. An exposed thermal pad must be provided on the PCB for the LT3518, and the rear face of the IC must be soldered to this pad. The author obtained good results by dimensioning the exposed pad large enough to extend beyond the outline of the IC. When assembling the board, first tin the pad and the rear face of the IC. Then heat the pad with a soldering iron. When the solder melts, withdraw the tip of the soldering iron to the edge of the pad and simultaneously place the IC on the pad and align it. After this the pins can be soldered.

Wireless LED Driver

There are times when you want to control a LED indicator light through the side of a plastic box, without wires and without drilling a hole in the box.  One example where this may be needed is in data collection systems.  These are often used out of doors in harsh environments and have to be hermetically sealed. Holes drilled in the side of the box for panel mounted LEDs or light pipes can often leak.

The circuit below solves this problem by sending power to the LED through the plastic, using a magnetic coupling technique. The circuit below can route power through plastic enclosures as thick as ¼ inch.  The circuit will not work through metal boxes.  An expensive inductor, driven by a series resonant mode 125KHz oscillator, forms the power transmitter.  A similar inductor, wired as a 125KHz parallel resonant circuit, forms the power receiver.  A voltage doubler circuit at the receiver efficiently converts the collected AC into DC.  The circuit will operate over a wide 3v to 6v supply range.

With a 5v supply, the circuit draws about 25ma of current.  However, by gating the oscillator on for a brief 20ms period, with a 0.5Hz rate, the average power can be reduced to about 250 microamps.  If you want to extend the range of operation out to ½ inch, try using a 74C14 (CD4069) with a 12v supply.  Using surface mounted components; the complete LED assembly can be encapsulated and glued to the outside surface of the box.  Tiny unshielded surface mounted inductors can be used to reduce the size of the transmitter and receiver.  However, smaller parts will reduce the power transfer range to perhaps only a 1/8 inch separation. 

A very nice bright green LED, which works great for this circuit, is one from Kingbright, available from Digikey, part number 754-1089-1. 

Light Sensitive and Differential Temperature Switch

n Fig. 1 see a precision light- sensitive switch that activates when the sensed quantities go above or below pre-set values. The LDR can be any cadmium sulfide unit that has a resistance in the range 500R to 20k at the required trip level. The RV1 adjust LDR at normal light level. 
Fig. 2 Differential Temperature Switch Circuit Diagram:
In Fig. 2 see a differential temperature switch circuit using ordinary silicon diodes as temperature sensing elements and responding to differentials of a fraction of degree. RV2 can be used to apply an effective offset of several degrees to the two diodes. To adjust the circuit, apply the required differential temperature to the diodes and then adjust RV2 so that the relay just turns on. The circuit responds to the relative temperatures, rather than the absolute temperatures, of the two diodes. 
Part List :
R1=LDR *see text 
R2-3=10Kohm 
R4=2.2Kohm 
R5-6-7-10=4.7Kohm 
R8-9=2.7Kohm 
RV1=22Kohm  pot. 
RV2=1Kohm  pot. 
D1-4=1N4001 
D3-4=1N4148 
Q1-2=BC214L 
IC1-2=LM741 
RL1-2=RELAY 12V >120 ohm