Accurate Rctime measurements
Luis_P
Posts: 246
Im getting different values when a measure resistance with the Rctime code below. Example sometimes I get 57 or 56 or 55. How can I get always the same value?
THIS IS THE CODE:
results VAR Word
LOW 0
PAUSE 50
top:
HIGH 0
PAUSE 500
RCTIME 0,1,results
DEBUG DEC results, CR
GOTO top
THE CIRCUIT ATTACHED:
I have a ceramic cap (0.1uF) one end connected to +5V other end to P0, one resistor(10K) connected to P0 other end to VSS(ground).
THIS IS THE CODE:
results VAR Word
LOW 0
PAUSE 50
top:
HIGH 0
PAUSE 500
RCTIME 0,1,results
DEBUG DEC results, CR
GOTO top
THE CIRCUIT ATTACHED:
I have a ceramic cap (0.1uF) one end connected to +5V other end to P0, one resistor(10K) connected to P0 other end to VSS(ground).
Comments
If you want accuracy, you can improve on RCTIME by using a comparator like 1/4 of an LM339 or 1/2 of an LM393. You can also do better using a polyester or mylar capacitor instead of a ceramic one. You may still get some variation in values, maybe movement between two adjacent values. You can improve that with averaging of a series of 3 or 5 values.
Thanks.
rctime ???,???,newValue
average = (average + newValue) / 2
oldValue = newValue
rctime ???,???,newValue
average = (average + oldValue + newValue) / 3
You'd read one initialization value for average or two initialization values for
average and newValue.
The idea here is that newer values have greater significance than older values,
yet the averaging causes a smoothing of the values and the average doesn't
change wildly.