Implementation of Temperature Sensor on PICM4520 Microcontroller

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

C:\Users\cunningh\StaysOnPC\ME430 Downloads & Projects\exam2_problem1\problem1Cunningham.c

ADC: Analog to Digital Conversion

Earthshine Design Arduino Starters Kit Manual - A Complete Beginners Guide to the Arduino. Project 13. Serial Temperature Sensor

Send Raspberry Pi Data to COSM

EK307 Lab: Microcontrollers

EEE394 Microprocessor and Microcontroller Laboratory Lab #6

Using a Temperature Sensor

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

Lab 4: Determining temperature from a temperature sensor

Evaluation Board User Guide UG-047

ECE 480 Team 5 Introduction to MAVRK module

Hitachi H48C 3-Axis Accelerometer Module (#28026)

TMP36 Temperature Sensor

COL862 - Low Power Computing

Lab-3: LCDs Serial Communication Analog Inputs Temperature Measurement System

The Atmel ATmega328P Microcontroller

LAB 1 Binary Numbers/ Introduction to C. Rajesh Rajamani. ME 4231 Department of Mechanical Engineering University Of Minnesota

Experiment 10 Fall 2012

The amount of current drawn and the temperature generated by DC motor are crucial in understanding the performance and reliability of motors.

IMPROVING PROCESS CONTROL APPLICATIONS BY USING IP COMMUNICATIONS

ADC to I 2 C. Data Sheet. 10 Channel Analog to Digital Converter. with output via I 2 C

Lab 5: LCD and A/D: Digital Voltmeter

PIC18F452 Oven Calibrator Using the MAX6674/MAX6675 Thermocouple-to-Digital Converter. Group: SMOKE Duston Cline Adam McCorkle

ECE 2036 Lab 4 Setup and Test mbed I/O Hardware Check-Off Deadline: Thursday, March 17, Name:

Intel Stratix 10 Analog to Digital Converter User Guide

Microcontroller Based Automatic Temperature Control System

MT2 Introduction Embedded Systems. MT2.1 Mechatronic systems

University Program Advance Material

TEMPERATURE SENSOR. Revision Class. Instructor / Professor LICENSE

Introduction to Mechatronics and the Mechatronic Design Center Microchip Technology Incorporated. All Rights Reserved. 1

ICP05 IBOARD LITE ICP05. - iboard lite

Remote Controlled KitchenAid Mixer for the Clients at ADEC. Appendices. Arnaud Bacye Karina Dubé Justin Erman Matthew Martin

Clock and Fuses. Prof. Prabhat Ranjan Dhirubhai Ambani Institute of Information and Communication Technology, Gandhinagar

Manual iaq-engine Indoor Air Quality sensor

Lab 5: LCD and A/D: Digital Voltmeter

Microcontroller Introduction

Bachelor of Engineering in Computer and Electronic Engineering

PVK40. User's manual. Feature Rich Development and Educational Kit for 40-pin Microchip PIC microcontrollers

Laboratory Exercise 5 - Analog to Digital Conversion

Color 7 click. PID: MIKROE 3062 Weight: 19 g

Lecture (04) PIC 16F84A programming I

AD Microcontroller No-OS Driver

PIC Microcontroller Introduction

LAMPIRAN I (LISTING PROGRAM)

Embedded Technology for Remote Data Logging, Monitoring and Controlling Using GSM/GPRS

ARDUINO MEGA INTRODUCTION

Environmental Data Acquisition Using (ENC28J60)

Temperature and Humidity Measurement System

The Atmel ATmega168A Microcontroller

n/a PIC12F629-I/P (RC) n/a PIC12F629-I/SN (RC) n/a PIC12F675-I/P (RC) n/a PIC12F675-I/SN MICROCONTROLLER (RC)

eip-24/100 Embedded TCP/IP 10/100-BaseT Network Module Features Description Applications

ECE2049: Embedded Computing in Engineering Design C Term Spring 2018 Lecture #15: More ADC Examples

ECG 2 click PID: MIKROE Weight: 30 g. Condition: New product. Table of contents

High Resolution Digital Weigh-Scale Design Using Z8 Encore! Microcontrollers

Pressure 4 click. PID: MIKROE 3020 Weight: 24 g

Onwards and Upwards, Your near space guide Overview of the NearSys Two Sensor Temperature Array Figure 1. A complete Two Sensor Temperature Array

DEV16T. LCD Daughter board

BalloonSat Sensor Array

Embedded Systems Lab Lab 1 Introduction to Microcontrollers Eng. Dalia A. Awad

Introduction to Microcontroller Apps for Amateur Radio Projects Using the HamStack Platform.

Freescale Semiconductor, I

Figure 1. A complete Temperature Sensor

Introduction to Programming. Writing an Arduino Program

PmodJSTK2 Reference Manual. Overview. 1 Functional Descriptions. Revised July 19, 2016 This manual applies to the PmodJSTK2 rev. C

Embedded Systems. PIC16F84A Internal Architecture. Eng. Anis Nazer First Semester

Thermo 6 click PID: MIKROE-2769

The Freescale MC908JL16 Microcontroller

AIRRS. Infrared Distance Measurement Analog Output Signal Narrow Field of View Reliable Easy to use. Analog Infra-Red Ranging System

PIXI click PID: MIKROE Weight: 28 g

ECE2049: Embedded Computing in Engineering Design A Term Fall 2017 Lecture #16: Interrupts and Event Driven Code

DSD: Delta Sigma Demodulator. XMC microcontrollers September 2016

Getting acquainted with the development tools June 27, 2006 ELE492 Embedded System Design Exercise 1

Ali Karimpour Associate Professor Ferdowsi University of Mashhad

ATMEGA32 MUSIC PLAYER

Embedded systems. Exercise session 3. Microcontroller Programming Lab Preparation

DEVBOARD3 DATASHEET. 10Mbits Ethernet & SD card Development Board PIC18F67J60 MICROCHIP

ATHENA32 PIC32 Evaluation Board ATHENA32. Product Datasheet. Francesco Ficili Date 13/01/2019. Pag. 1

Embedded Systems and Software

Project 24 LCD Temperature Display

The Analog to Digital Converter (ADC)

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

MARSLIFE Technical Report #3

TEMPERATURE AND HUMIDITY MONITOR AND CONTROL SYSTEM

Arduino Uno R3 INTRODUCTION

EasyPIC5 Development System

Microcontrollers and Interfacing week 10 exercises

Lab 5: EBI and ADC: Digital Voltmeter

ESPino - Specifications

A Simple & Economical Method For Reading A Thermistor With An EtherMeter.

SENSYLINK Microelectronics Co., LTD. (CT1701) Single-Wire Digital Temperature Sensor

8051 Training Kit Lab Book

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

Physics 120/220. Microcontrollers Extras. Prof. Anyes Taffard

TMP36 Temperature Sensor

I2C-AI418S I2C Bus Voltage and Current Analog Input Board

AVR XMEGA Product Line Introduction AVR XMEGA TM. Product Introduction.

Project 17 Shift Register 8-Bit Binary Counter


BIG8051. Development system. User manual

Transcription:

Implementation of Temperature Sensor on PICM4520 Microcontroller Application Note Brad Pasbjerg Design Team 7 March 30 th, 2012 1

Table of Contents Cover... 1 Table of Contents... 2 Abstract... 3 Keywords... 3 Introduction and Background... 3 Objective... 4 Configuring the ADC... 4 Programming the PIC18F4520... 6 Include Files... 6 Define Variables... 6 Main Program... 6 Conclusion... 8 References... 9 2

Abstract The TC1046VNBTR is a powerful temperature sensor that can transmit temperature information. This application note discusses how to implement the TC1046VNBTR to an ADC port on the PIC18F4520 Microcontroller (MCU). Keywords Analog to Digital Converter (ADC), Microcontroller Unit (MCU), MegaHertz (MHz), MilliVolts (mv) Introduction and Background The TC1046 is a linear output temperature sensor whose output voltage is directly proportional to measured temperature. The TC1046 can accurately measure temperature from -40 C to +125 C. The reading off this device will give us the actual temperature where the sensor is located The PIC18F4520 is a Microcontroller that has a high computational performance, with the addition of high endurance, Enhanced Flash program memory. Along with these features the PIC chip also has an Analog-to-Digital (A/D) converter module. This module has 13 input ports show in Figure 1. The ADC has a resolution of 10 bits, so the digital reading range is from 000 to 3FF as show in Figure 2. Based on the ADC reading and the known reference voltage you are able to derive the voltage reading by multiplying the reading by a constant. 3 Figure 1 PIC18F4520 ADC Ports

Figure 2 A/D Transfer Function Objective The objective of this document is to demonstrate how to implement the TC1046 temperature sensor and program the PIC18F4520 ADC ports, including initializing the Microcontroller ADC and reference ports, collecting data from the port, and how to interpret that data. Configuring the ADC The Microcontroller first needs to be powered in order to work. There are 4 pins that need to be connected to power the chip. Pins 11 & 32 need to be connected to 5V, pins 12 & 32 need to be connected to ground. Also without a clock the MCU will be unable to perform commands, Pin 13 needs to be connected to an Oscillator. The frequency of the Oscillator is typically 4 MHz. The next steps are to power the TC1046 and create a reference voltage. In order to power the temperature sensor, it is easiest to attach to a surface mount board due to its small size. As seen in figure 3, Pin1 will connect to the 5V power supply, Pin 3 will connect to ground, and the Pin 2, V out, will connect to the input ADC Pin ( for this application, the ADC port will be Pin 2 on the MCU). 4

Figure 3 TC1046 Package Type For creating the reference voltage the maximum voltage at ADC port (V OUT, Pin 2, of the temperature sensor) must be known. From the TC1046 data sheet we find the voltage range to be from 174mV to 1.205V. With a max of 1.205V, the reference should be made as close as possible to have the highest accuracy. The design in figure 4 shows a voltage divider that will produce 1.513V. The output of the voltage divider should go to Pin 5 on the MCU. Figure 4 Voltage Divider for Reference 5

Programming the PIC18f4520 Include Files The programming requires several modules in order to function. The required modules are ADCON1.c, SetChanADC.c, ConvertADC.c, BusyADC, and ReadADC. These can all be found within ADC.h. Useful libraries for this application are #include <p18cxxx.h> #include <string.h> #include <stdio.h> #include <ADC.h> #include <stdlib.h> Define Variables Variables must be defined to do the necessary calculations to retrieve the temperature from the ADC. A double is used in order to obtain a decimal value. All of the variables below like voltage and temperature will be determined within a few decimal points of accuracy. Integers like count and adc_result are used in order to follow a desired flow of programming. Main Program int adc_result; long int count; double number = 0; double voltage = 0; double tempc = 0; double tempf = 0; double test = 0; The first part of the program initializes the functions I call in the main program. These call functions help the main look clean and help visualize the flow of the program. void TempCalc ( void ); void VoltageAvg ( void ); 6

This part of the code is the main which shows the flow of the program itself. The first thing the main does is initialize the ADC ports so the conversion uses the reference voltage we made at Pin 5 and ground to calculate the hexadecimal result. The main then goes into a continuous while loop that continuously checks the ADC. This process does not stop until the system is forced to stop. So the temperature is being tracked in real time. void main () //Temp Sensor Initial OpenADC(ADC_FOSC_32 & ADC_RIGHT_JUST & ADC_12_TAD, ADC_CH0 & ADC_INT_OFF, 0); //open adc port for reading ADCON1 =0x10; //set VREF+ to Pin 5 and VREF- to GND (VSS) while ( 1 ) SetChanADC(ADC_CH0); //Set ADC to Pin 2 VoltageAvg(); TempCalc(); The VoltageAvg function first enters a for loop and retrieves the ADC result in hexadecimal form. The variable holding this is adc_result. The result is then transformed into a decimal using number. The voltage is then calculated using the formula for ADC conversions for a 10-bit number and reference voltage measured to be 1.509V. The purpose of the for loop is to retrieve an averaged value for the temperature sensor. This helps to cancel the effect of noise from the sensor and voltage supplies, which often causes inaccurate readings. The TempCalc function takes the voltage from the previous function and uses an equation from the TC1046 datasheet to calculate the temperature in Celsius and Fahrenheit. These values can now be used in combination with other applications to produce the temperature control system. 7 void VoltageAvg ( void ) for(count = 0; count < 50; count++) ConvertADC(); //perform ADC conversion while(busyadc()); //wait for result adc_result = ReadADC(); //get ADC result if(adc_result & 0x0008) number=8+number; if(adc_result & 0x0004) number=4+number;

if(adc_result & 0x0002) number=2+number; if(adc_result & 0x0001) number=1+number; if(adc_result & 0x0080) number=128+number; if(adc_result & 0x0040) number=64+number; if(adc_result & 0x0020) number=32+number; if(adc_result & 0x0010) number=16+number; if(adc_result & 0x0800) number=2048+number; if(adc_result & 0x0400) number=1024+number; if(adc_result & 0x0200) number=512+number; if(adc_result & 0x0100) number=256+number; voltage = (voltage + (number*1.509/1023))/2; number = 0; void TempCalc ( void ) tempc = (voltage*1000-424)/6.25; tempf = tempc*9/5+32; voltage = 0; Conclusion As demonstrated by this program, temperature sensing applications can be handled by simple wiring and programming. The above program is able to calculate temperatures in Celsius and Fahrenheit that would be recommended to be used in an LCD display or a PID controller applications. 8

References TC1046 Temperature sensor data sheet http://ww1.microchip.com/downloads/en/devicedoc/21496b.pdf PIC18F4520 Microcontroller data sheet http://ww1.microchip.com/downloads/en/devicedoc/39631a.pdf 9