Overview
This tutorial demonstrates the use of a PWM (pulse width modulation) port on a Netduino. A PWM port is often used for Servo’s. Much like those found in R/C cars, plans and boats.
Pulse width modulation is the process of alternating a signal between two extreme values with little to no intermediate steps. On a Netduino these extreme values are 0 volts and 3.3 volts respectively.
Code Sample
public class Program
{
public static void Main()
{
PWM pwm = new PWM(Pins.GPIO_PIN_D5);
const uint period = 3 * 1000 * 1000; // 3 ms
const uint duration = 1 * 1000 * 1000; // 1 ms
pwm.SetPulse(period, duration);
}
}
Details
The code in this example is meant to be simple and straight forward. On line 5, a PWM object is created on a specific port of the Netduino. Once this is created we declare a few variables used for the period and duration values.
Period is the “peak to peak” time. It is required for by the SetPulse(…) method and its value is in microseconds.
Duration is used for the “on” time for a cycle. It is required for the SetPulse(…) method and its value is in microseconds.
Lastly, on line 10, we set the pulse of the PWM appropriately. We suggest connecting a servo to the Netduino for this example to see the actual output.