Continue to Site

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.

  • 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.

Voltmeter

Status
Not open for further replies.

Kiko

New Member
Does anybody can explain how to implement a proton+ code to measure voltage between 0-25 volts using PIC16F877A, I'll connect this voltage on pin 2 (RA0) thru a resistor voltage divider like attached. If you have an example code I'll apreciate.

Thanks

Fabio Pedro
Brazil
 

Attachments

  • voltmeter.jpg
    voltmeter.jpg
    5.4 KB · Views: 1,259
Its an voltage divider.The voltage is 4,1 times higher than the PIC reeds.

An pic alone can only reed up to 5V this way it can up to 20V

The thing you are meshuring must also be able zo provide enugh curent since the input is 61K Ohm.(An PIC alsone has an way higher input inpendace)
 
Your schematic shows too high of an input impedance to provide the PIC. Recommended impedance is 2.5k max. The cap will not help. It will filter out some higher freq if you are sampling a signal with AC in it but not really fix your impedance problem.


You have a 2.2k in series with 47k. This only makes 49.9k. I don't know why you want to do 2 components here, the PIC can do math on it if you don't have the exact divider ratio you want.

1/((1/R1)+(1/R2)) <=2500
 
2,5K?

The PICs ADC dosent take much curent from it.If you just slitly toch the positve rail and a floting ADC pin it reads almost full voltage.So it wod work for shure.

What acuracy do you want?(Most PICs have 10 bit ADC)
 
It is truth that the maximum recomended impedance for ADC is 2K5, in order to maintain full 10bit resolution. If you don't need full resolution then it is not a problem. I would use a trimer instead of math functions to correct the ADC result, it simplier and faster.
 
Someone Electro said:
2,5K?

The PICs ADC dosent take much curent from it.If you just slitly toch the positve rail and a floting ADC pin it reads almost full voltage.So it wod work for shure.

What acuracy do you want?(Most PICs have 10 bit ADC)

The spec for the maximum source impedance is 2.5K, which is why my analogue tutorial board uses opamp buffers, then a series resistor (actually 2.7K) feeding the PIC - the resistor is added simply to prevent anything 'nasty' happening - like you set the I/O pin as an output!.

The reason for the 2.5K value is due to the sample and hold internally in the PIC A2D, the capacitor in the sample and hold has to charge (or discharge) from the impedance of the source. The higher the source impedance the longer this takes, otherwise you won't get a true reading (and could be a HUGE amount off).

As long as you're only using one A2D input, and the source is only slow changing, it's not a problem. BUT, if you use more than one input you may have to wait a number of seconds for the value to stabilise.

For example, two inputs, with too high a source impedance, one with 1V input, and the other with 3V input. If you read them too fast the first will read something under 2V, and the second something over 2V. As you can imagine, neither of these are very acceptable!.

As long as you can afford the wait?, it's not a problem, something like this:

Select input 1
Wait 5 seconds
Read A2D and store
Select input 2
Wait 5 seconds
Read A2D and store

The 5 seconds was just a nominal value I used, you can find it out experimentally, connect two analogue sources (one high and one low), and display the values on an LCD or something.

Make a note of the two readings, then reduce the wait time, until the readings start to change - you then know that you are reading the values too quickly. Pick a wait time a fair bit above the critical value, to give a bit of tolerance.

Or, add an opamp buffer? - it really depends on what you are doing!.
 
Question on how long a A/D conversion takes.

I have no experience in using the PIC A/D but from the datasheet I looked at, the A/D timings Microchip quoted are in terms of micro-seconds so I would think a full conversion can be completed realistically in milliseconds or tens of milliseconds at most.

The need to wait a few seconds for one conversion mentioned by Nigel came a bit of a surprise.

Any comments? :?
 
You need to wait seconds for the voltage to stabilaze if you use too great an input impedance.
 
25K (source impedance + PIC switch impedance) charging 120pF A/D capacitor.

Time constant is RC, which is 25000 x 120 x 10^-12 = 3 uS

A hundred RC time constant is still only 300uS. :shock:
 
It's just something you need to be aware of, and to make sure you don't read it before the capacitor is fully charged - OR, follow the MicroChip spec and use a source impedance no higher than 2.5Kohm.

As I suggested earlier, try two high impedance sources, with low and high voltages, and see how long you need to wait for switching between channels!.
 
Ok guys I'm not a enginner I'm curious... what do you suggest? is that going to work? I need measure a DC voltage only and up to 20 VDC will be enough no other inputs on PORTA, but my problem is that I don't know how to do it with picbasic I can do a code to measure up to 5V. I need some picbasic code examples.

Thanks

Fabio Pedro
Brazil
 
Kiko said:
Ok guys I'm not a enginner I'm curious... what do you suggest? is that going to work? I need measure a DC voltage only and up to 20 VDC will be enough no other inputs on PORTA, but my problem is that I don't know how to do it with picbasic I can do a code to measure up to 5V. I need some picbasic code examples.

Yes, it will work fine, as you're only measuring a single input, and not requiring fast readings, it won't be any problem.

As for your voltage reading, you just need to multiple the value you get by 5, this will compensate for your 4 to 1 attenuator feeding the A2D.
 
Status
Not open for further replies.

Latest threads

Back
Top