ombrastein
New Member
Im experincing very strange(to me at least) behavior from the ADC on my PIC18F452. Im trying to measure a very small voltage over a 0.1 ohm resistor. the resistor sits between GND and gnd on a servo. What i need to know is how much current is passed thru the servo, so i can tell how much load there is on said servo...
I know that with a 0.1 ohm resistor the ground conections resistanse will also play a part but its not all that important the actual numbers here... I only need to know the relative change in servo load, not to somehow calculate exatcly what that load is... thus it doesnt realy matter if the resistanse im measuring over is 0.1 or 0.3 ohm(at least this is the way ive imagined things .. could be wrong, wouldnt be the first time ).
The voltage drop measured between GND on the micro controler and the servo (measured over the 0.1 ohm resistor pluss the ground conection wires) is about 50 mV, wich should give a reading of 10 from the adc (using Vcc as ref and 10 bit => 5v/1024 = aprox 5mV per step). When i use my ICD debug to check what the ADC reads strange things happen...
Of course i have to make sure the servo is actualy loaded while the adc is measuring so heres what i do in code. I let the servo hold its position for 1 sec, then i take an adc reading (while servo is still beeing held with constant load, wich i know prdouces 50mV on the resistor).
Now to the odd thing. This works kind of randomly. i do get some readings for maybe 2 or 3 second (one reading per second from the adc) and then i suddenly get all 0's for a few seconds, before i again get some reasonable values again. It alternates continuasly between reasonable values and 0's. There is no pattern or periode to this. The value i read is not exactly 10, it varies between 10 and 15, but i gues that with Vcc as Vref i cant expect better acuracy then that, and of course the voltage im measuring is genereted by a motor pushing current thru a resistor so it wont be that acurate to begin with.
Ive tried to read thru the datasheet about 10 times but i cant find anything wrong with my setup. Is there a minimum resistance that the pic needs to see towards GND from the adc? in my circut it sees basicly 0.1 ohm...
Any bright ideas would be much apritiated ... im kind of lost right now as to what could be causing this ...
I know that with a 0.1 ohm resistor the ground conections resistanse will also play a part but its not all that important the actual numbers here... I only need to know the relative change in servo load, not to somehow calculate exatcly what that load is... thus it doesnt realy matter if the resistanse im measuring over is 0.1 or 0.3 ohm(at least this is the way ive imagined things .. could be wrong, wouldnt be the first time ).
The voltage drop measured between GND on the micro controler and the servo (measured over the 0.1 ohm resistor pluss the ground conection wires) is about 50 mV, wich should give a reading of 10 from the adc (using Vcc as ref and 10 bit => 5v/1024 = aprox 5mV per step). When i use my ICD debug to check what the ADC reads strange things happen...
Of course i have to make sure the servo is actualy loaded while the adc is measuring so heres what i do in code. I let the servo hold its position for 1 sec, then i take an adc reading (while servo is still beeing held with constant load, wich i know prdouces 50mV on the resistor).
Now to the odd thing. This works kind of randomly. i do get some readings for maybe 2 or 3 second (one reading per second from the adc) and then i suddenly get all 0's for a few seconds, before i again get some reasonable values again. It alternates continuasly between reasonable values and 0's. There is no pattern or periode to this. The value i read is not exactly 10, it varies between 10 and 15, but i gues that with Vcc as Vref i cant expect better acuracy then that, and of course the voltage im measuring is genereted by a motor pushing current thru a resistor so it wont be that acurate to begin with.
Ive tried to read thru the datasheet about 10 times but i cant find anything wrong with my setup. Is there a minimum resistance that the pic needs to see towards GND from the adc? in my circut it sees basicly 0.1 ohm...
Any bright ideas would be much apritiated ... im kind of lost right now as to what could be causing this ...