International Islamic University Chittagong (IIUC) Department of Electrical and Electronic Engineering (EEE)

Similar documents
ELCT706 MicroLab Session #3 7-segment LEDs and Analog to Digital Conversion. Eng. Salma Hesham

Data Conversion and Lab (17.368) Fall Lecture Outline

Chapter 11 Sections 1 3 Dr. Iyad Jafar

Section bit Analog-to-Digital Converter (ADC)

Converting between Analog and Digital Domains

Section Bit ADC with 4 Simultaneous Conversions

Interfacing Analog to Digital Data Converters. A/D D/A Converter 1

The Successive Approximation Converter Concept - 8 Bit, 5 Volt Example

Introduction to PIC Programming

Analog to Digital Conversion

ADC Peripheral in Microcontrollers. Petr Cesak, Jan Fischer, Jaroslav Roztocil

TV Synchronism Generation with PIC Microcontroller

ECE 372 Microcontroller Design

Experiment 3: Basic Embedded System Analysis and Design

EXPERIMENT 2: Elementary Input Output Programming

Embedded Systems. Interfacing PIC with external devices 7-Segment display. Eng. Anis Nazer Second Semester

Radio Clock with DCF77

Part 2 -- A digital thermometer or talk I2C to your atmel microcontroller

Tutorial Introduction

B I O E N / Biological Signals & Data Acquisition

Hello and welcome to this training module for the STM32L4 Liquid Crystal Display (LCD) controller. This controller can be used in a wide range of

Fig. 1 Analog pins of Arduino Mega

DESIGN AND DEVELOPMENT OF A MICROCONTROLLER BASED PORTABLE ECG MONITOR

Embedded Systems. Interfacing PIC with external devices 7-Segment display. Eng. Anis Nazer Second Semester

Introduction to Mechatronics. Fall Instructor: Professor Charles Ume. Analog to Digital Converter

Hello and welcome to this presentation of the STM32L4 Analog-to-Digital Converter block. It will cover the main features of this block, which is used

Point System (for instructor and TA use only)

SUBSYSTEMS FOR DATA ACQUISITION #39. Analog-to-Digital Converter (ADC) Function Card

Analog input and output

Solutions to Embedded System Design Challenges Part II

Analog-to-Digital Conversion

INDIAN INSTITUTE OF TECHNOLOGY KHARAGPUR NPTEL ONLINE CERTIFICATION COURSE. On Industrial Automation and Control

Model Solution and marking scheme for Examination Paper EEE305J1: Microcontroller Systems 2004/5 General Observations

Technical Data. HF Tuner WJ-9119 WATKINS-JOHNSON. Features

Integrated Circuit for Musical Instrument Tuners

CPE 310L EMBEDDED SYSTEM DESIGN (CPE)

This document describes a program for 7-segment LED display (dynamic lighting) and key matrix and input.

AN919: Using the EFM8LB1 ADC

Dynamic Animation Cube Group 1 Joseph Clark Michael Alberts Isaiah Walker Arnold Li

Digital Systems Principles and Applications. Chapter 1 Objectives

TV Character Generator

This document describes a program for 7-segment LED display (dynamic lighting).

8-BIT MCU WITH SINGLE VOLTAGE FLASH MEMORY, DATA EEPROM, ADC, TIMERS, SPI

Simple PICTIC Commands

Chapter 4: One-Shots, Counters, and Clocks

Digital Signal Processing Lecture One Introduction to Digital Signal Processing Third Stage Prepared by: Marwah Kareem

Analog Input & Output

Lab 1 Introduction to the Software Development Environment and Signal Sampling

Troubleshooting EMI in Embedded Designs White Paper

Ocean Sensor Systems, Inc. Wave Staff, OSSI F, Water Level Sensor With 0-5V, RS232 & Alarm Outputs, 1 to 20 Meter Staff

ASNT_PRBS20B_1 18Gbps PRBS7/15 Generator Featuring Jitter Insertion, Selectable Sync, and Output Amplitude Control

AD16-64(LPCI)LA. Non-isolated high precision analog input board for Low Profile PCI AD16-64(LPCI)LA 1. Ver.1.01

Converters: Analogue to Digital

Ocean Sensor Systems, Inc. Wave Staff III, OSSI With 0-5V & RS232 Output and A Self Grounding Coaxial Staff

NanoCom ADS-B. Datasheet An ADS-B receiver for space applications

Low-speed serial buses are used in wide variety of electronics products. Various low-speed buses exist in different

Power Supply and Watchdog Timer Monitoring Circuit ADM9690

ADC0804C, ADC BIT ANALOG-TO-DIGITAL CONVERTERS WITH DIFFERENTIAL INPUTS

Analog-to-Digital Conversion (Part 2) Microcomputer Architecture and Interfacing Colorado School of Mines Professor William Hoff

The University of Texas at Dallas Department of Computer Science CS 4141: Digital Systems Lab

PCM ENCODING PREPARATION... 2 PCM the PCM ENCODER module... 4

Digital Signal. Continuous. Continuous. amplitude. amplitude. Discrete-time Signal. Analog Signal. Discrete. Continuous. time. time.

Decade Counters Mod-5 counter: Decade Counter:

Laboratory Exercise 4

Workshop 4 (A): Telemetry and Data Acquisition

SignalTap Plus System Analyzer

Evaluating Oscilloscopes to Debug Mixed-Signal Designs

ExtIO Plugin User Guide

SDA 3302 Family. GHz PLL with I 2 C Bus and Four Chip Addresses

2 MHz Lock-In Amplifier

Lab 2: A/D, D/A, and Sampling Theorem

Logic Devices for Interfacing, The 8085 MPU Lecture 4

Vorne Industries. 87/719 Analog Input Module User's Manual Industrial Drive Itasca, IL (630) Telefax (630)

The 9S12 A/D converter Huang Section ATD_10B8C Block User Guide

4.3 8 bit TFT Digital Driver Board Specification

Analog-to-Digital Converter

Chapter 1. Introduction to Digital Signal Processing

Counter/timer 2 of the 83C552 microcontroller

GFT Channel Digital Delay Generator

QUICK START GUIDE FOR DEMONSTRATION CIRCUIT /12/14 BIT 10 TO 65 MSPS DUAL ADC

ES /2 digit with LCD

Chapter 5 Flip-Flops and Related Devices

AN3023 Application note

Digital IC Tester by Using PIC18F4550

Embedded System Training Module ABLab Solutions

Synchronizing Multiple ADC08xxxx Giga-Sample ADCs

Improved Synchronization System for Thermal Power Station

FM1200RTIM COMTECH TECHNOLOGY CO., LTD. 1. GENERAL SPECIFICATION. 2. STANDARD TEST CONDITION test for electrical specification shall be

HT8 MCU Integrated LCD Application Example (2) C Type Bias

RX40_V1_0 Measurement Report F.Faccio

QUICK START GUIDE FOR DEMONSTRATION CIRCUIT /12/14 BIT 10 TO 105 MSPS ADC

Introduction to Data Conversion and Processing

Interfacing the TLC5510 Analog-to-Digital Converter to the

Digital Clock. Perry Andrews. A Project By. Based on the PIC16F84A Micro controller. Revision C

Combo Board.

bit TFT Digital Driver Board Specification

DSM GHz Linear Chirping Source

Debugging Embedded Mixed-Signal Designs Using Mixed Signal Oscilloscopes

Tutorial on Technical and Performance Benefits of AD719x Family

Integration of Virtual Instrumentation into a Compressed Electricity and Electronic Curriculum

Transcription:

International Islamic University Chittagong (IIUC) Department of Electrical and Electronic Engineering (EEE) Course Code: EEE 3518 Course Title: Embedded System Sessional EXPERIMENT NO. 8 Name of the Experiment: Analog to digital conversion (ADC) by PIC 16F887 microcontroller. 8.1 Objective: The objectives of this experiment are- (a) To know the basic procedure of converting analog signal to digital signal. (b) Converting analog voltage into digital by PIC16F887 microcontroller. 8.2 Related Literature: Analog signals are continuously valued signal, with infinite possible values in between. Signals in the real world are analog: light, sound, temperature etc. So, realworld signals must be converted into digital (discretely valued signal), using a circuit called ADC (Analog-to-Digital Converter), before they can be manipulated by digital equipment. 8.2.1 Why digital? : There are some basic reasons to use digital signals instead of analog, noise being the number one. Since analog signals can assume any value, noise is interpreted as being part of the original signal. Digital systems, on the other hand, can only understand two numbers, zero and one. Anything different from this is discarded. In order to manipulate the data using a microprocessor, we need to convert the analog signals to the digital signals, so that the microprocessor will be able to read, understand and manipulate the data. Another advantage of digital system against analog is the data compression capability. Since the digital counterpart of an analog signal is just a bunch of numbers, these numbers can be compressed, just like you would compress a Word file using WinZip to shrink down the file size, for example. The compression can be done to save storage space or bandwidth.

8.2.2 Steps of ADC An analog signal is continuous in both time and amplitude, whereas a digital signal is discrete in time as well as in amplitude. Logically, an ADC has to covert an analog signal to an equivalent digital one in three steps: (a) Sampling: Converting the analog signal to a discrete in time signal which is called sampling. (b) Quantization: Converting the discrete time signal into a discrete in amplitude signal which is called quantization. (c) Coding: Finally every sample is represented by an n-bit digital code. Amplitude Time Figure: Analog Signal Amplitude Time Figure: Sampling

Amplitude 1111 1110 1101 1100 1011 1010 1001 1000 0111 0110 0101 0100 0011 0010 0001 0000 Time Figure: Quantization and coding 8.2.3 Analog Modules in PIC16F887 The A/D converter module has the following features: The converter generates a 10-bit binary result using the method of successive approximation and stores the conversion results into the ADC registers (ADRESL and ADRESH); There are 14 separate analog inputs; The A/D converter converts an analog input signal into a 10-bit binary number; The minimum resolution or quality of conversion may be adjusted to various needs by selecting voltage references Vref- and Vref+.

8.2.3.1 A/D CONVERTER The operation of A/D converter is in control of the bits of four registers: ADRESH Contains high byte of conversion result; ADRESL Contains low byte of conversion result; ADCON0 Control register 0; and ADCON1 Control register 1. 8.2.3.2 ADRESH and ADRESL Registers The result obtained after converting an analog value into digital is a10-bit number that is to be stored in the ADRESH and ADRESL registers. There are two ways of handling it - left and right justification which simplifies its use to a great extent. The format of conversion result depends on the ADFM bit of the ADCON1 register. In the event that the A/D converter is not used, these registers may be used as general-purpose registers.

8.2.3.3 HOW TO USE THE A/D CONVERTER? In order to enable the A/D converter to run without problems as well as to avoid unexpected results, it is necessary to consider the following: A/D converter does not differ between digital and analog signals. In order to avoid errors in measurement or chip damage, pins should be configured as analog inputs before the process of conversion starts. Bits used for this purpose are stored in the TRIS and ANSEL (ANSELH) registers; When reading the port with analog inputs, the state of the corresponding bits will be read as a logic zero (0); and Roughly speaking, voltage measurement in the converter is based on comparing input voltage with internal scale which has 1024 marks (2 10 = 1024). The lowest scale mark stands for the Vref- voltage, whilst its highest mark stands for the Vref+ voltage. 8.2.3.3 ADC control registers ADCON0 Register ADCS1, ADCS0 - A/D Conversion Clock Select bits select clock frequency used for internal synchronization of A/D converter. It also affects duration of conversion. ADCS1 ADCS2 CLOCK 0 0 Fosc/2

0 1 Fosc/8 1 0 Fosc/32 1 1 RC * * Clock is generated by internal oscillator which is built in the converter. CHS3-CHS0 - Analog Channel Select bits select a pin or an analog channel for A/D conversion, i.e. voltage measurement: CHS3 CHS2 CHS1 CHS0 CHAN NE L PI N 0 0 0 0 0 RA0/AN0 0 0 0 1 1 RA1/AN1 0 0 1 0 2 RA2/AN2 0 0 1 1 3 RA3/AN3 0 1 0 0 4 RA5/AN4 0 1 0 1 5 RE0/AN5 0 1 1 0 6 RE1/AN6 0 1 1 1 7 RE2/AN7 1 0 0 0 8 RB2/AN8 1 0 0 1 9 RB3/AN9 1 0 1 0 10 RB1/AN10 1 0 1 1 11 RB4/AN11 1 1 0 0 12 RB0/AN12 1 1 0 1 13 RB5/AN13 1 1 1 0 CVref 1 1 1 1 Vref = 0.6V GO/DONE - A/D Conversion Status bit determines current status of conversion: 1 - A/D conversion is in progress. 0 - A/D conversion is complete. This bit is automatically cleared by hardware when the A/D conversion is complete. ADON - A/D On bit enables A/D converter. 1 - A/D converter is enabled. 0 - A/D converter is disabled.

ADCON1 Register ADFM - A/D Result Format Select bit 1 - Conversion result is right justified. Six most significant bits of the ADRESH are not used. 0 - Conversion result is left justified. Six least significant bits of the ADRESL are not used. VCFG1 - Voltage Reference bit selects negative voltage reference source needed for the operation of A/D converter. 1 - Negative voltage reference is applied to the Vref- pin. 0 - Power supply voltage Vss is used as negative voltage reference source. VCFG0 - Voltage Reference bit selects positive voltage reference source needed for the operation of A/D converter. 1 - Positive voltage reference is applied to the Vref+ pin. 0 - Power supply voltage Vdd is used as positive voltage reference source. In Short In order to measure voltage on an input pin by the A/D converter, the following should be done: Step 1 - Port configuration: Write a logic one (1) to a bit of the TRIS register, thus configuring the appropriate pin as an input. Write a logic one (1) to a bit of the ANSEL register, thus configuring the appropriate pin as an analog input. Step 2 - ADC module configuration: Configure voltage reference in the ADCON1 register. Select ADC conversion clock in the ADCON0 register. Select one of input channels CH0-CH13 of the ADCON0 register. Select data format using the ADFM bit of the ADCON1 register. Enable A/D converter by setting the ADON bit of the ADCON0 register. Step 3 - ADC interrupt configuration (optionally): Clear the ADIF bit. Set the ADIE, PEIE and GIE bits. Step 4 - Wait for the required acquisition time to pass (approximately 20uS).

Step 5 - Start conversion by setting the GO/DONE bit of the ADCON0 register. Step 6 - Wait for ADC conversion to complete. It is necessary to check in the program loop whether the GO/DONE pin is cleared or wait for an A/D interrupt (must be previously enabled). Step 7 - Read ADC results: Read the ADRESH and ADRESL registers. 8.2.4 ADC library in MikroC PRO ADC_Init Prototype Returns void ADC_Init(); Nothing. Description This routine initializes PIC s internal ADC module to work with RC clock. Clock determines the time period necessary for performing AD conversion (min 12TAD). Requires MCU with built-in ADC module. Example ADC_Init(); // Initialize ADC module with default settings ADC_Get_Sample Prototype Returns unsigned ADC_Get_Sample(unsigned short channel); 10 or 12-bit unsigned value read from the specified channel (MCU dependent). Description The function aquires analog value from the specified channel. Parameter channel represents the channel from which the analog value is to be acquired. Refer to the appropriate datasheet for channel-to-pin mapping. Note : This function doesn't work with the external voltage reference source, only with the internal voltage reference. Parameters channel represents the channel from which the analog value is to be acquired. Requires The MCU with built-in ADC module. Prior to using this routine, ADC module needs to be initialized. See ADC_Init.

Before using the function, be sure to configure the appropriate TRISx bits to designate pins as inputs. Example unsigned adc_value;... adc_value = ADC_Get_Sample(2); channel 2 // read analog value from ADC module ADC_Read Prototype Returns unsigned ADC_Read(unsigned short channel); 10 or 12-bit unsigned value read from the specified channel (MCU dependent). Description Initializes PIC s internal ADC module to work with RC clock. Clock determines the time period necessary for performing AD conversion (min 12TAD). Parameter channel represents the channel from which the analog value is to be acquired. Refer to the appropriate datasheet for channel-to-pin mapping. Note : This function doesn't work with the external voltage reference source, only with the internal voltage reference. Requires Example Nothing. unsigned tmp;... tmp = ADC_Read(2); // Read analog value from channel 2

8.3 Measuring light Intensity 8.3.1 Circuit Diagram 8.3.2 Program: unsigned int light; void main() { ANSEL = 0x04; ANSELH = 0; C1ON_bit = 0; // Configure AN2 pin as analog // Configure other AN pins as digital I/O // Disable comparators C2ON_bit = 0; TRISA = 0xFF; TRISB = 0; // PORTA is input // PORTB is output while(1)

{ light = ADC_Read(2); // Get 10-bit results of AD conversion if(light<100) PORTB=0x6F; else if(light<200) PORTB=0x7F; else if(light<300) PORTB=0x07; else if(light<400) PORTB=0x7D; else if(light<500) PORTB=0x6D; else if(light<600) PORTB=0x66; else if(light<700) PORTB=0x4F; else if(light<800) PORTB=0x5B; else if(light<900) PORTB=0x06; else PORTB=0x3F; } }