28128 Parallax Inc, 28128 Datasheet - Page 67

no-image

28128

Manufacturer Part Number
28128
Description
KIT BASIC ANALOG/DIGI PARTS ONLY
Manufacturer
Parallax Inc
Datasheet

Specifications of 28128

Accessory Type
ADC, DAC
Product
Microcontroller Accessories
For Use With/related Products
BASIC Stamp® 2 and Board of Education
Lead Free Status / RoHS Status
Lead free / RoHS Compliant
In long division, calculating the part of the answer to the right of the decimal point is
repetitive. We multiply the remainder by 10, then divide by 255 again, then take another
remainder, multiply it by 10, and divide by 255 again, etc. A shortcut to this procedure is
to take the remainder, and multiply it by 100, then divide by 255. This gives us two
decimal places. Let's try it.
Remember: the BASIC Stamp cuts off everything to the right of the decimal point
without rounding. This is called truncating. The result we get is 23. This result should
have been rounded up to 24 because 23.5294 is more than half way to the next integer
value, 24. For now, let's stick with 23 to the right of the decimal point.
Our answer using this algorithm is the integer 3 to the left of the decimal point, and the
integer value 23 to the right of the decimal point. Since we used only integers in our
arithmetic, it should work using PBASIC and the BASIC Stamp.
Since the BASIC Stamp works with integers, it's not surprising that there is a PBASIC
command to calculate the integer remainder of a division problem. The operator for
division is / and the operator for getting the remainder is //. Let's try converting this
algorithm into PBASIC code to do the work for us. The steps for long division below
show the PBASIC commands corresponding to the steps in the algorithm.
v=5*adcBits/255
v2=(100*R)/255
Voltage
(60
What’s an Algorithm? An algorithm is a procedure for solving a problem. The procedure is
broken down into repeatable steps.
×
100)
=
÷
5
255
×
(Decimal
=
6000
255 5 adcBits
255 100 r
255
÷
A/D
×
255
×
v2
Output)
=
23.5924...
v r
+
=
3
+
a
Integer
remainder
Math
R=(5*adcBits//255)
23
of
60

Related parts for 28128