DioSetPwmPulseDuty


Function

Sets the PWM pulse duty cycle for the specified channel.

Format

Ret = DioSetPwmPulseDuty( Id , ChNo , ChNum , PulseDuty )

Parameters

Id [ C, C++: short ] [ Python: ctypes.c_short ]
Specify the device ID retrieved from DioInit.

ChNo [ C, C++: short * ] [ Python: ctypes.POINTER(ctypes.c_short) ]
Specify the start address of the array that stores the channel numbers to set.

ChNum [ C, C++: short ] [ Python: ctypes.c_short ]
Specify the number of channels specified in ChNo.

PulseDuty [ C, C++: unsigned short * ] [ Python: ctypes.POINTER(ctypes.c_ushort) ]
Specify the start address of the array that stored the PWM pulse duty cycle settings.

PulseDuty sets the ON time.
When the value is 0, the duty cycle is 0%. When the value is 65535, the duty cycle is 100%.

Setting range: 0 to 65535

Return Value

Ret [ C, C++: long ] [ Python: ctypes.c_long ]

Definition

Value

[Dec]

Description

DIO_ERR_SUCCESS

0

Normal completed.

DIO_ERR_DLL_INVALID_ID

10001

Invalid ID specified.

DIO_ERR_DLL_CALL_DRIVER

10002

Driver cannot be called (failed in ioctl).

DIO_ERR_DLL_BUFF_ADDRESS

10100

Invalid data buffer address

DIO_ERR_SYS_NOT_SUPPORTED

20001

This board couldn't use this function.

DIO_ERR_SYS_CH_NO

20105

Channel No. is outside the setting range.

DIO_ERR_SYS_CH_NUM

20106

Channel number is outside the setting range.

DIO_ERR_SYS_PWM_PULSE_DUTY

20902

The PWM pulse duty ratio is out of range.

DIO_ERR_SYS_DEVICE_ERR_DRIVER_IC_ERR

21200

Driver IC error occurred.

DIO_ERR_SYS_DEVICE_ERR_PCOM_FAILURE

21201

PCOM power failure occurred.

The others (See also: Details of Error Code)

Initial Value

0

Remarks

Sets the PWM pulse duty cycle for the specified channel.

The ON time is determined by the configured PWM pulse period and the value set for PulseDuty.
For details on the PWM pulse period, please refer to the DioSetPwmPulsePeriod function.

Examples of setting the PulseDuty value based on the duty ratio are shown below.

PWM pulse period

Desired Duty ratio

PulseDuty

The ON time
(0.1μsec unit)

(Reference) DioSetPwmPulsePeriod

PulsePeriodValue

PulsePeriodUnit

5.0μsec

0%

0

0.0μsec

5

DIO_PWM_PULSE_PERIOD_UNIT_US

25%

16384

1.2μsec

50%

32768

2.5μsec

75%

49152

3.7μsec

100%

65535

5.0μsec

250msec

0%

0

0.0μsec

250

DIO_PWM_PULSE_PERIOD_UNIT_MS

25%

16384

62,500.9μsec

50%

32768

125,001.9μsec

75%

49152

187,502.8μsec

100%

65535

250,000.0μsec

1sec

0%

0

0.0μsec

1

DIO_PWM_PULSE_PERIOD_UNIT_S

25%

16384

250,003.8μsec

50%

32768

500,007.6μsec

75%

49152

750,011.4μsec

100%

65535

1,000,000.0μsec

 

Example

Set the duty cycle of channel 0 to 25%(16384) and the duty cycle of channel 1 to 50%(32768).

C, C++

long Ret;
short ChNo[2]
unsigned short PulseDuty[2];

ChNo[0] = 0;
ChNo[1] = 1;
PulseDuty[0] = 16384;
PulseDuty[1] = 32768;
Ret = DioSetPwmPulseDuty( Id , &ChNo[0] , 2 , &PulseDuty[0] );
 

Python

Ret = ctypes.c_long()
ChNoType = ctypes.c_short * 2
ChNo = ChNoType()
PulseDutyType = ctypes.c_short * 2
PulseDuty = PulseDutyType()

ChNo[0] = 0
ChNo[1] = 1
PulseDuty[0] = 16384
PulseDuty[1] = 32768
Ret.value = cdio.DioSetPwmPulseDuty( Id , ChNo , 2 , PulseDuty )
 

See Also

DioGetPwmPulseDuty DioSetPwmPulsePeriod