Voltage Measurement with A PIC Microcontroller



Similar documents
Analog to Digital Conversion of Sound with the MSP430F2013

Chapter 12. Data Converters. à Read Section 19 of the Data Sheet for PIC18F46K20. Updated: 4/19/15

Microcontroller Code Example Explanation and Words of Wisdom For Senior Design

Using Arduino Microcontrollers to Sense DC Motor Speed and Position

Getting Started with PIC24F/PIC24H Programming and Interfacing in C

USB / Data-Acquisition Module NOW LEAD-FREE

Data Acquisition Module with I2C interface «I2C-FLEXEL» User s Guide

Conversion Between Analog and Digital Signals

Tire pressure monitoring

Wireless Security Camera

AN-812 APPLICATION NOTE

Lab 3 Microcontroller programming Interfacing to Sensors and Actuators with irobot

Digital To Analog Converter with Sine Wave Output

Interfacing Of PIC 18F252 Microcontroller with Real Time Clock via I2C Protocol

Evo Laser Firmware Developer s Manual

Microcomputers. Analog-to-Digital and Digital-to-Analog Conversion

PLL frequency synthesizer

Analog-to-Digital Converters

Chapter 13. PIC Family Microcontroller

Section 19. Voltage Reference

PICNet 1. PICNet 1 PIC18 Network & SD/MMC Development Board. Features. Applications. Description

Data Sheet. Adaptive Design ltd. Arduino Dual L6470 Stepper Motor Shield V th November L6470 Stepper Motor Shield

Design and Construction of Microcontroller Based Charge Controller for Photovoltaic Application

HANDLING SUSPEND MODE ON A USB MOUSE

Adafruit SHT31-D Temperature & Humidity Sensor Breakout

Eric Mitchell April 2, 2012 Application Note: Control of a 180 Servo Motor with Arduino UNO Development Board

INTERRUPTS. There are 2 methods for communicating between the microcontroller and the external system: POLLING INTERRUPTS

Your Multimeter. The Arduino Uno 10/1/2012. Using Your Arduino, Breadboard and Multimeter. EAS 199A Fall Work in teams of two!

Develop a Dallas 1-Wire Master Using the Z8F1680 Series of MCUs

Arduino DUE + DAC MCP4922 (SPI)

Real Time Clock USB Evaluation Board V3.0

Model 201 Wiegand Touchpad Reader Installation Guide

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

SC14404 Complete Baseband Processor for DECT Handsets

Arduino Lesson 14. Servo Motors

Mini Quadrotor Recon Drone

1. Learn about the 555 timer integrated circuit and applications 2. Apply the 555 timer to build an infrared (IR) transmitter and receiver

Electronics I - Laboratory 1 Diode I/V Characteristics

PCB Layout for the Ethernet PHY Interface

Schematic & Parts List: PIC16F688 Satellite Tracker & Rotor Controller

An Introduction to MPLAB Integrated Development Environment

If an occupancy of room is zero, i.e. room is empty then light source will be switched off automatically

ETEC Digital Controls PIC Lab 10 Pulse Width Modulation

QUICK START GUIDE FOR DEMONSTRATION CIRCUIT BIT DIFFERENTIAL ADC WITH I2C LTC2485 DESCRIPTION

Arduino Lesson 9. Sensing Light

ic-mq EVAL MQ1D EVALUATION BOARD DESCRIPTION

Section 28. In-Circuit Serial Programming (ICSP )

M68EVB908QL4 Development Board for Motorola MC68HC908QL4

SPI. Overview and Use of the PICmicro Serial Peripheral Interface. Getting Started: SPI

LC898300XA. Functions Automatic adjustment to the individual resonance frequency Automatic brake function Initial drive frequency adjustment function

Pmod peripheral modules are powered by the host via the interface s power and ground pins.

MAX5417L Evaluation Kit/Evaluation System

MCP4725 Digital to Analog Converter Hookup Guide

DS2438EVKIT+ Smart Battery Monitor Evaluation Kit

Real-time Operating Systems Lecture 27.1

LM 358 Op Amp. If you have small signals and need a more useful reading we could amplify it using the op amp, this is commonly used in sensors.

Bidirectional wireless communication using EmbedRF

AXE114S BINARY CLOCK. revolution Revolution Education Ltd. Web: Version /09/08 AXE114.PMD.

Design and Construction of Variable DC Source for Laboratory Using Solar Energy

DS2149DK/DS21349DK T1/J1 Line Interface Unit Design Kit

Web Site: Forums: forums.parallax.com Sales: Technical:

How To Use A Watt Saver On A Microcontroller (Watt Saver) On A Cell Phone Or Mp3 Player

AN111: Using 8-Bit MCUs in 5 Volt Systems

A Guide to IR/PIR Sensor Set-Up and Testing

PolyBot Board. User's Guide V1.11 9/20/08

Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science Electronic Circuits Spring 2007

UniPi technical documentation REV 1.1

It should be corrected as indicated by the shading below.

KiCad Step by Step Tutorial

Configuring SMC-Flex for Communications over Remote I/O Network using 20-COMM-R Card This document is intended to be used for reference purposes only.

Tutorial for MPLAB Starter Kit for PIC18F

The FT6x06 series ICs include FT6206 /FT6306, the difference of their specifications will be listed individually in this datasheet.

Electronic Brick of Current Sensor

Complete Train Control. Run Your Trains, Not Your Track!

Part 1. MAX BIT DAC with an Arduino Board. MIDI to Voltage Converter Part1

ABB Drives. User s Manual HTL Encoder Interface FEN-31

Arduino Due Back. Warning: Unlike other Arduino boards, the Arduino Due board runs at 3.3V. The maximum. Overview

EVAL-AD5680. Single Channel, 18-Bit, Serial Input, Voltage Output DAC Evaluation Board FEATURES GENERAL DESCRIPTION

Adafruit MCP9808 Precision I2C Temperature Sensor Guide

Peak Power Tracker Circuit Description (from

Microcomputer Based Electronics: Using the C Stamp in Pre- Engineering, Technology, and Engineering Programs

ADS9850 Signal Generator Module

DHT11 Humidity & Temperature Sensor D-Robotics UK (

Touch Screen for Pictiva OLED display. Application Note. Introduction

POCKET SCOPE 2. The idea 2. Design criteria 3

RC2200DK Demonstration Kit User Manual

ENGI E1112 Departmental Project Report: Computer Science/Computer Engineering

The I2C Bus. NXP Semiconductors: UM10204 I2C-bus specification and user manual HAW - Arduino 1

Microcontroller Programming Beginning with Arduino. Charlie Mooney

K128. USB PICmicro Programmer. DIY Electronics (HK) Ltd PO Box 88458, Sham Shui Po, Hong Kong. mailto:

ÇANKAYA ÜNİVERSİTESİ ECE 491 SENIOR PROJECT I ERDİNÇ YILMAZ

Micro-Step Driving for Stepper Motors: A Case Study

AVR125: ADC of tinyavr in Single Ended Mode. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

40-Segment 2.54 pitch LED Bar Display Board User s Guide

JTAG-HS2 Programming Cable for Xilinx FPGAs. Overview. Revised January 22, 2015 This manual applies to the HTAG-HS2 rev. A

LED board datasheet EB

Fondamenti su strumenti di sviluppo per microcontrollori PIC

EasyPIC4 User s Manual

Green House Monitoring and Controlling Using Android Mobile Application

Transcription:

Voltage Measurement with A PIC Microcontroller Ryan Popa 03/30/2012 Design Team 3 Abstract The purpose of this application note is to explain how to measure a voltage using a PIC18F4520 microcontroller. This note will start by explaining how to correctly power and wire the microcontroller for sensing voltage. It will then explain the code needed to measure a voltage and how it works. Keywords: PIC, voltage sensing, voltage measurement, PIC18F4520 Background The PIC18F4520 is a 40pin microcontroller with numerous functions and applications. One of its many functions is analog to digital conversion. Through this the PIC is capable of reading an analog voltage and turning it into a digital readout that can be used in a program. The circuitry and code required to create a basic voltage sensor is minimal. This note assumes a basic knowledge of how to create a PIC program and load it from the computer to the microcontroller. The objective of this note is to show how to wire a RJ11 jack to a PIC to allow communication with a computer, how to wire the PIC to power, how to connect an external clock to a PIC and where to connect a voltage source to read its value. It will also provide a small program to read in a voltage and convert it into a digital form for use within the program. Connecting the PIC Before any code can be written the PIC must first be connected and powered on. Minimal wiring for PIC operation is connecting it to power and wiring a communication port to be connected to a computer. The PIC18F4520 uses a 5V DC power source and communicates with a computer through a RJ11 jack like the one shown below, the pin layout of the jack below will be used as a reference for wiring the PIC in the rest of this note.

Connect pins 1, 4 and 5 on the RJ11 jack to pins 1, 40 and 39 on the PIC respectively. Pin 2 on the jack should be wired to VDD and pin 3 should be wired to ground. A properly wired setup is shown below where the RJ11 jack is connected on the bottom with pins 1 6 wired from left to right. Pin 6 on the RJ11 jack is not used.

The PIC microcontroller will also need to be wired to power in order to work properly. Pins 11 and 32 should be wired to VDD and pins 12 and 31 should be wired to ground. The last thing the controller needs to work properly is a clock. The PIC18F4520 does not have an internal clock so a 40M000 clock like the one below will be connected to the microcontroller. The bottom left corner of the clock has a little notch cut out of it to indicate its orientation. The bottom right pin of the clock needs to be wired to ground and the top left pin needs to be wired to VDD. The top right pin of the clock should be wired to pin 13 on the microcontroller. Lastly a 10KΩ resistor needs to be wired from pin 1 on the PIC to VDD. This resistor is acting as a pull-up resistor and keeps the microcontroller out of the reset state. A fully wired RJ11, PIC microcontroller and 40M000 clock is shown below.

Writing the Code Now that the microcontroller is powered and hooked up the code needs to be loaded to measure the voltage. The analog voltage will be connected to pin 2 of the PIC, and use VDD as a reference value. The digital value of the voltage will be read as an integer and the equivalent analog voltage can be calculated as a fraction of VDD. The voltage can be calculated as (x/1024) * VDD. As an example: using a VDD of 5V, the value returned from pin 2 of the PIC is 884. This means the analog voltage at pin 2 is

(884/1024) * 5V = 4.32V The annotated code to do this is shown below. #include <p18cxxx.h> #include <usart.h> #include <ADC.h> #pragma config LVP=OFF #pragma config WDT=OFF void rx_handler (void); //Declare the ISR function int adc_result; //The variable to store the ADC value in void main() { RCONbits.IPEN = 1; /* Enable interrupt priority */ IPR1bits.RCIP = 1; /* Make receive interrupt high priority */ INTCONbits.GIEH = 1; /* Enable all high priority interrupts */ OpenADC(ADC_FOSC_32 & ADC_RIGHT_JUST & ADC_12_TAD, ADC_CH0 & ADC_INT_OFF, 0); //open adc port for reading ADCON1 =0x00; //set VREF+ to VDD and VREF- to GND (VSS) while(1) { ConvertADC(); //perform ADC conversion while(busyadc()); //wait for result adc_result = ReadADC(); //get ADC result //////////////////////////////////////////////////////////////////////// // adc_result is the digital representation of the voltage at pin2 // it is a number out of 1024 that specifies a fraction of VDD //////////////////////////////////////////////////////////////////////// } } Conclusion This application note showed how to wire a PIC18F4520 microcontroller for basic voltage sensing and provided some code to read a voltage from pin 2 of the microcontroller. Also, it explained how to calculate an analog value from the digital result of the ADC measurement. This technique can be combined with any other amount of code to make a multifunction PIC program capable of reacting to changes in an analog voltage input.

References PIC18F4520 Data sheet: http://plc.mechatronika.hu/piclei/18f24-25-44-45_20.pdf Information about ADC: http://extremeelectronics.co.in/microchip-pic-tutorials/using-analog-to-digitalconverter-%e2%80%93-pic-microcontroller-tutorial/ Capstone lab about PIC: http://www.egr.msu.edu/classes/ece480/capstone/forminiprojects/lab3.pdf