4: BASIC Stamp Architecture – NCD, SIN
BASIC Stamp Programming Manual 2.0c
•
www.parallaxinc.com
•
Page 65
-- or --
Result VAR WORD
Result = 99 ' Put -99 (2's complement format) into Result.
DEBUG SDEC ? Result ' Display it on the screen as a signed #.
Result = - Result ' Negate the value
DEBUG SDEC ? Result ' Display it on the screen as a signed #.
The Encoder operator (NCD) is a "priority" encoder of a 16-bit value. NCD
takes a 16-bit value, finds the highest bit containing a 1 and returns the bit
position plus one (1 through 16). If no bit is set (the input value is 0) NCD
returns 0. NCD is a fast way to get an answer to the question “what is the
largest power of two that this value is greater than or equal to?” The
answer NCD returns will be that power, plus one. Example:
Result VAR WORD
Result = %1101 ' Highest bit set is bit 3.
DEBUG ? NCD Result ' Show the NCD of Result (4).
The Sine operator (SIN) returns the two’s complement, 16-bit sine of an
angle specified as an 8-bit (0 to 255) angle. To understand the SIN operator
more completely, let’s look at a typical sine function. By definition: given a
circle with a radius of 1 unit (known as a unit circle), the sine is the y-
coordinate distance from the center of the circle to its edge at a given
angle. Angles are measured relative to the 3-o'clock position on the circle,
increasing as you go around the circle counterclockwise.
At the origin point (0 degrees) the sine is 0, because that point has the
same y (vertical) coordinate as the circle center. At 45 degrees the sine is
0.707. At 90 degrees, sine is 1. At 180 degrees, sine is 0 again. At 270
degrees, sine is -1.
The BASIC Stamp SIN operator breaks the circle into 0 to 255 units instead
of 0 to 359 degrees. Some textbooks call this unit a binary radian or brad.
Each brad is equivalent to 1.406 degrees. And instead of a unit circle,
which results in fractional sine values between 0 and 1, BASIC Stamp SIN
is based on a 127-unit circle. Results are given in two’s complement form
in order to accommodate negative values. So, at the origin, SIN is 0. At 45
degrees (32 brads), sine is 90. At 90 degrees (64 brads), sine is 127. At 180
degrees (128 brads), sine is 0. At 270 degrees (192 brads), sine is -127.
2
e
2
sx
2
p
2
2
e
2
sx
2
p
2
2
e
2
sx
2
p
2
E
NCODER
: NCD
S
INE
: SIN
Содержание BASIC Stamp 1
Страница 1: ...BASIC Stamp Programming Manual Version 2 0c...
Страница 30: ...Introduction to the BASIC Stamps Page 28 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 34: ...Quick Start Guide Page 32 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 90: ...BUTTON BASIC Stamp Command Reference Page 88 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 118: ...END BASIC Stamp Command Reference Page 116 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 128: ...FREQOUT BASIC Stamp Command Reference Page 126 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 196: ...NAP BASIC Stamp Command Reference Page 194 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 206: ...OWIN BASIC Stamp Command Reference Page 204 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 214: ...OWOUT BASIC Stamp Command Reference Page 212 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 216: ...PAUSE BASIC Stamp Command Reference Page 214 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 226: ...POLLMODE BASIC Stamp Command Reference Page 224 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 232: ...POLLOUT BASIC Stamp Command Reference Page 230 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 236: ...POLLRUN BASIC Stamp Command Reference Page 234 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 240: ...POLLWAIT BASIC Stamp Command Reference Page 238 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 262: ...RCTIME BASIC Stamp Command Reference Page 260 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 274: ...RUN BASIC Stamp Command Reference Page 272 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 310: ...SEROUT BASIC Stamp Command Reference Page 308 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 324: ...STOP BASIC Stamp Command Reference Page 322 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 340: ...ASCII Chart Page 338 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 342: ...Reserved Words Page 340 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 346: ...Conversion Formatters Page 344 BASIC Stamp Programming Manual 2 0b www parallaxinc com...