Use of the RCtime Command - Capacitor Discharge
' Program RCTIME_1.BAS
'
' Charges external capacitor to near +5.0 VDC. On executing the RCtime
' command, the IO pin goes to a high impedance and capacitor discharges
' toward ground with a time constant RC. When the voltage decays below
' the logic threshold (V_thresh) such that it is seen as a zero by the
' BasicX the time is passed back to the calling function in T_fall.
'
' Note that T_fall = RC * ln (5.0/V_thresh) where V_thresh is nominally
' 1.4. Thus, knowing T_fall and C, the value of R may be determined.
'
' One problem with this technique is that the value of V_thresh may vary
' from one device to another. This may be remedied by using a calibration;
' that is, measuring T_fall with a known resistor.
'
' Another technique is to charge the capacitor and let it discharge toward
' ground; T_fall and to then discharge the capacitor and let it charge
' toward 5V; T_rise and then sum the two values.
'
' This is treated in RCTIME_2.BAS.
'
' Copyright, Peter H. Anderson, Baltimore, Sept, 99
Public Const P24 as byte = 24 ' RCTime pin
Sub Main()
Dim T_rise as Single
Dim T_fall as Single
Dim T_tot as Single
Call OpenSerialPort(2, 9600) ' For debugging
Do
Call PutPin(P24, bxOutputHigh) ' exert a one
Call Sleep(1.0) ' give it time to charge
Call RCtime(P24, 1, T_fall)
Call PutS(T_fall)
Call NewLine()
Loop
End Sub