Laboratory Exercise 5 - Analog to Digital Conversion

Similar documents
EEE394 Microprocessor and Microcontroller Laboratory Lab #6

Interfacing PIC Microcontrollers. ADC8BIT2 Schematic. This application demonstrates analogue input sampling

Dept. of Computer Engineering Final Exam, First Semester: 2016/2017

EECE.3170: Microprocessor Systems Design I Spring 2016

University of Jordan Faculty of Engineering and Technology Department of Computer Engineering Embedded Systems Laboratory

Flow Charts and Assembler Programs

Embedded systems. Exercise session 3. Microcontroller Programming Lab Preparation

Embedded Systems. PIC16F84A Sample Programs. Eng. Anis Nazer First Semester

EECE.3170: Microprocessor Systems Design I Summer 2017

Lesson 14. Title of the Experiment: Introduction to Microcontroller (Activity number of the GCE Advanced Level practical Guide 27)

Introduction. Embedded system functionality aspects. Processing. Storage. Communication. Transformation of data Implemented using processors

NH-67, TRICHY MAIN ROAD, PULIYUR, C.F , KARUR DT. DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING COURSE MATERIAL

CONNECT TO THE PIC. A Simple Development Board

Embedded Systems Programming and Architectures

When JP1 is cut, baud rate is Otherwise, baud rate is Factory default is that JP1 is shorted. (JP1 is jumper type in some model)

Timer2 Interrupts. NDSU Timer2 Interrupts September 20, Background:

Binary Outputs and Timing

PIC 16F84A programming (II)

Jordan University of Science and Technology Electrical Engineering Department Microcontrollers and Embedded Systems Spring 2011

Week1. EEE305 Microcontroller Key Points

ECE Homework #3

UNIVERSITY OF ULSTER UNIVERSITY EXAMINATIONS : 2001/2002 RESIT. Year 2 MICROCONTROLLER SYSTEMS. Module Code: EEE305J1. Time allowed: 3 Hours

CENG 336 INT. TO EMBEDDED SYSTEMS DEVELOPMENT. Spring 2006

Weekly Report: Interactive Wheel of Fortune Week 4 02/014/07-02/22/07 Written by: Yadverinder Singh

Hardware Interfacing. EE25M Introduction to microprocessors. Part V. 15 Interfacing methods. original author: Feisal Mohammed

Microchip 18F4550 Interface, Signal conditioning, USB, USB- RS-232, 16x2 LCD Interface

AN587. Interfacing to an LCD Module. Interfacing to an LCD Module INTRODUCTION OPERATION CONTROL SIGNAL FUNCTIONS TABLE 2: CONDITIONAL ASSEMBLY FLAGS

UNIVERSITY OF BOLTON SCHOOL OF ENGINEERING MSC SYSTEMS ENGINEERING AND ENGINEERING MANAGEMENT SEMESTER 2 EXAMINATION 2016/2017

LPTCOM. Bruce Misner Lakehead University h d3 RD2 pin 21. RD3 pin h d4. RD4 pin 27 RD5 pin h d5. RD6 pin 29 RD7 pin H d6

UNIVERSITY OF BOLTON SCHOOL OF ENGINEERING. BEng(Hons) Electrical and Electronics Engineering SEMESTER 1 EXAMINATION 2016/2017

Embedded System Design

Figure 1: Pushbutton without Pull-up.

SOLUTIONS!! DO NOT DISTRIBUTE PRIOR TO EXAM!!

UNIVERSITY OF BOLTON SCHOOL OF ENGINEERING B.ENG (HONS) ELECTRICAL AND ELECTRONIC ENGINEERING EXAMINATION SEMESTER /2016

Outlines. PIC Programming in C and Assembly. Krerk Piromsopa, Ph.D. Department of Computer Engineering Chulalongkorn University

Performance & Applications

/* PROGRAM FOR BLINKING LEDs CONEECTED TO PORT-D */

Lecture (04) PIC16F84A (3)

Chapter 5 Sections 1 6 Dr. Iyad Jafar

EEE111A/B Microprocessors

EECE.3170: Microprocessor Systems Design I Summer 2017 Homework 5 Solution

ECE Test #1: Name

Outline. Micriprocessor vs Microcontroller Introduction to PIC MCU PIC16F877 Hardware:

Experiment 7:The USART

PIC PROGRAMMING START. The next stage is always the setting up of the PORTS, the symbol used to indicate this and all Processes is a Rectangle.

Assembly Language Instructions

PIC Discussion. By Eng. Tamar Jomaa

Chapter 3: Further Microcontrollers

EXAMINATION PAPER EMBEDDED SYSTEMS 6EJ005

DERTS Design Requirements (1): Microcontroller Architecture & Programming

The University of Texas at Arlington Lecture 5

LAB WORK 2. 1) Debugger-Select Tool-MPLAB SIM View-Program Memory Trace the program by F7 button. Lab Work

GUIDE TO USE OF PIC 16F690 EEProm. The 16F690 PIC has a 256 byte EEProm (mapped to 0x x21FF).

Micro II and Embedded Systems

16.317: Microprocessor Systems Design I Fall 2013 Exam 3 Solution

UNIVERSITY OF ULSTER UNIVERSITY EXAMINATIONS : 2001/2002. Semester 2. Year 2 MICROCONTROLLER SYSTEMS. Module Code: EEE305J2. Time allowed: 3 Hours

Fortune. Semiconductor Corporation 富晶半導體股份有限公司. 8-bit MCU with 1k program ROM, 64-byte RAM, 1 R2F module and 3 13 LCD driver. TD Rev. 1.

Chapter 13. PIC Family Microcontroller

Hi Hsiao-Lung Chan Dept Electrical Engineering Chang Gung University, Taiwan

Small Scale PV Monitoring System Software Design

TOPIC 3 INTRODUCTION TO PIC ASSEMBLY LANGUAGE. E4160 Microprocessor & Microcontroller System. Prepared by : Puziah Yahaya JKE, POLISAS / DEC 2010

SOLUTIONS!! DO NOT DISTRIBUTE!!

APPLICATION NOTE 2361 Interfacing an SPI-Interface RTC with a PIC Microcontroller

1 Introduction to Computers and Computer Terminology Programs Memory Processor Data Sheet Example Application...

which means that writing to a port implies that the port pins are first read, then this value is modified and then written to the port data latch.

Laboratory 10. Programming a PIC Microcontroller - Part II

APPLICATION NOTE Wire Communication with a Microchip PICmicro Microcontroller

ﻢﯿﺣﺮﻟا ﻦﻤﺣﺮﻟا ﷲا ﻢﺴﺑ

Chapter 3 BRANCH, CALL, AND TIME DELAY LOOP

Chapter 4 Sections 1 4, 10 Dr. Iyad Jafar

The Freescale MC908JL16 Microcontroller

SOLAR TRACKING SYSTEM USING PIC16F84A STEPPER MOTOR AND 555TIMER

8051 Training Kit Lab Book

C and Embedded Systems. So Why Learn Assembly Language? C Compilation. PICC Lite C Compiler. PICC Lite C Optimization Results (Lab #13)

1 Introduction to Computers and Computer Terminology Programs Memory Processor Data Sheet... 4

THE UNIVERSITY OF THE WEST INDIES

Microcontroller Based Automatic Temperature Control System

Input/Output Ports and Interfacing

Explanation of PIC 16F84A processor data sheet Part 1: overview of the basics

PIC Microcontroller Trainer

Physics 335 Intro to MicroControllers and the PIC Microcontroller

Section 11. Timer0. Timer0 HIGHLIGHTS. This section of the manual contains the following major topics:

movwf prevcod ; a new button is pressed - rcnt=3 movwf (mtx_buffer+1) movlw 3 movwf rcnt

How Stuff Works: Processors

Simple cpik Tutorial

MICROPROCESSORS A (17.383) Fall Lecture Outline

DHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI DEPARTMENT OF ELECTRICAL AND ELECTRONICS ENGINEERING. EE6008 Microcontroller based system design

D:\PICstuff\PartCounter\PartCounter.asm

EXPERIMENT 4: Parallel Input/Output. Objectives Introduction to the Parallel Input/Output (I/O) Familiarization to Interfacing

11010 SBC 16-bit Architecture, C30 & Standard Peripherals Hand Out

PICDEM-1 USER S GUIDE

LCD. Configuration and Programming

Chapter 11: Interrupt On Change

Done 1 NVB THF TLF T/R POL 1SHOT. Figure 1: Status register

Mechatronics and Measurement. Lecturer:Dung-An Wang Lecture 6

Hitachi H48C 3-Axis Accelerometer Module (#28026)

Learning Objectives:

Section 30. In-Circuit Serial Programming (ICSP )

Appendix D: Source Codes. PDF created with pdffactory Pro trial version

CENG-336 Introduction to Embedded Systems Development. Timers

Transcription:

Laboratory Exercise 5 - Analog to Digital Conversion The purpose of this lab is to control the blinking speed of an LED through the Analog to Digital Conversion (ADC) module on PIC16 by varying the input voltage on pin RA0. What is ADC? There are 8 specific I/O pins on PIC16 that can be configured to take an analog input and convert it into a 10 bit digital number. 1 In another word, user can supply voltage to one of the pins, and convert this input to a digital value which can then be converted to obtain the value of the voltage. The 10 bit binary number gives a range of 0 1023 or 0 (2^10 1). If we set the reference voltage at 5V then 0 5 volts can be represented as 0 1023 in the digital format. For example 5V would be represented by 1023, and 2.5V would be represented by 512. The formula to calculate the digital value is X = (Vin / Vfullscale ) * (2^n 1) Eg. X = ( 2.5 / 5 ) * 1023 = 512 ADC registers There are in total four registers for A/D conversion in PIC6: Since the PIC16 is an 8 bit microcontroller, the 10 bit result of the ADC is stored in two registers: ADRESH and ADRESL. The result is stored in two forms: left justified or right justified. By setting ADFM bit in ADCON1, the user can manipulate the storing form of the result. 1 Look up section 7.3.2 of the Course Notes for pins that are capable of taking analog inputs.

When the result is left justified, the high 8 bits are stored in ADRESH, and the 7 th and 6 th bit of the ADRESL contains the low 2 bits. The rest are set to 0. ADCON0: The first two bits ADCS1 and ADCS0 are required to select the A/D clock. So for a 20 MHz clock, one would select 10 for Fosc/32. The next three bits of ADCON0 is channel select. Since PIC16 offers 8 input channels, the ADC module needs to know which channel the user wishes to select, and convert. We look up the following table to make channel selection:

Bit 2 of ADCON0 is the GO/DONE bit. Setting this bit high starts the A/D conversion and it is automatically cleared by hardware when it is complete. Bit 0 is ADON. When the bit is set it turns on the A/D, and when cleared it turns off. So it needs to be set high when A/D is desire. ADCON1: We already looked at bit 7 ADFM which is used to select the format of conversion result. Bit 6 4 is unimplement. Bit 3 0 is PCFG 3 0 which is used to select A/D port configuration. PCFG3: PCFG0 AN7 RE2 AN6 RE1 AN5 RE0 AN4 RA5 AN3 RA3 AN2 RA2 AN1 RA1 AN0 RA0 V REF+ V REF- 0000 A A A A A A A A V DD V SS 0001 A A A A V REF+ A A A RA3 V SS 0010 D D D A A A A A V DD V SS 0011 D D D A V REF+ A A A RA3 V SS 0100 D D D D A D A A V DD V SS 0101 D D D D V REF+ D A A RA3 V SS 011x D D D D D D D D V DD V SS 1000 A A A A V REF+ V REF- A A RA3 RA2 1001 D D A A A A A A V DD V SS 1010 D D A A V REF+ A A A RA3 V SS 1011 D D A A V REF+ V REF- A A RA3 RA2 1100 D D D A V REF+ V REF- A A RA3 RA2 1101 D D D D V REF+ V REF- A A RA3 RA2 1110 D D D D D D D A V DD V SS 1111 D D D D V REF+ V REF- D A RA3 RA2 This table looks complicated, but if we break it down, it offers us four options: 1. Setting a pin to analogue input. 2. Setting a pin to be digital input. 3. Setting the positive reference for the converter (Vref+).

4. Setting the Negative reference for the converter (Vref ). For this lab, we require RA0 to be the only analogue input, and set rest to digital input 2. Also we take Vdd and Vss to be reference voltage of 0 to 5V. Thusly, by looking up the above table we see that PCFG3 0 should be set as 1110. Sometimes a different reference voltage is desired, that is why the Microcontroller comes with an A2D module: The two potentiometers allow the user to set different voltage reference levels on pin RA2 and RA3. Short JP4 and JP5 to enable them. A/D Process (taken from Datasheet): 1. Configure the A/D module: Configure analog pins, voltage reference and digital I/O (ADCON1) Select result format (ADFM bit ADCON1) Select A/D input channel (ADCON0 CHS2:CHS0) Select A/D conversion clock (ADCON0 ADCS1:ADCS0) Turn on A/D module (ADCON0 ADON / bit 0) Configure the TRISA register for the analog inputs 2. Wait the required acquisition time (if required) 3. Start conversion Set the GO/DONE bit (ADCON0) 4. Wait for A/D conversion to complete, by polling for the GO/DONE bit to be cleared. 5. Read A/D result register pair (ADRESH:ADRESL) 2 It is often desired in codes that do not require ADC to set all pins to digital input.

Exercise: Write a piece of code that controls the blinking speed of an LED through the Analog to Digital Conversion (ADC) module on PIC16 by varying the input voltage on pin RA0. We use PORTD1 to control the LED. First construct a MAPLAB project and name is ADC, construct a main.asm and save it under the project source files. In the code, first switch to bank 1. TRISD1 is cleared to set the direction of the pins to output. Since the Microcontroller comes with a Debug module with LED already linked to PORTD1, no external LED is needed. Also set TRISA0 to make it an input pin. ADCON1 is used to set the voltage reference of the pins. They should be set to Vdd and Vss. It is also used to configure input analog pins. movlw b'00001110' movwf ADCON1 ;All digital input expect RA0, reference voltage Vdd Vss Now switch back to bank 0 and set ADCON0. Only one analog channel may be read at one time. Set bit 5:3 to 000 to select RA0. bcf STATUS,RP0 movlw b'11000001' movwf ADCON0 ;clock selected, ADC module turned on The configuration is complete. Setting the GO/DONE bit of ADCON0 (bit1) starts the A/D conversion. Completion is indicated when the bit is cleared. MainLoop bsf ADCON0,2 ;start conversion and wait for it to complete btfsc ADCON0,2 goto $ 2 Now blink PORTD1 and go back for looping:. bsf PORTD,1 ;toggle PORTD1 call DelayAD clrf PORTD call DelayAD goto MainLoop

Now to control the blinking speed of the LED we manipulate the DelayAD constants by using the A/D conversion result. DelayAD movfw ADRESH ;delay functions based on A/D result movwf Delay2 ;move 8 MSb from A/D result to Delay2 Delay incf Delay2,f ;make sure no overflows occur btfsc STATUS,Z decf Delay2,f decfsz Delay1, f goto Delay decfsz Delay2, f goto Delay return One thing to keep in mind is that we need to make sure that overflow does not occur. Try taking out this part of code and see what happens. Instead of staying constantly on and blinking slowly at the other, the LED blinks slowly at both extremes. This is because the DECFSZ instructions in the delay loop decrement Delay2 before testing it. When the A/D result is brought to 0, the DECFSZ instruction makes Delay2 overflow to 255, making the delay very long. To prevent this, we increment Delay2 by 1 unless it is already at a maximum. Circuit used to implement the potentiometer to control the input voltage is demonstrated below: After compiling and loading the code, the user should be able to control the blinking speed of RD1 LED light on Microcontroller by turning the potentiometer.