Writes to PWM outputs immediately.

Namespace:  Quanser.Hardware
Assembly:  Quanser.Hardware.Hil (in Quanser.Hardware.Hil.dll)

Syntax

Visual Basic (Declaration)
Public Sub WritePwm ( _
	channels As Integer(), _
	dutyCycles As Double() _
)
C#
public void WritePwm(
	int[] channels,
	double[] dutyCycles
)
Visual C++
public:
void WritePwm(
	array<int>^ channels, 
	array<double>^ dutyCycles
)
JavaScript
function writePwm(channels, dutyCycles);

Parameters

channels
Type: array< System..::.Int32 >[]()[]

An array containing the numbers of the PWM output channels to be written. Channel numbers are zero-based. Thus, channel 0 is the first channel, channel 1 the second channel, etc.

Select a board type to the list for board-specific details: .

dutyCycles
Type: array< System..::.Double >[]()[]

An array containing the duty cycles to write to the PWM outputs. Each element in the dutyCycles array corresponds to the same element in the channels array. Hence, there must be as many elements in the dutyCycles array as there are channels.

Remarks

The WritePwm method writes to the specified PWM output channels immediately. The method does not return until the data has been written.

The interpretation of the PWM samples to be written depends upon the PWM mode. Typically the data is interpreted as a duty cycle, in which a magnitude of 0.0 denotes a 0% duty cycle and magnitude of 1.0 indicates a 100% duty cycle. The sign determines the polarity of the output for those boards supporting bidirectional PWM outputs. However, other PWM modes are possible with some boards. Refer to the SetPwmMode(array<Int32>[]()[], array<Hil..::.PwmMode>[]()[]) method for details.

Examples

This example illustrates how to write PWM outputs immediately. It writes a 0%, 30%, 70% and 100% duty cycle to PWM channels 0-3 respectively. Exceptions are ignored for simplicity.
C# Copy Code
int []    channels = {  0,   1,   2,   3 };
double [] buffer   = { 0.0, 0.3, 0.7, 1.0 };

card.WritePwm(channels, buffer);
Visual Basic Copy Code
Dim channels() As Integer = {0, 1, 2, 3}
Dim buffer() As Double = {0.0, 0.3, 0.7, 1.0}

card.WritePwm(channels, buffer)
Visual C++ Copy Code
array<int>^    channels = {  0,   1,   2,   3 };
array<double>^ buffer   = { 0.0, 0.3, 0.7, 1.0 };

card->WritePwm(channels, buffer);

Exceptions

ExceptionCondition
Quanser.Hardware..::.HilException If the write cannot be performed then an exception is thrown. This situtation typically arises if the board does not support PWM outputs or the hardware resources required are in use by a task.

See Also