# Measure Current using PIC Microcontroller

#### blocco a spirale

Joined Jun 18, 2008
1,546
If you want the signal to be 10 times bigger, use a 1 Ohm I-sense resistor. Apart from the worst case 0.3V drop (which can be overcome) it's a whole lot better and less hassle than adding an op-amp.

#### SgtWookie

Joined Jul 17, 2007
22,230
If you want the signal to be 10 times bigger, use a 1 Ohm I-sense resistor. Apart from the worst case 0.3V drop (which can be overcome) it's a whole lot better and less hassle than adding an op-amp.
While changing Rsense to 1 Ohm would work, the OP would dissipate 10x the power across the 1 Ohm as the 0.1 Ohm resistor. The power dissipation will require going to a much higher rated power resistor; non-inductive versions of these can be difficult for a hobbyiest to find. Ohmite does make non-inductive wire wound power resistors; I've found them on Mouser and Digikey. However, at 0.3v/1 Ohm, he could still use a 1/2W carbon film resistor. It kind of depends on how the OP is powering their circuit, and what kind of efficiency they are expecting out of it.

For the OP's benefit - you would not want to use a typical wire-wound power resistor in your circuit, as when the current through the resistor changes significantly there will be an inductive "kick" or voltage spike across the inductive resistor. This will cause the output to fluctuate wildly.

Last edited:

#### SgtWookie

Joined Jul 17, 2007
22,230
If you wish to get close to 10x amplification, replace your 100k R2 with a 91k resistor.
At that point, gain = (R1+R2)/R1 = (10k+91k)/10k = 101k/10k = 10.1

#### blocco a spirale

Joined Jun 18, 2008
1,546
While changing Rsense to 1 Ohm would work, the OP would dissipate 10x the power across the 1 Ohm as the 0.1 Ohm resistor. The power dissipation will require going to a much higher rated power resistor; non-inductive versions of these can be difficult for a hobbyiest to find. Ohmite does make non-inductive wire wound power resistors; I've found them on Mouser and Digikey. However, at 0.3v/1 Ohm, he could still use a 1/2W carbon film resistor. It kind of depends on how the OP is powering their circuit, and what kind of efficiency they are expecting out of it.

For the OP's benefit - you would not want to use a typical wire-wound power resistor in your circuit, as when the current through the resistor changes significantly there will be an inductive "kick" or voltage spike across the inductive resistor. This will cause the output to fluctuate wildly.
I'm afraid I don't understand any of this talk of high-power wire-wound resistors as a 1 Ohm resistor only has to dissipate 0.09W worst-case which just about any old resistor will manage. 1% O.6W 1R metal films are available just about everywhere.

As I mentioned in a previous post, the I-sense resistor could be bypassed with a transistor most of the time thus dissipating zero power. With a bit of PIC magic the transistor can be switched off just long enough to get a current reading every second or several seconds.

A 1 Ohm resistor will also result in a considerably better signal to noise ratio than a 0.1 Ohm + op-amp.

#### jut

Joined Aug 25, 2007
224
OK I finally got the circuit working. It wasn't grounded properly. But anyways, I ended up using two 9V batters to get my dual power supply.

With the LM1458, I found an offset of about 6 mV. I discovered I had a TL082 on hand, which had an offset of 0.7 mV... much better. But the LT1006 (got a few samples on the way) has got them all beat with a "Guaranteed" offset of 0.05 mV max.

As luck would have it, I found a 1 Ω resistor (part number MPC722) in my salvage/junk box. I tested that out as my R-sense. It must be very close to 1 Ω because it drops the correct amount of voltage.

I haven't mentioned this yet... I plan on using a PIC to monitor the current output from my little 12" x 12" solar panel. It'll probably put out about 2 practical watts. So losing about 0.1 watts isn't a huge deal.

Thank you both for the help on this.

#### SgtWookie

Joined Jul 17, 2007
22,230
Your panel's output may be closer to 3W. I have a panel that's about 12"x8" and it outputs 2W.

Note that it's only the LT1006Ax that has the guaranteed 50uV or less offset. The LT1006M/C can go as high as 80, and the LT1006S can go as high as 400uV.

Don't forget to have your PIC take a snooze for a bit while the ADC is being read; your results will be much more accurate. If you don't, the digital noise created by the PIC itself will give you very significant errors.

[eta]
Read this analog design note from Microchip:

Last edited:

#### jut

Joined Aug 25, 2007
224
How did you measure the power output of your solar panel?

It turns out that the LT1006CN8 was the only sample in a DIP. But that sure beats the TL082's 700 uV.

Funny you mentioned that about the PIC. I've been on a quest trying to get an accurate A/D reading. I actually went through all those designs note from microchip recently. I just recently increased my accuracy by speeding up the conversion time (found this out in a silicon errata sheet). Last week I read the same thing about putting the PIC to sleep while doing the A/D conversion, but not from a microchip design note. Should the PIC be sleeping during the acquisition, or during the conversion, or both?

Right now my circuits are on protoboard with wirewrapping. Eventually I'm hoping to make my own PCBs on a CNC so I can have a ground plane.

#### SgtWookie

Joined Jul 17, 2007
22,230
Well, being wirewrapped on a protoboard, you're going to have one dickens of a time getting stable ADC readings. You probably won't be able to do it. Even "dead bug" style on a copper ground plane would likely get you much better results.

When you're eventually building your board, you might be tempted to put your PIC in a socket. Don't do it. If you weren't doing ADC, you'd be fine - but the socket will add a variable resistance to both your analog signal path and the path to the ground plane. Solder it down.

As far as the sleeping - it'll only take a few lines of code for you to find out.

For your resistors in the analog path - use 1% tolerance metal film. They will generate far less noise than other types (thick/thin film carbon). Putting current through a resistor is very similar to squirting water from the nozzle on a hose. Makes noise, right? It's a lot quieter if you toss the nozzle in a bucket of water. That's where capacitors come in.

#### shanthiga

Joined Jan 20, 2010
5
i want check the status of the electrical devices(light, heater..etc) through PIC 18F series..pls give ideas to monitor..

#### shanthiga

Joined Jan 20, 2010
5
im going to remotely check the status(on/off) of the electrical devices (<1500W)..how can i do this? i prefer the common circuit to do this function...