0% found this document useful (0 votes)
12 views30 pages

UNIT-3

The document covers the AVR ADC and interrupt systems, detailing sensor and analog information, ADC and DAC systems of ATMEGA 328 and 2560, and their programming in C. It discusses interfacing sensors, signal conditioning circuits, relays, opto-isolators, data acquisition, and control using microcontrollers, along with the interrupt systems of ATMEGA 328. Key features include ADC subsystem characteristics, programming steps for ATmega2560, and methods for interfacing and signal conditioning.

Uploaded by

9922005087
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views30 pages

UNIT-3

The document covers the AVR ADC and interrupt systems, detailing sensor and analog information, ADC and DAC systems of ATMEGA 328 and 2560, and their programming in C. It discusses interfacing sensors, signal conditioning circuits, relays, opto-isolators, data acquisition, and control using microcontrollers, along with the interrupt systems of ATMEGA 328. Key features include ADC subsystem characteristics, programming steps for ATmega2560, and methods for interfacing and signal conditioning.

Uploaded by

9922005087
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 30

UNIT-3

AVR ADC and interrupt


systems
Table of contents:
• Sensor and Analog information
• ADC and DAC systems of ATMEGA 328
• ATMEGA 2560 and their programming in C
• Interfacing of Sensors and Signal conditioning circuits with microcontrollers
• Relays and Opto-isolators hardware and interfacing
• Data acquisition and control using microcontrollers.
• Interrupt systems of ATMEGA 328, ATMEGA 2560 and their programming in C
Sensor and analog information
• A sensor is a device that produces an output signal for the purpose of sensing a physical
phenomenon.
• In the broadest definition, a sensor is a device, module, machine, or subsystem that detects
events or changes in its environment and sends the information to other electronics,
frequently a computer processor.
• Analog sensors such as potentiometers and force-sensing resistors are still widely used.
• Their applications include manufacturing and machinery, airplanes and aerospace, cars,
medicine, robotics and many other aspects of our day-to-day life.
• There is a wide range of other sensors that measure chemical and physical properties of
materials, including optical sensors for refractive index measurement, vibrational sensors for
fluid viscosity measurement, and electro-chemical sensors for monitoring pH of fluids.
• Since sensors cannot replicate an ideal transfer function, several types of deviations can occur which limit
sensor accuracy:
• Since the range of the output signal is always limited, the output signal will eventually reach a minimum or
maximum when the measured property exceeds the limits. The full scale range defines the maximum and
minimum values of the measured property.
• The sensitivity may in practice differ from the value specified. This is called a sensitivity error. This is an error in
the slope of a linear transfer function.
• If the output signal differs from the correct value by a constant, the sensor has an offset error or bias. This is an
error in the y-intercept of a linear transfer function.
• Nonlinearity is deviation of a sensor's transfer function from a straight line transfer function. Usually, this is
defined by the amount the output differs from ideal behavior over the full range of the sensor, often noted as a
percentage of the full range.
• Deviation caused by rapid changes of the measured property over time is a dynamic error. Often, this behavior
is described with a bode plot showing sensitivity error and phase shift as a function of the frequency of a
periodic input signal.
• If the output signal slowly changes independent of the measured property, this is defined as drift. Long term drift
over months or years is caused by physical changes in the sensor.
• Noise is a random deviation of the signal that varies in time.
• Analog information is an older, more dated type of means of visually showing a measurement.
• Analog is from the term analogy, which is the method of showing a reading such as temperature, pressure, etc. by the use of
another medium.
• Any dial that shows a temperature based upon a physical method of identification, such as mercury rising in a thermometer is an
analog signal.
• Analog is a representation of the item being measured
• Elements of information processing
• Humans receive information with their senses: sounds through hearing; images and text through sight; shape, temperature, and
affection through touch; and odours through smell.
• To interpret the signals received from the senses, humans have developed and learned complex systems of languages
consisting of “alphabets” of symbols and stimuli and the associated rules of usage.
• This has enabled them to recognize the objects they see, understand the messages they read or hear, and comprehend the
signs received through the tactile and olfactory senses.
• The carriers of information-conveying signs received by the senses are energy phenomena—audio waves, light waves, and
chemical and electrochemical stimuli.
• Until the development of the digital computer, cognitive information was stored and processed only in analog form, basically
through the technologies of printing, photography, and telephony.
ADC and DAC systems of ATMEGA 328

ATmega328P ADC Subsystem Features


• The ATmega48PA/88PA/168PA/328P features a 10-bit successive approximation ADC.
• 0.5 LSB Integral Non-linearity
• ± 2 LSB Absolute Accuracy
• 15 k samples per second (kSPS) at Maximum Resolution and up to 76.9 kSPS (13 μs Conversion Time)
• 6 Multiplexed Single Ended Input Channels
• Temperature Sensor Input Channel
• Free Running or Single Conversion Mode
• Interrupt on ADC Conversion Complete
• ATmega328p has 6 single ended Multiplexed analog input channels in the 28 pin DIP package version.The 6
analog channels are multiplexed with other I/O ports.
• The 32 pin TQFP and QFN version of the ATmega328p has 2 additional purely analog channels which would
make the total number of analog channels [6+2] = 8.
• The programs listed in this tutorial will work with both packages,please select the required channel from the #
define statement in the code .
• All the analog channels in the ATmega328p are single ended which means that they cannot be used for
differential analog measurement.
• If you require differential measurement you can either use ATmega32 or ATmega128 both which comes
with differential input channels.
Setting up Analog Reference pin AREF of ATmega
• The reference voltage for the ADC (VREF ) indicates the conversion range for the ADC. Single ended channels that exceed
VREF will result in codes close to 0x3FF (1023 in Decimal).
• VREF can be selected as either
• AVCC (Connected internally),
• internal 1.1V reference
• or external AREF pin (Microcontroller Pin)
• REFS0 and REFS1 bits of ADMUX register controls the reference voltage selection process.Default selection is AREF pin and
ADC takes the voltage at that pin to be its VREF.
• AVCC is connected to the ADC through a passive switch internally.
• AREF pin is directly connected to the ADC, and the reference voltage can be made more immune to noise by connecting a
capacitor between the AREF pin and ground.
• Bits for selecting the AREF value REFS[1:0] are located in
the ADMUX register as shown below.
if AREF pin is connected to a fixed voltage source for example AVCC as shown below,user will not be
able to switch between various voltage reference sources (internal 1.1V or AV CC).
If no external voltage is applied to the AREF pin, the user may switch between AVCC and 1.1V as reference selection.
The below circuit shows how to connect the AREF pin so that the user may be switch between AVCC and internal 1.1V internal voltage reference.
ATMEGA 2560 and their programming in C

• To write your first C program for the ATmega2560 microcontroller open a new design project in AVR Studio 5 by
selecting File>New>Project to bring up the following dialogue window.

• Under installed templates choose AVR GCC>C and select the C executable project, enter a name for your
project e.g. HelloWorldC and click OK. The device selector window will then appear. Select the ATmega2560 as
before and click OK.
• This will now create your project and open a blank HelloWorldC.c file in the editor.
• Paste the following Hello World C code into the editor. This code causes the LED attached to pin 13 of the
Arduino board to blink at about 1Hz.
How to program a ATmega2560?

1. Open the code or sketch written in the Arduino software.


2. Select the type of board. The ATmega2560 microcontroller is used in the Arduino Mega. ...
3. Select the port. Click on the Tools -> Port (select the port). ...
4. Now, upload and run the written code or sketch.
1/*
2 * AVRGCC_Blink.c
3*
4 * Created: 03/11/2011 08:58:43
5 * Author: Benn Thomsen
6 */
7
8#define F_CPU 16000000UL /* 16 MHz Crystal Oscillator */
9
10#include <avr/io.h>
11#include <inttypes.h>
12#include <util/delay.h>
13
14/* function prototypes */
15void delay_ms(uint16_t ms);
16//
17
18void main(void)
19{
20 DDRB=0xFF; // Enable all pins as output on port B3:
21 while(1)
22 {
23 PORTB= 0xFF; // Set Port B all HIGH.
24 delay_ms(1000);
25 PORTB= 0x00; // Set Port B all LOW.
26 delay_ms(1000);
27 }
28}
29
30/* function for long delay */
31void delay_ms(uint16_t ms)
32{
33 while ( ms )
34 {
35 _delay_ms(1);
36 ms--;
37 }
38}
Interfacing of Sensors and Signal conditioning circuits with
microcontrollers
• a few signal conditioning methods to interface analog and digital signals to processors, microcontroller,
microprocessors etc will be introduced.
• The readers will get a good idea about different stages required to make an intelligent sensing and
measurement system.
• The process involves passive and/or active devices and use circuits such as filters, current-to-voltage
converters or vice-versa and so on.
• The main purpose of this chapter is to provide some fundamentals of interfacing the signals obtained
from different sensors to be available to the digital processor for the necessary computation.
• The digital signal may be directly connected to a digital input of a processor provided it is within the
required voltage range.

• The analog signals are usually connected to the Analog-to-Digital converters of the processor.
• Change of Bias and Level of Signals In most applications the sensor signals need some form of change of bias and/or
shift of voltage level.
• For example, the output voltage available from the sensor may vary from 0.2 V to 1.3 V as a change of the input
variable over the entire range of measurement.
• When the output of the sensor is connected to a microcontroller, it may require a voltage level from 0 V to 3.3 V for
the same variation of the input variable.
• The required signal conditioning is done by changing the output of the sensor from 0.2 V to 0 V with the input
variable is 0 V.
• This may be done simply by subtracting 0.2 V from the output of the sensor.
• This may be defined as a bias adjustment or zero shift of the output.
• Once the bias adjustment is done, the output of the sensor is now varying from 0 V to 1.1 V.
• In order to utilise the full range of 0 V to 3.3 V of the processor, the signal is multiplied by a gain of 3
• This process is known as amplification and the amplifying factor (3 in this case) is known as gain. In many situations,
the output to the processor need to be reduced, this is known as attenuation.
• Both the amplification and attenuation is achieved by the same circuit, known as amplifier.
• The gain of the amplifier is more than unity for an amplifier and is less than unity for an attenuator.
• It is important to take note of the frequency response, input impedance and output impedance while the bias and
amplifier circuits are designed.
• Loading Effect on Sensor’s Output It is useful to understand the loading effect of sensor’s output while
designing the signal conditioning circuit.
• The voltage measured across the output of the sensor is the open-circuit voltage.
• When the sensor is connected to a circuit, the voltage across the terminals of the sensor drops down to a
value and is less than the opencircuit voltage.
• The output of the sensor is represented by the source voltage Vs.
• The impedance of the sensor (the output resistance) is Rs.
• The sensor is connected to a load of resistance Rload which can be the input resistance of any amplifier or
any port pin of the processor.
• +62061Under open-circuit condition the output of the sensor is Vs.
• RELAYS AND OPTOISOLATORS

• This section begins with an overview of the basic operations of electromechanical relays, solid-state relays, reed
switches, and optoisolators.
• Then we describe how to interface them to the 8051. We use both Assembly and C language programs to
demonstrate their control.
• The maximum DC/AC voltage and current that can be handled by the contacts.This is in the range of a few volts
to hundreds of volts, while the current can be from a few amps to 40A or more, depending on the relay.
• Notice the difference between this voltage/current specification and the voltage/current needed for energizing
the coil.
• The fact that one can use such a small amount of voltage/current on one side to handle a large amount of
voltage/current on the other side is what makes relays so widely used in industrial controls.
Relay diagrams
Driving a relay
Digital systems and microcontroller pins lack sufficient current to drive the relay. While the relay’s coil
needs around 10 mA to be energized, the microcontroller’s pin can provide a maximum of 1-2 mA
current. For this reason, we place a driver, such as the ULN2803, or a power transistor between the
microcontroller and the relay
• Interfacing an optoisolator

• The optoisolator comes in a small 1C package with four or more pins. There are also packages that
contain more than one optoisolator. When placing an optoisolator between two circuits, we must
use two separate voltage sources, one for each side
• Unlike relays, no drivers need to be placed between the microcontroller/digital output and the
optoisolators.


Data acquisition and control using microcontrollers

• Data acquisition is the process of sampling signals that measure real-world physical conditions
and converting the resulting samples into digital numeric values that can be manipulated by a
computer. Data acquisition systems, abbreviated by the acronyms DAS, DAQ, or DAU, typically
convert analog waveforms into digital values for processing. The components of data acquisition
systems include:
• Sensors, to convert physical parameters to electrical signals.
• Signal conditioning circuitry, to convert sensor signals into a form that can be converted to digital values.
• Analog-to-digital converters, to convert conditioned sensor signals to digital values.
Hardware
• Computer Automated Measurement and Control (CAMAC)
• Industrial Ethernet
• Industrial USB
• LAN eXtensions for Instrumentation
• Network interface controller
• PCI eXtensions for Instrumentation
• VMEbus
• VXI
Interrupt systems of ATMEGA 328

• The ATmega 328P supports two external interrupts which are individually enabled by setting bits
INT1 and INT0 in the External Interrupt Mask Register (Section 12.2. 2 EIMSK). becomes set (one).
• If the I-bit in SREG and the INT0 bit in EIMSK are set (one), the MCU will jump to the
corresponding Interrupt Vector.
ATmega328P Interrupt Processing
• (1) When an interrupt occurs, (2) the microcontroller completes the current instruction and (3) stores the address
of the next instruction on the stack
• It also turns off the interrupt system to prevent further interrupts while one is in progress. This is done by (4)
clearing the SREG Global Interrupt Enable I-bit.
• The (5) Interrupt flag bit is cleared for Type 1 Interrupts only (see the next page for Type definitions).
• The execution of the ISR is performed by (6) loading the beginning address of the ISR specific for that
interrupt into the program counter. The AVR processor starts running the ISR.
• (7) Execution of the ISR continues until the return from interrupt instruction (reti) is encountered. The
(8) SREG I-bit is automatically set when the reti instruction is executed (i.e., Interrupts enabled).
• When the AVR exits from an interrupt, it will always (9) return to the interrupted program and (10) execute
one more instruction before any pending interrupt is served.
• The Status Register is not automatically stored when entering an interrupt routine, nor restored when
returning from an interrupt routine. This must be handled by software.
• push reg_F
in reg_F,SREG
:
out SREG,reg_F
pop reg_F
By the numbers
Type 1

• The user software can write logic one to the I-bit to enable nested interrupts. All enabled interrupts can then
interrupt the current interrupt routine.
• The SREG I-bit is automatically set to logic one when a Return from Interrupt instruction – RETI – is
executed.
• There are basically two types of interrupts…The first type (Type 1) is triggered by an event that sets the
Interrupt Flag. For these interrupts, the Program Counter is vectored to the actual Interrupt Vector in order to
execute the interrupt handling routine, and hardware clears the corresponding Interrupt Flag.
• If the same interrupt condition occurs while the corresponding interrupt enable bit is cleared, the Interrupt
Flag will be set and remembered until the interrupt is enabled, or the flag is cleared by software (interrupt
cancelled).
• Interrupt Flag can be cleared by writing a logic one to the flag bit position(s) to be cleared.
• If one or more interrupt conditions occur while the Global Interrupt Enable (SREG I) bit is cleared, the
corresponding Interrupt Flag(s) will be set and remembered until the Global Interrupt Enable bit is set on
return (reti), and will then be executed by order of priority.
Type 2
• The second type (Type 2) of interrupts will trigger as long as the interrupt condition is present. These interrupts
do not necessarily have Interrupt Flags. If the interrupt condition disappears before the interrupt is enabled, the
interrupt will not be triggered.

You might also like