28029 Parallax Inc, 28029 Datasheet - Page 88

KIT PARTS SMART SENSORS W/TEXT

28029

Manufacturer Part Number
28029
Description
KIT PARTS SMART SENSORS W/TEXT
Manufacturer
Parallax Inc
Datasheet

Specifications of 28029

Accessory Type
Parts Kit
Product
Microcontroller Accessories
Lead Free Status / RoHS Status
Contains lead / RoHS non-compliant
For Use With/related Products
BASIC Stamp® or Javelin Modules
Lead Free Status / RoHS Status
Lead free / RoHS Compliant, Contains lead / RoHS non-compliant
Other names
28029PAR
Page 76 · Smart Sensors and Applications
ACTIVITY #3: SCALING DOWN AND OFFSETTING INPUT VALUES
When working with the MX2125 and BASIC Stamp 2, tilt measurements range between
1875 and 3125. This range may have to be scaled and offset any number of ways. For
example, Activity #4 scales this to a range of −100 to 100. Activity #5 scales it to −127
and 127.
Introducing an offset into a range of values is easy, and typically involves an addition or
subtraction operation. Scaling can be a little trickier, especially with a processor like the
BASIC Stamp, which does all its calculations with integer math. This activity introduces
the simplest and most accurate way to scale a larger range of values into a smaller range
with a PBASIC program. The technique introduced here helps prevent errors from
creeping into your sensor measurements with each successive PBASIC calculation, and it
will be used and re-used in many of this book's activities.
Scale and Offset Example
In this first example, we'll take an input value that could be anywhere between 1875 and
3125, and scale and offset it to a corresponding output value that falls in a range from
−127 to 127. Figure 3-9 shows how this should work. The position of the value in the
output scale should be proportional to the position of the value in the input scale. For
example, if the input value is 2500, which is halfway between 1875 and 3125, we should
expect the output value to be 0, which is half way between −127 and 127.
Figure 3-9: Example Input and Output Scales
To apply scale and offset in PBASIC, remember these three steps:
1) Apply offset to align the input scale to zero.
2) Apply the scale.
3) Apply any additional offset that is needed for our output scale.

Related parts for 28029