GETRC

Top  Previous  Next

Action

Retrieves the value of a resistor or a capacitor.

 

 

Syntax

var = GETRC( pin )

 

 

Remarks

var

The variable that receives the value.

pin

The port pin the R/C is connect to.

 

GETRC needs a resistor and capacitor in order to work. The capacitor is discharged and the charging time will vary depending on the user resistor/capacitor value.

bm47

 

Uses

This function uses TIMER0.

 

 

See also

NONE

 

 

Example

'-----------------------------------------------------------------------

'                            GETRC.BAS

'  Retrieve resistor value

'  Connect 10KOhm variable resistor from +5V to P1.7 for this example

'  Connect 10nF capacitor from P1.7 to ground

'  The GETRC(pin) function measures the time needed to discharge the capacitor

'-----------------------------------------------------------------------

Config Timer0 = Timer , Gate = Internal , Mode = 1       'the GETRC() functions needs timer 0

Config Getrc = 10                                             '10mS wait for charging the capacitor. This is the default so for 10 the CONFIG is not needed

$baud = 9600                             'just my settings

$crystal = 11059200

Dim W As Word                           'allocate space for variable

 

Do                                       'forever

W = Getrc(p1.7)                         'get RC value

Print W                                 'print it

Wait 1                                 'wait a moment

Loop

 

 

'return values for cap=10nF .The resistor values where measured with a DVM

'             250 for 10K9

'             198 for  9K02

'             182 for  8K04

'             166 for  7K

'             154 for  6K02

'             138 for  5K04

'             122 for  4K04

'             106 for  3K06

'              86 for  2K16

'              54 for  1K00

'              22 for   198 ohm

'              18 for   150 ohm

'              10 for   104 ohm

'               6 for     1 ohm (minimum)

 

'As you can see there is a reasonable linearity

'So you can do some math to get the resistor value

'But the function is intended to serve as a rough indication for resistor values

'You can also change the capacitor to get larger values.

'With 10nF, the return value fits into a byte