5: BASIC Stamp Command Reference – PWM
BASIC Stamp Programming Manual 2.0c
•
www.parallaxinc.com
•
Page 247
PWM
BS1 BS2 BS2e BS2sx BS2p
PWM
Pin, Duty, Cycles
Function
Convert a digital value to analog output via pulse-width modulation.
•
Pin
is a variable/constant/expression (0 – 15) that specifies the I/O
pin to use. This pin will be set to output mode initially then set to
input mode when the command finishes.
•
Duty
is a variable/constant/expression (0 - 255) that specifies the
analog output level (0 to 5V).
•
Cycles
is a variable/constant/expression (0 - 255) that specifies the
duration of the PWM signal.
Quick Facts
BS2
BS2e
BS2sx
BS2p
Units in Cycles
1 ms
1 ms
400
µ
s
652
µ
s
Average voltage
equation
Average Voltage = (Duty / 255) * 5 volts
Require charge
time (Cycles)
equation
Charge time = 4 * R * C
Special notes
Pin is set to output initially, and set to input at end
Explanation
Pulse-width modulation (PWM) allows the BASIC Stamp (a purely digital
device) to generate an analog voltage. The basic idea is this: If you make a
pin output high, the voltage at that pin will be close to 5V. Output low is
close to 0V. What if you switched the pin rapidly between high and low
so that it was high half the time and low half the time? The average
voltage over time would be halfway between 0 and 5V (2.5V). PWM emits
a burst of 1s and 0s whose ratio is proportional to the duty value you
specify.
The proportion of 1s to 0s in PWM is called the duty cycle. The duty cycle
controls the analog voltage in a very direct way; the higher the duty cycle
the higher the voltage. In the case of the BASIC Stamp, the duty cycle can
range from 0 to 255. Duty is literally the proportion of 1s to 0s output by
the PWM command. To determine the proportional PWM output voltage,
e
2
sx
2
p
2
Table 5.65: PWM Quick Facts.
1
2
D
ETERMINING AVERAGE VOLTAGE FOR
A PARTICULAR DUTY CYCLE
.
1
NOTE: Expressions are not
allowed as arguments on the BS1.
The range of the Pin argument on
the BS1 is 0 – 7.
Содержание 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...