View previous topic :: View next topic |
Author |
Message |
ssaakmnt
Joined: 03 Dec 2011 Posts: 27
|
reading volt with pic16f877 ADC |
Posted: Wed Jan 02, 2013 12:53 pm |
|
|
This code uses the pic as digital voltmeter to measure 5 volt:
Code: |
#include <float.h>
main() {
float value;
printf("\n\rSampling:\r\n");
setup_port_a( ALL_ANALOG );
setup_adc( ADC_CLOCK_INTERNAL );
set_adc_channel( 0 );
while (TRUE); {
delay_ms(1000);
value = Read_ADC();
printf("\rvalue: \%4.2f \r\n",value/51); ) // the resolution is 8 bit so 255/5=51
}
} |
I want to use same method to measure a current signal (0-20mA)
by reading the voltage across 250 ohm resistor.
So I want to know if this going to work ? |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9243 Location: Greensville,Ontario
|
|
Posted: Wed Jan 02, 2013 1:11 pm |
|
|
No, usually current loops are 'floating', ie: no reference to ground, so one way to measure the current of the loop is to connect a differential amplifier across the 250r resistor. The output is then fed into the PIC adc pin.This 'changes' 4mv to 0 volts, 20ma into 5 volts. It's up to you to design/build/test the diffamp circuit to get the correct range for the circuit. It can be as simple as a single rail2rail opamp and 4 resistors. They do make special 'instrumentation amplifiers' for this as well but they cost more!
The 4ma as '0' is a standard, allows for 'open loop' detection...a fault condition.
Yes, IF the current loop is grounded (one end of the 250r is grounded).
hth
jay |
|
|
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
|
Posted: Wed Jan 02, 2013 2:23 pm |
|
|
What is your supply rail voltage?
Mike |
|
|
ssaakmnt
Joined: 03 Dec 2011 Posts: 27
|
|
Posted: Wed Jan 02, 2013 3:39 pm |
|
|
One end of the resistor is grounded, the supply is 24vdc converted to (connected) to 15v regulator and then connected to 5v regulator, Vdd and Vss are the voltage references, 24vdc also supplies the current measuring tranceduser which has two ends:
1- output 0-20mA/4-20mA
2- 0v
What I did was connecting all the grounds and zeros together, and my design does not contain any amps or coupling caps connected to pic. In fact I test it and the results were not bad except for some instability, 10 bit resolution is more accurate but also more unstable. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9243 Location: Greensville,Ontario
|
|
Posted: Wed Jan 02, 2013 4:12 pm |
|
|
If you're using the program you listed earlier, you're only sampling once every second.
It is common practice to sample several times and compute an average.
As the programmer, it's up to you to decide what methods you use to give 'correct' results. Some filter noise mechanically (caps, resistors, chokes) , others digitally (multiple samples, averages, etc.) though in the real world both techniques are usually used.
hth
jay |
|
|
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
|
Posted: Wed Jan 02, 2013 4:20 pm |
|
|
Is your 20mA Transducer connected like this?
Code: | 24V ---------
|
|
-----------
| |
| 4-20mA |
! sensor |
| |
-----------
|
|
0V --WWWWW---
250R
|
If yes; can the sensor tolerate working from 19V to 24V?
Mike |
|
|
ssaakmnt
Joined: 03 Dec 2011 Posts: 27
|
|
Posted: Thu Jan 03, 2013 3:00 am |
|
|
it is like this Code: |
24----| |----0v
-----------
4-20ma
sensor
-----------
| |
output gnd
|
then I connected one end of 250ohm in parallel between transducer and pic and other end to 0v Code: |
output
|
250 |
0v--wwwww--
|
|
pic |
so is this good connection ? |
|
|
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
|
Posted: Thu Jan 03, 2013 3:58 am |
|
|
OK. Your circuit now looks like this:-
Code: |
24V -----
|
|
---------------
| |
| 4-20mA |
! sensor |
| |
---------------
Gnd| |0V |Output
| | |
0V ------------WWWWW-------------PIC I/P
250R
|
If the sensor is happy with these connections then the PIC should be OK.
The potential problem could be if output exceeds 20mA. Then you will over-volt the PIC I/P.
Maybe a good idea to protect the PIC I/P and low pass filter the signal.
Mike |
|
|
ssaakmnt
Joined: 03 Dec 2011 Posts: 27
|
|
Posted: Thu Jan 03, 2013 4:47 am |
|
|
Ok I will search that I/P protection and low pass filter ,also I will search what temtronic said about multiple samples and averages..I don't have much experience with ADC module so i will search more..thank all for responses and I don't if there any other reliable methods to implement Ammeter code with ADC . |
|
|
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
Ammeters |
Posted: Thu Jan 03, 2013 5:27 am |
|
|
The reason for my inital question is that the normal method of implementing an ammeter is to use a low value shunt which yields ~100mV max. (Whether digital or analogue.)
In your case you may be able to get away with 5V across the shunt.
Many digital voltmeters (and modules) have an FSD ~100mV at maximum sensitivity, so can be used in much the same way as their analogue precursors.
When using a PIC which requires ~5V I/P, it's usual to use a low value shunt and some sort of OPA preamplifier. (As outlined by temtronic.)
Earlier you mentioned instability. It may be worth investigating the cause.
Mike |
|
|
ssaakmnt
Joined: 03 Dec 2011 Posts: 27
|
|
Posted: Thu Jan 03, 2013 6:03 am |
|
|
Hmm.. OK the instability I think (as lot of people say) due to noise , when I compare the reading from pic to digital ammeter I find for example :
11.55A,12.4A,12.5A these reading are same for both pic and ammeter it last for moment and then reading of pic jumps to 13A and 14A and back again ? |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9243 Location: Greensville,Ontario
|
|
Posted: Thu Jan 03, 2013 6:35 am |
|
|
Good news is the PIC and your ammeter read the same. Most DMM,DAM,DVM,... sample 3-4 times per second.
You don't say what the source of the 'load' is that you're measuring.If it's a motor, electrical noise is a real possibility.and you will need to 'filter' the readings either with R-C circuitry or digitally( Olympic average).
Hay, you're making good progress !
hth
jay |
|
|
ssaakmnt
Joined: 03 Dec 2011 Posts: 27
|
|
Posted: Thu Jan 03, 2013 7:22 am |
|
|
yes..it supposed to measure current of 3 phase motor through current transformer 50/5A kn and 5A feed to transducer which output 4-20mA.
but is this varying value from (correct 11.5 and 12A )to 13.5 and 14A
because I didn't sample or about voltage reference range or what ? thank you . |
|
|
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
|
Posted: Thu Jan 03, 2013 10:05 am |
|
|
Quote: | it supposed to measure current of 3 phase motor through current transformer 50/5A kn and 5A feed to transducer which output 4-20mA.
but is this varying value from (correct 11.5 and 12A )to 13.5 and 14A
because I didn't sample or about voltage reference range or what ? | Don't know.
What does signal across your 250R burden resistor look like?
OR
Can you provide a link to the sensor?
Mike |
|
|
ssaakmnt
Joined: 03 Dec 2011 Posts: 27
|
|
|
|