Table of Contents

Advertisement

2
2
1
e
1
NOTE: Expressions are not
allowed as arguments on the BS1.
The range of the Pin argument on
the BS1 is 0 – 7.
Table 5.65: PWM Quick Facts.
D
ETERMINING AVERAGE VOLTAGE FOR
.
A PARTICULAR DUTY CYCLE
5: BASIC Stamp Command Reference – PWM

PWM

2
2
PWM Pin, Duty, Cycles
p
sx
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
Units in Cycles
Average voltage
equation
Require charge
time (Cycles)
equation
Special notes
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,
BS1
BS2
BS2e BS2sx BS2p
BS2
BS2e
1 ms
1 ms
Average Voltage = (Duty / 255) * 5 volts
Charge time = 4 * R * C
Pin is set to output initially, and set to input at end
BASIC Stamp Programming Manual 2.0c • www.parallaxinc.com • Page 247
BS2sx
BS2p
400 µs
652 µs

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the BASIC Stamp 2e and is the answer not in the manual?

Table of Contents