28129 Parallax Inc, 28129 Datasheet - Page 66

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
The PBASIC command set for the BASIC Stamp does arithmetic using integer values.
Integers are the counting numbers: …-2, -1, 0, 1, 2, 3, etc. The largest integer the BASIC
Stamp can process is 65535. When using integer arithmetic, the fractional part of any
answer is discarded. Fortunately, we can still use integer arithmetic to find the fractional
values we are trying to display.
Before dividing, the A/D output is multiplied by 5. This doesn’t cause any problems.
In our voltage calculation example, that’s
less than 65535, this part of the calculation goes without a hitch. The problem occurs
when we try to divide 825 by 255. The answer has a fractional component that never gets
calculated with integer math.
Doing “long division” with a pencil and a piece of paper takes several steps, and it relies
solely on integer arithmetic. Let's look at how to calculate the answer for this division
problem.
5
×
(Decimal
A/D
Output)
is essentially the same as
5
×
165
=
5
825.
×
adcBits
Since 825 is an integer that is
.
Figure 3-7
Debug Terminal
Output for Program
Listing 3.1, Revision
2.

Related parts for 28129