pic16* amper meter
OK
Here you go
v1---/\/\/\/\---v2
3.35v............3.15v
The different between v1 and v2 is 200mv
Lets say you using the PIC VCC for reference "5V"
10 bit ad 5/1024 =0.0048828125
Each step is equal with 0.0048828125 volt
So if you read 512 from you AD registers, that will be 512*0.0048828125=2.5V
Floating point math would be to hard on you, so scale it up and round it.
Make each step to be 488 instead of the 0.0048828125.
Then again if you read 512 form your AD register's multiply it with 488.
512*488=249856 uV, the error is ~0.5%, isted of 250000 uV
On your ADCH0 you will get 686 in the AD registers, and for ADCH1 you get 645
the different is 686-645=41, now multiply this 41 with 488 and you get 20008.
That is very close to the real value of 20000 uV.
Now divide this 20008 uV with the upscaled resistor value of 15, it is 100 times more than the actual resistance.
So 20008/15=1333.86, now divide it by 1000 or move you decimal point 3 digit to the left, and you get 1.333 A
If you AD register different is 1 then, ((1*488)/15)/1000 or move decimal 3 times to the left. equal 0.032 Amp, in the real life the current is 0.032552083 Amp.
As you can see, the resolution is 32mA
Now if you need higher precision, and you maximum current is low, then you can use different voltage divider on the ADCH1 to make it 10*more than ADCH0.
This way you can get 3.2mA resolution.
There is many free examples of 16,24,32 bit math asm code out there, find them and use them.
If I'm wrong about this or you did not get it, "SORRY"
I'm just a human
Csaba