ADC SCALER METHOD V REF R TOP V ADC R BOT

Similar documents
Things to know about Numeric Computation

Natural Numbers and Integers. Big Ideas in Numerical Methods. Overflow. Real Numbers 29/07/2011. Taking some ideas from NM course a little further

MA 1128: Lecture 02 1/22/2018

Application Note. A Thermistor Based Thermometer, PSoC Style

CS367 Test 1 Review Guide

CMPSCI 145 MIDTERM #1 Solution Key. SPRING 2017 March 3, 2017 Professor William T. Verts

DLD VIDYA SAGAR P. potharajuvidyasagar.wordpress.com. Vignana Bharathi Institute of Technology UNIT 1 DLD P VIDYA SAGAR

Mathematical Data Operators

ROUNDING ERRORS LAB 1. OBJECTIVE 2. INTRODUCTION

Computer Organization

/* defines are mostly used to declare constants */ #define MAX_ITER 10 // max number of iterations

Computer Architecture and System Software Lecture 02: Overview of Computer Systems & Start of Chapter 2

But first, encode deck of cards. Integer Representation. Two possible representations. Two better representations WELLESLEY CS 240 9/8/15

A complement number system is used to represent positive and negative integers. A complement number system is based on a fixed length representation

Direct Format Usage for PMBus Data Transfer

Arithmetic and Bitwise Operations on Binary Data

4.1 QUANTIZATION NOISE

ECE 550D Fundamentals of Computer Systems and Engineering. Fall 2017

The CPU and Memory. How does a computer work? How does a computer interact with data? How are instructions performed? Recall schematic diagram:

Chapter 1. Solutions Solution 1.1. Most RAMs are volatile, meaning the information is lost if power is removed then restored.

Kinds Of Data CHAPTER 3 DATA REPRESENTATION. Numbers Are Different! Positional Number Systems. Text. Numbers. Other

Number Systems and Computer Arithmetic

Dr. Chuck Cartledge. 3 June 2015

CS 31: Intro to Systems Binary Representation. Kevin Webb Swarthmore College September 6, 2018

MOTENC Axis PCI Motion & I/O Control Board. Reference Manual Rev 1A, April Copyright 2004 VITAL Systems Inc

COMP 122/L Lecture 2. Kyle Dewey

Level ISA3: Information Representation

Introduction to Computer Systems Recitation 2 May 29, Marjorie Carlson Aditya Gupta Shailin Desai

Chapter 3 Data Representation

Number Systems. Both numbers are positive

Topic Notes: Bits and Bytes and Numbers

ECE2049-E18 Lecture 6 Notes 1. ECE2049: Embedded Computing in Engineering Design E Term Lecture #6: Exam Review

Introduction to Computers and Programming. Numeric Values

Binary Values. CSE 410 Lecture 02

Hi everyone. Starting this week I'm going to make a couple tweaks to how section is run. The first thing is that I'm going to go over all the slides

Microcomputers. Outline. Number Systems and Digital Logic Review

2SKILL. Variables Lesson 6. Remembering numbers (and other stuff)...

Slide Set 1. for ENEL 339 Fall 2014 Lecture Section 02. Steve Norman, PhD, PEng

Experiment 10 Fall 2012

CS125 : Introduction to Computer Science. Lecture Notes #38 and #39 Quicksort. c 2005, 2003, 2002, 2000 Jason Zych

The type of all data used in a C++ program must be specified

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

Bear in mind that the weights of BCD digit bits are 8,4,2,1 multiplied by the decimal position, i.e. 1, 10, 100, etc.

Memory Addressing, Binary, and Hexadecimal Review

Review: Computer Organization

Computer Science 324 Computer Architecture Mount Holyoke College Fall Topic Notes: Bits and Bytes and Numbers

Data Representation Type of Data Representation Integers Bits Unsigned 2 s Comp Excess 7 Excess 8

Read this before starting!

ECE2049: Embedded Computing in Engineering Design A Term Fall Lecture #9: Exam Review w/ Solutions

Introduction IN THIS ARTICLE ACKNOWLEDGEMENTS. PICAXE Calculator. Author: Jeremy Leach June 2006

CS33 Project Gear Up. Data

COMP Overview of Tutorial #2

CS 31: Intro to Systems Binary Representation. Kevin Webb Swarthmore College January 27, 2015

Logic, Words, and Integers

Arithmetic and Bitwise Operations on Binary Data

Numbers and Computers. Debdeep Mukhopadhyay Assistant Professor Dept of Computer Sc and Engg IIT Madras

Integer Encoding and Manipulation

9/3/2015. Data Representation II. 2.4 Signed Integer Representation. 2.4 Signed Integer Representation

CHAPTER 1 Numerical Representation

Data Representation 1

Goals for this Week. CSC 2400: Computer Systems. Bits, Bytes and Data Types. Binary number system. Finite representations of binary integers

MOTENC-Lite 4-Axis PCI Motion & I/O Control Board. Reference Manual Rev 1.1, June 20, Copyright 2005 VITAL Systems Inc

2015 Paper E2.1: Digital Electronics II

ECE2049: Embedded Systems in Engineering Design Lab Exercise #3 C Term Making a Time and Temperature Display

Chapter 10 - Computer Arithmetic

ECE2049-E17 Lecture 6 1. ECE2049: Embedded Computing in Engineering Design E Term Lecture #6: Exam Review

Data Representation. Class Reminders. From Last Time... Interpreting bits to give them meaning. Part 2: Hexadecimal and Practical Issues

Module 2: Computer Arithmetic

Data Representation. Interpreting bits to give them meaning. Part 2: Hexadecimal and Practical Issues

Manipulating Integers

Binary Adders: Half Adders and Full Adders

Chapter 03: Computer Arithmetic. Lesson 09: Arithmetic using floating point numbers

Slide 1 Side Effects Duration: 00:00:53 Advance mode: Auto

CS2630: Computer Organization Homework 1 Bits, bytes, and memory organization Due January 25, 2017, 11:59pm

Representing numbers on the computer. Computer memory/processors consist of items that exist in one of two possible states (binary states).

PAS 9737/AI-SMT ENGINEERING SPECIFICATION

EE445L Fall 2010 Final Version A Page 1 of 10

Practical Numerical Methods in Physics and Astronomy. Lecture 1 Intro & IEEE Variable Types and Arithmetic

Floating point. Today! IEEE Floating Point Standard! Rounding! Floating Point Operations! Mathematical properties. Next time. !

Number Systems. Decimal numbers. Binary numbers. Chapter 1 <1> 8's column. 1000's column. 2's column. 4's column

Instruction Sets: Characteristics and Functions

CSE 410 Computer Systems. Hal Perkins Spring 2010 Lecture 12 More About Caches

Numeric Precision 101

The type of all data used in a C (or C++) program must be specified

Switching Circuits and Logic Design Prof. Indranil Sengupta Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur

Review Topics. Midterm Exam Review Slides

COMP2611: Computer Organization. Data Representation

Computer Organisation CS303

Features: Analog to Digital: 12 bit resolution TTL outputs, RS-232 tolerant inputs 4.096V reference (1mV/count) 115K max speed

What Is It? Instruction Register Address Register Data Register

Topic Notes: Bits and Bytes and Numbers

(+A) + ( B) + (A B) (B A) + (A B) ( A) + (+ B) (A B) + (B A) + (A B) (+ A) (+ B) + (A - B) (B A) + (A B) ( A) ( B) (A B) + (B A) + (A B)

Floating-Point Arithmetic

Number Systems CHAPTER Positional Number Systems

COSC 243. Data Representation 3. Lecture 3 - Data Representation 3 1. COSC 243 (Computer Architecture)

9/23/15. Agenda. Goals of this Lecture. For Your Amusement. Number Systems and Number Representation. The Binary Number System

Lecture Numbers. Richard E Sarkis CSC 161: The Art of Programming

Characters, Strings, and Floats

CS 31: Intro to Systems Binary Arithmetic. Martin Gagné Swarthmore College January 24, 2016

Basic data types. Building blocks of computation

Transcription:

ADC SCALER METHOD The purpose of this scaler calculation is to eliminate long division in the conversion of raw ADC data into a human readable decimal value using only integer math. This scale factor will account for the voltage gain Av, the voltage division of the Rtop-Rbot divider network, the ADC Vref, the ADC resolution and the sample count when averaging is used. A computation result equal to Volts x 1000 (in the examples used below) is computed with a minimal loss of accuracy due to rounding errors while using just a single multiplication operation followed by a fast binary byte shift division. By adjusting this scaler to reflect the actual system, all of the various error sources can be calibrated out at once. This is best used for circuits with linear transfer functions; non-linear systems such as thermistor curves are better converted using multi-point linear interpolation techniques. A V V REF R TOP V ADC 8,10,12 bits etc R BOT The main object of this exercise is to multiply up information to the right of the decimal point, moving as many significant digits to the left of the decimal point as possible at the beginning, saving any division to be done for the very last step. To begin with the ratio below shows generically how an ADC reading is converted to a "Voltage". ADC COUNTS Or re-written... ADC COUNTS x For the following examples, a 10 bit ADC with an input at half its full scale limit would compute out to a value of 2.4975V. Note that there is no way to get a result of 2.5000V because there is no integer that is exactly half of 1023. Adding more bits will only make the distance from exactly half progressively smaller. 511 VOLTS x 5.000 IN 2.4975 1023

This calculation is fine as is when done on a PC with unlimited processing power and memory space to do floating point math on every calculation, but in the limited resources of an embedded processor you can simply move the decimal to the left to prevent the need for floating point math using the much faster and compact integer math that can be done in hardware, all except of course the division. 511 VOLTS x 5000 IN 2497(.5) 1023 Note that the decimal in the result is displayed parenthetically: Integer math will essentially round every result down to the lower integer value, discarding anything to the right of the decimal point. When displaying this result, the first digit is displayed, then a decimal point and then the next three digits! By doing the math in the order shown above we are still doing long, non-binary division which tends to eat a lot of instruction cycles and a lot of RAM so a short-cut is to create a "Scale factor" or "Scaler" by doing the division ahead of time. We can then simply multiply the ADC reading by the scaler. Scaler 5000 1023 4.8875855; 511 x 4.8875855 2497(.6) Of course, now we have a decimal in the math again and this is not good for an embedded CPU! This is where binary math comes to the rescue... If you want to divide a number by 2, you can simply shift all of the bits to the right by 1 space where the least significant bit drops into oblivion. Likewise, division by any power of 2 is done by shifting to the right by that power of 2; n/21 shift, n/4 2 shifts, n/83 shifts and so on. 546 / 2 1000100010 >> 1 0100010001 273 When shifts are done 8 and 16 at a time as when dividing by 256 and 65536, you can simply discard the lower bytes and get your result without shifting. In an 8 bit RAM processor, this works out really well as all data is already stored as groups of 8 bits. 4532 / 256 00010001 00000000 00010001 17 1114112 / 65536 00010001 00000000 00000000 00010001 17 How does this help us? If we take the decimal scaler of 4.8875855 from the previous example and multiply it by any power of 2 ^ (n x 8) bits such as 256, 65536 or 16777216, we can do some simple byte shift division where the accuracy gets progressively better as n is increased since we are throwing away fewer and fewer digits of the scaler constant after the decimal point. From the previous example of an ADC reading of 511 and a multiplier of 2 ^ (2 x 8) and using hex to show the byte-wise division operation: Scaler 4.8875855 x 65536 320312.73 (use 320313) (511 x 320313) / 65536 0x09C18EC7 0x09C1 2497

This is a good time to note the one major limitation of this method: If for instance 32 bit math is used to convert a number down to a 16 bit value with a 16 bit divider, the multiplication result MUST NOT exceed 32 bits! Just like with shifts to the right, overflows to the left go into oblivion! This may seem like a lot of work to end up with the same result, but on a RISC processor, long division can consume hundreds of microseconds and this can add up when a lot of different inputs are converted continuously. Another benefit of this method is that the scaler can be adjusted to simultaneously perform the averaging of an accumulated number of readings in addition to scaling the result. Even when the number of samples is an even power of 2 such as 16, just the shift dividing to get the average of the raw ADC data in a 16 bit variable using an 8 bit processor requires about 40 instructions... by combining the averaging and the scaler by this method, the whole operation can be done in about 8 instructions! Scaler 4.8875855 x 65536 / 11 29119.3 (use 29119) Average (511 x 5) + (512 x 6) 5621 (5627 x 29119) / 65536 0x09C43145 0x09C4 2500 The accumulation of samples for the purpose of averaging is a very fast process as it simply requires addition of each successive sample, something any micro-processor is really good at. As can be seen in the above example, another advantage of averaging is that averaged ADC readings can have more resolution than the ADC is actually capable. From the example above for an input of exactly 1/2 the full scale range, any single reading can only consist of 511 or 512 counts; never the 511.5 counts of exactly 1/2 full scale (One half of 1023 for the 10 bit example). However, by averaging a signal that is right at the boundary of counts 511 and 512 where some number of samples read 511 and some number reads 512, we can actually achieve a result equal to the elusive 2.500V for a virtual resolution of 11, 12 and more bits for a 10 bit ADC! When writing the firmware for ADC conversions the optimal scaler computed from the ideal circuit elements can be used but what do you do when the real world errors that exist at every stage of a circuit are considered? This question brings us to the final level of refinement for this method because reference voltages are never EXACTLY what they are supposed to be and resistor dividers are never operate EXACTLY as the values printed on the parts would suggest; everything must allow for some level of error or "Tolerance" in order to be manufacturable. With a scaler, the procedure to calibrate out these errors is quite simple: First you use the optimal scaler as a default and apply a known voltage to the input to be calibrated. Next, you take the value you wanted and divide it by the value you got using the optimal scaler and multiply the optimal scaler by the result. This becomes the calibrated scaler that can then be saved and the firmware can be written such that if a calibrated scaler is available then use it, otherwise use the optimal scaler that has been hard coded as a default. As an example of a calibration step, a scale factor of 40039 was computed to give an optimal reading of 5.000V for a 5.000V input, however because of the various sources of errors, the ADC read function returned 4.879V when the input was actually 5.012V: 41131 is the calibrated scaler where 40039 would be the uncalibrated hard coded default scaler. 5.012V 4.879V x 40039 41131 The equations used in the scaler calculator are shown below. VOUTfullscale is the maximum

input into the network that will result in the input to the ADC being equal to the ADC reference voltage, i.e. to output its maximum code where a resistor divider has a gain < 1, an amplifier will have a gain > 1. Keep in mind that this could apply just to "Amps" full scale so that for instance if you are measuring current with a 2 ohm resistor, the gain would be 2 where a 0.1 ohm resistor would have a gain of 1/10. ( ) V ( REF R BOT ) x (R + R ) BOT TOP Gain 65536 Scaler x x 1000 Samples ( ) When making the math fit into a 32 bit unsigned integer, the two numbers that will have the greatest effect are the PostDivider (65536) and the ResultMultiplier (1000). Remember that the ResultMultiplier is the distance to shift the decimal point to the right and so should match the resolution of the ADC: 6 decimal places for an 8 bit ADC result does not have a lot of meaning and 3 decimal places for a 16 bit result throws away useful information. The ResultMultiplier should therefore be established first based on maintaining the maximum information from your ADC and then the PostDivider should be as large as possible such that the scaler multiplied by the raw ADC data still fits into the available 32 bit integer. Below is sample code from my switcher efficiency sweeper that reads 16 samples from 4 inputs and then scales them to volts or amps using calibrated scalers. The post-calibrated accuracy achieved by using the scalers is better than 0.2% for all channels. //global variables: calibration constants //Vref is 3.05V //Vin and Vout use a 75K/30.1K divider //Iin has a gain of 5 and a 20K/30.1K divider //Iout has a gain of 2 and no divider (Rtop0) unsigned int16 r_vin_cal42835; //Opt 42640 unsigned int16 r_iin_cal4882; // 4065 unsigned int16 r_vout_cal42946; // 42640 unsigned int16 r_iout_cal6106; // 6106 //global variables: function return variables unsigned int16 in_volts; unsigned int16 in_amps; unsigned int16 out_volts; unsigned int16 out_amps; //function to read ADCs and compute results void read_all(void){ unsigned int8 i; //loop counter unsigned int32 temp32; //32 bit math variable //initialize averages to zero (Block averages)

in_volts0; in_amps0; out_volts0; out_amps0; //interleave read 16 samples from each input for (i16;i>0;i--) { set_adc_channel(0); //set the ADC channel //mux settling time in_volts+read_adc(); //add to the average set_adc_channel(1); in_amps+read_adc(); set_adc_channel(2); out_volts+read_adc(); set_adc_channel(4); out_amps+read_adc(); } //each average (16bits) is multiplied by its //calibrated scaler (16bits) and then the 32bit //result is byte shift divided to a 16 bit //scaled result. temp32(int32) in_volts * (int32) r_vin_cal; in_voltsmake16(make8(temp32,3),make8(temp32,2)); temp32(int32) in_amps * (int32) r_iin_cal; in_ampsmake16(make8(temp32,3),make8(temp32,2)); temp32(int32) out_volts * (int32) r_vout_cal; out_voltsmake16(make8(temp32,3),make8(temp32,2)); temp32(int32) out_amps * (int32) r_iout_cal; out_ampsmake16(make8(temp32,3),make8(temp32,2)); }