Measuring Resistance Using Digital I/O



Similar documents
AUTOMATIC NIGHT LAMP WITH MORNING ALARM USING MICROPROCESSOR

Using a Thermistor to Measure Temperature. Thermistors are resistors that vary their resistance according to temperature.

MEITRACK Fuel Sensor User Guide. Applicable Model: MVT600/T1/MVT800/T333

8051 MICROCONTROLLER COURSE

Designing VM2 Application Boards

Accurate Measurement of the Mains Electricity Frequency

Conversion Between Analog and Digital Signals

COM Port Stress Test

etape Continuous Fluid Level Sensor Operating Instructions and Application Notes

Lab Experiment 1: The LPC 2148 Education Board

RIGtalk. Revision 5. Owner s Manual 2012.

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

UDG1000 Hach PCX2200 Serial Port Input Driver configuration

PACKAGE OUTLINE DALLAS DS2434 DS2434 GND. PR 35 PACKAGE See Mech. Drawings Section

Wiki Lab Book. This week is practice for wiki usage during the project.

Advanced Data Capture and Control Systems

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

Testing PCI/ISA & PCMCIA Serial Cards

A Digital Timer Implementation using 7 Segment Displays

Tutorial for MPLAB Starter Kit for PIC18F

NortechCommander Software Operating Manual MAN R6

udrive-usd-g1 Embedded DOS micro-drive Module Data Sheet

Temperature & Humidity SMS Alert Controller

Keep it Simple Timing

User Manual. AS-Interface Programmer

Kokii BatteryDAQ. BMS Software Manual. Battery Analyzer Battery DAS

8-Bit Flash Microcontroller for Smart Cards. AT89SCXXXXA Summary. Features. Description. Complete datasheet available under NDA

Digital Single Axis Controller

TCP/IP MODULE CA-ETHR-A INSTALLATION MANUAL

User's Guide. Integrating Sound Level Datalogger. Model Introduction

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

Using Xbee in Serial Communication

Crow Limited Warranty. Print Version 017

SUDT AccessPort TM Advanced Terminal / Monitor / Debugger Version 1.37 User Manual

AVR151: Setup and Use of the SPI. Introduction. Features. Atmel AVR 8-bit Microcontroller APPLICATION NOTE

Tire pressure monitoring

Debouncing Switches. Mechanical switches are one of the most common interfaces to a uc.

AN2680 Application note

Serial Communications

ARRL Morse Code Oscillator, How It Works By: Mark Spencer, WA8SME

NTE2053 Integrated Circuit 8 Bit MPU Compatible A/D Converter

USER GUIDE EDBG. Description

DVI to Analog Converter

An Introduction to MPLAB Integrated Development Environment

HANDLING SUSPEND MODE ON A USB MOUSE

Current Digital to Analog Converter

Brushless DC Motor Controller Product Specification Assembly 025F0129

A Lesson on Digital Clocks, One Shots and Counters

Application Note 82 Using the Dallas Trickle Charge Timekeeper

How to Read a Datasheet

A Lesson on Digital Clocks, One Shots and Counters

Sierra Dual 24 Volt Brushless DC Motor Controller Product Specification

Controlling a Dot Matrix LED Display with a Microcontroller

Flash Corruption: Software Bug or Supply Voltage Fault?

RDF1. RF Receiver Decoder. Features. Applications. Description. Ordering Information. Part Number Description Packages available

Special Lecture. Basic Stamp 2 Programming. (Presented on popular demand)

DS1621 Digital Thermometer and Thermostat

DATASHEET. ADAM Arduino Display Adaptor Module. Arduino Compatible Shield P/N: 4Display-Shield-FT843 For the 4D Systems 4DLCD-FT843 Display

Microcontroller Code Example Explanation and Words of Wisdom For Senior Design

Portal Software GSM-PRO Run LED displays module activity Com LED displays activity on the GSM network GSM-PRO

CHAPTER 11: Flip Flops

8-bit RISC Microcontroller. Application Note. AVR182: Zero Cross Detector

BLWR23MDA Series. 24V, 15A Brushless Controller / Motor. User s Guide. 910 East Orangefair Lane, Anaheim, CA info@anaheimautomation.

Point of view HDMI Smart TV dongle Mini RF Keyboard

RS232 Board datasheet

ADC-20/ADC-24 Terminal Board. User Guide DO117-5

DS1821 Programmable Digital Thermostat and Thermometer

APPLICATION NOTE. Atmel AT01095: Joystick Game Controller Reference Design. 8-/16-bit Atmel Microcontrollers. Features.

C8051F020 Utilization in an Embedded Digital Design Project Course. Daren R. Wilcox Southern Polytechnic State University Marietta, Georgia

AVR353: Voltage Reference Calibration and Voltage ADC Usage. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

How to design and implement firmware for embedded systems

LAB4: Audio Synthesizer

ET-BASE AVR ATmega64/128

APPLICATION. Using the PB-100 to Make Calls and Announcements From a Database. Using the PB-100 for All-Call Dialing

Radio sensor powered by a mini solar cell the EnOcean STM 110 now functions with even less light

Cold-Junction-Compensated K-Thermocoupleto-Digital Converter (0 C to C)

Bluetooth + USB 16 Servo Controller [RKI-1005 & RKI-1205]

AN3265 Application note

Antenna Rotator System

C Programming. for Embedded Microcontrollers. Warwick A. Smith. Postbus 11. Elektor International Media BV. 6114ZG Susteren The Netherlands

Supply voltage Supervisor TL77xx Series. Author: Eilhard Haseloff

2.0 Command and Data Handling Subsystem

PC Base Adapter Daughter Card UART GPIO. Figure 1. ToolStick Development Platform Block Diagram

EVAL-UFDC-1/UFDC-1M-16

User Manual. Humidity-Temperature Chart Recorder. Model RH520

Designing an Induction Cooker Using the S08PT Family

APPLICATION NOTES: Dimming InGaN LED

Section 3. Sensor to ADC Design Example

AVR Butterfly Training. Atmel Norway, AVR Applications Group

Preview of the book Testing Electronic Components. Brought to you by Jestine Yong.

Proactive Performance Management for Enterprise Databases

INTMOD485-LH Protocol Converter

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

Application Note SX V Timer (Next Gen 555) Application Note AN Advanced Communications and Sensing

INTEGRATED CIRCUITS. NE558 Quad timer. Product data Supersedes data of 2001 Aug Feb 14

User Manual. Product Model: MiTraveler 10C3. OS: Android 4.0

Production Flash Programming Best Practices for Kinetis K- and L-series MCUs

Thermistor. Created by Ladyada. Last updated on :30:46 PM EDT

FFT Frequency Detection on the dspic

USER GUIDE Programming Adapter Cable for Fujitsu Flash Microcontroller- F²MC-16LX/FR Family Fujitsu Microelectronics America, Inc.

Transcription:

Measuring Resistance Using Digital I/O Using a Microcontroller for Measuring Resistance Without using an ADC. Copyright 2011 John Main http://www.best-microcontroller-projects.com Page 1 of 10

Table of Contents Legal...3 Resources...4 Essential Ezine...4 PIC C Course...4 PIC Interrupt Secrets...5 State Machine Secrets...5 Measuring Analogue Parameters With No ADC...6 Measuring A Resistance...6 PC Joystick Method...7 Calibration...8 Conversion...8 Applied to the PIC...8 Operation...9 RS232 Settings...10 RS232 output...10 Device...10 Compiler...11 Code Download...11 http://www.best-microcontroller-projects.com Page 2 of 10

Rights NOTICE: You DO Have the Right Give Away This Report, As long as you don t change anything, use SPAM or generally do something you re not supposed to do. Copyright 2011 John Main http://www.best-microcontroller-projects.com All rights reserved. No part of this ebook may be reproduced, stored in a retrieval system or transmitted in any form or by any means electronic, mechanical, photocopying, recording or otherwise without express written, dated and signed permission from the author John Main. Legal DISCLAIMER AND/OR LEGAL NOTICES: Terms of use: All software, hardware and information found in this ebook or associated with it shall be hereafter referred to as the product. All persons using or acting on the product shall be hereafter referred to as the user. By using the product the user agrees to abide by the following conditions. Disclaimer: All products are provided 'as is' and without warranty of any kind, either expressed or implied. The entire risk as to the quality and performance of the product is borne by the user. Should the product prove defective in any respect, the user will assume the entire cost of any service and repair and will assume full liability for any indirect, special, incidental or consequential damages arising out of the use of or inability to use the product, including, without limitation, damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses, even if advised of the possibility thereof, and regardless of the legal or equitable theory (contract, tort or otherwise) upon which the claim is based. http://www.best-microcontroller-projects.com Page 3 of 10

Resources PIC C Course A Complete C course for PIC micros in 11 parts. CLICK the image. Or Click Here PIC Interrupt Secrets How to Use PIC Interrupts to Maximum effect. CLICK the image. Or Click Here. State Machine Secrets. How to use state machines to create Solutions to complex problems including fully debugged examples one is coding a scrolling menu on a standard LCD display. CLICK the Image Or Click Here. http://www.best-microcontroller-projects.com Page 4 of 10

Measuring Analogue Parameters With No ADC Here's a trick I have been meaning to try and it could be useful for you if you either run out of ADC inputs or your device doesn't have one in the first place. It's not a true analogue measurement but allows you to measure a resistance that results in an analogue voltage e.g. components that vary their resistance in response to a physical parameter. Quite often you will be using components that change their resistance depending on a physical parameter e.g. temperature (TCR), humidity, Light (LDR), potentiometer (POT) and the method described here will let you measure their resistances without using an ADC. The idea is not new since it was first used on PCs to implement very cheap analogue input for joysticks using only digital inputs. A single joystick is made from two orthogonal potentiometers 100k-470k and the trick is getting the value from the pots into the PC since, at the time, ADCs were tons of money so there was no way they would manufacture a joystick with ADCs - just for game playing! It's done using capacitors. Measuring A Resistance As any engineer will tell you their first experience of (difficult at the time) equations is when you solve the differential equations for charging and discharging a capacitor and you figure out the RC time constant Tor. That time constant is the key since if you keep the capacitance the same and vary the resistance then the time taken for charging the capacitor will vary in proportion to the value of the resistance. If you choose the capacitance and max. pot value appropriately then you can cycle through measurements quickly enough (for game playing) so that it appears that the pot is continuously read. All you need is a way of discharging the capacitor and then apply a known voltage to the capacitor via the pot. http://www.best-microcontroller-projects.com Page 5 of 10

The Basic PC Joystick Interface (reads one of the four potentiometers - some game pads have two joysticks) PC Joystick Method This is the way that the PC joystick was read (although now more reliable methods are used) and it employs a monostable which when triggered discharged the capacitor. The monostable then sets its output low until the capacitor voltage reaches a threshold at which point the output goes high. Therefore the time taken for the capacitor to charge is proportional to the value of the pot so the value of the pot can be estimated. By measuring the duration of the monostable signal you obtain a value that is proportional to the value of the resistance. For the PC this was not a spectacular success for the following reasons: PC computer speeds were different from each other. Port interfaces were different from each other. Problems with OS differences. Big tolerance differences in components (different joystick manufacturers). Computer intensive polling of the port. Takes a long time to reach max pot value....and although the joystick worked it required calibration for each computer and each game, and required slightly different software to cope with different PC hardware and OS. http://www.best-microcontroller-projects.com Page 6 of 10

This gives you an idea of why this method is not for commercial usage. But you won't have this huge problem because you will NOT be running the software on a multi-purpose platform so all you should be concerned about is the component tolerances ( capacitor/potentiometer change with temperature and time (aging) ) and power supply tolerance. Note: You may need to calibrate depending on your application. Calibration One problem is that you may need to calibrate the system. And this is for two reasons: 1. Unknown inaccurate power supply. 2. Inaccurate pot/capacitance. Note: Just remember to check and test and don't use this technique in a commercial system (where you run out thousands of boards because you will get into trouble) - alternatively reduce the resolution required e.g. for a 5V system measure 25%,50%,75%,100% of the supply etc. then the tolerance will be less important. Conversion Although the value is proportional it is on an exponential curve i.e. it's not linear so you need to use a table to convert it into resistance values or use a calculation in the code to convert from exponential. Applied to the PIC The difference between the PIC and the PC is that the PIC digital pin can be configured as an input or as an output on the fly (so you can discharge the capacitor by setting the pin as an output and at logic low) and then set it as an input and by using the standard PIC input voltage levels (2V - logic high) as the threshold you don't need any extra ICs. http://www.best-microcontroller-projects.com Page 7 of 10

Operation The procedure for using it is: 1. Change the pin to an output. 2. Set the output low (to discharge the capacitor) for >2ms. 3. Set the pin to an input. 4. Start the timer. 5. Stop the timer when the input goes high. 6. Read out value from timer which is proportional to resistance. By changing the digital input to an output (with the output set low) the capacitor will be discharged to zero current limited to 5V/220 = 23mA. (you could probably get away without using the 220R since the internal pin circuitry limits the current sink to 25mA - actually I forgot it when testing and it works fine without it - it's really a protection if the pot is set to zero resistance - I just tested it using a selection of resistors so I did not have that problem). Then changing the pin to an input - it effectively becomes isolated from the circuit since very little current is drawn by an input pin - the capacitor will charge from nearly zero (nearly zero because of the 220R resistor - the input can't quite reach zero - this will be low enough to register as logic zero) to 5V via the potentiometer. As the input voltage crosses the 2V (ish) threshold for logic high the PIC input will be logic 1. Note: For a more accurate (repeatable) threshold choose a Schmitt trigger input or use an internal comparator. Measuring this time from reset to logic 1 will give a value proportional to the value of the potentiometer (one arm of the pot = variable resistor). For the 100k & 10n components Tor = 1ms which is 63% of the time to charge http://www.best-microcontroller-projects.com Page 8 of 10

to the final voltage and this gives some idea of the order of time to be detected by the microcontroller. The program outputs two values: A confidence loop counter (just a variable that increments) The Timer1 value. Note: If you use Vista - putty.exe (google for it) is a suitable replacement for hyperterminal. Hyperterminal was removed from Vista! RS232 Settings You should set hyperterminal or putty to the following settings: Baud 2400 Data Bits 8 Parity Stop bits 1 Flow control None None RS232 output The terminal output looks like this: 39353 115 The upper value is the confidence output and lower is Timer1 value. This is kept at the same position on the screen using VT100 codes (I really hate the screen scrolling continuously - then again there's no history). Something to Notice If you remove the resistance completely then the code is always waiting for the capacitor to charge and it never will! This is an example of the type of problem that can be created by an unforeseen circumstance. Although this example is http://www.best-microcontroller-projects.com Page 9 of 10

trivial it demonstrates that if you don't allow for every different external or internal state the code could hang. The code is forever stuck unless the state changes. In this case it does not matter because the code is a demonstration and not critical but the way around it is to use the watchdog timer to force a reset. By changing the code i.e. using a more complex project having a user interface it would be possible to allow the user to stop the test or put up a warning message. At the very least it would allow the user to interact with the system before it gets stuck again. Device The device used is the 12F675 (with the ADC turned off) this is just a device I had handy but you can run the code on any PIC chip. Compiler The compiler used is the MikroC compiler which lets you use it free for the 1 st 2k Hex output. Code Download Download the code here: Click Here To Download http://www.best-microcontroller-projects.com Page 10 of 10