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 support@ccsinfo.com

best way to measure voltage/current with PIC??
Goto page 1, 2, 3  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
buckeyes1997
Guest







best way to measure voltage/current with PIC??
PostPosted: Sun Dec 19, 2004 9:54 pm     Reply with quote

i have been using the search to try and find out the best way to take both current and voltage measurements with a PIC. I am mostly looking for the external circuit that is used. i want to be able to accurately measure current from say 0-20A and voltages from 0-25V.

i spose the voltage would be easiest since all i would need is a voltage divider that reduces the max to say 5v right? maybe an op-amp with a negative gain?

the only way i could see for calculating the current is with a resistive shunt. i would think a high known resistance in series and then the voltage drop would be measured then use Ohms law?? on second thought the resistance would have to be very small so as not to affect the circuit in question. this would generate quite a lot of heat at 20A.

any ideas???
thanks everyone
buckeyes1997
Guest







oops
PostPosted: Sun Dec 19, 2004 9:55 pm     Reply with quote

guess i should mention this is DC so phase angle need not be worried about.
thanks
matt
Kenny



Joined: 07 Sep 2003
Posts: 173
Location: Australia

View user's profile Send private message

PostPosted: Mon Dec 20, 2004 1:40 am     Reply with quote

A voltage divider would be OK for the voltage measurement.
Keep in mind that the A/D on pics have a maximum resistance spec. eg it's 10K on the 16F876 to maintain the full 10 bit accuracy.
If concerned about current consumed by the divider use high resistance values on the divider and a unity gain buffer op-amp.

Re current, The MAX472 is a good chip
http://pdfserv.maxim-ic.com/en/ds/MAX471-MAX472.pdf

A short length of tinned copper wire rated for 20A is all that is needed for the resistor. Don't try to measure the resistance directly, instead send a constant current through it and slide your voltmeter probe along it till you get the right voltage (calculated from the required resistance). Then cut it and wind it, on a pen for example, into a loose coil.
neil



Joined: 08 Sep 2003
Posts: 128

View user's profile Send private message

Current sensing
PostPosted: Mon Dec 20, 2004 3:43 am     Reply with quote

Hi Matt,

what is your cost limit? There are some nice current transducers made by LEM www.lem.com These use hall effect sensing to measure DC current without electrical connection to the circuit, eg. no volts dropped across a shunt! The DCCTs usually measure AC RMS as well.

Also, you can buy precision shunts with a specified Volts-per-amp rating. Depends on your budget. If it is tight, the best option might be Kenny's copper wire around a pencil. I have used these before with success.

Bear in mind though, a 20A shunt would have to develop only a very small voltage to be viable. 20A at 200mV would be a 10mΩ resistance. This would dissipate 4Watts. Quite warm if it's in a small space. For these small voltages, you would need a low noise differential op-amp with gain to make a voltage to match the full-scale of the ADC.

For measuring accurate voltages with the PIC, I always use an external precision voltage reference. Maxim do these as single devices (shunt type) and are available in 'binary' voltages such as 2.048V, 4.096V. This gives a whole number voltage for each LSB change. a 10 bit ADC with a 2.048V reference would have a 2mV LSB step. This makes any software scaling from hex to 'volts' easy and sometimes even direct.

Make sure any resistors you use for dividing voltage are precision ones. You might consider a precision divider resistor, where there are two accurately tolerance matched resistors in one package.

I hope these suggestions have helped, and forgive me if I'm telling you things you already know!
Regards,
Neil.
buckeyes1886
Guest







more info
PostPosted: Mon Dec 20, 2004 10:09 am     Reply with quote

my cost limit is cheaper is better but dont want to comprimise accuracy too much. if i understand correctly the best way to measure the voltage is to use a very high resistance divider that feeds into a unity (or maybe scaled to get more sensitivity) op-amp. this circuit should consume very little power and be reasonably accurate with a PIC.

im still not sure how i want to proceed with current measurement. i looked over the maxim chip suggested and it looks very complicated to setup. i think the idea about the copper wire is more along the lines of what i was looking for so long as it doesnt glow bright red with heat..haha. im not sure i understand your method of using it though, could you explain in a little more detail for me. i will google it and see what i can come up with also.

thanks guys
matt
buckeyes1997
Guest







solid voltage reference
PostPosted: Mon Dec 20, 2004 10:11 am     Reply with quote

if i run the pic at 5v and assume that it wont drop below say 3v, i should be able to use a zener for a voltage reference of say 2.5v to the adc right? what problems would this cause? what are the problems with using the internal voltage references as long as they are below the minimum Vdd supply voltage??
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

Re: solid voltage reference
PostPosted: Mon Dec 20, 2004 10:59 am     Reply with quote

buckeyes1997 wrote:
if i run the pic at 5v and assume that it wont drop below say 3v, i should be able to use a zener for a voltage reference of say 2.5v to the adc right? what problems would this cause? what are the problems with using the internal voltage references as long as they are below the minimum Vdd supply voltage??

It all depends on what accuracy you need. You may well get away with using Vdd as the reference. A garden variety zener may be no better. If your PIC has an internal reference, look at its specs and compare to your requirements. Few applications need an external reference if you are only digitizing to 8 or 10 bits.
Tell us more about the application.
_________________
The search for better is endless. Instead simply find very good and get the job done.
buckeyes1997
Guest







more about the design
PostPosted: Mon Dec 20, 2004 1:47 pm     Reply with quote

im wanting to make a box that has an LCD and two wires coming in and two wires going out. the magic box will calculate and display the voltage on the input as well as the current thru the box and therefore the power. the ratings will be 0-25v and 0-25A. the box will be a serial inline device that should not modify or affect the input hardly any.

basically i think a voltage divider with a 10k in series and a 2.5k in parallel will produce 5v when the input is 25v and meets the req of 10k to the adc.

now to measure current i am investigating different approaches. i thought about maybe using a current shunt and a chip to measure small currents like the maxims. i had thought about using some variation on a hall effect sensor (and like the idea because its isolated) to relate the field to calculate the current. im looking for some suggestions on ways to calculate the current accurately and CHEAPLY. i also dont want an overly complicated external circuit which is why i was asking about using the internal Vref or just a zener off of Vdd to set the adc reference rather than using another IC to control the Vref.

thanks
jds-pic



Joined: 17 Sep 2003
Posts: 205

View user's profile Send private message

Re: more about the design
PostPosted: Mon Dec 20, 2004 2:18 pm     Reply with quote

buckeyes1997 wrote:
im wanting to make a box that has an LCD and two wires coming in and two wires going out.

the very first question that i have to ask in these applications is whether the voltage/current you are trying to measure has the same ground reference as the PIC. if it is not, you will have to do some work on input isolation.

the next question is whether you have looked at commerical implementations and what advanteges/disadvantages do you see with rolling your own?
e.g.
http://www.powerwerx.com/product.asp?ProdID=3376&CtgID=3587
and
http://www.powerwerx.com/techdata/PA-60100.pdf

jds-pic
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Mon Dec 20, 2004 2:53 pm     Reply with quote

If the LCD is the only I/O I would float the whole circuit at the "Ground" potential of the DC you are measuring. If you can power the PIC from batteries or a wall wart transformer the isolation problem jds-pic mentions goes away. If you were measuring 110VAC I would not recommend this unless you really REALLY know what you are doing. But for 24VDC it should be fine.

As far a accuracy of the Vref, we still don't know what accuracy you need. If you are just monitoring electric toy trains then 8 bits should be fine and you can use +5V from any regulator to power the PIC and as Vref. If it is some precision medical instrument or space probe things are different. One point of reference: How many digits does your LCD have? There is no sense in measuring to more precision than you can display.
_________________
The search for better is endless. Instead simply find very good and get the job done.
Kenny



Joined: 07 Sep 2003
Posts: 173
Location: Australia

View user's profile Send private message

PostPosted: Mon Dec 20, 2004 3:15 pm     Reply with quote

The current spec. has crept up a bit and the sensor would be in a box so I'd definitely go for the Hall Effect device as mentioned by Neil, if you still want to make your own.
Some of these are reasonably priced.
20A was pushing it for the MAX472 - in the table the resistance values shown are for 50mV across the sense resistor. At 20A and 2.5 milliohm the dissipation would be 1W.
However, accuracy would be only a few percent - as it says in the data sheet "offsets become less significant when the sense voltage is bigger."
But more voltage means more heat.
Sorry for the bum steer.
buckeyes1997
Guest







PostPosted: Mon Dec 20, 2004 9:23 pm     Reply with quote

i know i can buy a commercial unit that will work but where's the fun in that. also by designing my own i can customize it to do exactly what i want they way i want it done.

the accuracy needs to be good but its for measuring the power systems for RC motors such as planes, cars, boats, etc. the LCD need only display 2 or 3 digits beyond the decimal. the link to the medusa unit is basically what im shooting for so perhaps check that link out and you will see roughly what im aiming for.

i dont think they use external power supplies or batteries so they must be using the input for power also. that would be nice if its not too much of a problem, otherwise a 9v battery and 7805 5v regulator works for me...hehe.

are we in agreement about using the voltage divider with my calculated values for the voltage measurement???

what would the consensus be on current? using a max chip with a source resistance external to the chip works for me if thats what seems like the best comprimise of accuracy, affordability and ease of design. a small toroid coil with one leg of the input wrapped around and then induces a small current in a secondary that is passed thru a resister might be another option if its small enough??

thanks
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Tue Dec 21, 2004 8:14 am     Reply with quote

The input range of 0V to 25V drove me away from powering the unit from that input (0V???). But if the Medusa's 4.5V minimum input is OK you could regulate that to a stable 4.0V which should run everything. At low currents you must realize the display shows the OUTPUT current, not the INPUT current. The Medusa seems to have a resolution of about 1:380 (19A/0.05A) which is about 8.5 bits. They don't give an accuracy spec, but 1% resistors, or 5% resistors and trimming with software, should get you enough accuracy for the task.

A voltage divider should do fine for voltage. If the divider can take a few milliamps then you don't need an opamp. The opamp would probably take a few milliamps anyway and it all comes from the same source.

For current the MAX472 is a good flexable chip. In this case you have the luxury of measuring in either the (+) or the (-) lead which is often not the case. If you put your measuring resistance in the (-) all you need is a rail-to-rail input opamp to boost the signal to the A/D range (now 4V).

The toroid as you describe it won't work for DC. The Hall effect device has a DC magnetic sensor, not just a sense winding. For educational purposes I recommend using a shunt resistor over buying a Hall effect "black box" unless you want to research how the Hall sensor works. (Note that the toroid's properties change with temperature. How do they deal with that?)
_________________
The search for better is endless. Instead simply find very good and get the job done.
neil



Joined: 08 Sep 2003
Posts: 128

View user's profile Send private message

Current sensing
PostPosted: Tue Dec 21, 2004 8:30 am     Reply with quote

Hi Matt,

with regards to the last line in your last post, remember you are measuring DC current, so a toroid as a CT will not work as it needs AC to produce a changing magnetic field. The hall effect devices use an air-gapped core, with a hall-effect wafer in the gap. This measures the static magnetic field around your current carrying wire.

If this device is going to be measuring current & power through model plane/boat motors, I would strongly recommend the hall effect sensor, as you really don't want any dropped volts. (Model motors are often 9.6V?). If you were to make an accurate measurement of current with volts dropped across a shunt, when you connect the motor in the proper end circuit, the current will be higher than that measured.
neil



Joined: 08 Sep 2003
Posts: 128

View user's profile Send private message

whoops!
PostPosted: Tue Dec 21, 2004 8:38 am     Reply with quote

Sorry SherpaDoug, looks like our posts crossed!

I would still also go for a binary voltage reference eg. a MAX6021 as this makes your software scaling of the ADC value very simple and accurate. Personally, I would never use the Vdd as a reference if I was measuring voltage.

Remember, Maxim give away free samples, but unfortunately, nearly all of their products are surface mount.
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, 3  Next
Page 1 of 3

 
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