# How to measure the current by AVR

Discussion in 'Embedded Systems and Microcontrollers' started by SaraSa, Jun 19, 2011.

1. ### SaraSa Thread Starter Member

Feb 11, 2009
25
0
Hello all,
I should measure the current of a circuit by a micro controller. When the current becomes more than 20A, micro will not allow the circuit works. I know that I should work with ADC in micro. the voltage is obvious; 5V.
but the problem is that both resistance and current are unknown.

what's the maximum current of micro? is there a relation with them??

How should I solve this problem??

any help will be appreciated.

2. ### MrChips Moderator

Oct 2, 2009
12,625
3,451
I believe you are approaching this problem incorrectly, if I understand the problem.

To measure current, use the smallest value resistor in series with your circuit, a value that will give you reasonable voltage that you can measure.
You know the value of the resistor, measure the voltage across the resistor with the micro and calculate the current through the resistor.

3. ### Tahmid Active Member

Jul 2, 2008
344
27
This should clear things up:

The sense resistor (R1) should be chosen to have a low resistance and still give a voltage reading that the PIC can detect. If the voltage reading is too small, you can use an op-amp to amplify it.

Initially, the PIC turns on a transistor that turns the relay on.

Say you have a 0.1R resistor. If 15A current passes, according to Ohm's Law, V=IR = 15*0.1 = 1.5v, ie voltage across R1 is 1.5V. When I = 20A, V=20*0.1 = 2V. In the PIC code, set it such that when the reading is greater than 20A, ie, the voltage read by the ADC is greater than 2V, then the micro turns the relay off and stays in that state until power reset or something like that.

Hope this helps.
Tahmid.

SaraSa likes this.
4. ### SaraSa Thread Starter Member

Feb 11, 2009
25
0
Thanx alot.
but I want to know the current before the relay is on.
you say the relay is on at first, then measure the current, finally micro decides that relay goes out... In this situation, if the current is more than 20 A, for example the voltage in the input of ADC is 7V, the port burns. because the port of ADC can tolerate less than 5 V.

what's your suggestion to measure current before the circuit works?
in fact, we should control the circuit before it starts to work.

Any help is appreciated.

5. ### MrChips Moderator

Oct 2, 2009
12,625
3,451
I don't think you are following what Tahmid has suggested or analyzing the circuit correctly.
The current sense resistor in series with the load is on the GND side. You select the value of this resistor so that the voltage across it is in the measurable range, e.g. 2V at 20A.
He has also given you a voltage clamp on the input to the micro to prevent the voltage from exceeding 5.1V.

Assuming you are trying to build an electronic circuit breaker that trips when the load current exceeds 20A, you begin with the relay contacts closed allowing you to monitor the current. Once the limit has been exceeded you open the contacts and disconnect the power reducing the current to zero.

Once the breaker has been tripped the only way to re-energize the relay is to provide a manual reset button.
Hence the solution Tahmid provides is sound and good.

Tahmid and SaraSa like this.
6. ### Tahmid Active Member

Jul 2, 2008
344
27
MrChips has explained everything, but I'll just add it to clarify if necessary.

You choose the resistor value assuming that the trip current causes a specific voltage drop across the sense resistor that lies within the voltage range of the microcontroller AND making sure that it does not dissipate too much power across the resistor itself.

So, you may choose a resistance that causes a 2V drop at 20A as I suggested above. In reality you will need to choose something smaller to keep power drop across the resistor small as power across the resistor = VI = 2*20 = 40W! You don't want that across the resistor. Try to keep it within 5W, otherwise at least under 10W. So, P=I*I*R as V=IR. So to keep power dissipation at 5W when 20A current flows, R=P/(I*I) = 5/(400) = 0.0125. A close value is 0.01 ohms. So, let's say you have 0.01 ohms resistance. V= IR = 20*.01 = 0.2V. The microcontroller can quite easily read this voltage using the ADC.

IF by any chance voltage is greater than 5v to the microcontroller (I don't think it ever will get that large and if it does, it'll probably burn your sense resistor), there's a clamp (5.1v zener) that'll clamp the voltage to 5.1v +- something depending on the precision of the zener diode.

I hope I could explain everything.

Hope this helps.
Tahmid.