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.
Summary of Contents for BASIC Stamp 1
Page 1: ...BASIC Stamp Programming Manual Version 2 0c...
Page 34: ...Quick Start Guide Page 32 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Page 340: ...ASCII Chart Page 338 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Page 342: ...Reserved Words Page 340 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Page 346: ...Conversion Formatters Page 344 BASIC Stamp Programming Manual 2 0b www parallaxinc com...