1. Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
    Dismiss Notice

16F84A - voltmeter

Discussion in 'Microcontrollers' started by golfather, Oct 4, 2005.

  1. golfather

    golfather New Member

    Joined:
    Nov 18, 2004
    Messages:
    6
    Likes:
    0
    Hi all,

    I bet this question has been asked many times. I’m newbie to the wonderful world of PIC’s and electronics.

    I would like to build a voltmeter using 16F84A (have these at hand) and LCD to display the voltage.

    The voltage I would like to measure is 0 – 16V. I assume I would need to use an ADC such ADC0831.

    I know I will need to do some scaling, as the ADC will only be able to read 0 – 5V.

    Need help in designing the circuit. I should be fine with the code side for the pic.

    All the help given would be appreciated.


    Thank you
    Ray (UK, North East)
     
  2. Nigel Goodwin

    Nigel Goodwin Super Moderator Most Helpful Member

    Joined:
    Nov 17, 2003
    Messages:
    39,228
    Likes:
    641
    Location:
    Derbyshire, UK
    Dump the 16F84A, it's long obselete and not much use for this purpose. Rather than buy a seperate ADC, simply chose a PIC with internal ones, and use that instead.

    Check my PIC tutorial for all you need to know, based on the 16F876/7, but easily moved to the 16F819 or 16F88 which are 18 pin like the 16F84A. Both the circuit and suitable code are included.
     
  3. eblc1388

    eblc1388 Active Member

    Joined:
    Jan 25, 2005
    Messages:
    2,228
    Likes:
    18
    Location:
    UK
    As suggested by Nigel, a PIC with an internal A/D converter is simpler than using a sepatate ADC0831 especially if you have to buy it anyway. A PIC gives you 10-bit resolution while the ADC0831 gives only 8-bit.

    You will need a 4x voltage divider to drop the 16V max input into 0-4V(I like 0-4V range, precisely 0-4.096V, because it is much easier to scale it into 0-16V later), follows by an 1:1 opamp voltage buffer. This would mean that another supply of +7V or higher or some +/- supplies is required just to power up the opamp.

    Regarding the LCD interface you can use the LCD in the 4-bit mode driving it with 6 pins of the PIC and there are plenty of code examples around from the internet. As such a 18-pin PIC with A/D would fit in comfortably.

    I think that's about it, apart from the three replies you have already got from the postings in Yahoos.Group a few days ago.
     
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. golfather

    golfather New Member

    Joined:
    Nov 18, 2004
    Messages:
    6
    Likes:
    0

    Thank you all

    eblc1388 its worth asking for me around other forums due to me been a newbie in pics and electronic world.

    The only way to learn is from others experience.

    I find people generally helpful, but their replies lack the fine details. I think because of my lack of experience I need to be spoon fed as they say.


    Thank you so far
     
  6. eblc1388

    eblc1388 Active Member

    Joined:
    Jan 25, 2005
    Messages:
    2,228
    Likes:
    18
    Location:
    UK
    I'm not saying you have done anything inappropriate, in fact sometimes it's good to ask in different forums as particular reply would not cover every aspects of your question.

    It is very difficult to give a balanced reply simply because it is impossible to judge how well the poster know about a certain aspect unless there are clues in the question. So in general the reply is either too brief or too detailed. Most would err on the brief side in the hope that the OP would reply and provide extra details/requirement.

    So, does the replies you got from here helpful to your problem?
     
  7. golfather

    golfather New Member

    Joined:
    Nov 18, 2004
    Messages:
    6
    Likes:
    0
    Hi eblc1388

    thank you for your understanding, yes and no. I'm reading Nigel tutorials at the moment.

    I was hoping to use 16F84 I have quite a few of these at hand. These will go to waste otherwise. I know they're not the best pic because they don't have an adc and they're only have 1k space.

    I wanted details of how to build the buffer circuit (op amp) and to do the scaling. Example so for 5v using an 8bit ADC how can I scale 0 -16v and the components I would need. How to calculate the values needed

    Forum members like yourself, Nigel and others are great help.


    many thanks
     
  8. williB

    williB New Member

    Joined:
    Aug 30, 2004
    Messages:
    2,217
    Likes:
    3
    Location:
    New Jersey
    did you know that there is such a thing as a serial A/D chip i think microchip makes at least one..
    the way it works is , after you start a conversion, and wait the appropriate amt. of time , the chip outputs a code of ones and zeros ..which i'm sure the F84 can handle.. :)
     
  9. eblc1388

    eblc1388 Active Member

    Joined:
    Jan 25, 2005
    Messages:
    2,228
    Likes:
    18
    Location:
    UK
    Your 16F84 will not go to waste. They can be used for all sorts of other application which don't need a A/D converter. What I was saying is an external A/D conversion chip would properly be more expensive than a new PIC with in-built A/D, at least this is the case for 16F88 here in UK.

    The requirement of the opamp buffer circuit is due to leakage current of the PIC pin. A buffer may not be needed if you use other chip to do the conversion where a simple voltage divider will suffice. Different A/D converter chips has different input requirement and their datasheet usually have example circuit for such purposes.

    You have to decide on which chip you would use for the A/D first. It is also important that you indicates on what you are measuring? Is it a power supply output, transducer output....etc? and how accurate you want the measurement to be.
     
  10. Nigel Goodwin

    Nigel Goodwin Super Moderator Most Helpful Member

    Joined:
    Nov 17, 2003
    Messages:
    39,228
    Likes:
    641
    Location:
    Derbyshire, UK
    No it's not! - it's due to the current required to charge the internal sample and hold capacitor - this forms a time constant with the external source resistance, and you have to allow it sufficient time to charge the capacitor fully. With a high source resistance this takes far longer, so you need to take readings much less often.
     
  11. eblc1388

    eblc1388 Active Member

    Joined:
    Jan 25, 2005
    Messages:
    2,228
    Likes:
    18
    Location:
    UK
    Even if you take one reading per day and use the remaining time charging this capacitor, the source resistance must still be less than 10K if the full accuracy of the A/D is required.
     
  12. Nigel Goodwin

    Nigel Goodwin Super Moderator Most Helpful Member

    Joined:
    Nov 17, 2003
    Messages:
    39,228
    Likes:
    641
    Location:
    Derbyshire, UK
    Have you perhaps tried this?, and if so how did you evaluate resolution to 0.1%?.

    The datasheet (for a 16F877) RECOMMENDS the source impedance is no more than 10K, it doesn't suggest accuracy may be any less if it's not, and the possible leakage currents are exceedingly small, and shouldn't affect reading accuracy until you reach much greater source impedances.
     
  13. eblc1388

    eblc1388 Active Member

    Joined:
    Jan 25, 2005
    Messages:
    2,228
    Likes:
    18
    Location:
    UK
    Actually, the datasheet(16F Reference Manual) did mention about the effect of this leakage resistance.
     

    Attached Files:

  14. golfather

    golfather New Member

    Joined:
    Nov 18, 2004
    Messages:
    6
    Likes:
    0
    Hi all

    I wanted to measure a car battery voltage.

    thank you
    Ray
     
  15. eblc1388

    eblc1388 Active Member

    Joined:
    Jan 25, 2005
    Messages:
    2,228
    Likes:
    18
    Location:
    UK
    This is the voltage divider and opamp circuit for your project.

    In the following circuit:

    With 16V input at L1, adjusts R3 VR 1K to give exactly 4.00V at point A.
     

    Attached Files:

  16. Nigel Goodwin

    Nigel Goodwin Super Moderator Most Helpful Member

    Joined:
    Nov 17, 2003
    Messages:
    39,228
    Likes:
    641
    Location:
    Derbyshire, UK
    I can see a number of problems with that (somewhat over complicated) circuit.

    For a start, what is the function of the diode on the output of the opamp?, or the feedback resistor?.

    The opamp won't be able to reach down to zero volts, although for this application it hardly matters?.

    You should have a capacitor on the input of the 78L05 as well as the output, both of them as close as possible to the regulator.

    No current limiting resistor between the opamp and PIC, in case something causes the output of the opamp to go high (like too high an input voltage).

    Why an opamp at all? - a simple potential divider is all that's required, as it's from a car battery the current doesn't really matter, so simply divide the potential divider values by ten, and feed that directly into the PIC pin.

    This keeps it well below the maximum recommended source impedance, and prevents the opamp points I noted above.

    I would also suggest using an external precision reference for the PIC's A2D, rather than the not so stable output of the 78L05 - and the potential divider values should be recalculated accordingly.

    As far as that goes I would advise (most strongly!), that you DON'T divide exactly by four (or eight, if using a 2.5V reference). Doing so makes the scaling for display rather crude and messy - if you scale it so you get maximum output (1023 decimal) for an input of 20.46 volts, then you can simply multiply the result by two, insert the decimal point, and you have a nice simple accurate reading.
     
  17. eblc1388

    eblc1388 Active Member

    Joined:
    Jan 25, 2005
    Messages:
    2,228
    Likes:
    18
    Location:
    UK
    Agree. A simple potential divider is good enough for a car battery voltge measurement. I guess I prepared that circuit that works for most cases in case the OP use it for other purposes.

    For car battery voltage measurement, the 78L05 is good enough in my opinion.

    Good idea. Here is the calculation.

    Assuming he is using a 2.5V reference, then 20.46V input should produces 2.5V at the voltage divider to give 1023 counts.

    Choosing 2K7 as the resistor to ground, the current is 2.5V/2K7. So the voltage drop on the top resistor is (20.46-2.5)=17.96V and the resistance equals 17.96/2.5*2.7 = 19.39K. Therefore we can use a resistor of 18K in series with a 2K VR.
     

    Attached Files:

  18. golfather

    golfather New Member

    Joined:
    Nov 18, 2004
    Messages:
    6
    Likes:
    0
    Thank you eblc1388 for the diagram.

    Nigel thank you for the comment on eblc1388. Nigel would it be possible for you to show me a circuit for what you have suggested.

    Thank you eblc1388 and Nigel once again

    Ray
     
  19. Nigel Goodwin

    Nigel Goodwin Super Moderator Most Helpful Member

    Joined:
    Nov 17, 2003
    Messages:
    39,228
    Likes:
    641
    Location:
    Derbyshire, UK
    The two posts of eblc1388 show it pretty well, remove the opamp and associated components from the first poest, and add the resistor network from the second.

    For an external reference voltage, check my analogue tutorial hardware.
     

Share This Page