PWM Functions

This section describes the PWM Interface functions. They are used to control and monitor the PWM module of a DLN-series adapter.

General information:

DlnPwmGetPortCount()

Retrieves the number of ports that can be assigned to the PWM module.

DlnPwmEnable()

Assigns a port to the PWM module.

DlnPwmDisable()

Unassigns a port to the PWM module.

DlnPwmIsEnabled()

Retrieves whether a port is assigned to the PWM module.

DlnPwmGetChannelCount()

Retrieves the number of channels available to the PWM port.

DlnPwmChannelEnable()

Activates a channel of the PWM port.

DlnPwmChannelDisable()

Releases a channel of the PWM port.

DlnPwmChannelIsEnabled()

Retrieves whether a channel is activated.

Configuration functions:

DlnPwmSetDutyCycle()

Configures the duty cycle value for the specified PWM port.

DlnPwmGetDutyCycle()

Retrieves the current duty cycle value for the specified PWM port.

DlnPwmSetFrequency()

Configures the frequency value for the specified PWM port.

DlnPwmGetFrequency()

Retrieves the current frequency value for the specified PWM port.

DlnPwmGetMaxFrequency()

Retrieves the maximum frequency value for the specified PWM port.

DlnPwmGetMinFrequency()

Retrieves the minimum frequency value for the specified PWM port.

The dln_pwm.h file declares the PWM Interface functions.

Rating: 
Голосов пока нет

DlnPwmGetPortCount() Function

The DlnPwmGetPortCount() function retrieves the number of PWM ports available in your DLN-series adapter.

Syntax
C/C++
DLN_RESULT DlnPwmGetPortCount(
    HDLN handle,
    uint8_t* count
);
Parameters
handle

A handle to the DLN-series adapter.

count

A pointer to an unsigned 8-bit integer that receives the number of available PWM ports.

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully retrieved the number of PWM ports.

Remarks

The DlnPwmGetPortCount() function is defined in the dln_pwm.h file.

DlnPwmEnable() Function

The DlnPwmEnable() function activates the corresponding PWM port of your DLN-series adapter.

Syntax
C/C++
DLN_RESULT DlnPwmEnable(
    HDLN handle, 
    uint8_t port,
    uint16_t* conflict
);
Parameters
handle

A handle to the DLN-series adapter.

port

A number of the PWM port.

conflict

A pointer to an unsigned 16-bit integer that receives the number of the conflicted pin, if any.A conflict arises if a pin is already assigned to another module of the DLN-series adapter and cannot be used for the PWM module. To fix this, check which module uses the pin (call the DlnGetPinCfg()function), disconnect the pin from that module and call the DlnPwmEnable() function once again. In case there still are conflicted pins, only the number of the next one will be returned.

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully activated the PWM port.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

The port number is not valid. Use the DlnPwmGetPortCount() function to find the maximum possible port number.

DLN_RES_PIN_IN_USE (0xA5)

The port cannot be activated as the PWM port because one or more pins of the port are assigned to another module. The conflict parameter contains the number of a conflicting pin.

Remarks

The DlnPwmEnable() function is defined in the dln_pwm.h file.

DlnPwmDisable() Function

The DlnPwmDisable() function releases the specified PWM port of your DLN-series adapter.

Syntax
C/C++
DLN_RESULT DlnPwmDisable(
    HDLN handle,
    uint8_t port
);
Parameters
handle

A handle to the DLN-series adapter.

port

A number of the PWM port.

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully released the PWM port.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

The port number is not valid. Use the DlnPwmGetPortCount() function to find the maximum possible port number.

Remarks

The DlnPwmDisable() function is defined in the dln_pwm.h file.

DlnPwmIsEnabled() Function

The DlnPwmIsEnabled() function retrieves information, whether the specified port is assigned to the PWM module.

Syntax
C/C++
DLN_RESULT DlnPwmIsEnabled(
    HDLN handle,
    uint8_t port,
    uint8_t* enabled
);
Parameters
handle

A handle to the DLN-series adapter.

port

A number of the PWM port.

enabled

A pointer to an unsigned 8-bit integer. The integer will be filled with the information whether the specified PWM port is activated. There are two possible values:

  • 0 or DLN_PWM_DISABLED - PWM port is deactivated.

  • 1 or DLN_PWM_ENABLED - PWM port is activated.

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully retrieved the PWM port state.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

The port number is not valid. Use the DlnPwmGetPortCount() function to find the maximum possible port number.

Remarks

The DlnPwmIsEnabled() function is defined in the dln_pwm.h file.

DlnPwmGetChannelCount() Function

The DlnPwmGetChannelCount() function retrieves the number of PWM channels available in the specified PWM-port of your DLN-series adapter.

Syntax
C/C++
DLN_RESULT DlnPwmGetChannelCount(
    HDLN handle,
    uint8_t port,
    uint8_t* count
);
Parameters
handle

A handle to the DLN-series adapter.

port

A PWM port to retrieve the number of channels from.

count

A pointer to an unsigned 8-bit integer that receives the available number of channels in the specified PWM port of the DLN-series adapter.

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully retrieved the number of channels.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

The port number is not valid. Use the DlnPwmGetPortCount() function to find the maximum possible port number.

Remarks

The DlnPwmGetChannelCount() function is defined in the dln_pwm.h file.

DlnPwmChannelEnable() Function

The DlnPwmChannelEnable() function activates the specified channel from the corresponding PWM port of your DLN-series adapter.

Syntax
C/C++
DLN_RESULT DlnPwmChannelEnable(
    HDLN handle,
    uint8_t port,
    uint8_t channel
);
Parameters
handle

A handle to the DLN-series adapter.

port

A number of the PWM port.

channel

A number of the channel.

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully activated the channel.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

The port number is not valid. Use the DlnPwmGetPortCount() function to find the maximum possible port number.

DLN_RES_INVALID_CHANNEL_NUMBER (0xC0)

The channel number is not valid. Use the DlnPwmGetChannelCount() function to find the maximum possible port number.

Remarks

The DlnPwmChannelEnable() function is defined in the dln_pwm.h file.

DlnPwmChannelDisable() Function

The DlnPwmChannelDisable() function releases the specified channel from the corresponding PWM port of your DLN-series adapter.

Syntax
C/C++
DLN_RESULT DlnPwmChannelDisable(
    HDLN handle,
    uint8_t port,
    uint8_t channel
);
Parameters
handle

A handle to the DLN-series adapter.

port

A number of the PWM port.

channel

A number of the channel.

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully released the channel.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

The port number is not valid. Use the DlnPwmGetPortCount() function to find the maximum possible port number.

DLN_RES_INVALID_CHANNEL_NUMBER (0xC0)

The channel number is not valid. Use the DlnPwmGetChannelCount() function to find the maximum possible port number.

Remarks

The DlnPwmChannelDisable() function is defined in the dln_pwm.h file.

DlnPwmChannelIsEnabled() Function

The DlnPwmChannelIsEnabled() retrieves information, whether the specified PWM channel is activated.

Syntax
C/C++
DLN_RESULT DlnPwmChannelIsEnabled(
    HDLN handle, 
    uint8_t port,
    uint8_t channel,
    uint8_t* enabled
);
Parameters
handle

A handle to the DLN-series adapter.

port

A number of the PWM port.

channel

A number of the PWM channel.

enabled

A pointer to an unsigned 8-bit integer that receives the information about the specified PWM channel. There are two possible values:

  • 0 or DLN_PWM_DISABLED - The PWM channel is released.

  • 1 or DLN_PWM_ENABLED - The PWM channel is activated.

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully retrieved information about the channel.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

The port number is not valid. Use the DlnPwmGetPortCount() function to find the maximum possible port number.

DLN_RES_INVALID_CHANNEL_NUMBER (0xC0)

The channel number is not valid. Use the DlnPwmGetChannelCount() function to find the maximum possible port number.

Remarks

The DlnPwmChannelIsEnabled() function is defined in the dln_pwm.h file.

DlnPwmSetDutyCycle() Function

The DlnPwmSetDutyCycle() function defines a PWM duty cycle value, which is the ratio of the high time to the PWM period.

Syntax
C/C++
DLN_RESULT DlnPwmSetDutyCycle(
   HDLN handle, 
   uint8_t port, 
   uint8_t channel,
   double dutyCycle,
   double* actualDutyCycle
);
Parameters
handle

A handle to the DLN-series adapter.

port

A number of the PWM port.

channel

A number of the PWM channel.

dutyCycle

A double precision floating point number. Must contain a duty cycle that should to be set. The value is specified in percents.

actualDutyCycle

A pointer to a double precision floating point number that receives the actual duty cycle value.

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully defined the duty cycle value.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

The port number is not valid. Use the DlnPwmGetPortCount() function to find the maximum possible port number.

DLN_RES_INVALID_CHANNEL_NUMBER (0xC0)

The channel number is not valid. Use the DlnPwmGetChannelCount() function to find the maximum possible port number.

DLN_RES_PWM_INVALID_DUTY_CYCLE (0xC4)

The provided value is not valid.

Remarks

The DlnPwmSetDutyCycle() function is defined in the dln_pwm.h file.

DlnPwmGetDutyCycle() Function

The DlnPwmGetDutyCycle() function retrieves the current PWM duty cycle value.

Syntax
C/C++
DLN_RESULT DlnPwmGetDutyCycle(
   HDLN handle, 
   uint8_t port,
   uint8_t channel,
   double* dutyCycle
);
Parameters
handle

A handle to the DLN-series adapter.

port

A number of the PWM port.

channel

A number of the PWM channel.

dutyCycle

A pointer to the double precision floating point number that receives the current duty cycle.

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully retrieved the current duty cycle value.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

The port number is not valid. Use the DlnPwmGetPortCount() function to find the maximum possible port number.

DLN_RES_INVALID_CHANNEL_NUMBER (0xC0)

The channel number is not valid. Use the DlnPwmGetChannelCount() function to find the maximum possible port number.

Remarks

The DlnPwmGetDutyCycle() function is defined in the dln_pwm.h file.

DlnPwmSetFrequency() Function

The DlnPwmSetFrequency() function defines the PWM frequency.

Syntax
C/C++
DLN_RESULT DlnPwmSetFrequency(
   HDLN handle, 
   uint8_t port,
   uint8_t channel,
   uint32_t frequency,
   uint32_t* actualFrequency
);
Parameters
handle

A handle to the DLN-series adapter.

port

A number of the PWM port.

channel

A number of the PWM channel.

frequency

The frequency value, specified in Hz. You may specify any value within the range, supported by the DLN-series adapter. This range can be retrieved using the respective function. If you enter an incompatible value, it will be approximated as the closest lower frequency value, supported by the adapter.

actualFrequency

A pointer to an unsigned 32-bit integer that receives the actually set frequency approximated as the closest to user-defined lower value.

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully defined the frequency value.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

The port number is not valid. Use the DlnPwmGetPortCount() function to find the maximum possible port number.

DLN_RES_INVALID_CHANNEL_NUMBER (0xC0)

The channel number is not valid. Use the DlnPwmGetChannelCount() function to find the maximum possible port number.

DLN_RES_VALUE_ROUNDED (0x21)

The function approximated the frequency value to the closest supported value.

Remarks

The DlnPwmSetFrequency() function is defined in the dln_pwm.h file.

DlnPwmGetFrequency() Function

The DlnPwmGetFrequency() function retrieves the current PWM frequency.

Syntax
C/C++
DLN_RESULT DlnPwmGetFrequency(
  HDLN handle, 
  uint8_t port,
  uint8_t channel,
  uint32_t* frequency,
);	
Parameters
handle

A handle to the DLN-series adapter.

port

A number of the PWM port.

channel

A number of the PWM channel.

frequency

A pointer to an unsigned 32-bit integer that receives the current frequency setting for the DLN-series adapter.

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully retrieved the current frequency value.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

The port number is not valid. Use the DlnPwmGetPortCount() function to find the maximum possible port number.

DLN_RES_INVALID_CHANNEL_NUMBER (0xC0)

The channel number is not valid. Use the DlnPwmGetChannelCount() function to find the maximum possible port number.

Remarks

The DlnPwmGetFrequency() function is defined in the dln_pwm.h file.

DlnPwmGetMaxFrequency() Function

The DlnPwmGetMaxFrequency() function retrieves the maximum possible value of the PWM frequency.

Syntax
C/C++
DLN_RESULT DlnPwmGetMaxFrequency(
    HDLN handle, 
    uint8_t port, 
    uint32_t *frequency
);
Parameters
handle

A handle to the DLN-series adapter.

port

A number of the PWM port.

frequency

A pointer to an unsigned 32-bit integer that receives the maximum frequency value for the DLN-series adapter.

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully retrieved the maximum possible frequency value.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

The port number is not valid. Use the DlnPwmGetPortCount() function to find the maximum possible port number.

DLN_RES_INVALID_CHANNEL_NUMBER (0xC0)

The channel number is not valid. Use the DlnPwmGetChannelCount() function to find the maximum possible port number.

Remarks

The DlnPwmGetMaxFrequency() function is defined in the dln_pwm.h file.

DlnPwmGetMinFrequency() Function

The DlnPwmGetMinFrequency() function retrieves the minimum possible value of the PWM frequency.

Syntax
C/C++
DLN_RESULT DlnPwmGetMinFrequency(
    HDLN handle, 
    uint8_t port, 
    uint32_t *frequency
);
Parameters
handle

A handle to the DLN-series adapter.

port

A number of the PWM port.

frequency

A pointer to an unsigned 32-bit integer that receives the minimum frequency value for the DLN-series adapter.

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully retrieved the minimum possible frequency value.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

The port number is not valid. Use the DlnPwmGetPortCount() function to find the maximum possible port number.

DLN_RES_INVALID_CHANNEL_NUMBER (0xC0)

The channel number is not valid. Use the DlnPwmGetChannelCount() function to find the maximum possible port number.

Remarks

The DlnPwmGetMinFrequency() function is defined in the dln_pwm.h file.