Sets the duty cycles of the PWM outputs on the card.

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

Syntax

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

Parameters

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

An array containing the numbers of the PWM channels whose duty cycles will be set. Channel numbers are zero-based. Thus, channel 0 is the first channel, channel 1 the second channel, etc.

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

dutyCycles
Type: array< System..::.Double >[]()[]
An array of modes containing the new duty cycles for each channel. Duty cycle values must be fractions between 0.0 and 1.0, where 0.0 indicates 0% and 1.0 denotes 100%. The value may be signed for those boards which support bidirectional 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 SetPwmDutyCycle method sets the duty cycles that will be used for PWM outputs. This method is typically used in Hil.PwmMode.Frequency or Hil.PwmMode.Period mode. Refer to the Hil..::.PwmMode enumeration for a list of the valid PWM modes.

The actual PWM output duty cycles are not changed until the PWM outputs are used in one of the following functions:

Examples

This sample illustrates how to use the SetPwmDutyCycle(array<Int32>[]()[], array<Double>[]()[]) method. It sets the PWM duty cycle to 50% for PWM output channel 0 and 75% for PWM output channel 1.
C# Copy Code
int []    channels   = {  0,    1  };
double [] dutyCycles = { 0.5, 0.75 };

board.SetPwmDutyCycle(channels, dutyCycles);
Visual Basic Copy Code
Dim channels() As Integer = {0, 1}
Dim dutyCycles() As Double = {0.5, 0.75}

board.SetPwmDutyCycle(channels, dutyCycles)
Visual C++ Copy Code
array<int>^    channels   = {  0,    1  };
array<double>^ dutyCycles = { 0.5, 0.75 };

board->SetPwmDutyCycle(channels, dutyCycles);

Exceptions

ExceptionCondition
Quanser.Hardware..::.HilException If the PWM duty cycles cannot be set then an exception is thrown. This situtation typically arises when a duty cycle is out of range or the card does not support programmable PWM duty cycles.

See Also