28129 Parallax Inc, 28129 Datasheet - Page 65

TEXT BASIC ANALOG & DIGITAL

28129

Manufacturer Part Number
28129
Description
TEXT BASIC ANALOG & DIGITAL
Manufacturer
Parallax Inc
Type
Programmingr
Datasheet

Specifications of 28129

Style
Book
Title
Basic Analog and Digital
Contents
Basic Analog and Digital Text
Product
Microcontroller Accessories
Lead Free Status / RoHS Status
Not applicable / Not applicable
So, now we know to multiply by 5 and divide by 255 for a 5 volt scale with 256 levels.
We can calculate the voltage from Figure 3-6 where the ADC0831’s output is 10100101
= 165. The measured voltage is:
To calculate and display this voltage using the BASIC Stamp, we’ll add some code to
both the
expressed in PBASIC code. Here is an example of some code that could reasonably be
expected to work.
This PBASIC calculation looks like it will give us the output we want, but it won’t. It’s
instructive to try it this way and see what happens. Modify the
subroutines in Program Listing 3.1 as follows:
We calculated that 165 would lead to a measured voltage of 3.24 volts. The 003 volts
shown in Figure 3-7 is only accurate to the nearest volt! What happened?
v = 5 * adcBits / 255
Calc_Volts:
RETURN
Display:
RETURN
Voltage
Calc_Volts
v = 5 * adcBits / 255
DEBUG HOME
DEBUG "8-bit binary value:
DEBUG CR, CR, "Decimal value:
DEBUG CR, CR, "DVM Reading:
=
5
×
255
165
and
=
Display
3.24
Volts
subroutines. First, the voltage equation needs to be
rounded
", BIN8 adcBits
to
", DEC3 v, " Volts"
two
", DEC3 adcBits
decimal
places
Calc_Volts
.
'
'
and
new line
new line
Display

Related parts for 28129