Kronos Robotics and Electronics
Site Map
 
Home Zeus Projects App Notes Downloads Dios Athena Forums
 

DAN127

Build an Auto Ranging Voltmeter

  By Michael Simpson

This  one of 4 applications notes that will be used in a upcoming project called the Ultimate Utility Meter.

Have you ever wanted to build your own voltmeter.  That way you could customize it to meet your exact needs. 

One of the problems with using AtoD and a microcontroller is that you can not insert a voltage higher than VCC or you stand a chance of blowing the controller.  

One answer is to add a resistor or two to lower the voltage before entering the microcontroller.  This works but at you loose resolution when measuring lower voltages.

By using a 74HC4066 analog switch we can solve the resolution problem.

 

First Look at Voltmeter

Lets take a look at a the basic voltmeter code.

func main()
   dim voltage as float

   AtoDinit(14) 'Init 1 Analog port 0

loop:
   voltage = AtoD(0) * .00486
   printfloat(voltage,.2)
   pause 200
   goto loop
endfunc

include \lib\DiosAtoD.lib
include \lib\DiosDispFloat.lib

To display the actual voltage we multiply the AtoD reading by a reference value. 

This value is calculated by the taking the maximum voltage and dividing by the number of steps.  In the case of this circuit the max voltage is 4.97 volts (regulator output).  The AtoD is 10 bits so that yields 1024 steps.  

So 4.98 / 1024 = .00486

An AtoD reading of 576 would be 2.8v

Important Note

Always use a resistor in series with your test lead when measuring an unknown voltage.  This way if you accidentally place your test lead on a voltage higher than the controller can handle it wont blow it.  I found a 100k resistor works pretty good.

Now lets look at the Auto Ranger

To build an auto ranger we will need an additional hardware component.  The 74HC4066 quad analog switch.  This Chip will let us select various resistors for the different scales we want to create.

In order to create this voltmeter you must have a regulated power source.  Other wise your readings will drift.  Here you see I am using a Breadboard regulator.  Any 7805 will works just as well.  We are not so concerned about the exact tolerances of the resistors as we will calibrate once the meter is assembled. 

R1 is the most important resistor.  If it bypassed or omitted you will blow the controller.

Essentially what we are doing is switching in various resistors to ground.

Let Take a Look at the Program (Download it here)

func main()

  '4066 analog switch pins
    const SWA 1
    const SWB 2
    const SWC 3
    output SWA,SWB,SWC

    dim scale
    dim reading
    dim voltage as float
    dim vref(4) as float

  'Adjust for each scale
    vref(0)=.00486
    vref(1)=.00969
    vref(2)=.01507
    vref(3)=.02658

  'Default scale
    scale = 0
    low SWA,SWB,SWC

    AtoDinit(14) 'Init 1 Analog port 0
 

'-----------------------------------------------------------------------------------------
loop:
    pause 400
loop2:
    reading=AtoD(0)

    voltage = reading * vref(scale)

    if reading < 500 and scale > 0 then
      scale = scale -1
      goto setscale
    endif

    if reading > 1022 and scale < 3 then
      scale = scale + 1
      goto setscale
    endif

    print scale," ",reading," ";
    printfloat(voltage,.2)
    goto loop
 

'-----------------------------------------------------------------------------------------
setscale:
    branch scale,setscale0,setscale1,setscale2,setscale3

setscale0:
    low SWA,SWB,SWC
    goto loop2

setscale1:
    low SWA,SWB,SWC
    high SWA
    goto loop2

setscale2:
    low SWA,SWB,SWC
    high SWB
    goto loop2

setscale3:
    low SWA,SWB,SWC
    high SWC
    goto loop2

endfunc


include \lib\DiosAtoD.lib
include \lib\DiosDispFloat.lib

 

There are three sections in the code. 

Initialization

This section sets up the AtoD library for 1 line.  It also Initializes a few variables.  The most important variables are the vref variables.   There are 4 one for each scale.   These can be calibrated by using an existing volt meter. 

Reading

In this section we take a reading verify that we are not under or over scale and display the results.  The display will output to the debug window so make sure you have it opened and enabled.  Each measurement will display three items.  Scale, Reading, Voltage.   Use these to help you calibrate the reference numbers.  

Setscale

This section sets the input resistors by selecting various control pins on the 74HC4066.    I'm only using 3 of the 4 available switches so you can expand.  Also note that I am only using one resistor at a time.  By selecting multipls you can add further scales.

 

Calibrating the meter

Calibration is simple.  Hook up an existing voltmeter to the same to your input test lead.  You will need a voltage source for each scale. 

What you do is tweak the reference voltage for the scale you are testing then reprogram.  Start with very minor adjustments.   As you go up in scale the resolution will drop so don't expect to get .004 resolution in scale 3.

What next

You can add a parallel LCD and display the readings to an LCD if you like.   In a future project we will be doing just that.

 

 

Parts list

74HC4066

 

DiosPro 40 Pin Chip

Dios Workboard Deluxe

 

Easy RS232 Driver  

DiosPro 28 Pin Chip

Dios 32 Pin Carrier (Carrier #1)

 

9 Pin Cable

Breadboard Regulator

 

Copyright © 2001 - 2007 Kronos Robotics