Analog to Digital Conversion

Slides:



Advertisements
Similar presentations
Analog to digital converter
Advertisements

8086 [2] Ahad. Internal! External? 8086 vs _bit Data Bus 20_bit Address 8_bit Data Bus 20_bit Address Only external bus of 8088 is.
Mark Neil - Microprocessor Course 1 Device Drivers – Digital Voltmeter.
More fun with Timer/Counters
8051 Core Specification.
Kuliah Mikrokontroler AVR Comparator AVR Eru©September 2009 PENS.
Analog/Digital Subsystem
Analog to Digital Convertor MTT48 V1.0 ADC - 1 ANALOG TO DIGITAL CONVERTOR (ADC)
Analog Comparator Positive input chooses bet. PB2 and Bandgap Reference. Negative input chooses bet. PB3 and the 8 inputs of the A/D. ACME= Analog Comparator.
Oscilloscope Watch Teardown. Agenda History and General overview Hardware design: – Block diagram and general overview – Choice of the microcontroller.
Analog to Digital Converter
1 Lab2: A/D Converter. 2 This circuit connects a variable voltage to an A/D port on the AVR mcu. Your software running on the AVR mcu will read the digital.
Kuliah Mikrokontroler AVR ADC AVR Eru©September 2009 PENS.
Microprocessor based Design for Biomedical Applications MBE 3 – MDBA IV : The ATmega8 Basic Features (3)
Introduction of Holtek HT-46 series MCU
SPI on the ATmega SS’ line only used in Slave mode SPDR
Mark Neil - Microprocessor Course 1 Timers and Interrupts.
8-Bit Timer/Counter 0 Counter/Timer 0 and 2 (TCNT0, TCNT2) are nearly identical. Differences: -TCNT0 can run off an external 32Khz clock (Tosc) or the.
External & internal Interrupts. Interrupt Sources There are 21 different interrupts and each one has its own vector located in a predefined location at.
Lecture 9 Timer Operations and Programming. 2  Introduction  Summary of timers  Timer programming sequence  Summary of timer SFRs  Timer 0: 8-bit.
Renesas Electronics Europe GmbH A © 2010 Renesas Electronics Corporation. All rights reserved. RL78 Clock Generator.
System Clocks.
Timers The timers of the PIC16C7X microcontroller can be briefly described in only one sentence. There are three completely independent timers/counters.
Clock Options and Sleep Modes. Clock Sources Flash Fuse bits can be programmed to choose one of the following Clock sources: 1. External RC Osc. f = 1/(3RC).
MCU: Interrupts and Timers Ganesh Pitchiah. What’s an MCU ?
Embedded System Design Laboratory October 11, 2002Stanford University - EE281 Lecture #4#1 Lecture #4 Outline Announcements Project Proposal AVR Processor.
Digital to Analogue Converter
ELE2MIC Lecture 21 The AVR Sleep Modes ATMEGA128’s Analog to Digital Converter –Features –Block Diagram –Clock Source –Input Sources –Interrupts –BandGap.
PIC16F877 ISR Points to note Interrupt Triggers –Individual interrupt flag bits are set, regardless of the status of their corresponding mask bit, PEIE.
SIGMA-DELTA ADC SD16_A Sigma-Delta ADC Shruthi Sujendra.
Robotics Research Laboratory Louisiana State University.
Advanced uC Session Speaker : Chiraag Juvekar Jan 13, 2011 Speaker : Chiraag Juvekar Jan 13, 2011.
ELE22MIC Lecture 18 The AVR Sleep Modes The ATMEGA128’s Timer System
Atmel Atmega128 Overview ALU Particulars RISC Architecture 133, Mostly single cycle instructions 2 Address instructions (opcode, Rs, Rd, offset) 32x8 Register.
ECE/CS-352: Embedded Microcontroller Systems The Silicon Laboratories C8051F020 Enhanced 8051 Part 4 Timer3, Temperature Sensor, AD0WINT.
ATtiny23131 A SEMINAR ON AVR MICROCONTROLLER ATtiny2313.
Suleyman Demirel University CSS340 Microprocessor Systems – Lecture 2 ATMEGA328P ARCHITECTURE ANALOG INPUTS.
The Silicon Laboratories C8051F020
CS-280 Dr. Mark L. Hornick 1 Atmel Timer/Counter System Most microcontrollers include some type of timer system Facilitates real-time monitoring and control.
Interrupts  An interrupt is any service request that causes the CPU to stop its current execution stream and to execute an instruction stream that services.
Lab 3: ADC.
Lecture 4 General-Purpose Input/Output NCHUEE 720A Lab Prof. Jichiang Tsai.
Analog to Digital Converter (ADC)
Analog to Digital Conversion - ADC Mark Neil - Microprocessor Course 1 Device Drivers – Measuring Voltages.
MICROPROCESSOR DETAILS 1 Updated April 2011 ©Paul R. Godin prgodin gmail.com.
CS-280 Dr. Mark L. Hornick 1 Sequential Execution Normally, CPU sequentially executes instructions in a program Subroutine calls are synchronous to the.
Chapter Microcontroller
0808/0809 ADC. Block Diagram ADC ADC0808/ADC Bit μP Compatible A/D Converters with 8-Channel Multiplexer The 8-bit A/D converter uses successive.
ADC 1 Analog to Digital Converter. ADC 2 ADC Features n General Features -Supports 8 or 10-bit resolution Modes, -Track period fully programmable up to.
Sensing Algorithm using IR Sensor and ADC Soong-sil University. Robotics 기 정 두 원.
1 Lab 4: D/A Converter Lab 4: D/A Converter This is a simple resistive network for a D/A converter Port 1, Port 0 are digital inputs ==> 00 (minimum),
By: Shivanshi pandya(30) Ayushi chourasia (3) Pranavi chhikniwala(6)
Application Case Study Christmas Lights Controller
Servos Elementary Robotics with Servos
Analog Comparator An analog comparator is available on pins PE2(AIN0), PE3(AIN1) The comparator operates like any other comparator. -when (+) exceeds (-)
Refer to Chapter 10 in the reference book
ADC,DAC and sensor interface
BITS EDU. CAMPUS , VARNAMA
Sound Sensor TYWu.
AVR Addressing Modes Subject: Microcontoller & Interfacing
Interrupt Source: under
Timer/Counter Modified from Dr. Lam Phung’s Slides.
8-bit Timer/Counter0 with PWM
8-bit Timer/Counter2 with PWM and Asynchronous Operation
ADC and DAC Programming in AVR
Interrupt Chapter 10.
Device Drivers – Digital Voltmeter
Timer/Counter Timer/Counter 0 Timer/Counter 1 Timer/Counter 2 8 bit
Presentation transcript:

Analog to Digital Conversion Using ATMEL’s ATmega168

ATmega168 Pins PDIP PC5 PC4 PC3 PC2 PC1 PC0 GND AREF AVCC PB5 PB4 PB3 PB2 PB1 PC6 PD0 PD1 PD2 PD3 PD4 VCC PB6 PB7 PD5 PD6 PD7 PB0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 28 27 26 25 24 23 22 21 20 19 18 17 16 15 (ADC5/SCL/PCINT13) (ADC4/SDA/PCINT12) (ADC3/PCINT11) (ADC2/PCINT10) (ADC1/PCINT9) (ADC0/PCINT8) (SCK/PCINT5) (MISO/PCINT4) (MOSI/OC2A/PCINT3) (OC1A/PCINT1) (PCINT16/RXT) (PCINT17/TXD) (PCINT18/INT0) (PCINT19/OC2B/INT1) (PCINT20/XCK/T0) (PCINT6/XTAL1/TOSC1 (PCINT7/XTAL2/TOSC2 (PCINT21/OC0B/T1) (PCINT23/AIN1) PCINT0/CLK0/ICP1) (PCINT22/OC0A/AIN0) Caveat: If using ADC0-3, do not use any other of these pins as a Digital Output (Noise). If using ADC4-5, do not use the other pin as a Digital Output.

ADC Multiplexer Key Registers to enable ADC ADMUX – ADC Multiplexer Selection Register ADCSRA – ADC Control and Status Register A ADCSRB – ADC Control and Status Register B DIDR0 – Digital Input Disable Register 0

1. ADMUX – ADC Multiplexer Selection Register Bit 7 6 5 4 3 2 1 0x7C REFS1 REFS0 ADLAR - MUX3 MUX2 MUX1 MUX0 Read/Write R/W Initial Value • Bit 7:6 – REFS1:0: Reference Selection Bits These bits select the voltage reference for the ADC, as shown below. If these bits are changed during a conversion, the change will not go in effect until this conversion is complete (ADIF in ADCSRA is set). The internal voltage reference options may not be used if an external reference voltage is being applied to the AREF pin. Voltage Reference Selections for ADC REFS1 REFS0 Voltage Reference Selection AREF, Internal Vref turned off 1 AVCC with external capacitor at AREF pin Reserved Internal 1.1V Voltage Reference with external capacitor at AREF pin

1. ADMUX – ADC Multiplexer Selection Register Bit 7 6 5 4 3 2 1 0x7C REFS1 REFS0 ADLAR - MUX3 MUX2 MUX1 MUX0 Read/Write R/W Initial Value • Bit 5 – ADLAR: ADC Left Adjust Result The ADLAR bit affects the presentation of the ADC conversion result in the ADC Data Register. Write one to ADLAR to left adjust the result. Otherwise, the result is right adjusted. Changing the ADLAR bit will affect the ADC Data Register immediately, regardless of any ongoing conversions. For a complete description of this bit, see ”ADCL and ADCH – The ADC Data Register” in the datasheet. ADLAR set to 0 (Right Adjust) ADCH 7 6 5 4 3 2 1 - 9 8 ADCL 7 6 5 4 3 2 1 adc_low = ADCL; adc_high = ((unsigned int) (ADCH<<8)); adc_data = adc_low | adc_high; ADLAR set to 1 (Left Adjust) ADCH 7 6 5 4 3 2 1 9 8 ADCL 7 6 5 4 3 2 1 - adc_data = adc_high; Caveat: Must read ADCL before ADCH

1. ADMUX – ADC Multiplexer Selection Register Bit 7 6 5 4 3 2 1 0x7C REFS1 REFS0 ADLAR - MUX3 MUX2 MUX1 MUX0 Read/Write R/W Initial Value • Bits 3:0 – MUX3:0: Analog Channel Selection Bits The value of these bits selects which analog inputs are connected to the ADC. (See Table below for details). If these bits are changed during a conversion, the change will not go in effect until this conversion is complete (ADIF in ADCSRA is set). MUX3..0 Single Ended Input 0000 ADC0 0001 ADC1 0010 ADC2 0011 ADC3 0100 ADC4 0101 ADC5 Caveat: You can only use one pin at a time (e.g., you must change the MUX setting before reading that pin)

2. ADCSRA – ADC Control and Status Register A Bit 7 6 5 4 3 2 1 (0x7A) ADEN ADSC ADATE ADIF ADIE ADPS2 ADPS1 ADPS0 Read/Write R/W Initial Value • Bit 7 – ADEN: ADC Enable Writing this bit to one enables the ADC. By writing it to zero, the ADC is turned off. Turning the ADC off while a conversion is in progress, will terminate this conversion.

2. ADCSRA – ADC Control and Status Register A Bit 7 6 5 4 3 2 1 (0x7A) ADEN ADSC ADATE ADIF ADIE ADPS2 ADPS1 ADPS0 Read/Write R/W Initial Value • Bit 6 – ADSC: ADC Start Conversion In Single Conversion mode, write this bit to one to start each conversion. In Free Running mode, write this bit to one to start the first conversion. The first conversion after ADSC has been written after the ADC has been enabled, or if ADSC is written at the same time as the ADC is enabled, will take 25 ADC clock cycles instead of the normal 13. This first conversion performs initialization of the ADC. ADSC will read as one as long as a conversion is in progress. When the conversion is complete, it returns to zero. Writing zero to this bit has no effect. Caveat. If you are controlling when you want to take a sample, this is how you do it. By setting ADSC to 1 you begin a conversion.

2. ADCSRA – ADC Control and Status Register A Bit 7 6 5 4 3 2 1 (0x7A) ADEN ADSC ADATE ADIF ADIE ADPS2 ADPS1 ADPS0 Read/Write R/W Initial Value • Bit 5 – ADATE: ADC Auto Trigger Enable When this bit is written to one, Auto Triggering of the ADC is enabled. The ADC will start a conversion on a positive edge of the selected trigger signal. The trigger source is selected by setting the ADC Trigger Select bits, ADTS in ADCSRB.

2. ADCSRA – ADC Control and Status Register A Bit 7 6 5 4 3 2 1 (0x7A) ADEN ADSC ADATE ADIF ADIE ADPS2 ADPS1 ADPS0 Read/Write R/W Initial Value • Bit 4 – ADIF: ADC Interrupt Flag This bit is set when an ADC conversion completes and the Data Registers are updated. The ADC Conversion Complete Interrupt is executed if the ADIE bit and the I-bit in SREG are set. ADIF is cleared by hardware when executing the corresponding interrupt handling vector. Alternatively, ADIF is cleared by writing a logical one to the flag. Beware that if doing a Read-Modify-Write on ADCSRA, a pending Interrupt can be disabled. This also applies if the SBI and CBI instructions are used. Question: How do you determine what code will be executed when an interrupt is encountered?

2. ADCSRA – ADC Control and Status Register A Bit 7 6 5 4 3 2 1 (0x7A) ADEN ADSC ADATE ADIF ADIE ADPS2 ADPS1 ADPS0 Read/Write R/W Initial Value • Bit 3 – ADIE: ADC Interrupt Enable When this bit is written to one and the I-bit in SREG is set, the ADC Conversion Complete Interrupt is activated.

2. ADCSRA – ADC Control and Status Register A Bit 7 6 5 4 3 2 1 (0x7A) ADEN ADSC ADATE ADIF ADIE ADPS2 ADPS1 ADPS0 Read/Write R/W Initial Value • Bits 2:0 – ADPS2:0: ADC Prescaler Select Bits These bits determine the division factor between the system clock frequency and the input clock to the ADC ADC Prescaler Selections: ADPS2 ADPS1 ADPS0 Division Factor 2 1 4 8 16 32 64 128 Caveat: The ADC clock must be between 50kHz and 200kHz. Determine what is the minimum Division Factor you can use for our setup.

3. ADCSRB – ADC Control and Status Register B Bit 7 6 5 4 3 2 1 (0x7B) - ACME – ADTS2 ADTS1 ADTS0 Read/Write R R/W Initial Value • Bit 2:0 – ADTS2:0: ADC Auto Trigger Source If ADATE in ADCSRA is written to one, the value of these bits selects which source will trigger an ADC conversion. If ADATE is cleared, the ADTS2:0 settings will have no effect. A conversion will be triggered by the rising edge of the selected Interrupt Flag. Note that switching from a trigger source that is cleared to a trigger source that is set, will generate a positive edge on the trigger signal. If ADEN in ADCSRA is set, this will start a conversion. Switching to Free Running mode (ADTS[2:0]=0) will not cause a trigger event, even if the ADC Interrupt Flag is set. ADTS2 ADTS1 ADTS0 Trigger Source Free Running mode 1 Analog Comparator External Interrupt Request 0 Timer/Counter0 Compare Match A Timer/Counter0 Overflow Timer/Counter1 Compare Match B Timer/Counter1 Overflow Timer/Counter1 Capture Event ADC Auto Trigger Source Selections:

4. DIDR0 – Digital Input Disable Register 0 Bit 7 6 5 4 3 2 1 (0x7E) – ADC5D ADC4D ADC3D ADC2D ADC1D ADC0D Read/Write R R/W Initial Value • Bit 5:0 – ADC5D..ADC0D: ADC5..0 Digital Input Disable When this bit is written logic one, the digital input buffer on the corresponding ADC pin is disabled. The corresponding PIN Register bit will always read as zero when this bit is set. When an analog signal is applied to the ADC5..0 pin and the digital input from this pin is not needed, this bit should be written logic one to reduce power consumption in the digital input buffer. Note that ADC pins ADC7 and ADC6 do not have digital input buffers, and therefore do not require Digital Input Disable bits.

Lab 3 – Search Lab Wiring Diagram