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

best way to measure voltage/current with PIC??
Goto page Previous  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
SherpaDoug



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

View user's profile Send private message

PostPosted: Tue Dec 21, 2004 9:05 am     Reply with quote

I work with model trains (play with toy trains) and sometimes I only really need 4 bits of accuracy. Often Vcc works just fine as Vref.
I also work with oceanographic instruments (20+ bits), and on more accurate gear I tend to tweak software constants to compensate for resistor errors and sensor gains and offsets. So I have never seen the value of binary voltage references as I am always multiplying by odd constants anyway.
The Hall sensor is OK if the price is right and you just want the job done. If you are looking for the "educational experience" I would stay with little building blocks you understand well, and stay away from magical black box solutions.
Each will follow his own path....
_________________
The search for better is endless. Instead simply find very good and get the job done.
buckeyes1997
Guest







boy dont i feel dumb
PostPosted: Tue Dec 21, 2004 11:35 am     Reply with quote

hahaha yep no point using a transformer with a DC...duh.

i seem to be getting two nice options. the hall effect and the shunt with the max chip. it seems like both would work well. the current carrying wire with DC will have orbiting magnetic field which with a hall effect measuring the field could be scalled to read a current producing it by one of the formulas that i dont recall..haha.

the max chip would work also but wasnt i limited on current capacity to 20A? wonder how the medusa design is doing it?? they can measure up to 100A without overheating. im not sure what you mean by the op amp across the rails on the max option?? is that just because the output from the chip is going to be only up to a few millivolts??

thanks guys
SherpaDoug



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

View user's profile Send private message

PostPosted: Tue Dec 21, 2004 12:13 pm     Reply with quote

The MAX472 takes an external shunt, so it can handle any current you have a shunt for. Consider this from Digi-key:
http://www.digikey.com/scripts/DkSearch/dksus.dll?Detail?Ref=99690&Row=138425&Site=US
The MAX472 is designed for the shunt to be in the (+) lead which you need if your load and supply are both hard grounded. If you can put the shunt in the (-) lead so one end of the shunt is at ground of the A/D you can just use a rail-to-rail input opamp instead of the MAX472.
The MAX472 doesn't need an opamp with the right resistor selection, but as far as I know it is only available from Maxim. For a commercial product you may wish to avoid "sole source" parts. For a home project Maxim gives free samples, so a liability turns into a benefit!
_________________
The search for better is endless. Instead simply find very good and get the job done.
buckeyes1997
Guest







interesting
PostPosted: Tue Dec 21, 2004 3:34 pm     Reply with quote

i like the idea of not relying on the max chip and just using the op amp.
can you explain it a little more detail for me. i dont see why i couldnt put the sense resistor in the neg rail. then im basically using the op amp to amplify the voltage across the sense resistor and can caclulte the current using i=v/r????

using this method i would have the plus and minus input and the plus and minus output and it would be a common ground right? and the sense resistor is inline with the neg rail and the op amp pulls plus voltage in from positive rail to increase the voltage from the millivolts across the sense resistor to something readable like 4v for the adc pin right??


the only advantage of using the max chip is what? it hardware calculates the current directly rather than using software to take a voltage and known resistance and calculating current?? ill read over the spec sheet again. the link to digikey you posted didnt work can you tell me what you searched for on their site and ill look at that too.

thanks
matt
buckeyes1997
Guest







okay good
PostPosted: Tue Dec 21, 2004 3:53 pm     Reply with quote

okay i checked out the max472 and it looks like it would be the hot ticket but still need to figure out what to use for the sense resistor. i see that im going to have to do like the medusa and say the voltage is from say 4-25v rather than from zero so that the unit will run from the source rather than relying on say an additional source for the uC and the LCD.....althought a seperate source might still simplify the overall design...hmmmm.

seems like i could use an op amp and a sense resistor like you suggested instead of the max chip and then i would not rely on any magic boxes or chips. from an educational stand that would be better i think. the output of the max is a current that they drop thru a resistor to get the proportional voltage for the ADC anyway so they are basically using the same principle only all in one package.
SherpaDoug



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

View user's profile Send private message

PostPosted: Tue Dec 21, 2004 4:19 pm     Reply with quote

I think you have it about right. You don't quite have a common ground because the sense resistor is in the ground giving a few mV between the supply GND and the load GND. Use a rail-to-rail input opamp because most other amps don't like to have their inputs too close to their power supply voltages. Look at a OPA705 from TI for starters.
Also look up the LMC6681 datasheet. Figure 27 of the datasheet is the schematic you want, and a short description of how it works.
In Digi-key I searched for "current sense resistor", then picked the appropriate resistance and saw what wattages were available. Or you might be able to use some copper wire, or a paperclip. I have a large paperclip on my desk of about 0.040" steel wire that reads 0.028 Ohms in a 6" length. At 20A that would give .560V so an amplifier gain of 7.14 would give 4.0V full scale.
Better still if you used 1" of wire to give 0.0047 Ohms you would need a gain of 42.8 to get 4.0V. That is a reasonable gain and the heat loss is only 1.88W and voltage loss of 0.094V. The steel wire will heat up and its resistance will drift slightly, so a "professional" resistor will give better accuracy, but they cost $10 and don't teach you as much!
_________________
The search for better is endless. Instead simply find very good and get the job done.
buckeyes1997
Guest







okay so this should work
PostPosted: Tue Dec 21, 2004 4:24 pm     Reply with quote

okay so i should be able to use this circuit http://hyperphysics.phy-astr.gsu.edu/hbase/electronic/opampvar6.html#c2

this will give me the small voltage drop across a sense resistor in either the positive or negative rail which can then be amplified with the resistors to be in the range acceptable for the ADC. i think this is a better solution for me than using an IC to do it for me. This way i learn more and can use readily available parts to make it.

all i need to know is how to make a sense resistor that is capable of operating within my 0-25A current range. i found a website that shows how to make shunts out of large guage copper wire so maybe that will work since they would be so small that they hardly affect the external circuit and shouldnt heat up very much since the I^2 R losses would be small due to the very small R. the output from the difference amp would be low impedence which is less than 10K for the ADC on the PIC.

hopefully this sounds like a winner.

im wondering about using a second op amp and doing a difference amplifier with ground and the input to scale the voltage and read the voltage directly as a difference between 0 and input voltage????
djwallace



Joined: 26 Nov 2004
Posts: 10

View user's profile Send private message Send e-mail MSN Messenger

similar problem
PostPosted: Tue Dec 21, 2004 4:57 pm     Reply with quote

I have a similar problem where I want to measure the voltage/ current..

I am currently designing a maximum power point tracker and accuracy is important. I have been trying to use a hall effect current sensor from LEM.. the LTS-6 (0-6A range) is the one I want, and the LTS-15(0-15A Range) is the one I have for testing right now..

the problem is that the current range from 0-15 AMPS on this sensor, the output ranges from 2.5V-3.125 V.. now I'm not sure why they did this.. a large range would've been better.

anyhoo.. I need 0-6A range preferribly brought down to a 0-5V singal range (for maximum resolution).. any suggestions?
_________________
darryl
buckeyes1997
Guest







PostPosted: Tue Dec 21, 2004 5:07 pm     Reply with quote

what do you mean by rail-to-rail?? does that simply mean its gets its negative from the negative rail and its positive from the positive rail?? im a little confused about which amp to choose.

if i could use a regular 741 type op amp i could get the dual package on a chip and use one for voltage and one for current??
thanks
matt

djwallace:
im not sure what you would need for that LEM module which is why i tried to stay away from using a "magic chip" design. you could use a level shifter to shift it down to 0-3v and then amplify it to get the 0-5v for better resolution?? these guys are good and can certainly help.
djwallace



Joined: 26 Nov 2004
Posts: 10

View user's profile Send private message Send e-mail MSN Messenger

yo
PostPosted: Tue Dec 21, 2004 7:08 pm     Reply with quote

I have no idea what a 'level-shifter' is..

could you please elaborate on that?
_________________
darryl
kender



Joined: 09 Aug 2004
Posts: 768
Location: Silicon Valley

View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger

PostPosted: Wed Dec 22, 2004 12:00 am     Reply with quote

I would recommend the Hall-effect current sensors.

http://www.allegromicro.com/hall/currentsensor.asp
neil



Joined: 08 Sep 2003
Posts: 128

View user's profile Send private message

Rail to Rail
PostPosted: Wed Dec 22, 2004 4:59 am     Reply with quote

Hi Matt,

just to settle this definition: Rail to rail is the capability of an op-amp's input and/or output to go to the high and low power rail. The high and low power rail can be +V and -V or just +V and GND respectively, for op-amps which are capable of single supply operation.

Rail-to-rail input simply means that you can connect either + or - inputs (AKA non-inverting and inverting inputs) to either power rail without damage.

Rail-to-rail output means that the amplifier's output can swing through a signal range from -V to +V. This might not mean a lot, and you may say that well, surely they would all be able to do that, but in practise a lot of op-amps can't because of their internal architecture. They are essentially built our of transistors, which have inherent volt-drops. A rail to rail amp will usually have a FET(s) in their design to reduce volt drops.

The need for rail to rail capability is such in this design because you are measuring a voltage (across a shunt) which is close to the power rail. One side of the shunt will be at 0V (so also make sure your op-amp is single supply capable AND rail to rail) and the other side of the shunt will be a few mV above 0V. In terms of your load, the less volt drop the better; in terms of your measurement signal to noise ratio, the higher the better. This will have to be a trade-off!

You will also have to consider that your ADC will probably occasionally read noise spikes from your model motor (I know some of these are a bit ropey!) Make sure there is a capacitor (snubber) across your motor, and in terms of software, I think it would be good to take a bunch of ADC readings and then average them before updating to the LCD.

That's one for the 'real programmers' out there, ie. not me!!

A good book which covers analogue electronics very well, albeit a bit old now is Horowitz & Hill's 'Art of Electronics'. It's about the thickness of a dictionary, so not cheap but worth having!

Best of luck,
Neil.
buckeyes1997
Guest







PostPosted: Wed Dec 22, 2004 9:59 am     Reply with quote

okay so i need a single supply op amp that can swing from rail to rail. some of the cheap ones like the lm324 wont swing high well so what i found was this one.

microchip mcp601
here is a link to some specs and design apps. the very last one for the difference amp is what im planning to use it for so it looks like a match right??

http://ww1.microchip.com/downloads/en/AppNotes/00682c.pdf

i will just scale the resisters to drop the high side of the sense resistor to output a small voltage and the low side of the sense resisotr to output a smaller voltage and the difference will then be scaled from 0-5v for the ADC right?
buckeyes1997
Guest







PostPosted: Wed Dec 22, 2004 10:01 am     Reply with quote

yes neil i think there will have to be some knd of averaging algorithm in software to control spikes on the load. im thinking of updating the lcd each second with a time counter, voltage, current readings displayed as well as mah or power etc. that gives me time to read the ADC a handful of times and take the average each second. probably an interupt that reads the ADC values every so many ms and returns to mail where the average and LCD function is done each around every second.
neil



Joined: 08 Sep 2003
Posts: 128

View user's profile Send private message

PostPosted: Wed Dec 22, 2004 11:27 am     Reply with quote

Hi Matt,
That's the one. The differntial amp is ideal because it has high common mode noise rejection. Any noise which is common to both the V1 and V2 inputs is cancelled out and only the difference between the two is amplified.

However, I may be misleading you. As mentioned before, you have the luxury of being able to put your shunt in the negative rail. In which case, I see no point in having a differential amp, as one side of the shut is 'at ground'. For this you would only need a straight-forward non-inverting amp with gain, meaning you save 2 resistors!

The differential amp would only be needed if the shunt was in the positive rail.

Aside from this... I have requested samples of those Allegro hall-effect current sensors. They look very simple and should be cheap. I've gone for the 200A version, as I have a use for one of those! I'll post back when I have tried one.

Anyway, I'm off for Christmas now and will be back in mid-January. Have a good one everybody! Very Happy

Neil.
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 Previous  1, 2, 3  Next
Page 2 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