admin Comment(0)

Get started with a FREE account. The AVR Microcontroller and Embedded System by Muhammad Ali Mazidi. Pages Download The Microcontroller and Embedded Systems Using Assembly and C Second Edition Muhammad. As of today we have 76,, eBooks for you to download for free. No annoying ads, no The AVR Microcontroller and Embedded System by Muhammad Ali Mazidi Pic Microcontroller Projects List - ebook- PIC Microcontroller. ABSTRACT This textbook provides practicing scientists and engineers a primer on Load AVR Studio (free download from ukraine-europe.info) Ensure that the.

Language: English, Spanish, Hindi
Country: Micronesia
Genre: Personal Growth
Pages: 714
Published (Last): 30.11.2015
ISBN: 365-8-26396-947-6
ePub File Size: 28.33 MB
PDF File Size: 17.50 MB
Distribution: Free* [*Free Regsitration Required]
Downloads: 35455
Uploaded by: CATHEY

DOWNLOAD The AVR Microcontroller and Embedded Systems Using Assembly and Naimi, Sarmad Naimi, Muhammad Ali Mazidi [PDF EBOOK EPUB KINDLE] and C: Using Arduino Uno and Atmel Studio download free of book in format. All the C-instructions will be explained on behalf of different examples that are implemented with the FREE tool AVR Studio (free download and no limitation). In this E-Book (Free download for Members) we show how these As this series shows, the popular AVR microcontroller can be used for.

Slideshare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our User Agreement and Privacy Policy. See our Privacy Policy and User Agreement for details. Published on Sep 15, Both Assembly and C languages are used in all the peripherals programming. In the first 6 chapters, Assembly language is used to cover the AVR architecture and starting with chapter 7, both Assembly and C languages are used to show the peripherals programming and interfacing.

Submit Search. Successfully reported this slideshow. We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime. Upcoming SlideShare. Like this presentation? Why not share! An annual anal Embed Size px. Start on. Show related SlideShares at end. WordPress Shortcode. Published in: Full Name Comment goes here. Are you sure you want to Yes No.

Be the first to like this. No Downloads. Views Total views. Actions Shares. Cindy, Heidi, Heather, Jon R. As always, without you none of this would matter. We love you!

Free E-Book AVR Software Defined Radio

ATmega16 Testbench. Serial Communication Subsystem. Analog-to-Digital Conversion. Interrupt Subsystem. Timing Subsystem. Flight Simulator Panel. ATmega16 Register Set. ATmega16 Header File. A brief introduction is warranted because we will be programming mainly in C throughout the course of the book. We then provide a detailed description of the ATmega16 hardware architecture.

Microcontroller operation is controlled by a user-written program interacting with the fixed hardware architecture resident within the microcontroller. A specific microcontroller architecture can be categorized as accumulator-based, register-based, stack-based, or a pipeline architecture.

The Atmel ATmega16 is a register-based architecture. In this type of architecture, both operands of an operation are stored in registers collocated with the central processing unit CPU. This means that before an operation is performed, the computer loads all necessary data for the operation to its CPU. The result of the operation is also stored in a register.

The Monk Who Sold His Ferrari

During program execution, the CPU interacts with the register set and minimizes slower memory accesses. Memory accesses are typically handled as background operations. A RISC processor is equipped with a complement of very simple and efficient basic operations.

More complex instructions are built up from these very basic operations. This allows for efficient program operation. Most can be executed in a single clock cycle. The ATmega16 is also equipped with additional hardware to allow for the multiplication operation in two clock cycles. In many other microcontroller architectures, multiplication typically requires many more clock cycles. Also, the processor is designed following the Harvard Architecture format.

That is, it is equipped with separate, dedicated memories and buses for program and data information. The register-based Harvard Architecture coupled with the RISC-based instruction set allows for fast and efficient program execution and allows the processor to complete an assembly language instruction every clock cycle.

Atmel indicates the ATmega16 can execute 16 million instructions per second when operating at a clock speed of 16 MHz. A large number of instructions provide flexibility but require more complex hardware. Thus, an instruction set is unique for a given hardware and cannot be used with another hardware configuration.

Atmel has equipped the ATmega16 with different instructions. For the most efficient and fast execution of a given microcontroller, assembly language should be used.

To effectively use the assembly language, the programmer must be thoroughly familiar with the low-level architecture details of the controller. Furthermore, the learning curve for a given assembly language is quite steep and lessons learned do not always transfer to another microcontroller. We will program the Atmel ATmega16 using the C language throughout the text. The C programming language allows for direct control of microcontroller hardware at the register level while being portable to other microcontrollers in the AVR line.

When a C program is compiled during the software development process, the program is first converted to assembly language and then to the machine code for the specific microcontroller. We must emphasize that programming in C is not better than assembly language or vice versa. Both approaches have their inherent advantages and disadvantages. We have chosen to use C in this textbook for the reasons previously discussed.

Free ebook download microcontroller avr

The ATmega16 also contains a timer subsystem, an analog-to-digital converter ADC , an interrupt subsystem, memory components, and a communication subsystem. In the next several subsections, we briefly describe each of these internal subsystems shown in the figure.

Detailed descriptions of selected subsystem operation and programming are provided later in this book. We cannot cover all features of the microcontroller because of limited space.

Instead, we focus on the primary functional components of the ATmega16 to fulfill the purpose of this book as a basic primer to the ATmega We discuss each memory component in turn. It can be erased and programmed as a single unit. Also, should a program require a large table of constants, it may be included as a global variable within a program and programmed into flash EEPROM with the rest of the program.

The ATmega16 is equipped with 16K bytes of onboard reprogrammable flash memory. This memory component is organized into 8K locations, with 16 bits at each location.

In-system programmability means the microcontroller can be programmed while resident within a circuit. It does not have to be removed from the circuit for programming. Instead, a host personal computer PC connected via a cable to a microcontroller downloads the program to the microcontroller.

Figure used with permission of Atmel. We will use this technique throughout the book. It too is nonvolatile. It is especially useful for logging system malfunctions and fault data during program execution. It is also useful for storing data that must be retained during a power failure but might need to be changed periodically. Examples where this type of memory is used are found in applications to store system parameters, electronic lock combinations, and automatic garage door electronic unlock sequences.

That is, if the microcontroller loses power, the contents of SRAM memory are lost. It can be written to and read from during program execution. A complete ATmega16 register listing and accompanying header file is provided in Appendices A and B, respectively.

During program execution, RAM is used to store global variables, support dynamic memory allocation of variables, and provide a location for the stack to be discussed later. These lock bits are programmed using the Atmel STK programming board. The lock bits may be configured for the following options: All of these ports also have alternate functions, which will be described later.

As shown in Figure 1. ATmega16 port configuration registers: Figure 1. If selected for input, the pin may be selected for either an input pin or to operate in the high-impedance Hi-Z mode. In Hi-Z mode, the input appears as high impedance to a particular pin.

If selected for output, the pin may be further configured for either logic low or logic high. Port pins are usually configured at the beginning of a program for either input or output, and their initial values are then set. Usually, all eight pins for a given port are configured simultaneously. A code example is provided below to show how ports are configured. Note that because we are using the C programming language with a compiler include file, the register contents are simply referred to by name.

Note that the data direction register DDRx is first used to set the pins as either input or output, and then the data register PORTx is used to set the initial value of the output port pins. Note the variable used to read the value from the input pins is declared as an unsigned char because both the port and this variable type are 8 bits wide. It should be emphasized that these features are the internal subsystems contained within the confines of the microcontroller chip.

These built-in features allow complex and sophisticated tasks to be accomplished by the microcontroller.

It responds to program steps in a sequential manner as dictated by a user-written program. The microcontroller sequences through a predictable fetch--decode--execute sequence. Each unique assembly language program instruction issues a series of signals to control the microcontroller hardware to accomplish instruction related operations. The speed at which a microcontroller sequences through these actions is controlled by a precise time base called the clock.

The clock source is routed throughout the microcontroller to provide a time base for all peripheral subsystems. The ATmega16 may be clocked internally, using a user-selectable resistor capacitor RC time base, or externally.

The RC internal time base is selected using programmable fuse bits. We will discuss how to do this in the application section of this chapter. You may choose an internal fixed clock operating frequency of 1, 2, 4, or 8 MHz.

To provide for a wider range of frequency selections, an external time source may be used. The external time sources, in order of increasing accuracy and stability, are an external RC network, a ceramic resonator, or a crystal oscillator.

The system designer chooses the time base frequency and clock source device appropriate for the application at hand. We discuss the operation, programming, and application of the timing system in Chapter 5 of the text. Duty cycle is the percentage of time a repetitive signal is logic high during the signal period.

The PWM channels coupled with the flexibility of dividing the time base down to different PWM subsystem clock source frequencies allows the user to generate a wide variety of PWM signals, from relatively high-frequency, low-duty cycle signals to relatively low-frequency, high-duty cycle signals.

PWM signals are used in a wide variety of applications, including controlling the position of a servo motor and controlling the speed of a DC motor. We discuss the operation, programming, and application of the PWM system in Chapter 5 of the text. What all of these systems have in common is the serial transmission of data.

In a serial communications transmission scheme, data are sent a single bit at a time from transmitter to receiver. This is accomplished by equipping the ATmega16 with independent hardware for the transmitter and receiver. That is, there is not a common clock between the transmitter and receiver to keep them synchronized with one another. To maintain synchronization between the transmitter and receiver, framing start and stop bits are used at the beginning and end of each data byte in a transmission sequence.

It has the capability to be set to a variety of data transmission rates known as the baud bits per second rate. Furthermore, the ATmega16 is equipped with a hardware-generated parity bit even or odd and parity check hardware at the receiver. A single parity bit allows for the detection of a single bit error within a byte of data. The ATmega16 SPI can also be used for two-way serial communication between a transmitter and a receiver. In the SPI system, the transmitter and receiver share a common clock source.

This requires an additional clock line between the transmitter and receiver but allows for higher data transmission rates as compared with the USART. The SPI may be viewed as a synchronous bit shift register with an 8-bit half residing in the transmitter and the other 8-bit half residing in the receiver.

The transmitter is designated the master because it provides the synchronizing clock source between the transmitter and the receiver. The receiver is designated as the slave. We discuss the operation, programming, and application of the SPI in Chapter 2 of the text. The TWI subsystem allows the system designer to network a number of related devices microcontrollers, transducers, displays, memory storage, etc. The TWI allows a maximum of devices to be connected together.

Each device has its own unique address and may both transmit and receive over the two-wire bus at frequencies up to kHz.

This allows the device to freely exchange information with other devices in the network within a small area. The ADC converts an analog signal from the outside world into a binary representation suitable for use by the microcontroller. This means that an analog voltage between 0 and 5 V will be encoded into one of binary representations between 16 and 3F F This provides the ATmega16 with a voltage resolution of approximately 4.

We discuss the operation, programming, and application of the ADC in Chapter 3 of the text. However, sometimes, this normal sequence of events must be interrupted to respond to high-priority faults and status both inside and outside the microcontroller.

When these higher-priority events occur, the microcontroller must temporarily suspend normal operation and execute event specific actions called an interrupt service routine. Once the higher priority event has been serviced, the microcontroller returns and continues processing the normal program. The ATmega16 is equipped with a complement of 21 interrupt sources. Three of the interrupts are provided for external interrupt sources, whereas the remaining 19 interrupts support the efficient operation of peripheral subsystems aboard the microcontroller.

We discuss the operation, programming, and application of the interrupt system in Chapter 4 of the text. As a system designer, it is important to know the various physical and operating parameter options available to select the best option for a given application.

The Pinout Diagram for the different packaging options are provided in Figure 1. The ATmega16L operates at supply voltages from 2. In the application examples that follow, we will use a standard laboratory 5-VDC power supply and also discuss a method of providing a 5-VDC supply using an off-the-shelf 9-VDC battery.

The current draw for the microcontroller is quite low. When placed in the idle mode, the microcontroller current draw reduces to less than 0. To minimize power consumption, the microcontroller can be placed into various lowcurrent sleep modes. There are six different sleep modes available to the system designer. Additionally, power consumption can be further reduced by operating the microcontroller at the lowest practical clock frequency for a given application.

As previously discussed, the operating speed of the microcontroller is set by the time base chosen for the processor. One might believe that faster microcontroller operation is always better. This is not the case. The system designer must determine the minimum practical speed of microcontroller operation for a given application.

That is, the faster the operating speed of the microcontroller, the higher its power consumption. This becomes especially critical in portable, battery-operated embedded systems applications. That completes our brief introduction to the features of the ATmega In the next section, we apply what we have learned in developing a testbench for the ATmega Most importantly, the Testbench will serve as a template to develop your own applications.

In this chapter, we provide the hardware configuration of a barebones testbench and a basic software framework to get the system up and operating.

PORTA is configured with eight tact momentary switches with accompanying debouncing hardware. We discuss the debounce circuit in detail in Chapter 6. We discuss this circuit in detail in Chapter 6. ATmega16 Testbench hardware. SW7 SW0 0. A standard 5-VDC power supply may be used for the power connections. Pins 9 through 11 have a resistor 1 M , two capacitors 1. The program contains the following sections: This file provides the software link between the names of the ATmega16 hardware registers and the actual hardware locations.

When a register is used by name in the program, reference is made to the contents of that register. We begin the main program by calling the function to initialize the ports and then enter a continuous loop. We briefly mention required components here. Software tools: This is an excellent, user-friendly compiler. There are other excellent compilers available.

The compiler is used to translate the source file testbench. Please refer to Figure 1. It should be noted that the STK will be used to program the microcontroller, which will then be placed in the Testbench circuit. Load AVR Studio free download from www. Connect the STK as shown in Figure 1. Insert the ATmega16 into the red pin socket.

Note the location of pin 1 in Figure 1. Power up the STK It is on the second line of the toolbar about halfway across the screen. At the bottom of the Program tab window, verify that the STK was autodetected. Set all tab settings: Input HEX file, Browse and find machine code file: Programming step: Power down the STK Remove the programmed chip from the STK board and place it in the Testbench circuit.

To ease the transition to another microcontroller, it is suggested using a direct bit assignment technique. Instead of setting an entire register content at once, selected bits may be set.

The individual bit definitions for the ATmega16 are provided in Appendix B. Information presented in this chapter can be readily applied to other microcontrollers in the AVR line. We then provided the Testbench hardware and software that we use throughout the text to illustrate peripheral subsystem operation aboard the ATmega In upcoming chapters, we provide additional details on selected ATmega16 subsystems. What is a RISC processor? How does the ATmega16 interact with the external world?

What are the different methods of applying a clock source to the ATmega16? List the inherent advantages of each type.

Describe the three different types of memory components aboard the ATmega What is each used for? Describe the three registers associated with each port. With a specific port, can some port pins be declared as output pins while others as input pins? Describe the serial communication features aboard the ATmega Provide a suggested application for each. What is the purpose of the ADC system?

What is the purpose of the interrupt system? What is the purpose of the PWM system? What is the best clock speed to operate the ATmega16 at for a specific application? Sketch a flow chart or UML activity diagram for the testbench. Data may be exchanged by using parallel or serial techniques. With parallel techniques, an entire byte of data is typically sent simultaneously from the transmitting device to the receiver device. Although this is efficient from a time point of view, it requires eight separate lines for the data transfer [1].

In serial transmission, a byte of data is sent a single bit at a time. Once 8 bits have been received at the receiver, the data byte is reconstructed. Although this is inefficient from a time point of view, it only requires a line or two to transmit the data. Before discussing the different serial communication features aboard the ATmega16, we review serial communication terminology. In an asynchronous serial communication system, such as the USART aboard the ATmega16, framing bits are used at the beginning and end of a data byte.

These framing bits alert the receiver that an incoming data byte has arrived and also signals the completion of the data byte reception. The data rate for an asynchronous serial system is typically much slower than the synchronous system, but it only requires a single wire between the transmitter and receiver. Data bits are sent and received on the edge of the clock. This allows data transfer rates higher than with asynchronous techniques but requires two lines, data and clock, to connect the receiver and transmitter.

For example, baud indicates data are being transferred at bits per second. To do both transmission and reception simultaneously requires separate hardware for transmission and reception. A single duplex system has a single complement of hardware that must be switched from transmission to reception configuration. A full duplex serial communication system has separate hardware for transmission and reception.

The important point is the transmitter and receiver must use a common coding standard so data may be interpreted correctly at the receiving end. The Atmel ATmega16 [2] uses a nonreturn to zero coding standard. In nonreturn to zero, coding a logic 1 is signaled by a logic high during the entire time slot allocated for a single bit, whereas a logic 0 is signaled by a logic low during the entire time slot allocated for a single bit.

Over long distances, logic levels degrade and may be corrupted by noise. At the receiving end, it is difficult to discern a logic high from a logic low. The RS standard has been around for some time. Chips are commonly available e. The RS standard also specifies other features for this communication protocol. Parity is an additional bit or bits that may be transmitted with the data byte.

The ATmega16 uses a single parity bit. With a single parity bit, a single-bit error may be detected. Parity may be even or odd. At the receiver, the number of bits within a data byte including the parity bit are counted to ensure that parity has not changed, indicating an error, during transmission. It has been in use for many decades, so some of the characters and actions listed in the ASCII table are not in common use today.

It provides standardized bit encoding format for the written languages of the world. The interested reader is referred to the Unicode home page website at www. It has the capability to be set to a variety of data transmission or baud bits per second rates. Because of space limitations, we cover only the most basic capability of this flexible and powerful serial communication system. The block diagram may appear a bit overwhelming, but realize there are four basic pieces to the diagram: We discuss each in turn.

L] and several additional dividers to set the baud rate. The start and stop framing bits are automatically appended to the data within the Transmit Shift Register. The parity is automatically calculated and appended to the Transmit Shift Register. Data are then shifted out of the Transmit Shift Register via the TxD pin a single bit at a time at the established baud rate. The UDRE flag sets when the transmit buffer is empty, indicating it is ready to receive new data. The TXC flag bit is set to logic 1 when the entire frame in the Transmit Shift Register has been shifted out and there are no new data currently present in the transmit buffer.

The TXC bit may be reset by writing a logic 1 to it. Data are received a single bit at a time via the RxD pin at the established baud rate. The RXC flag is logic 1 when unread data exist in the receive buffer.

USART registers. The function of these bits has already been discussed. This allows the user to customize the data features to the application at hand.

It should be emphasized that both the transmitter and receiver be configured with the same data features for proper data transmission. These activities are summarized in Figure 2. Both the transmitter and receiver must be initialized with the same communication parameters for proper data transmission.

The transmission and reception activities are similar except for the direction of data flow. In transmission, we monitor for the UDRE flag to set, indicating the data register is empty. We then load the data for transmission into the UDR register.

We then retrieve the data from the UDR register. USART activities. In the sample code provided, we assume the ATmega16 is operating at 10 MHz and we desire a baud rate of , asynchronous operation, no parity, one stop bit, and eight data bits. To achieve baud with an operating frequency of 10 MHz requires that we set the UBRR registers to 64, which is 0x The SPI system allows for fast and efficient data exchange between microcontrollers or peripheral devices.

There are many SPI-compatible external systems available to extend the features of the microcontroller. The SPI may be viewed as a synchronous bit shift register with an 8-bit half residing in the transmitter and the other 8-bit half residing in the receiver as shown in Figure 2. A slave is chosen for reception by taking its slave select SS line low. SPI overview. SCK pulse.

Download ebook avr microcontroller free

The data are received at the MOSI pin of the slave designated device. After eight master SCK clock pulses, a byte of data has been exchanged between the master and slave designated SPI devices. At that time, another data byte may be transmitted.

The registers for the SPI system are provided in Figure 2. We will discuss each one in turn. SPI Control Register. It also provides the flexibility for the SPI to be connected to a wide variety of devices with different data formats. It is important that both the SPI master and slave devices be configured for compatible data formats for proper data transmission.

The SPCR contains the following bits: A logic 1 turns the system on and logic 0 turns it off. SPI registers. This contains the SPIF. The flag sets when eight data bits have been transferred from the master to the slave. SPI Data Register. To program the SPI system, the system must first be initialized with the desired data format. Data transmission may then commence.

Functions for initialization, transmission, and reception are provided below. In this specific example, we divide the clock oscillator frequency by to set the SCK clock frequency.

Space does not permit a detailed discussion of this advanced serial communication system. Summarize the differences between parallel and serial conversion. Draw the schematic of a system consisting of two ATmega16 that will exchange data via the SPI system. The system should include RS level shifting. Write the code to implement the system described in the question above. A microcontroller is used to process information from the natural world, decide on a course of action based on the information collected, and then issue control signals to implement the decision.

Because much of the information from the natural world is analog or continuous in nature and the microcontroller is a digital or discrete-based processor, a method to convert an analog signal to digital is required [1].

We will discuss both types of converters in this chapter. In the first section, we present the fundamental concepts associated with the ADC process.

In the following section, we discuss the conversion process itself, followed by a presentation of different hardware implementations of the process. Much of these early sections contain the same material you will find in our text, Microcontroller Fundamentals for Engineers and Scientists. We conclude our discussion of the ADC with several illustrative code examples.

We conclude the chapter with a discussion of the DAC process. We start with some definitions on analog and digital signals. The collection can be as small as only one value or can have as many values as you wish. In engineering, we usually arrange the values in order, for example, over time or over a spatial axis, to display the information.

The time and spatial variables are called independent variables, because they are not affected by the physical variables of interests. For example, we measure the temperature change over time. The temperature measured is dependent on the time, not the other way around. Figure 3. The signal shows how the altitude of the bird changes continuously. The image captured the light intensities of the scene using a charge-coupled device camera. If we move from the left to the right on the image and observe the intensity changes, we can find vertical edges by detecting signal FIGURE 3.

Altitude trajectory generated by a flying bird. A photo of a walking robot. The same analysis can be performed as we move from the top to the bottom of the image. Analog signals are those whose physical variable values change continuously over their independent variable. Most physical variables, your speech, movement of stars, and the music you hear at a concert are analog signals, signals that we find all around us. Digital signals, on the other hand, have their physical variables defined only for discrete instances over their independent variables.

Although it may look continuous to human eyes, the photo example shown in Figure 3. The image is only a finite composition of intensity values seen by a discrete number of pixels.

Digital signals are important because all signals represented in digital systems, computers, and microcontrollers are in digital forms. For example, human voices must be converted to corresponding digital signals before they can be routed by digital switching circuits in telephone communication systems.

Microcontroller Books

Similarly, voice commands to robots must be converted to a digital form before robots can understand the command. As shown in the examples above, we live in an analog world; that is, physical variables are analog signals. It is precisely this reason why the ADC is so very important in any digital systems that interact with an analog environment. We first start with the subject of sampling. Imagine yourself as a photographer in an Olympic diving stadium.

Your job is taking a sequence of pictures of divers jumping off from a diving board 10 meters above the surface of the diving pool. Your goal is to put the sequence of pictures together to reconstruct the motion of each diver. If a diver tries a complex motion and you want to faithfully reconstruct his motion, you must take enough pictures from the start to the end of the dive.

If a diver makes a simple routine dive, you only need to take a few pictures over the period of the dive. Two very different cases of motions generated by a diver is shown in Figure 3. The same time sequence is used to capture samples for both motions.

As can be seen from figure, frame a motion cannot be regenerated from the samples, whereas the motion shown in frame b can clearly be reconstructed from the same number of samples used to capture both motions. Naturally, when we sample a signal, we want to sample it in an optimal fashion such that we can capture the essence of the signal while minimizing the use of resources.

In essence, we want to minimize the number of samples while faithfully reconstructing the original signal from the samples. As can be deduced from our discussion above, the rate of change in a signal determines the number of samples required to faithfully reconstruct the signal, provided that all adjacent samples are captured with the same sample timing intervals.

Harry Nyquist from Bell Laboratory studied the sampling process and derived a criterion that determines the minimum sampling rate for any continuous analog signals.

His, now famous, minimum sampling rate is known as the Nyquist sampling rate, which states that one must sample a signal at least twice as fast as the highest frequency content of the signal of interest. Engineers who work for telephone companies must deal with such issues. Two divers jumping off the platforms: Sampling is important because when we want to represent an analog signal in a digital system, such as a computer, we must use the appropriate sampling rate to capture the analog signal for a faithful representation in digital systems.

Now that we understand the sampling process, let us move on to the second process of the ADC, quantization. Each digital system has a number of bits, which it uses as the basic units to represent data. A bit is the most basic unit where single binary information, 1 or 0, is represented.

A nibble is made up of 4 bits put together. A byte is 8 bits. In the previous section, we tacitly avoided the discussion of the form of captured signal samples. The quantization of a sampled signal is how the signal is represented as one of quantization level. Suppose you have a single bit to represent an incoming signal. You only have two different numbers, 0 and 1. You may say that you can distinguish only low from high. Suppose you have 2 bits. You can represent four different levels, 00, 01, 10, and What if you have 3 bits?

You now can represent eight different levels: Think of it as follows. When you had 2 bits, you were able to represent four different levels. If we add one more bit, that bit can be 1 or 0, making the total possibilities 8.

Similar discussion can lead us to conclude that given n bits, we have 2n different numbers or levels one can represent. In many digital systems, the incoming signals are voltage signals. The voltage signals are first obtained from physical signals with the help of transducers, such as microphones, angle sensors, and infrared sensors. The voltage signals are then conditioned to map their range with the input range of a digital system, typically 0 to 5 V.

In Figure 3. As can be seen from the figure, higher quantization levels means better mapping of an incoming signal to its true value. If we only had a single bit, we can only represent levels 0 and 1. Any analog signal value in between the range had to be mapped either as level 0 or level 1, not many choices. Now imagine what happens as we increase the number of bits available for the quantization levels.

What happens when the available number of bits is 8? How many different quantization levels are available now? Yes, How about 10, 12, or 14?

Finally, the encoding process involves converting a quantized signal into a digital binary number. Suppose again we are using 8 bits to quantize a sampled analog signal. The quantization levels are determined by the 8 bits, and each sampled signal is quantized as one of quantization levels.

Ebook avr download microcontroller free

Consider the two sampled signals shown in Figure 3. The first sample is mapped to quantization level 2 and the second one is mapped to quantization level Quantization with fewer bits. Now consider Figure 3. The same signal is sampled at the same time but quantized using a less number of bits. Note that the quantization error is inversely proportional to the number of bits used to quantize the signal.

Once a sampled signal is quantized, the encoding process involves representing the quantization level with the available bits. Thus, for the first sample, the encoded sampled value is , whereas the encoded sampled value for the second sample is As a result of the encoding process, sampled analog signals are now represented as a set of binary numbers.

Thus, the encoding is the last necessary step to represent a sampled analog signal into its corresponding digital form, shown in Figure 3. The resolution in this case is 2. You can imagine how your TV screen will look if you only had only two levels to represent each pixel, black and white.

The maximum error, called the resolution error, is 2. Suppose you now have 4 bits to represent quantization levels. The resolution now becomes 1. Suppose you have 20 bits for quantization levels. The resolution now becomes 4.

The discussion we presented simply illustrates that as we increase the available number of quantization levels within a range, the distance between adjacent levels decreases, reducing the quantization error of a sampled signal. As the number grows, the error decreases, making the representation of a sampled analog signal more accurate in the corresponding digital form. The number of bits used for the quantization is directly proportional to the resolution of a system.

You now should understand the technical background when you watch high-definition television broadcasting. Now let us move onto the discussion of the data rate. The definition of the data rate is the amount of data generated by a system per some time unit. Typically, the number of bits or the number of bytes per second is used as the data rate of a system. We just saw that the more bits we use for the quantization levels, the more accurate we can represent a sampled analog signal.

Why not use the maximum number of bits current technologies can offer for all digital systems, when we convert analog signals to digital counterparts? It has to do with the cost involved.

In particular, suppose you are working for a telephone company and your switching system must accommodate , customers. For each individual phone conversation, suppose the company uses an 8-kHz sampling rate and you are using 10 bits for the quantization levels for each sampled signal.

You will need some major computing power to meet the requirement. For such reasons, when designers make decisions on the number of bits used for the quantization levels, they must consider the computational burden the selection will produce on the computational capabilities of a digital system versus the required system resolution. You will also encounter the term dynamic range when you consider finding appropriate ADCs. The dynamic range is a measure used to describe the signal to noise ratio.

The unit used for the measurement is decibel, which is the strength of a signal with respect to a reference signal. The greater the decibel number, the stronger the signal is compared with a noise signal. The definition of the dynamic range is 20 log 2b , where b is the number of bits used to convert analog signals 1 For the sake of our discussion, we ignore other overheads involved in processing a phone call such as multiplexing, demultiplexing, and serial-to-parallel conversion.

Typically, you will find 8 to 12 bits used in commercial ADCs, translating the dynamic range from 20 log 28 dB to 20 log dB Oppenheim and Schafer [3]. Toward this end, three signal processing procedures, sampling, quantization, and encoding, described in the previous section must be combined together. Before the ADC process takes place, we first need to convert a physical signal into an electrical signal with the help of a transducer.

Depending on the purpose, we categorize a transducer as an input transducer or an output transducer. If the conversion is from physical to electrical, we call it an input transducer.

The mouse, the keyboard, and the microphone for your PC all fall under this category. A camera, an infrared sensor, and a temperature sensor are also input transducers. The output transducer converts electrical signals to physical signals. The computer screen and the printer for your computer are output transducers.

Speakers and electrical motors are also output transducers. Therefore, transducers play the central part for digital systems to operate in our physical world by transforming physical signals to and from electrical signals. In addition to transducers, we also need signal conditioning circuitry before we apply the ADC process or its opposite process of DAC process. The signal conditioning circuitry is called the transducer interface. The objective of the transducer interface circuit is to scale and shift the electrical signal range to map the output of the input transducer to the input of the ADC.

The output of the input transducer is first scaled by constant K. The box with constant K maps the output range of the input transducer to the input range of the converter. Once the range has been mapped, the signal now needs to be shifted.

The second portion of the circuit shifts the range by 2. Actual implementation of the circuit components is accomplished using amplifiers with some feedback loops. In general, the scaling and bias process may be described by two equations: A block diagram of the signal conditioning for an ADC.

The range of the sensor voltage output is mapped to the ADC input voltage range. The scalar multiplier maps the magnitudes of the two ranges, and the bias voltage is used to align two limits.

The AVR Microcontroller and Embedded System by Muhammad Ali Mazidi - PDF Drive

The variable V1 max represents the maximum output voltage from the input transducer. This voltage occurs when the maximum physical variable Xmax is presented to the input transducer. This voltage must be scaled by the scalar multiplier K and then have a DC offset bias voltage B added to provide the voltage V2 max to the input of the ADC converter. Similarly, The variable V1 min represents the minimum output voltage from the input transducer.

This voltage occurs when the minimum physical variable Xmin is presented to the input transducer. This voltage must be scaled by the scalar multiplier K and then have a DC offset bias voltage B added to produce voltage V2 min to the input of the ADC converter. Usually, the values of V1 max and V1 min are provided with the documentation for the transducer.

Also, the values of V2 max and V2 min are known. We thus have two equations and two unknowns to solve for K and B. The circuits to scale by K and add the offset B are usually implemented with operational amplifiers. We refer interested readers to Thomas and Rosa [4] listed in the References section.

Once a physical signal has been converted to its corresponding electrical signal with the help of an input transducer and the output of the transducer mapped correctly to the input of the ADC, the ADC process can start.

The first step of the ADC process is the sampling of the analog signal. When selecting a converter, one must consider the type of physical signal that is being converted to properly ensure the sampling rate. What this means for the reader is to select an ADC that can handle a required conversion rate.

Because most microcontrollers now come with a built-in ADC, one must study the user manual portion discussing the conversion rate and make sure that the required sampling rate for the application falls under the advertised conversion rate. On the other hand, if you are dealing with human voice, you need at least an 8-kHz sampling rate capacity see Enderle et al. Once the analog signal has been sampled, the quantization process takes place. For this process, again one must decide how much quantization error can be allowed.

At one extreme where you are only concerned with finding out only two states, say on and off, quantization error of 1 V is not important. We can operate safely with 2 bits with maximum quantization error of 1. On the other hand, if we can only operate with maximum quantization error of 0. To determine the number of bits and its corresponding maximum quantization error, we use the following equation.

Once the quantization level has been determined, we can now encode it using the available bits. As seen in the previous section, the process is a simple conversion of a decimal number quantization level to a binary number. Note that the binary number should use all available bits. For example, quantization level 4 using 8 bits is converted as , not In summary, the ADC process has three steps for completion: In the next section, we delve into four different technologies used to implement the ADC process.

Example 3. The photodiode is used with a transimpedance amplifier to convert the output current to an output voltage. In this section, we will discuss this type of conversion process as well as other techniques.

In certain applications, you are required to use converter technologies external to the microcontroller. We begin by briefly discussing four different types of technologies used in ADCs: For a detailed discussion, we refer the interested readers to Barrett and Pack [2]. For the following discussion of different ADC technologies, see Figure 3. One can group all existing technologies into two different categories: The successive approximation conversion, counter-based conversion, and parallel conversion use techniques to directly convert analog input signals into their digital counterparts.

They are all considered to fall under the direct conversion category. The integration method uses conversion time as the means to indirectly measure the magnitude of the incoming analog signals, an indirect approach. Starting from the MSB down to the LSB, the controller turns on each bit at a time and generates an analog signal, with the help of the DAC, to be compared with the original input analog signal.

Based on the result of the comparison, the controller changes or leaves the current bit and turns on the next MSB. The process continues until decisions are made for all available bits. One can consider the process similar to a game children play often.

One child thinks of a number in the range of 0 to 10 and asks another child to guess the number within n turns. The first child will tell the second child whether a guessed number is higher or lower than the answer at the end of each turn.

The optimal strategy in such a situation is to guess the middle number in the range, say 5. If the answer is higher than 5, the second guess should be 8. If the answer is lower than 5, the second guess should be 3. The strategy is to narrow down to the answer by partitioning the available range into two equal parts at every turn. Four different technologies used to convert analog signals to digital signals: The advantage of this technique is that the conversion time is uniform for any input, but the disadvantage of the technology is the use of complex hardware for implementation.

A sampled analog signal is integrated over a fixed period, say n clock cycles of the digital system. Another fixed reference signal is integrated over time and compared with the input analog signal integrated. Although the value of the reference signal integrated is smaller than the input analog signal integrated, the reference signal is continuously integrated, and the time for the integration is measured.

When the two integrated values equal, the measured time is converted to a digital encoded value. One disadvantage of this technique is the varying time for the conversion process. A small analog value will take less time to convert compared with a large value. This conversion is performed with the help of a counter, a DAC, and a comparator. The counter starts at 0 and counts up. As the counter counts up, the corresponding value is converted to an analog value and compared with an input analog signal.

As long as the input analog signal is greater than the signal generated by the DAC, the counter counts up and the process continues. When the comparator detects that the signal from the DAC is greater than the input analog signal, the counter value is then converted to a digital value representing the sampled analog signal. Similar to the converter based on the integration principle, the disadvantage of this type of converter is the varying conversion time. A parallel converter uses a large number of comparators and circuitry to simultaneously measure the input signal and convert it to a digital value.

The obvious disadvantage of this technique is the cost involved in building the circuitry. It has the following features: Let us discuss each feature in turn. It requires 13 analog-to-digital clock cycles to perform an ADC conversion. The ADC system may be run at a slower clock frequency than the main microcontroller clock source.

The ADC is equipped with a single successive approximation converter. Only a single ADC channel may be converted at a given time. The input of the ADC is equipped with an eight-input analog multiplexer.

The analog input for conversion is selected using the MUX[4: