CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

reading volt with pic16f877 ADC
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
ssaakmnt



Joined: 03 Dec 2011
Posts: 27

View user's profile Send private message

reading volt with pic16f877 ADC
PostPosted: Wed Jan 02, 2013 12:53 pm     Reply with quote

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: 9226
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Wed Jan 02, 2013 1:11 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Jan 02, 2013 2:23 pm     Reply with quote

What is your supply rail voltage?

Mike
ssaakmnt



Joined: 03 Dec 2011
Posts: 27

View user's profile Send private message

PostPosted: Wed Jan 02, 2013 3:39 pm     Reply with quote

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: 9226
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Wed Jan 02, 2013 4:12 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Jan 02, 2013 4:20 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Jan 03, 2013 3:00 am     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Jan 03, 2013 3:58 am     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Jan 03, 2013 4:47 am     Reply with quote

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

View user's profile Send private message

Ammeters
PostPosted: Thu Jan 03, 2013 5:27 am     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Jan 03, 2013 6:03 am     Reply with quote

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: 9226
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Thu Jan 03, 2013 6:35 am     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Jan 03, 2013 7:22 am     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Jan 03, 2013 10:05 am     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Jan 03, 2013 12:12 pm     Reply with quote

it is MACX MCR-SL-CAC-5-I(-UP) http://select.phoenixcontact.com/phoenix/dwl/dwlfr1.jsp?lang=en Order Number or product typ: 2810612
it is originally works with PLC unit but I try here to see what happens with pic .
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group