Voltage Measurement for your Robot

by Scott Preston - 2007-09-06 10:07:46
I was able to do this with 2 resistors and 1 capacitor.
      681 kohm        470 ohm 
Vx ----/\/\/\---o-----/\/\/\----Pin to stamp
unknown         |
voltage       ===== 0.01 uF film
                |
               Vss

The source code for the basic stamp is:

' {$STAMP BS2}
' {$PBASIC 2.5}
' {$PORT COM1}

rct VAR Word    ' RCtime value
Vx VAR Word     ' voltage value calculated
Cn1 CON 48576   ' first constant, see below
Cn2 CON 8       ' second constant, ditto
' circuit attached to P15
LOW 15
start:
RCTIME 15,0,rct
LOW 15
Vx= Cn1 / rct + Cn2
DEBUG DEC ? rct,DEC ? vx
PAUSE 500
GOTO start

You will have to experiment with the constants and values. I had to sit with my battery and take readings while I worked on the robot, then as the battery drained I took readings and voltage measurements and made my self a look-up table.