# Calculate how much current is a microcontroller's pin drawing

I am reading up on microcontrollers and I want to know the current that RA0 is drawing when the switch is open but I think I'am getting it wrong. Also my electronics knowledge is elementary at best.

I=V/R
I=5V/4700Ohm
I=1.06mA (rounded off)


I expected to get something close to 50mA or something because of the table below

I need some help.

-

You calculation is based on the assumption, that the RA0 pin will sink the current. But this is only true, when the pin is configured as an output and driven low.

Since pin RA0 apparently is sensing, whether the button is pushed, the pin is likely to be configured as an input. In this case almost no current (only some leakage current) will flow when the button is open.

The table you are reffering to shows the absolute maximum ratings. Your pins should never sink/source more than the current given there.

-

If you configured your pin, RA0, as an input it means that your pin is in Hi-Impedence mode and it will draw an insignificant amount of current, called Input Leakage Current.

You'll find the value of the Input Leakage Current in the PIC16F84 datasheet, page 55:

So RA0 will only draw 1uA.

Your calculation would be correct if you would configure the pin as an output and set it to 0/low. Then the pin will sink 1.06mA.

-

The current you've calculated is correct and passes through 4K7 when the switch is closed.

When it's opened, some current flows through RA0, provided it's configured as input. The logic level in RA0 will be logic 1. Voltage level will be near 5V. Current will be near zero. The exact value doesn't appear in the tables you've provided, but it should be uA or nA. Consider it initially as 1uA, as our colleague informed.

But you could also measure that current:

• measure the resistance of the 4K7 resistor
• use a precision (the best you've at hand, anyway) voltmeter, to measure the voltage drop V across R when the switch is opened
• calculate I=V/R, as you know

Xezi

-
 Why dont measure the current directly? When the multimeter has the capability to measure resistance and when you dissemble the resistor to measure the resistance, measuring the current directly would be easier, imo. – PetPaulsen Mar 30 '12 at 20:56