Interrupts are used to suspend the normalexecution of the main program and take theprogram counter to the subroutine known as theinterrupt service routine ISR. After the ISR isexecuted, the program counter returns to the mainloop. The following illustration shows how thecode in an ISR is executed. All interrupts are assigned individual enablebits, which must be set to logic one as is theglobal interrupt enable bit in the status register inorder to enable the interrupt.
When an ISR isexecuting, the global interrupt enable bit is clearedby default, and hence, no furthers interrupts arepossibleunless the user program has specificallyenabled the global interrupt enable bit to allownested interrupts, that is, an interrupt withinanother interrupt.
The universal serial interface, or USI, provides the basic hardware resources needed for serialcommunication. This interface can be configuredto follow either a three-wire protocol, which is. Combined with aminimum of control software, the USI allowssignificantly higher transfer rates and uses lesscode space than solutions based on software only.
Interrupts are included to minimize the processorload. AVR devices provide a comparator, whichmeasures the analog input voltage on two of itsterminals and gives digital output logic 0 or 1 ,depending on whether the voltage on the positiveterminal is high or that on the negative terminal ishigh.
The change inoutput of the comparator can be used as aninterrupt source. The output of the comparator isavailable on the analog comparator output ACO pin. The following illustration shows the blockdiagram of the analog comparator. These devices have a ten-bit, successiveapproximationtype ADC with multiple single-ended input channels. Some devices also havedifferential channels to convert analog voltagedifferences between two points into a digital value.
In some devices, to increase the resolution ofmeasurement, there is a provision to amplify theinput voltage before conversion occurs. Thereference voltage for measurement can be. The followingillustration shows the block diagram of the ADC. The system clock sources in the AVR devicesinclude the calibrated resistor capacitor RC oscillator, the external clock, crystal oscillator,watchdog oscillator, low-frequency crystaloscillator, and phase lock loop PLL oscillator.
The main clock can be selected to be any one ofthese through the fuse bits. The selected mainclock can be further prescaled by setting suitablebits in the clock prescaler register during theinitialization part of the user software. This gives more accurate ADCconversion results. The following illustrationshows the various clock options. It is necessary for the modern generation ofcontrollers to manage their power resources in theutmost efficient manner, and AVR devices cannotafford to lag behind in this race of optimization.
They support certain sleep modes, which can beconfigured by user software and allow the user toshut down unused modules, thereby saving power. The sleep modes supported include powerdown, power save, idle, ADC noise reduction, etc. Different devices support different modes, and thedetails can always be found in the datasheets. Furthermore, each mode has a different set ofwakeup sources to come out of that mode and goto full running state. Power-on reset The microcontroller unit MCU is reset when the supply voltage isbelow the power-on reset threshold.
Watchdog reset The MCU is reset when thewatchdog is enabled and the watchdog timerperiod expires. Brown-out reset The MCU is reset when thebrown-out detector is enabled and the supplyvoltage VCC is below the brown-out resetthreshold. After reset, the source can be found by softwareby checking the individual bits of the MCU statusregister. The followingillustration shows the block diagram of variousreset sources.
This data can also be read back from the controlleralong with signature bytes for identification of thedevice. Tiny devices can be programmed usingserial programming or high-voltage parallelprogramming. Unless otherwise mentioned,throughout this book we have used serialprogramming for the Tiny microcontrollers. HVSP is onlyapplicable to eight-pin microcontrollers as analternative to parallel programming, because thesedevices have too few pins to use parallelprogramming. It also programs the lock bits and fusebytes.
There is one more method to program thesedevicesthe debugWIRE on-chip debug system,which is described in the next section. The lock bits are used for protection of the usersoftware in order to prevent duplicity, and fusebytes are used for initial settings of the controller. The following illustration shows thesignals for ISP serial programming.
After enablingthis interface, the RESET pin becomes thecommunication gateway between the target andemulator. Thus, external reset doesnt work if thisinterface is enabled. The following illustrationshows the debug WIRE interface.
This book shows several projects spanning a widespectrum of ideas and involving several applicationdomains. These projects can be built for fun aswell as education. However, it is important todwell upon the design and development process.
How does one go about making a system or aproject that no one has thought of before? Ofcourse, you have to think what you need. Sometimes, the trigger for this need might comeby looking at other peoples projects. Its anabstract process, but an example might help toillustrate it. Suppose you saw LEDs being used insome system: bright, blinking LEDs that captureyour imagination, and you think, hey! This idea for something unique is the mostimportant thing. The illustration on this pageshows the design and development process.
Once an idea germinates in your mind, you cancontinue to evolve it. At the same time, an Internetsearch is recommended to ensure that no one elsehas already thought of the same idea.
There is nopoint in reinventing the wheel. If the idea has beenalready implemented, maybe it would be good tothink how it can be further improved. If you doindeed take up the implementation and improveupon it, a good plan of action would be to share itwith the original source of the implementation, soas to acknowledge the work and also to put onrecord your own contribution.
This way, one canenrich the system by contributing back to it. Inother cases, you may need to check up on theappropriate thing to do. It would be all right inmost cases if you intend to use the original or youradaptation for personal use. If you intend to use itfor commercial applications, however, it isabsolutely necessary to check with the originalsource to avoid future problems. There are two distinct elements in a project, as seen in the illustration, namely the hardwarecomponents and the software.
The hardware partcan be implemented in many ways, but using amicrocontroller is an easy option, and since thisbook is about using microcontrollers in projects,that is what we are going to concentrate on. Apartfrom the microcontroller, the system needs asource of power to operate. It would also needadditional hardware components specific to theproject even though modern microcontrollersintegrate a lot of features, as seen in the nextillustration.
For example, even though amicrocontroller has digital output pins to control abank of seven-segment displays, it does not havethe capability to provide the large enough currentthat may be needed, so you will have to provideexternal current drivers. Similarly, if you want to. The illustration on this page shows theelements of a modern microcontroller. The software component refers to the applicationprogram that runs on the microcontroller, but may also refer to a custom program that runs on a PC, for example, to communicate with themicrocontroller.
The project development process requires that thetwo elements of the project, the hardware elementsand the software elements, be developed in parallel. The software component that runs on themicrocontroller is developed on a host PC, and alarge section of the code can be developed evenwithout the hardware prototype completed.
Some parts of the code thatrequire external signals or synchronization withother hardware events cannot be tested, and thistesting must be postponed until the software isintegrated with the hardware. Once the hardwareprototype is ready, it must be integrated with thesoftware part and the integrated version of theproject tested for compliance with the requirements. The integration may not be smooth and may requireseveral iterative development cycles.
Apart from the hardware components, whichwould be specific to a given project and thesoftware, some hardware components are commonacross most projects.
These are related to thepower supply and a clock source for themicrocontroller. These elements of the project areshown in the next illustration. The power supplysource and the regulation of the supply voltage arediscussed in detail in a later section. The clock. Fortunately, some sort of clock source is oftenintegrated in the microcontroller itself. This isusually an RC oscillator that is not very accurateand whose actual value depends on the operatingvoltage, but is quite suitable for many applications.
Only if the application requires critical timemeasurements does one need to hook up anexternal clock oscillator. All of themicrocontrollers in the AVR family have an on-chip clock source, and in most projects in thisbook, we use the same. The rate of programexecution is directly dependent upon the clockfrequency; a high clock frequency means yourprogram executes faster. However, a high clockfrequency also has a downside: the systemconsumes more power.
There is a lineardependence of power and clock frequency. If you double the clock frequency, the powerconsumption would also double. So, it is not verywise to choose the highest available frequency ofoperation, but rather to determine the frequencybased on the program execution rate requirement. As we illustrate in Project 1 later in this chapter,by choosing to use the lowest available clockfrequency, we are able to keep the requiredoperating power to a minimal level.
The followingillustration shows the elements of a project. Apart from the clock source, power supplysource, and voltage regulator, the project requiresinput and output devices and a suitable enclosurefor housing the project, as shown in theillustration. For any system to run, a power supply is needed.
Without the required supply, the system is only asgood as a paperweight. Selecting the right sourceof power is important. For a portable system,connecting it to the main grid would tie it up to aphysical location, and it would hardly be classifiedas a portable system then.
Batteries are the most common source of energyfor portable electronics applications. They areavailable in a variety of types, packages, andenergy ratings. The energy rating of a batteryrefers to the amount of energy stored in it.
Mostbatteries are of two types: primary and secondary. Primary batteries are disposable batteries. Thesebatteries can provide energy as soon as they areassembled and continue to provide energy throughtheir lifetimes or until they are discharged. Theycannot be recharged and must be discarded. Secondary batteries, on the other hand, need to becharged before they can be used. They can berecharged several times in their usable lifetimeand, therefore, are preferred over primary batteries,although secondary batteries are more expensive.
Also, the energy density of a primary battery isbetter than that of a secondary battery. Energydensity refers to the amount of energy stored in abattery per unit weight. So a primary battery withthe same weight as a secondary battery canprovide operating voltage for a longer time thanthe secondary battery can. A popular primary battery is the zinc-carbonbattery. In a zinc-carbon battery, the container ismade out of zinc, which also serves as the negativeterminal of the battery.
The container is filled witha paste of zinc chloride and ammonium chloride,which serves as the electrolyte. The positiveterminal of the battery is a carbon or graphite rodsurrounded by a mixture of manganese dioxide andcarbon powder.
As the battery is used, the zinccontainer becomes thinner and thinner due to thechemical reaction leading to the oxidation of zinc and eventually the electrolyte starts to leak out ofthe zinc container. Zinc-carbon batteries are alsothe cheapest primary batteries.
Another popularprimary battery is the alkaline battery. Alkalinebatteries are similar to zinc-carbon batteries, butthe difference is that alkaline batteries usepotassium hydroxide as an electrolyte rather thanammonium chloride or zinc chloride.
Figure shows some alkaline batteries. The nominal opencircuit voltage of zinc-carbon and alkaline batteriesis 1. Other common primary battery chemistriesinclude the silver oxide and lithium variant.
Thesilver oxide battery offers superior performancecompared to the zinc chloride battery in terms ofenergy density. It has an open circuit terminalvoltage of 1. The lithium battery, on theother hand, uses a variety of chemical compounds,and depending upon these compounds, it has anopen circuit terminal voltage between 1.
Figure shows lithium and alkalinebatteries in the form of button cells. The only issue with primary batteries is thatonce the charge in the battery is consumed, it mustbe disposed of safely. This is where the use ofsecondary batteries looks very attractive: they canbe recharged several times before you need todispose of them. Rechargeable batteries areavailable in standard as well as custom sizes andshapes. Figure shows a lithium-ion battery. Chargingthese batteries requires a specialized charger, andonly a suitable charger should be used with aparticular battery.
Charging a lithium-ion batterywith a battery charger meant for, say, NiMHbatteries, is not advisable and would certainly. Figure The smaller LR44 cell is an alkalinebattery.
The bigger CR cell is alithium battery. Primary and rechargeable batteries are availablein many standard sizes. A few of the morecommon ones are listed in Table Energy content or capacity This isexpressed in Ah or mAh ampere hour ormilliampere hour.
This is an importantcharacteristic that indicates how long thebattery can last before it discharges andbecomes useless. For a given battery type, thecapacity also dictates the battery size. A batterywith a larger Ah rating will necessarily bebigger in volume than a similar battery with asmaller Ah rating. Shelf life This indicates how long the batterywill last before it discharges on its own. Thereis no point in buying a stock of batteries for thenext ten years if the shelf life of the batteriesis, say, only one year.
Operating temperature Batteries havenotoriously poor temperature characteristics. This is because the batteries depend upon a chemical reaction to produce power and thechemical reaction is temperature dependent. Batteries perform rather poorly at lowtemperatures.
Duty cycle Some batteries perform for alonger period if they are used intermittently. The duty cycle of the battery indicates if thebattery can be used continuously or not,without loss of performance. Some of the fruits and vegetables we eat can beused to make electricity. The electrolytes in manyfruits and vegetables, together with electrodesmade of various metals, can be used to makeprimary cells.
One of the most easily availablefruits, the lemon, can be used to make a fruit celltogether with copper and zinc electrodes. Theterminal voltage produced by such a cell is about0. For the battery, we need a few lemons for theelectrolyte and pieces of copper and zinc to form theelectrodes.
For the copper, we just use a bare printedcircuit board PCB , and for the zinc we chose touse zinc strips extracted from a 1. Start with a piece of bare PCB. The size of thePCB should be large enough so that you cancreate three or four islands on it. Each islandwill be used to hold a half-cut lemon.
Next, open up a few 1. Solder wire to each strip. Insteadof these zinc strips, you can also usehousehold nails. Nails are galvanized withzinc and can be easily used for making thebattery. On the bare copper PCB, cut islands with afile or hacksaw and solder the other end of thewire from the zinc strip to each copper island. For each cell, you need half a lemon, oneisland of copper, and one zinc strip.
Place the lemons on each copper island withthe cut facedown as seen in Figure Makeincisions in the lemons to insert the zincstrips. The photograph in Figure shows alemon battery with four cells. If you use an alternating current AC outputadapter, then the rectifier and filter capacitorcircuit must be built into the embeddedapplication, as shown in Figure The rectifiercould be built with discrete rectifier diodes suchas 1N , or a complete rectifier unit could beused.
The rectifier should be suitably rated,keeping in mind the current requirements. If thepower supply unit is to provide mA of current,the diodes should be rated at least 1A. The otherrating of the diode to consider is the PIV peakinverse voltage. This is the maximum peak reversevoltage that the diode can withstand beforebreaking down.
The peak rectified voltage that appears at thefilter capacitor is 1. Thefilter capacitor must be of sufficiently largecapacity to provide sustained current. The filtercapacitor must also be rated to handle the DCvoltage.
For a 14V DC, at least a 25V ratingcapacitor should be employed. The rectifier filtercircuit shown in Figure can also be used with aDC input voltage. With this arrangement, it wouldnot matter what polarity of the DC voltage isapplied to the input of the circuit. Once raw DC voltage is available, it must beregulated before powering the embeddedapplication. Integrated voltage regulator circuitsare available. Voltage regulators are broadlyclassified as linear or switching.
The switchingregulators are of two types: step up or step down. We shall look at some of the voltage regulators,especially the so-called micropower regulators. It is common to use the 78XX type of three-terminal regulator. This regulator is made byscores of companies and is available in manypackage options. To power the AVR processor, youwould choose the regulator for 5V outputvoltage.
You could also choose an LM three-terminal variable voltage regulator and adjust theoutput voltage to 1. A voltage regulator is an active component, andwhen you use this to provide a stable outputvoltage, it also consumes some current. Thiscurrent is on the order of tens of milliamperes andis called the quiescent or bias current.
Micropowerregulators are special voltage regulators that haveextremely low quiescent current. They areideally suited for use in battery-poweredapplications.
These are the mostpopular three-terminal micropower regulators, andwe use them in many of the projects. It is available on PCsand laptop computers. It is primarily used forcommunication between the PC as the host andperipheral devices such as a camera, keyboard, etc. The USB is a four-wire interface with two wiresfor power supply and the other two for datacommunication.
The purpose of providing a power supply on theUSB is to provide power to the external devicesthat wish to connect to and communicate with thePC. For example, a mouse requires a power supplyfor operation and it can use the USB power.
However, this voltage can be used to powerexternal devices also, even if the device is notgoing to be used by the PC. We use USB power toprovide operating voltage to an embeddedapplication, especially if it is going to be operatedin the vicinity of a PC or laptop. The embeddedcircuit can draw up to mA from the USBconnector; although the USB can provide largercurrent, it cannot do so without negotiation i. Table shows the pins ofthe USB port that provide power and signal.
Solar energy could be used to power electroniccircuits by using photovoltaic cells. They providepower as long as the cell is exposed to sunlight. Solar cells provide a range of power, from lessthan a watt to hundreds of watts. The output powerof a solar cell is directly proportional to theincident light and inversely proportional to the celltemperature. To ensure maximum ambient light,the solar cell must be held perpendicular to theincident light.
A conversion circuit is often used toregulate the output of the cell. The most commonuse of a solar cell is to charge a battery so thatcontinuous power from the battery can be derived. More details on the use of solar cells are coveredin a later chapter. The operating voltage required for many smallembedded portable projects can be met by aninteresting device that converts mechanical energyinto electrical energy.
This uses the famousFaradays law. The device based on this principleis shown in Figure The system uses a hollowPerspex tube of suitable diameter and length.
Inside the tube is placed a rare earth magnet. Thetube is wound with several hundred turns of copperenameled wire. The ends of the tube are sealed. Togenerate the voltage, the tube is simply shaken. Asthe magnet traverses the length of the tube, it. The onlyissue with this method is you have to keep shakingthe tube for as long as you want to power thecircuit. Once you stop shaking the tube, it will stopproducing the voltage and only the residual voltageon the capacitor will be available.
In manyapplications, this may not be an issue. Onepossible solution is to use supercapacitors insteadof normal capacitors. However, it would take along time and a lot of effort to charge thesupercapacitors to the required voltage.
The DC voltage produced at the capacitorterminals may further require a voltage regulatorbefore the voltage is connected to the applicationcircuit, and a low dropout and low quiescent voltageregulator such as the LP is recommended. The photograph in Figure shows the output ofthe Faraday generator captured on an oscilloscope.
The output is more than 17V peak to peak. Radio frequency RF waves are ubiquitous, andtherefore it is possible to receive the radiofrequency energy using a suitable antenna andconvert this to DC operating voltage.
Unfortunately, this scheme requires a largetransmitted power from the source, or a largeantenna, or close proximity to the source. In many. One such application is the radio frequencyidentification device RFID systems. The blockdiagram of such a system is shown in Figure The system consists of an unmodulated radiofrequency transmitter transmitting RF power at asuitable frequency. The frequency of operation isdetermined by the quartz crystal used.
A higherfrequency of operation would require a smallertransmission antenna. The transmitter is poweredwith a DC supply voltage of a suitable value. Theradiated signal is received by a tuned circuitconsisting of an inductor and a variable capacitorin parallel that is tuned to the frequency of thetransmitter. The tuned circuit feeds a dioderectifier, filter, and a suitable low-power voltageregulator. The output of the regulator provides the. Such a system can provide few milliwatts of poweracross distances in the range of few tens ofcentimeters.
A practical system based on this approach isdescribed in the following EDN Design Idea:Wireless battery energizes low-power devices:www.
To develop and make prototypes for the projectsdescribed in this book, we have used somecommonly available tools. These tools are:. Solder iron, 35 watts, with a fine solder tipA soldering station is highly recommended, butis not mandatory. The soldering station offersisolated supply to the solder iron heater, thusreducing the leakage currents from the tip ofthe solder iron. Solder wire A thin-gauge solder wire isrecommended.
We use 26 SWG solder wire. The photograph in Figure shows thesolder wire and iron. Eye loupe To inspect PCBs, solder joints,etc. Eye loupe and copper braid are shown inFigure Multimeter A digital multimeter withvoltage, current, and resistance measurementfacilities is useful for testing andmeasurements.
It is shown in Figure Nipper To cut the component leads. This is afancy name for the regular lead cutter. A nipperhas sharp edges that make a neat cut.
Screwdriver set Tweezers, nipper, needle-nose pliers, and screwdriver set are shown inFigure Drill machine hand operated will do , withan assorted collection of drill bits Used fordrilling holes in the PCB, enclosures, etc.
The advantage of developing a programmablesystem cannot be realized without writing efficientcode for the programmable devices of your system,in this case, tinyAVR microcontrollers. Throughoutthis book, we will use C language for programmingthem. C is a high-level programming language, andcode written in C language has to be convertedinto machine language that your target controllerunderstands and can execute.
The tool that doesthis conversion is called a compiler. The Tinycontrollers understand only binary format and haveto be fed in bytes. A common way of storing acollection of bytes to be transferred to thecontroller is to use a hex file that contains thebytes in the form of hexadecimal notation.
So theremust be a tool that can convert C code into the hexfile. This software comes integrated withthe WinAVR compiler. Figure is the screen shot of Programmers Notepad. As you can see, it has various tabs. The mostimportant tab, Tools, is shown displayed.
Asyou can see, it has three important commands:. Make Clean To remove all the hex filesand other dependencies. Generally usedbefore recompiling the program. Make Program This can be used forburning your hex file into the microcontroller,but it requires a special-purpose ISPprogrammer. If yougive all the commands each time, one by one,when you compile your code, your task wouldbecome cumbersome.
It integrates all itscommands in one place and does the completejob by giving instructions one by one to thecompiler. Set your options and save the file. Working with WinAVR and its components canbe a little tricky during the initial stages. On theother hand, AVR Studio from Atmel allows easymanagement of C projects with automatic handlingof make commands required to compile the codewritten for the GCC compiler.
The latest. However, you can use either of the two methods. The instructions forgetting started with both methods are given next. After clicking New Project, a pop-up menuappears, as shown in the next illustration. Here, settings are shownfor making a C language project.
Audio Software icon An illustration of a 3. Software Images icon An illustration of two photographs. Images Donate icon An illustration of a heart shape Donate Ellipses icon An illustration of text ellipses. Metropolitan Museum Cleveland Museum of Art. Internet Arcade Console Living Room. Books to Borrow Open Library. Search the Wayback Machine Search icon An illustration of a magnifying glass.
Sign up for free Log in. EMBED for wordpress. Want more? Advanced embedding details, examples, and help!
You've reached the maximum number of titles you can currently recommend for purchase. Your session has expired. Please sign in again so you can continue to borrow titles and access your Loans, Wish list, and Holds pages. If you're still having trouble, follow these steps to sign in. Add a library card to your account to borrow titles, place holds, and add titles to your wish list.
Have a card? Add it now to start borrowing from the collection. The library card you previously added can't be used to complete this action. Please add your card again, or add a different card. If you receive an error message, please contact your library for help.
Error loading page. Try refreshing the page. If that doesn't work, there may be a network issue, and you can use our self test page to see what's preventing the page from loading.
Learn more about possible network issues or contact support for more help. National Library Board Singapore. Search Search Search Browse menu. Sign in. Description Details Publisher's Note: Products purchased from Third Party sellers are not guaranteed by the publisher for quality, authenticity, or access to any online entitlements included with the product.
Capture a web page as it appears now for use as a trusted citation in the future. Better World Books. Uploaded by station Search icon An illustration of a magnifying glass. User icon An illustration of a person's head and chest.
Sign up Log in. Web icon An illustration of a computer application window Wayback Machine Texts icon An illustration of an open book. Books Video icon An illustration of two cells of a film strip. Video Audio icon An illustration of an audio speaker. Audio Software icon An illustration of a 3. Software Images icon An illustration of two photographs.