Log in

View Full Version : Reading curnt consumption with 16F877A



comwarrior
- 2nd October 2009, 16:18
I'm wanting to measure curent consumption of my pulse motor thats being ran from my 16F877A.
At the moment I'm using one analogue line for pulse timing and one to measure input voltage and display on an LCD...

What i'm after is a way of measuring curent consumption.
Normally, i'd measure the voltage across a resister and use V=IR...
But, a PIC using internal VREF (as mine is) cant measure the diference between two independant points...

as I see it, theirs two ways I could do it...
1)
Use the external VREF on the drain side of the resister and one analogue line on the source side and re-program for external VREF on the fly...

2)
Use two analogue lines (VIA voltage deviders) and subtract one from the other to get the voltage diference...

However, need to be aware that the source voltage is anywhere from 12 to 16 volts DC (hence the voltage deviders)
The smallest value resister I've got is 5ohms...

Can the external VREF handle such voltage?

If so, which is the faster / better way?

Is their a third way?

Any idea what the overhead is in terms of instructions associated with each option?

Thanks

:edit
Curent consumption should be only upto 200mA
so, V=IR
V=0.2 X 5
So, diference should be 1 volt or less

:edit2
Just found the a bit in the datasheet, Comparator voltage can not go above VDD, so that whould mean using a voltage devider on the VREF input too

Ioannis
- 2nd October 2009, 17:46
Normally, the resistor on which you would measure the voltage drop is very small. This leads to the conclusion that the voltage also is going to be very low.

1. Put the resistor in reference with the ground. I mean Gnd-resistor-Motor+Vcc

2. On the resistor you have to filter and amplify the voltage with an op-amp to bring it to a level enough for the PIC to measure it.

Ioannis

timmers
- 2nd October 2009, 20:27
If you can put a low value resistor into the ground return path, you can measure the "ON" state current.
Remember to calculate the mark / space period and apply this as an averaging factor to calculate the average current.

The voltage accross a current sense resistor will be quite low, and will probably need amplifying using an opamp to bring it into range of the PIC.
Alternatively, use a chip designed for the job! I had a recent application where I needed to measure the current at 50 volts. The INA206 (http://focus.ti.com/lit/ds/symlink/ina206.pdf) is a current sense amplifier upto 75 volts above the PICs 5v. Easy to use as well.

Tim.

comwarrior
- 2nd October 2009, 21:05
Scratches head...
Scratches head some more...

re-rerads posts
Scratches head yet more...

I can see what TIMMERS means but I'm still scratching my head at IOANNIS's surgestion... i not sure what ya mean...

acording to my calculation, a resistance of 5 ohms will give me a voltage drop of 1 volt @ 200mA. a 1volt loss is acceptable since i was going to add a diode in to re-use the forward EMF, so i was looking at a voltage drop of 0.3V anyways... so now, i'll just pump up the input voltage by 1.5V to compensate...

so, i've added 6 resisters in series to make 5 ohms to give a high wattage...
I've make two voltage deviders [4:1] ether side of the resisters using 100k resisters... so now i hoinh to solder it up write the subroutine and see how many diferent ways it can tell me to get stuffed... lol

Ioannis
- 2nd October 2009, 21:39
A ready made solution like the chip timmers suggested is perfect but can be expensive too.

5 ohm is too high for the job. Put a low one in the range of 0.1 to 0.5 ohms. There is no need to dissipate too much power on this resistor.

And besides this, you need some form of filtering after you get your voltage sample. A low pass filter is necessary as the motors do produce spikes.

Then the analog input of a PIC needs at least 2.5 to 3 volts so you have to amplify with an op-amp the voltage of the resistor by a factor of 50 to get from a 0.5ohm at 200mA the 0-5 Volt PIC input.

A LMC66x series is a good choice for the op-amp that has to work at low Vdd voltages (+5V) and is rail to rail output.

Ioannis

comwarrior
- 2nd October 2009, 22:23
what you mean a pic needs 2.5-3 volts? It doesn't say that in the datasheet...

Ioannis
- 3rd October 2009, 09:20
Not all PIC ADCs are the same. Look carefully in the data sheets of the specific ADC. You cannot have a voltage spn of 1,7 volt an expct the PIC ADC to have full scale on 0-1,7. The PICs reference voltage has a minimum and this is what you have to look for.

Ioannis

comwarrior
- 3rd October 2009, 19:06
ahhh, i see... in that case if i use normal 5V REF and just subtract the low ADC from the high ADC...

After adding in all the software last night, i compiled it... 250 ish lines of pic basic... allmost 1200 words used once compiled :eek:

Runs slightly slower, and i still not added in the unfinished auto tune sub routine...

So, looks like i'm going to have to take the core of the control system and drop it to my pic18 and use a 16f877 to do all the maths and the display...
Raises the question of whats the fastest way of getting them to talk without using up bucket loads of IO lines... and preferably without interupts...