Skip to main content

PWM

Syntax

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

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

PWM 4, 127, 6000

Differences from other BASICs

  • none from Visual BASIC
  • duration in PBASIC is CPU dependent and measured in ticks

See also