Menu

Volt meter?

Help
Jonny!!!
2008-08-11
2013-05-30
  • Jonny!!!

    Jonny!!! - 2008-08-11

    I want to be able to read voltages up to about 14 volts (in an automotive setting).
    However, PIC's can only read up to Vdd or about 5 volts using the Vref pin.

    I would like to get some opinions on how to best do this?

    I was thinking of maybe some clever use of a voltage divider type setup, any ideas?

     
    • kent_twt4

      kent_twt4 - 2008-08-11

      The way I did it is not particularly clever, but keeping to whole number (i.e. integer) math simplifies things.  Since charging voltage could be 14.4V or more, need to take that into account.  Set the test input voltage to 16V, and then found a matched pair of resistors for the a-d divider circuit of 4V, which gave me a 4X multiplier of the input voltage.  Helps to have an adjustable power supply or voltage regulator and a reasonably accurate DVM, other input values or multipliers would surely work.

      The setup I had, did have a certain amount of noise component (a few hundredths of a volt), maybe due to some stray capacitance or?  One idea not implemented would be to take a fair number of a-d readings, and then take the mean value of those readings.

       
    • Jonny!!!

      Jonny!!! - 2008-08-11

      so would you say a 1:4 ratio of the voltage divider? so like 10k and 40k resistors? Is that what you mean by "multiplier"? (16/4 = 4v)?

       
    • kent_twt4

      kent_twt4 - 2008-08-11

      I think the max input impedance for the midrange Pics is 10k, 2.5k for 18f's.  Pick R1 to be under those values per  http://en.wikipedia.org/wiki/Voltage_divider  By that formula then resistors that divide by three, like 1.5k ohm and 500 ohm, (or ?) would work for a divide by four circuit.  Maybe change the divider Vin/Vout to match resistors on hand.

      Yes should have said divide by four (16V/4V) on the input voltage.  Meant 4X multiplier for the resultant value, as in RealValue = 4 x ReadAD(AN0).

       
    • Jonny!!!

      Jonny!!! - 2008-08-12

      Well, success for the most part. Now what should I do about the accuracy?

      i consider 5 volts the highest it can read, so mV/bit should be 5v/256, correct? this is about 19.5mV/bit.
      When I take the AD value alone, and multiply it by the 19.5 mV with my calc, I get a bang-on voltage meter. However, I can not do decimals, and division isn't working so well (the modulus % doesn't seem to be working?). How can I multiply by a non-integer (19.5)? I'm not too concerned about dividing by 1000 to get volts from mV, since the the readout isn't important.

      Isn't it possible to change the % of the reference to Vdd? Would this make it easier to find the voltage without multiplying by non-integers?

       
    • kent_twt4

      kent_twt4 - 2008-08-12

      For more accuracy use ReadAD10, and a precision reference voltage applied to the Vref+ pin as previously discussed in this forum.  Make sure the a-d Vref+ bit (VCFG0 bit for 18'fs) is set, or check if GCBasic ReadAD function sets it for you.

      #define Volt AN0
      dir PortA.0 in
      dim BatVolt as word
      Set VCFG0 On ;18f
      ...
      ...
      BatVolt = RVAD10(Volt)
      ;Vref+=4.096 volts/1024 or 4mv per bit
      ;Use voltage divider circuit on input
      ;So Vin/Vout = 4
      ;Scale up to 16.4V multiply again by 4
      ;And drop off the LSB (not really req'd)
      BatVolt = (BatVolt*16)/10
                            

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.