Skip to main content

PWM

Pulse-Width Modulation (PWM) generates a square-wave signal of fixed frequency and variable duty cycle. It is commonly used to simulate an analog voltage, drive a servo, control LED brightness, and generate simple tones. Both the frequency and the duty cycle are set in software.

Endpoint uses the standard System.Device.Pwm API. The only Endpoint-specific step is calling PwmController.Initialize(pin) first, which claims the pin for its timer channel and gives you the chip and channel ids that PwmChannel.Create needs.

using System.Device.Pwm;
using GHIElectronics.Endpoint.Core;

// Buzzer pin on EP-Domino24
var pin = EPDomino24.Pwm.Pin.PF9;

PwmController.Initialize(pin);

using var pwm = PwmChannel.Create(
PwmController.GetChipId(pin),
PwmController.GetChannelId(pin),
frequency: 1000,
dutyCyclePercentage: 0.25);

pwm.Start();
Thread.Sleep(1000);
pwm.Stop();