Microprocessors A Lab 4 Fall Analog to Digital Conversion Using the PIC16F684 Microcontroller

Similar documents
MICROPROCESSORS A (17.383) Fall Lecture Outline

Microprocessors B Lab 4 Spring Motor Control Using Pulse Width Modulation (PWM)

Embedded Systems. Interfacing PIC with external devices Analog to digital Converter. Eng. Anis Nazer Second Semester

Interfacing to Analog World Sensor Interfacing

Designing with a Microcontroller (v6)

Data Conversion and Lab Lab 4 Fall Digital to Analog Conversions

PIC ADC to PWM and Mosfet Low-Side Driver

PIC Analog Voltage to PWM Duty Cycle

GF of 9 THE GADGET FREAK FILES CASE #165. Analog Clock Measures Time in Meters

Pulse-Width-Modulation Motor Speed Control with a PIC (modified from lab text by Alciatore)

Part (A) Using the Potentiometer and the ADC* Part (B) LEDs and Stepper Motors with Interrupts* Part (D) Breadboard PIC Running a Stepper Motor

For this exercise, you will need a partner, an Arduino kit (in the plastic tub), and a laptop with the Arduino programming environment.

Data Conversion and Lab Lab 3 Spring Analog to Digital Converter

The University of Texas at Arlington Lecture 10 ADC and DAC

Data Conversion and Lab Lab 1 Fall Operational Amplifiers

Lab 3: Embedded Systems

Experiment #3: Micro-controlled Movement

νµθωερτψυιοπασδφγηϕκλζξχϖβνµθωερτ ψυιοπασδφγηϕκλζξχϖβνµθωερτψυιοπα σδφγηϕκλζξχϖβνµθωερτψυιοπασδφγηϕκ χϖβνµθωερτψυιοπασδφγηϕκλζξχϖβνµθ

Embedded Test System. Design and Implementation of Digital to Analog Converter. TEAM BIG HERO 3 John Sopczynski Karim Shik-Khahil Yanzhe Zhao

Arduino STEAM Academy Arduino STEM Academy Art without Engineering is dreaming. Engineering without Art is calculating. - Steven K.

3 Design Lab III: An Electronic Governor for Electric Motor Speed Control

MAE106 Laboratory Exercises Lab # 1 - Laboratory tools

University of Pennsylvania. Department of Electrical and Systems Engineering. ESE Undergraduate Laboratory. Analog to Digital Converter

EXPERIMENT 6: Advanced I/O Programming

EE283 Laboratory Exercise 1-Page 1

Understanding the Arduino to LabVIEW Interface

Lab Exercise 6: Digital/Analog conversion

HAW-Arduino. Sensors and Arduino F. Schubert HAW - Arduino 1

PART 1: DESCRIPTION OF THE DIGITAL CONTROL SYSTEM

Part 1: DC Concepts and Measurement

Building an Analog Communications System

Section 22. Basic 8-bit A/D Converter

EE-110 Introduction to Engineering & Laboratory Experience Saeid Rahimi, Ph.D. Labs Introduction to Arduino

Lifetime Power Energy Harvesting Development Kit for Wireless Sensors User s Manual - featuring PIC MCU with extreme Low Power (XLP) Technology

RC Filters and Basic Timer Functionality

LABORATORY EXPERIMENT. Infrared Transmitter/Receiver

Laboratory 11. Pulse-Width-Modulation Motor Speed Control with a PIC

Assembly Manual for VFO Board 2 August 2018

Class #3: Experiment Signals, Instrumentation, and Basic Circuits

PHYS Contemporary Physics Laboratory Laboratory Exercise: LAB 01 Resistivity, Root-mean-square Voltage, Potentiometer (updated 1/25/2017)

Microcontroller Based Wind Direction Measurement System

Microchip mtouch Solution Microchip Technology Incorporated. All Rights Reserved. Insert Class Code Here

Lab 3 Final report: Embedded Systems Digital Potentiometer Subsystem TEAM: RAR

EE 308 Spring S12 SUBSYSTEMS: PULSE WIDTH MODULATION, A/D CONVERTER, AND SYNCHRONOUS SERIAN INTERFACE

14. Card Test Methods

HANDS-ON LAB INSTRUCTION SHEETS MODULE

EE 210: CIRCUITS AND DEVICES

DTMF Signal Detection Using Z8 Encore! XP F64xx Series MCUs

6. HARDWARE PROTOTYPE AND EXPERIMENTAL RESULTS

Ten Tec DDS Board Assembly Procedure

Dedan Kimathi University of technology. Department of Electrical and Electronic Engineering. EEE2406: Instrumentation. Lab 2

DC Motor and Servo motor Control with ARM and Arduino. Created by:

Introduction to Using the PIC16F877 Justin Rice IMDL Spring 2002

Lab 2: Blinkie Lab. Objectives. Materials. Theory

Controlling DC Brush Motor using MD10B or MD30B. Version 1.2. Aug Cytron Technologies Sdn. Bhd.

Analog to Digital Conversion

Laboration: AD-conversion and the Thevenin theorem.

Analog to Digital Conversion

Follow this and additional works at: Part of the Engineering Commons

Programming PIC Microcontrollers in PicBasic Pro LCD Lesson 3 Cornerstone Electronics Technology and Robotics II

EE 109 Midterm Review

Using Circuits, Signals and Instruments

Formal Report of. Project 2: Advanced Multimeter using VHDL

P a g e 1. Introduction

EE 1210 Op Amps, Gain, and Signal Integrity Laboratory Project 6

Figure 1: One Possible Advanced Control System

Outline. Analog/Digital Conversion

University of California at Berkeley Donald A. Glaser Physics 111A Instrumentation Laboratory

Exercise 1: The Rheostat

OP5340-1/OP USER GUIDE

ME 461 Laboratory #3 Analog-to-Digital Conversion

MicroToys Guide: Motors A. Danowitz, A. Adibi December A rotary shaft encoder is an electromechanical device that can be used to

Data acquisition and instrumentation. Data acquisition

Analog-to-Digital Converter. Student's name & ID (1): Partner's name & ID (2): Your Section number & TA's name

PS2-SMC-06 Servo Motor Controller Interface

Instructional Demos, In-Class Projects, & Hands-On Homework: Active Learning for Electrical Engineering using the Analog Discovery

Revision: Jan 29, E Main Suite D Pullman, WA (509) Voice and Fax

' The PicBasic Pro Compiler Manual is on line at: '

ECEN 449: Microprocessor System Design Department of Electrical and Computer Engineering Texas A&M University

University of Portland EE 271 Electrical Circuits Laboratory. Experiment: Op Amps

Lecture 7: Analog Signals and Conversion

EGG 101L INTRODUCTION TO ENGINEERING EXPERIENCE

Using Z8 Encore! XP MCU for RMS Calculation

Module: Arduino as Signal Generator

INA169 Breakout Board Hookup Guide

Lecture 4: Basic Electronics. Lecture 4 Brief Introduction to Electronics and the Arduino

Physics 335 Lab 7 - Microcontroller PWM Waveform Generation

Laboratory 2 More Resistor Networks and Potentiometers.

Project Proposal. Underwater Fish 02/16/2007 Nathan Smith,

KUMU A O CUBESAT: THERMAL SENSORS ON A CUBESAT

SPEED CONTROL OF DC MOTOR USING PWM TECHNIQUE

Community College of Allegheny County Unit 7 Page #1. Analog to Digital

UNIVERSITY of PENNSYLVANIA DEPARTMENT OF ELECTRICAL AND SYSTEMS ENGINEERING ESE Undergraduate Labs Electrical Circuits and Systems II Laboratory

IME-100 ECE. Lab 1. Electrical and Computer Engineering Department Kettering University. G. Tewolde, IME100-ECE,

Direct Current Waveforms

Triple Stage Incubator

Rodni What will yours be?

o What happens if S1 and S2 or S3 and S4 are closed simultaneously? o Perform Motor Control, H-Bridges LAB 2 H-Bridges with SPST Switches

TECH 3232 Fall 2010 Lab #1 Into To Digital Circuits. To review basic logic gates and digital logic circuit construction and testing.

1 Second Time Base From Crystal Oscillator

Transcription:

Objectives Materials 17.383 Microprocessors A Analog to Digital Conversion Using the PIC16F684 Microcontroller 1) To use MPLAB IDE software, PICC Compiler, and external hardware to demonstrate the following: a. Analog to Digital Conversion b. Construct a circuit to demonstrate Analog to Digital Conversion using the PIC16F684 c. Develop Code to utilize the PIC16F684 Analog to Digital capabilities 1 Computer (PC) with an available USB Port MPLAB IDE and HI-Tech PICC Lite software installed on PC 1 PICkit 1 with USB cable 1 PIC16F684 supplied with PICkit 1 Starter Kit 1 Voltmeter 1 1000 picofarad capacitor (102) note: AKA 1 nanofarad or 0.001 microfarad 11 470 ohm resistors (yellow violet brown) 1 1 k ohm resister ( brown black red) 1 10k ohm potentiometer 10 LEDs or Bargraph Display below 1 LED Bargraph Display or 10 LEDs above Voltage Regulator Circuit (Parts only needed if not previously constructed) 1 Breadboard 1 Oscilloscope 1 Voltmeter 1 DC Power Supply or 9 volt battery 1 9 volt battery clip (if using a 9 volt battery) 1 LM7805 Voltage Regulator 1 0.33 microfarad capacitor (334) 1 0.1 microfarad capacitor (104) 1 470 ohm resistors (yellow violet brown) 1 LED 1

WARNINGS AND PRECAUTIONS 17.383 Microprocessors A 1) Never remove the PIC16F684 from an energized circuit 2) Do not construct circuits while energized 3) Follow electrical safety precautions Source File Locations 1) HI-TECH C PRO Toolsuite HI-TECH C Compiler for PIC10/12/16 MCUs C:\Program Files\HI-TECH Software\PICC\x.xx\bin\picc.exe 2) Microchip MPASM Toolsuite Where x.xx is the software version I.E. 9.70 MPASM Assembler (mpasmwin.exe) C:\Program Files\Microchip\MPASM Suite\mpasmwin.exe MPLINK Object Linker (mplink.exe) C:\Program Files\Microchip\MPASM Suite\mplink.exe MPLIB Librarian (mplib.exe) Programming the PIC16F684 C:\Program Files\Microchip\MPASM Suite\mplib.exe 1) Programming using the PICkit 1 a. Power down the PICkit 1 and the breadboard. Remove the PIC16F684 from the breadboard (if required) b. Install the PIC16F684 in the PICkit 1 c. Program the PIC16F684 2

d. Power down the PICkit 1. Remove the PIC16F684. Verify power is secured to the breadboard. Install the PIC16F684 (on breadboard). Power up the breadboard and verify proper circuit operation. 2) Programming the PIC16F684 using either the PICkit 2 or PICkit 3 WARNING when using the PICkit 2 or PICkit 3, you must remove the PICkit from the circuit after the PIC16F684 has been programmed in order for the circuit to operate properly a. Power down the breadboard b. Install the PICkit 2 or PICkit 3 onto the Programming header as shown in Figure 3A. c. Power on the breadboard d. Program the PIC16F684 e. Power down the development board and remove the PICkit 2 or PICkit 3. Power up the breadboard and verify proper circuit operation. Background Information Before we get into the specifics of the PIC16F684 Analog to Digital Converter (ADC) converter lets focus on the fundamentals of A/D conversions. First an analog signal is continuous in amplitude & time within certain limits, i.e., it changes smoothly without interruptions. An example is a sinusoidal signal. A Digital signal is discrete in amplitude and time i.e., it can only take certain specific values within certain limits at specific time intervals. When numbers are assigned to these steps (usually binary numbers) the result is a digital signal. An example is a square wave, a 1-Bit digital signal with its high level being a binary 1 and its low level being a binary 0. An Analog-to-Digital converter (ADC) is an electronic circuit that changes or converts a continuous analog signal into a digital signal without altering its critical content. An Analog-to-Digital converter samples an analog waveform at uniform time intervals and assigns a digital value to each sample. 3

Sampling is the process of analyzing the continuous analog signal with measurements taken at discrete and standard intervals. In conjunction with sampling the device needs to be able to hold the signal for a finite amount of time. During the hold time, the ADC will perform its function of converting the signal from analog to digital. The hold is performed via a storage capacitor. Up to the time the hold is commanded, the capacitor is tracking/sampling the analog signal. The PIC16F684 Analog-to-Digital converter (A/D) allows conversion of an analog input signal to a 10-bit binary representation of that signal. The PIC16F684 has eight analog inputs, multiplexed into one sample and hold circuit. The output of the sample and hold is connected to the input of the converter. The converter generates a binary result via successive approximation and stores the result in a 10-bit register. The voltage reference used in the conversion is software selectable to either VDD or a voltage applied by the VREF pin. There are three registers available to control the functionality of the A/D module: ANSEL (Register 9-1) ADCON0 (Register 9-2) ADCON1 (Register 9-3) The A/D conversion can be supplied in two formats, either left or right shifted. The ADFM bit (ADCON0<7>) controls the output format. Steps to follow for analog to digital conversion: 1. Configure the A/D module 2. Configure A/D interrupts (if desired) 3. Wait the required acquisition time 4. Start conversion 5. Wait for A/D conversion to complete 6. Read A/D Result register pair 7. For the next conversion go to step 1 or step 2 as required This lab will use the PIC16F684 ADC function. The results will be verified by comparing the actual input to the LED converted value. Pre-Lab Preparation o Develop the required code as outlined in the procedural steps o Construct the required circuit on your breadboard 4

Procedure Experiment 1. VOLTAGE REGULATOR CIRCUIT a. If not already constructed from a previous lab, construct the voltage regulator circuit as outlined in Experiment 1.b. through 1.h, otherwise go to Experiment 2. b. Review lab Warnings and Precautions. c. Construct the schematic shown in Figure 1 on your breadboard. DO NOT INCLUDE JP2. Some guidelines for your construction follows: 1. Locate your voltage regulator circuit in a corner of your board as this circuit will be required throughout the semester. d. Apply 9 volts to the VIN connection. e. Using the voltmeter and an oscilloscope, verify that the +5V_REG port reads +5 volts and the output is clean and free of interference. f. Power down the circuit. g. Construct the circuit shown in Figure 2. This will be a visual aid in determining if voltage is present (when the LED is turned on). h. Apply 9 volts to VIN connection and verify that the LED lights. i. Power down the circuit. Experiment 2. ANALOG TO DIGITAL CONVERSION a. Develop a MPLAB IDE Project using the Code provided in Figure 5 which is also contained in the text file called Lab_4A.txt located on the course website. The Code provided will execute as follows: 1. Performs Analog to Digital Conversion using the PIC16F684 and the circuitry of the PICkit 1 Starter Kit. 5

2. PICkit 1 Starter Kit LEDs will display the digital result of the ADC operation. The Most Significant Bit (MSB) is represented by LED D7. This corresponds to 2 10. The two Least Significant Bits (LSB) will not be displayed; therefore, D0 represents the 2 2 bit. We are ignoring the two least significant bits in this portion of the lab. PICKit 1 Starter Kit LED configuration is shown in Figure 3. 3. The PICkit 1 Starter Kit potentiometer RP1 is connected to RA0 and will be used to vary the voltage to the ADC (Figure 4). b. Examine the code provided along with the schematic shown in Figure 4. Understand how the Code was developed, what features of the PIC16F684 are turned on/off as well as what the expected voltages will be seen by the ADC. c. Modify the Code provided so that your code contains the following: 1. Code written in C. Use the PICC software to produce the code files. 2. Code contains header information as shown in Figure 6. 3. Save the program as Lab_4A.c. 4. Build you code. Once successful, burn the code to the PIC16F684 using the PICkit 1 Starter kit. d. Turn RP1 counter clock wise (CCW) until it hits the stops. All LEDs should be extinguished at this point. e. Slowly turn RP1 clock wise (CW). You should see the LEDs start to turn on/off. The binary representation of the LEDs will increase until all the LEDs are on when RP1 hits the other stop. f. Turn RP1 CCW until it hits the stops again. All LEDs should be extinguished at this point. g. Measure the voltage from RA0 (pin 13) to ground or at RP1 pin 2. h. Record the voltage from Experiment 2.g. in Table 1. Table 1 is also provided in Excel format on the Class Web Site. i. Rotate RP1 CW until your voltmeter reads 0.0 volts (NOTE: FULL CCW and 0.0 may be the same position). Record the state of each LED, the actual 6

voltage on your voltmeter, and calculate the voltage by using the LED display. j. Repeat Experiment 2.i. for all the values listed in Table 1. k. Insert a copy of your code, Lab_4A.c at the end of the lab report in the space provided as well as email a copy. Voltage (Volts) TABLE 1 LED State ("1" or "0") Actual Voltage Calculated Voltage D7 D6 D5 D4 D3 D2 D1 D0 FULL CCW 0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 FULL CW l. QUESTION: How accurate was the ADC as compared to the actual voltages applied to Pin 13 or RP1 pin 2? Experiment 3. ANALOG TO DIGITAL CONVERSION USING ALL 10 BITS a. Construct your own circuit that will utilize all 10 bits from the ADC and an analog input (0 to 5 volt DC) of the same type circuit shown in Figure 4. Circuit can be constructed such that it utilizes the LED configuration shown in Figure 3, however, you can construct the circuit as you desire. A circuit diagram shall be submitted with your Lab Report (hand drawn is acceptable). The following precautions need to be observed: 7

1. Protect the LEDs and PIC16F684 by using 470 ohm resisters, vice the 150 ohm resisters shown in Figure 3. b. Modify the Code from Experiment 2 or write your own Code that will perform the operations described in Experiment 3.a. Save the program as Lab_4B.c. c. Construct a Table similar to that of Table 1 to verify proper operation of your circuit and your code. d. When the hardware and software are functioning as desired, do the following: 1. Notify the instructor so the operation can be observed. Have the instructor initial your Lab Notebook in the space you provided. 2. Insert a copy of your code, Lab_4B.c at the end of the lab report in the space provided as well as email a copy. Summary: The microcontroller can be used for more than just digital input/output as demonstrated by this lab. The PIC16F684 has eight analog to digital converters available for use. The conversion performed by the device provides an accurate conversion of the analog value. Ease of use is also a plus. In real world applications we see that sensors provide analog outputs. Without the ability to convert these signals to a digital format would make processing these signals more complex. We have utilized both analog and digital applications in the process of performing this lab. Lab Report: 1. Use template provided on the Class Web Site. 8

Figure 1 Voltage Regulator Circuit 7805 Pin Connections - Top View 9

Figure 2 - PICkit 1 Starter Kit Power Indication Circuit 470 ohms 10

Figure 3 - PICkit 1 Starter Kit LED Layout 11

Figure 4 PICkit 1 Starter Kit ADC Input Circuit 12

Figure 5 Lab_4A.c Code #include <pic.h> / Function: main Description: D0 - D7 on PICkit 1 will Display the results of the ADC Notes: RA0 - Input from RP1 Returns: This routine contains an infinite loop / / Configuration Word / CONFIG(INTIO & WDTDIS & PWRTEN & MCLRDIS & UNPROTECT \ & UNPROTECT & BORDIS & IESODIS & FCMDIS); void PORTA_init(void); void ADC_Disp(void); void Delay_LED_On(void); int ADC_Value = 0; const char PORTA_Value[8] = { 0b010000, // D0 0b100000, // D1 0b010000, // D2 0b000100, // D3 0b100000, // D4 0b000100, // D5 0b000100, // D6 0b000010}; // D7 const char TRISA_Value[8] = { 0b001111, // D0 0b001111, // D1 0b101011, // D2 0b101011, // D3 0b011011, // D4 0b011011, // D5 0b111001, // D6 b111001}; // D7 Continued next page 13

main() { PORTA_init(); ANSEL = 1; TRISA0 = 1; ADCON0 = 0b00000001; ADCON1 = 0b00010000; Continued from previous page // Just RA0 is an Analog Input // Corresponding TRIS bit is set as input // Turn on the ADC // Bit 7 - Left Justified Sample // // Bit 6 Bit 4:2 - Use VDD - Channel 0 // Bit 1 - Do not Start // Bit 0 - Turn on ADC // Select the Clock as Fosc/8 ADC_Disp(); GODONE = 1; // Start A/D Conversion while(1 == 1) { // Loop Forever if (GODONE == 0) // Is A/D Conversion complete? { ADC_Disp(); // Display A/D Conversion Results ADC_Value = ADRESH; // Get new A/D value GODONE = 1; // Start the next A/D Conversion } else // A/D Conversion still in progress ADC_Disp(); } } / END OF main ROUTINE / / Function: PORT_init Description: Initializes PORTA to a known condition Notes: None Returns: None / void PORTA_init(void) { PORTA = 0; // All PORTA Pins are low CMCON0 = 7; // Turn off Comparators ANSEL = 0; // Turn off ADC return; } / END OF PORTA_init / Continued next page 14

Continued from previous page / Function: ADC_Disp Description: Displays the value of A/D Conversion on D0 - D7 Notes: Returns: None / void ADC_Disp(void) { int i; for (i = 0; i < 8; i++ ) { // Loop through Each of the 8 LEDS Delay_LED_On(); // Allows time for individual LEDs to light if ((ADC_Value & (1 << i)) == 0) PORTA = 0; else PORTA = PORTA_Value[i]; TRISA = TRISA_Value[i]; } // return; } / END OF ADC_Disp / / Function: delay_led_on Description: Causes a delay in program execution Notes: Delay was determined through trial and error Returns: None / void Delay_LED_On(void) { int j; for (j = 0; j < 60; j++); // Display "On" Loop return; } / END OF Delay_LED_On / 15

Figure 6 Required Header Code / Program Title: xxxx Program File Name: Lab_XA.c Microprocessors A 17.383 xxxxxxxx - Put in Semester (i.e. ) here xxxxxxxx - Put in your name here xx/xx/xx - Put date here / 16