RPICSIO

The PWMPortFS Class

 

The PWMPortFS Class

The PWMPortFS class controls one of the two PWM bus On Chip Peripheral (OCP) devices integrated into the Raspberry Pi 2 CPU via the PWM file system access method.

Note that the device tree overlays that ship with the default Raspian operating system (at the time of writing this documentation) do not work properly. You will need to download a version of the device tree overlays that enables an internal hardware clock. See the notes on the PWM Port Example page for more information.

IMPORTANT NOTE: Before creating any RPICSIO Port class you will need to ensure that the RPICSIO Library knows which type of Raspberry Pi you are dealing with. This is done by executing a call (only once is necessary) like the one below somewhere in your code before you create any port.

            RPICSIOConfig.Instance.RPIType = RPITypeEnum.RPITYPE_RPI2;

 

Source Code

The source code for this class is available online for download and also in browseable form.

 

Example Code

Example code which demonstrates the use of this class can be found on the PWM Port Example page.

 

Syntax

public class PWMPortFS : PortFS

Provides Pulse Width Modulation (PWM) port functionality for a Raspberry Pi (File System Version).

 

Public Constructors

public PWMPortFS(PWMPortEnum pwmPortIn) : base(GpioEnum.GPIO_NONE)

Constructor.

Parameters
pwmPortIn - The PWM port to access.

 

Public Methods

public override void ClosePort()

Closes the port.

 

public void Dispose()

Implements IDisposable. Should be called after the class is closed to release resources.

 

public override PortDirectionEnum PortDirection()

Gets the PortDirection

Returns
A PortDirectionEnum value. This value is always PortDirectionEnum.PORTDIR_OUTPUT.

 

Public Properties

public uint DutyNS { get; set; }

Gets/Sets the duty cycle of the PWM output square wave form in nanoseconds

The duty cycle is the part of the wave form devoted to a high state.

value
the duty cycle of the PWM output in nanoseconds. This should always be less than the PeriodNS.

 

public double DutyPercent { get; set; }

Gets/Sets the duty cycle of the PWM output square wave form as a percent

value
percentage of the input value. Must be between 0 and 100.

 

public uint FrequencyHz { get; set;}

Gets/Sets the frequency of the PWM output square wave form.

value
frequency in Hz.

 

public uint PeriodNS { get; set;}

Gets/Sets the period of the PWM output square wave form

value
the period (1/Freq) in nano seconds.

 

public PWMPortEnum PWMPort { get; }

Gets the PWM Port. There is no Set accessor this is set in the constructor

value
The working PWMPortEnum.

 

public bool RunState { get; set;}

Gets/Sets the run state of the PWM output square wave

value
true - begin running, false - stop running.