probably more of a math question...
Bobb Fwed
Posts: 1,119
I am running an RC Time to measure voltage. I have a few data points, but I do not have the math know how to convert it to a readable voltage (I have a similar problem with a rctime temperature measurement).
Here is the info (collected off my own RC Time object). This is the voltage range I need to read, but reading beyond 10.41 and 15.85V would be great too. It doesn't have to be perfectly accurate (but within 0.2V would be great across the range below), and for ease of programming I can use integers with a 10x multiplier (e.g. an output of 123 is representative of 12.3V).
@0.1µF, >2ms low
26000 = 10.41V
24249 = 11.00V
21673 = 12.00V
19585 = 13.00V
17785 = 14.00V
16241 = 15.00V
15073 = 15.85V
Obviously having something written in spin, or some instruction on how I would do it would be great.
Here is the info (collected off my own RC Time object). This is the voltage range I need to read, but reading beyond 10.41 and 15.85V would be great too. It doesn't have to be perfectly accurate (but within 0.2V would be great across the range below), and for ease of programming I can use integers with a 10x multiplier (e.g. an output of 123 is representative of 12.3V).
@0.1µF, >2ms low
26000 = 10.41V
24249 = 11.00V
21673 = 12.00V
19585 = 13.00V
17785 = 14.00V
16241 = 15.00V
15073 = 15.85V
Obviously having something written in spin, or some instruction on how I would do it would be great.
Comments
Voltage = A/counts + B
A = 195598.0736
B = 2.9486494
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
lonesock
Piranha are people too.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
lonesock
Piranha are people too.
http://forums.parallax.com/showthread.php?p=753026
I plugged your values into the formulas:
V1: HIGH voltage applied to circuit = 15.85
RCT1: corresponding raw RCtime value = 15073
V2: LOW voltage applied to circuit = 10.42
RCT2: corresponding raw RCtime value = 26000
K1 = 10 * (V1 - V2) * ( RCT1 * RCT2 ) / ( RCT2 - RCT1 ) = 1951062
K2 = 10 * V1 - ( K1 / RCT1) = 29
The spin code should be then,
Voltage := 1951062 / RCT + 29 ' corrected typo, 1951062 not 21951062
This is the explicit solution of two equations in two unknowns:
V1 = K1 / RCT1 + K2
V2 = K1 / RTC2 + K2
and applies whenever V1 and V2 are sufficiently greater than the Prop threshold (~1.65 volts).
edit:
These values are close to the ones that lonesock found from the EXCEL solver, which I think uses a least squares fit. The above formula fits the curve exactly at two points.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
Post Edited (Tracy Allen) : 9/23/2008 5:33:45 PM GMT
run the numbers...this is much better (within 0.1 -- it looks like -- until you get above 15.5V).
(It only give 1 decimal value, but that is good enough for me)
... 24249 == 11V ... 21951062 / RCT + 29 gives me 934 (9.34V?)
... 17785 == 14V ... 1263 (12.63?)
Voltage := 1951062 / RCT + 29 ' not 21951062
1951062 / 26000 + 29 = 104 (10.41 volt ' reference point)
1951062 / 24249 + 29 = 109 (11 volts)
1951062 / 17785+29 = 138 (14 volts)
1951062 / 15073 + 29 = 158 (15.85 volt ' reference point)
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
-Phil
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
'Still some PropSTICK Kit bare PCBs left!