5: BASIC Stamp Command Reference – PWM
BASIC Stamp Programming Manual 2.0c
•
www.parallaxinc.com
•
Page 249
voltage setting established by PWM. Keep in mind that leakage currents
of up to 1 µA can flow into or out of this “disconnected” pin. Over time,
these small currents will cause the voltage on the capacitor to drift. The
same applies for leakage current from an op-amp’s input, as well as the
capacitor’s own internal leakage. Executing PWM occasionally will reset
the capacitor voltage to the intended value.
PWM charges the capacitor; the load presented by your circuit discharges
it. How long the charge lasts (and therefore how often your program
should repeat the PWM command to refresh the charge) depends on how
much current the circuit draws, and how stable the voltage must be. You
may need to buffer PWM output with a simple op-amp follower if your
load or stability requirements are more than the passive circuit of Figure
5.27 can handle.
The term “PWM” applies only loosely to the action of the BASIC Stamp's
PWM command. Most systems that output PWM do so by splitting a
fixed period of time into an on time (1) and an off time (0). Suppose the
interval is 1 ms and the duty cycle is 100 / 255. Conventional PWM would
turn the output on for 0.39 ms and off for 0.61 ms, repeating this process
each millisecond. The main advantage of this kind of PWM is its
predictability; you know the exact frequency of the pulses (in this case,
1 kHz), and their widths are controlled by the duty cycle.
BASIC Stamp's PWM does not work this way. It outputs a rapid sequence
of on/off pulses, as short as 1.6 µs in duration, whose overall proportion
over the course of a full PWM cycle of approximately a millisecond is
equal to the duty cycle. This has the advantage of very quickly zeroing in
on the desired output voltage, but it does not produce the neat, orderly
pulses that you might expect. The BS2, BS2e, BS2sx and BS2p also uses
this high-speed PWM to generate pseudo-sine wave tones with the
DTMFOUT and FREQOUT instructions.
H
OW
P
ULSE
-W
IDTH
-M
ODULATION IS
GENERATED
.
Summary of Contents for BASIC Stamp 2e
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...