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.

Slides:



Advertisements
Similar presentations
Mark Neil - Microprocessor Course 1 Device Drivers – Digital Voltmeter.
Advertisements

Lab7: Introduction to Arduino
C Examples 1.
Analog-to-Digital Converter (ADC) And
Lecture 17: Analog to Digital Converters Lecturers: Professor John Devlin Mr Robert Ross.
Analog to Digital Conversion
ECE 265 – LECTURE 14 Analog Signal Acquisition The A/D converters 5/14/ ECE265.
Data Acquisition Concepts Data Translation, Inc. Basics of Data Acquisition.
Kuliah Mikrokontroler AVR Comparator AVR Eru©September 2009 PENS.
Analog/Digital Subsystem
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.
-Done By Haresh Miriyala
Introduction of Holtek HT-46 series MCU
Railway Foundation Electronic, Electrical and Processor Engineering.
Railway Foundation Electronic, Electrical and Processor Engineering.
An Embedded C Program 1 Mainly from textbook: Embedded C Programming and the Atmel AVR 2 nd Edition Barnett, Cox and O’Cull.
16-Bit Timer/Counter 1 and 3 Counter/Timer 1,3 (TCNT1, TCNT3) are identical in function. Three separate comparison registers exist. Thus, three separate.
Renesas Electronics Europe GmbH A © 2010 Renesas Electronics Corporation. All rights reserved. RL78 Clock Generator.
ECE 371- Unit 11 Timers and Counters (“Stop Watches and Alarm Clocks”)
7/23 Timers in Coldfire Processor Computer Science & Engineering Department Arizona State University Tempe, AZ Dr. Yann-Hang Lee (480)
System Clocks.
Lab 1 - Microcontrollers Complete the program template below being sure to select the correct parameters to meet the requirements (see the Microcontroller.
A Few Words From Dilbert
Unit 10.2 Timer Examples. Example – Music Generation Channel 6 – Set up as a timer Output to Generate Square Waves Channel 4 – Set up as a timer Output.
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.
1 Lab 1: Introduction. 2 Configure ATMEL AVR Starter Kit 500 (STK500), a prototyping/development board for Lab1. ATmega16 ( V) is the chip used.
Microcontroller based system design Asst. Prof. Dr. Alper ŞİŞMAN.
1 Lab 5: Controls and feedback. 2 Lab 5: Control and Feedback This embedded system uses the Photo sensor to detect the light intensity of the environment.
Advanced uC Session Speaker : Chiraag Juvekar Jan 13, 2011 Speaker : Chiraag Juvekar Jan 13, 2011.
Atmel Atmega128 Overview ALU Particulars RISC Architecture 133, Mostly single cycle instructions 2 Address instructions (opcode, Rs, Rd, offset) 32x8 Register.
Timers and Interrupts Anurag Dwivedi. Let Us Revise.
Suleyman Demirel University CSS340 Microprocessor Systems – Lecture 2 ATMEGA328P ARCHITECTURE ANALOG INPUTS.
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.
Microcontroller Programming
By James Cockrell and Justin Loveless
Analog to Digital Converter (ADC). Analog to Digital Converters  Microcontroller understands only digital language.  To convert the analog output from.
Chapter 5 - Interrupts.
Lecture 11: Liquid Level Control System: A Case Study 1.
Water Flow GROUP A. Analogue input voltage results: Motor Input voltage( V) pin 12 Analogue input voltage (V) Display number
Lab 3: ADC.
충북인력개발원 전자과 공학박사 강원찬 3. Timer & Counter &PWM. uP AVR (Atmega128) PWM1=OC1A(PB5) PWM2=OC1B(PB6) T0=T1(PD6) T1=T2(PD7)
Analog to Digital Converter (ADC)
Analog to Digital Conversion - ADC Mark Neil - Microprocessor Course 1 Device Drivers – Measuring Voltages.
ECET 340 Entire Course (All ilabs and Homework) For more classes visit ECET 340 Week 1 HomeWork 1 ECET 340 Week 1 iLab 1 ECET 340.
Electronic instrumentation Digitization of Analog Signal in TD
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),
One more PIC18F252 example and revision for exam B222L Branislav Vuksanovic, UoP, ECE.
Microprocessors A practical approach..
FOR MORE CLASSES VISIT   ECET 340 Week 1 HomeWork 1  ECET 340 Week 1 iLab 1  ECET 340 Week 2 HomeWork 2  ECET 340 Week 2 iLab.
Application Case Study Christmas Lights Controller
EET 2261 Unit 13 Enhanced Capture Timer
Why are Timer Functions Important?
Servos Elementary Robotics with Servos
Application Case Study Security Camera Controller
Environment Temperature Monitor
Analog Comparator An analog comparator is available on pins PE2(AIN0), PE3(AIN1) The comparator operates like any other comparator. -when (+) exceeds (-)
Prof. Chung-Ta King Department of Computer Science
AVR Addressing Modes Subject: Microcontoller & Interfacing
Timer/Counter Modified from Dr. Lam Phung’s Slides.
ECET 340 Competitive Success/snaptutorial.com
CSCI1600: Embedded and Real Time Software
ADC and DAC Programming in AVR
Device Drivers – Digital Voltmeter
Prof. Chung-Ta King Department of Computer Science
Presentation transcript:

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 value and display the percent and raw value of the voltage, V A as shown in Table 1. The interface consists of some analog circuitry as well as wiring the analog circuit to the STK500 and running corresponding software on the AVR mcu. Each circuit requires a unique C- routine.

3 We use ATmega16 having the same pin layout Atmeg16

4 Pin 40 = PA0 = ADC0 AD converter Channel 0 Pin 32 = AREF (= VTG on STK500 board) Pin 31 = GND = AVR board ground Use the AVR board ground

5

6 Pin layout is different from Atmeg16 Atmega8515 is at SCKT3000D3 Port A also serves as AD inputs

7 Lab2: A/D Converter Pre-Lab Assignments Read the ATmega16/ATmega8515 on-line data book available in the course website, pages 202 through 220. Read B, C, and O (course text), chapter 2. Read the AVR STK500 User Guide, page 3-11 and pages 3-16 through Answer Pre-Lab Questions

8 1.What is the range of an n-bit A/D converter? 2. Our ATmeg16/ATmega8515 has an 10-bit A/D converter. What is the resolution if the full-scale input range is 5V? 3. Briefly describe the two operating modes of the ADC in the ATmeg16/ATmega8515. Pre_lab questions 4. What are the ADC noise canceling techniques? 5. What two registers are used by the ADC and what are their purposes? ADCSRA ADMUX ADCW

9 ADCSRA bit definitions (Textbook: page 143) Bit Bit7: ADC Enable bit Bit6: ADC start conversion bit Bit5: ADC free running bit Bit0-Bit2: ADC prescaler select bit ADCSRA=0xE9; /*enable ADC, free run, started, clock prescaler of 64 */ ADCSRA =

10 There are two operating modes of ADC: 1.In the interrupt-driven, (single-conversion) mode, only one conversion occurs after setting the start conversion bit and the bit must be set again before another conversion. 2.In the free-running mode, successive conversions are restarted automatically once the first conversion completes.

11 Lab2 software requirements The ADC program can use a 100 ms clock to trigger the ISR. The ISR set a flag and the actual work of reading the ADC and running the math can be done in main(). Every 5 times through the ISR – i.e. every 500 ms – the ISR blinked an LED. This is done to provide a heartbeat signal. If the rest of the program is not working but the LED is blinking, we know that the  P is OK and that the software is not hung. This was very useful in the troubleshooting phase. Demo and produce Table 1

12 Voltage Measured Value at Point V A Display VoltageDigital ValuePercentage of Full Scale 0.00 V 0x0000% 0.50 V 0x06810% V4.79 V0x3D695% Table 1 Voltage and Percentage of Full Scale

13 Measured Voltage (V) Displayed Voltage (V) Digital Value (Decimal) Percent of Full Scale (%) Table 1. ADC Measurements for Different Potentiometer Settings

14 Lab2 software requirement  For noise elimination you can make your program to measure the ADC channel 4 times, then throws out the highest and the lowest and takes an average of the remaining 2 data points.  This makes sure that outlying data points (flyers) do not affect the final result.  The main issue is an occasional data point that is obviously very far out of the normal band. The technique used for noise elimination can eliminate those data points. The resulting output was quite stable. Output data was solidly +/- 1 unit (5 mV) with an occasional jump to +/- 2 units.

15 main() Initialize peripherals in Atmeg16  P: Port B : output, initialized to all 1’s = LED’s off. Timer 1 : 278  s period, interrupt on, reload for 100 ms period. ADC: turn ADC on, enable the interrupt and set ADC clock to 115 kHz Wait until the ADC flag is set by the ISR. Clear the ADC flag. Initialize loop variables and select channel 1. Run ADC measure loop 4 times ………… more work.

16 Timer 1, ISR() Reload counter for 100 ms. Increment the 1-5 counter. If the 1-5 counter overflows, blink the heartbeat LED. Set the ADC flag. …….. ADC, ISR() Set the ADC done flag.

17 #include // Standard Input/Output functions #include char adcFlag = 0; char ledFlag = 0; char adcDone = 0; char count = 0; unsigned char led1 = 0xFF; unsigned char led2 = 0xFE; ….

// Timer 1 overflow interrupt service routine interrupt [TIM1_OVF] void timer1_ovf_isr(void) { // Reinitialize Timer 1 value TCNT1H=0xFE; TCNT1L=0x97; // Place your code here adcFlag = 1; // Increment the count // Every 5 times through (500 ms) blink the LED (heartbeat LED) …………..

interrupt [ADC_INT] void adc_isr(void) { adcDone = 1; } void main(void) // Main Control Loop while (1){ // When ADC flag is set by interrupt, // do conversion and show results // Wait for ISR to set flag // Wait until conversion is done while(adcDone == 0){ } // Get and process data volts = ADCW; //printf(" v = %d", volts); if(volts < loV){ loV = volts; } if(volts > hiV){ hiV = volts; } sumV += volts;

20 Another approach 1.write the read_adc function 2.main calls the read_adc function

21 while (1) { // Place your code here delay_ms(900);// delay 900 ms; ADC_sum=0; // initialize ADC_sum; for (i=0;i < 10; i++){ // start to sum 10 ADC samples; delay_ms(10);// take ADC sample every 10 ms; ADC_sum += read_adc(0); // read ADC output from PA0 and add to ADC_sum; } ADC_output = ADC_sum/10;// averaged ADC output; ADC_percent = ADC_output*25/256; // calculate percentage of ADC full range for current ADC output; printf("ADC Output = %4d ADC Percentage = %3d%\r", ADC_output, ADC_percent); // Display ADC output to terminal; if (ADC_output > 0x0332)// threshold detection at 4.0V; PORTB = 0xFE;//turn on LED0 when ADC output > 4.0V; else PORTB = 0xFF; }; This is another example of reading ADC output.