PWM
 
Syntax

 

#include <PULSE.bas>                               ' source in /Program Files/Coridium/BASIClib

#include <PULSE17.bas>   ' expands support to port 1 and 2 for SuperPRO/ PROplus as pins 32-63 and 64-95

SUB PWM ( pin, duty, milliseconds)

Description


Generate an analog signal on pin for milliseconds with a duty cycle of 0 to 255.
A duty cycle of 255 corresponds to an output value of 100%.

The IO direction of the pin will be set to output, the PWM pulse train is output, and then the pin is set to tristate (input).  If the pin is connected to an RC filter, then the voltage will stay on the capacitor for a period of time determined by the load.

Example

#include <PULSE.bas>

  '  Generate a 1.65 volt (half of 3.3V) on pin 4 for 6 seconds.

PWM (4, 127, 6000)

Differences from other BASICs

See also