ADC and DAC Programming in AVR

Slides:



Advertisements
Similar presentations
Analog to digital converter
Advertisements

Mark Neil - Microprocessor Course 1 Device Drivers – Digital Voltmeter.
Analog to Digital Conversion
Analog/Digital Subsystem
Chapter 11 It’s an Analog World Learning to use the Analog to Digital Converter.
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.
Khaled A. Al-Utaibi  Digital Vs Analog Signals  Converting an Analog Signal to a Digital One  Reading Analog Sensors with the.
-Done By Haresh Miriyala
Analog to Digital Converter
Lecture 12 Analog to Digital Converters. 2  What is an ADC?  Output vs. input  Input range  Single-ended vs. differential inputs  Output coding:
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)
Explain the introduction to ADC, ADC characteristics, Programming ADC using PIC18, Introduction to DAC and DAC interfacing with PIC18.
Interfacing ADC to 8051.
 Circuit building blocks that compare the strength of two signals (usually Volts) and provide an output signal when one is bigger than the other are.
SPI on the ATmega SS’ line only used in Slave mode SPDR
 | bit OR & bit AND ~ bit NOT ^ bit EXLUSIVE OR (XOR) > bit RIGHT SHIFT.
IO in Embedded Systems Martin Schöberl. Embedded IO2 Overview Input/Output Digital, Analog Translation Heater control example.
AVR Programming CS-212 Dick Steflik. ATmega328P I/O for our labs To get data into and out of our Arduino its a little trickier than using printf and.
Robotics Research Laboratory Louisiana State University.
Data Converters ELEC 330 Digital Systems Engineering Dr. Ron Hayne
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.
RS232 #use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7
Robotics Research Laboratory Louisiana State University.
Advanced uC Session Speaker : Chiraag Juvekar Jan 13, 2011 Speaker : Chiraag Juvekar Jan 13, 2011.
Data Acquisition ET 228 Chapter 15 Subjects Covered Analog to Digital Converter Characteristics Integrating ADCs Successive Approximation ADCs Flash ADCs.
Suleyman Demirel University CSS340 Microprocessor Systems – Lecture 2 ATMEGA328P ARCHITECTURE ANALOG INPUTS.
The Silicon Laboratories C8051F020
Analog to Digital Converter (ADC). Analog to Digital Converters  Microcontroller understands only digital language.  To convert the analog output from.
Lecture 11: Liquid Level Control System: A Case Study 1.
Comparators, DAC, and ADC
Arduino Mega Arduino Mega 2560 Arduino Mega 2560.
Analog to Digital Converter (ADC)
Analog to Digital Conversion - ADC Mark Neil - Microprocessor Course 1 Device Drivers – Measuring Voltages.
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.
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)
Servos Elementary Robotics with Servos
What is a DAC? A digital to analog converter (DAC) converts a digital signal to an analog voltage or current output DAC.
Chapter 12: Analog-to-Digital Converter
LCD Interfacing using Atmega 32
AVR ATMEGA 8 MICRO-CONTROLLER
Analog Comparator An analog comparator is available on pins PE2(AIN0), PE3(AIN1) The comparator operates like any other comparator. -when (+) exceeds (-)
ADC,DAC and sensor interface
Interfacing of LCD with µP
ADC, DAC, and Sensor Interfacing
ADC, DAC, and Sensor Interfacing
The Arduino Microcontroller: Atmel AVR Atmega 328
Digital to Analog Converters
ADC, DAC, and Sensor Interfacing
ECE 354 Computer Systems Lab II
I/O Ports in AVR Sepehr Naimi
ADC, DAC, and Sensor Interfacing
CSE 171 Lab 11 Digital Voltmeter.
UART Protocol Chapter 11 Sepehr Naimi
PIC18F458 Analog-to-Digital
AVR Programming in C Chapter 7
SPI Protocol Sepehr Naimi
AVR Programming in C Chapter 7
I/O Ports in AVR Sepehr Naimi
ADC and DAC Data Converter
ADC and Sensor Programming
Wave Generation and Input Capturing
Device Drivers – Digital Voltmeter
ADC and DAC Data Converter
PIC Microcontroller ADC interfacing Prof. Ashvini Kulkarni
Presentation transcript:

ADC and DAC Programming in AVR

Analog vs. Digital Signals

DAC Vout 4 3 2 1 VREF Step size = input 00 01 10 11 Num of steps input 00 01 10 11 Num of steps VOUT = num × step size DAC n Binary number (input) VOUT Vref

Connecting a DAC to the microcontroller

Generating a saw-tooth wave using DAC #include <avr/io.h> int main (void) { unsigned char i = 0; //define a counter DDRD = 0xFF; //make Port D an output while (1) //do forever PORTD = i;//copy i into PORTD to be converted i++;//increment the counter }

ADC ADC n Vin Output (binary number) Vref

Successive Approximation ADC

ADC in AVR

ADC in AVR

ADMUX MUX0-MUX1: input select ADLAR: REFS1-REFS0: Vref selection 0: right adjust the result 1: left adjust the result REFS1-REFS0: Vref selection ADLAR = 0 ADLAR =1

ADCSA

ADC Prescaler PreScaler Bits let us change the clock frequency of ADC The frequency of ADC should not be more than 200 KHz Conversion time is longer in the first conversion

Steps in programming ADC 1. Make the pin for the selected ADC channel an input pin. 2. Turn on the ADC module 3. Select the conversion speed 4. Select voltage reference and ADC input channels. 5. Activate the start conversion bit by writing a one to the ADSC bit of ADCSRA. 6. Wait for the conversion to be completed by polling the ADIF bit in the ADCSRA register. 7. After the ADIF bit has gone HIGH, read the ADCL and ADCH registers to get the digital data output. 8. If you want to read the selected channel again, go back to step 5. 9. If you want to select another Vref source or input channel, go back to step 4.

A program with ADC This program gets data from channel 0 (ADC0) of ;ADC and displays the result on Port B and Port D. #include <avr/io.h> #define F_CPU 16000000UL #include <util/delay.h> int main (void) { DDRB = 0xFF;//make Port B an output DDRD = 0xFF; //make Port D an output ADCSRA= 0x87;//make ADC enable and select ck/128 ADMUX= 0xC8;//1.1V Vref, temp. sensor, right-justified while(1) ADCSRA |= (1<<ADSC);//start conversion while((ADCSRA&(1<<ADIF))==0);//wait for conversion to finish ADCSRA |= (1<<ADIF); PORTD = ADCL;//give the low byte to PORTD PORTB = ADCH;//give the high byte to PORTB _delay_ms(100); }

Sensors Sensor: Converts a physical signal (e.g. light, temperature, humidity, etc.) to an electrical signal (e.g. resistance, voltage, current, capacitance, etc)

LM35 & LM34 (Temperature Sensors) LM35 and LM34: convert temp. to voltage 10mV for each degree

Using LM35 //this program reads the sensor and displays it on Port D #include <avr/io.h> //standard AVR header int main (void) { DDRB = 0xFF; //make Port B an output DDRC = 0;//make Port C an input for ADC input ADCSRA = 0x87;//make ADC enable and select ck/128 ADMUX = 0xC0;//1.1V Vref, ADC0, right-justified while (1){ ADCSRA |= (1<<ADSC);//start conversion while((ADCSRA&(1<<ADIF))==0); //wait for end of conversion ADCSRA |= (1<<ADIF); //clear the ADIF flag PORTB = (ADCL|(ADCH<<8))*10/93;//PORTB = adc value/9.3 }

Thermistor (a temperature sensor) Converts temperature to resistance It is not linear

Signal conditioning The output of some sensors (e.g. PT100) is in form of resistance Some humidity sensor provide the result in form of Capacitance We need to convert these signals to voltage, however, in order to send input to an ADC. This conversion is called signal conditioning.