27297 Parallax Inc, 27297 Datasheet - Page 218

KIT STAMPWORKS WITH BS2-IC

27297

Manufacturer Part Number
27297
Description
KIT STAMPWORKS WITH BS2-IC
Manufacturer
Parallax Inc
Datasheet

Specifications of 27297

Lead Free Status
Contains lead
Product
Microcontroller Accessories
Lead Free Status / Rohs Status
Lead free / RoHS Compliant

Available stocks

Company
Part Number
Manufacturer
Quantity
Price
Part Number:
27297SQ
Manufacturer:
NS
Quantity:
4
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 27297