27220 Parallax Inc, 27220 Datasheet - Page 218

BOOK STAMPWORKS

27220

Manufacturer Part Number
27220
Description
BOOK STAMPWORKS
Manufacturer
Parallax Inc
Datasheet

Specifications of 27220

Accessory Type
Booklet
Product
Microcontroller Accessories
Lead Free Status / RoHS Status
Not applicable / Not applicable
For Use With/related Products
StampWorks
Lead Free Status / RoHS Status
Lead free / RoHS Compliant, Not applicable / Not applicable
Get_ADC:
Behind the Scenes
A comparator is a circuit used to compare two voltages; when the voltage on the +
(noninverting) input of the comparator is greater than the voltage on the –
(inverting) input, the output will be high, otherwise it is low. Using this behavior an
unknown voltage can be determined by applying a known voltage to the other side
of the comparator and checking the output.
This process can, of course, be done with any BASIC Stamp and an external
comparator. For this experiment we will take advantage of the built-in comparator
feature of the BS2px. By doing so we use just three I/O pins and a few standard
components.
A simplistic method for determining the unknown voltage would be a loop that
essentially sneaks up on the unknown voltage:
The problem with this strategy is the length of conversion when the unknown voltage
is biased toward the high side of the scale. The solution this problem is a technique
adcVal = 0
bias = 128
DO
LOOP UNTIL (bias = 0)
RETURN
adcVal = adcVal + bias
PWM DacOut, adcVal, 15
COMPARE 2, result
IF (result = 1) THEN
ENDIF
bias = bias / 2
adcVal = adcVal - bias
Get_ADC_Simple:
adcVal = 0
DO
LOOP UNTIL (adcVal = 255)
RETURN
PWM DacOut, adcVal, 15
COMPARE 2, result
IF (result = 1) THEN EXIT
adcVal = adcVal + 1
' clear ADC
' start in middle
' add bias to adc result
' output new test value
' check comparator
' if unknown lower than test
' -- reduce adcVal
' check next half
' slow version
' output new value
' check comparator
' voltage found
' increment result

Related parts for 27220