Pulse Counter Interface

Pulse counter interface allows to count with pulses and set timers.

To start using Pulse counter module you need to enable Pulse counter port. It can be done with the DlnPlsCntEnable() function. Also pulse counter module mode need to be set with DlnPlsCntSetMode() function.

At any moment pulse counter or timer value can be read with function DlnPlsCntGetValue().

You can also enable the events to get alert when condition is met. One of the few conditions can be selected: pulse counter/timer overflow, when it matches selected value or repeat event for selected period. Use DlnPlsCntSetEventCfg() to setup events.

Rating: 
Средняя: 2.8 (5 оценок)

Pulse Counter Modes

There are 3 available modes: free run mode, time-based mode and pulse-based mode.

In "Free Run Mode" pulses are counted continuously. You can suspend, resume or reset the counter and get the number of pulses at any time.

In "Time-Based Mode" pulses are counted during the user-defined time period. When the predefined time period (limit) is exceeded, the counting starts again from 0. The pulse counter can send a match event to PC if activated. The event contains the number of pulses detected during this period.

In "Pulse-Based Mode" Pulses are counted until the number of pulses reaches the user-defined value (limit). Then the counting starts again from 0. The counter can send an event to PC if activated. The event contains time elapsed from the moment you started the counter.

Pulse counter module mode can be set or changes by calling DlnPlsCntSetMode() function. You can also retrieve the current mode by calling DlnPlsCntGetMode() function.

There are also constants available for each mode in the dln_pls_cnt.h header file: DLN_PLS_CNT_MODE_FREE_RUN(0), DLN_PLS_CNT_MODE_TIME_BASED(1), DLN_PLS_CNT_MODE_PULSE_BASED(2).

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

Simple Pulse Counter Module Example

This example shows how to setup pulse counter module, read timer and pulse counter values. You can find the complete example in the “..\Program Files\Diolan\DLN\examples\c_cpp\examples\ simple” folder after DLN setup package installation.

C/C++
#include "..\..\..\common\dln_generic.h"
#include "..\..\..\common\dln_pls_cnt.h"
#pragma comment(lib, "..\\..\\..\\bin\\dln.lib")


int _tmain(int argc, _TCHAR* argv[])
{
	// Open device
	HDLN device;
	DlnOpenUsbDevice(&device);

	// Set Free Run mode
	DlnPlsCntSetMode(device, 0, DLN_PLS_CNT_MODE_FREE_RUN, 0);
	// Enable counter
	uint16_t conflict;
	DlnPlsCntEnable(device, 0, &conflict);

	// Do some delay
	for (int i = 0; i < 10000; i++);

	// Read counter values
	uint32_t timerValue, counterValue;
	DlnPlsCntGetValue(device, 0, &timerValue, &counterValue);
	printf("Timer Value = %u, Counter Value = %u\n", timerValue, counterValue);

	// Close device
	DlnCloseHandle(device);
	return 0;
}

  • Line 1:#include "..\..\..\common\dln_generic.h"

    The dln_generic..h header file declares functions and data structures for the generic interface. In current example this header is used to call DlnOpenUsbDevice() and DlnCloseHandle() functions.

  • Line 2:#include "..\..\..\common\dln_pls_cnt.h"

    The dln_pwm.h header file declares functions and data structures for the PWM interface. In current example this header is used to call DlnPlsCntSetMode(), DlnPlsCntEnable(), DlnPlsCntGetValue() functions.

  • Line 3:#pragma comment(lib, "..\\..\\..\\bin\\dln.lib")

    Use dln.lib library while project linking.

  • Line 10:DlnOpenUsbDevice(&device);

    The function establishes the connection with the DLN adapter. This application uses the USB connectivity of the adapter. For additional options, refer to the Device Opening & Identification section.

  • Line 13:DlnPlsCntSetMode(device, 0, DLN_PLS_CNT_MODE_FREE_RUN, 0);

    The function sets pulse counter mode to “Free run mode”. You can read more about pulse counter modes at Pulse Counter Modes section.

  • Line 16:DlnPlsCntEnable(device, 0, &conflict);

    The function enables pulse counter module.

  • Line 19:for (int i = 0; i < 10000; i++);

    Performing delay for more continuous mode of counter.

  • Line 23:DlnPlsCntGetValue(device, 0, &timerValue, &counterValue);

    The function retrieves timer and pulse counter values.

  • Line 24:printf("Timer Value = %u, Counter Value = %u\n", timerValue, counterValue);

    Printing retrieved timer and pulse counter values to console.

  • Line 27:DlnCloseHandle(device);

    The application closes handle to the DLN adapter.

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

Pulse Counter Functions

This section describes the Pulse Counter module functions. They are used to control Pulse Counter interface and modify its settings.

Actual control of the device is performed by use of commands and responses. Each function utilizes respective commands and responses. You can send such commands directly if necessary.

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

DlnPlsCntGetPortCount() Function

The DlnPlsCntGetPortCount() function retrieves the number of pulse counter ports available in your DLN-series adapter.

Syntax
C/C++
DLN_RESULT DlnPlsCntGetPortCount(
  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 Pulse counter ports.

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully retrieved the number of available pulse counter ports.

Remarks

The DlnPlsCntGetPortCount() function is defined in the dln_pls_cnt.h file.

DlnPlsCntEnable() Function

The DlnPlsCntEnable() function configures a port as Pulse counter.

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

A handle to the DLN-series adapter.

port

A number of the port.

conflict

A pointer to an unsigned 16-bit integer that receives the conflicted pin information.

A conflict arises if any pin of the port is already assigned to another module of the DLN adapter and cannot be used for the Pulse counter module. To fix this, check which module uses the pin (call the DlnGetPinCfg()function), disconnect the pin from that module and call the DlnPlsCntEnable() function once again. In case there still are conflicted pins, the number of the next one will be returned.

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully configured the port as Pulse counter.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

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

DLN_RES_PIN_IN_USE (0xA5)

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

DLN_RES_NO_FREE_TIMER (0xD0)

Remarks

The DlnPlsCntEnable() function is defined in the dln_pls_cnt.h file.

DlnPlsCntDisable() Function

The DlnPlsCntDisable() function releases a port from Pulse counter.

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

A handle to the DLN-series adapter.

port

A number of the port.

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully released the port from Pulse counter.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

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

Remarks

The DlnPlsCntDisable() function is defined in the dln_pls_cnt.h file.

DlnPlsCntIsEnabled() Function

The DlnPlsCntIsEnabled() function informs whether a port is currently configured as Pulse counter.

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

A handle to the DLN-series adapter.

port

A number of the port.

enabled

A pointer to an unsigned 8-bit integer that receives the current port configuration.

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully retrieved information about the Pulse counter port.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

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

Remarks

The DlnPlsCntIsEnabled() function is defined in the dln_pls_cnt.h file.

DlnPlsCntSetMode() Function

The DlnPlsCntSetMode() function is used to set mode and limit parameters of specified Pulse Counter port.

Syntax
C/C++
DLN_RESULT DlnPlsCntSetMode(
  HDLN handle, 
  uint8_t port,
  uint8_t mode, 
  uint32_t limit
);
Parameters
handle

A handle to the DLN-series adapter.

port

A number of the port to retrieve information about.

mode

Defines the mode parameter of the Pulse Counter port.

Pulse Counter Module Modes
Mode IdMode TitleMode Description

0

Free Run Mode

Pulses are counted continuously. You can suspend, resume or reset the counter and get the number of pulses at any time.

1

Time Based Mode

Pulses are counted during the user-defined time period. When the predefined time period (limit) is exceeded, the counting starts again from 0. The pulse counter can send a match event to PC if activated. The event contains the number of pulses detected during this period.

2

Pulse Based Mode

Pulses are counted until the number of pulses reaches the user-defined value (limit). Then the counting starts again from 0. The counter can send an event to PC if activated. The event contains time elapsed from the moment you started the counter.

limit

Defines the limit parameter of the Pulse Counter port.

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully configured the Pulse counter port.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

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

DLN_RES_OVERFLOW (0xB5)

DLN_RES_BUSY (0xB6)

The function cannot configure the Pulse counter port while it is busy.

DLN_RES_INVALID_MODE (0xC7)

The mode value is not valid.

Remarks

The DlnPlsCntSetMode() function is defined in the dln_pls_cnt.h file.

DlnPlsCntGetMode() Function

The DlnPlsCntGetMode() function is used to get mode and limit parameters of the specified Pulse Counter port.

Syntax
C/C++
DLN_RESULT DlnPlsCntGetMode(
  HDLN handle, 
  uint8_t port, 
  uint8_t *mode, 
  uint32_t *limit
);
Parameters
handle

A handle to the DLN-series adapter.

port

A number of the port.

mode

A pointer to an unsigned 8-bit integer that receives the current mode parameter of the Pulse Counter port.

limit

A pointer to an unsigned 32-bit integer that receives the current limit parameter of the Pulse Counter port.

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully retrieved the Pulse counter port configuration.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

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

Remarks

The DlnPlsCntGetMode() function is defined in the dln_pls_cnt.h file.

DlnPlsCntGetResolution() Function

The DlnPlsCntGetResolution() function retrieves the current Pulse Counter Module resolution.

Syntax
C/C++
DLN_RESULT DlnPlsCntGetResolution(
  HDLN handle, 
  uint8_t port, 
  uint8_t *resolution
);
Parameters
handle

A handle to the DLN-series adapter.

port

A number of the port to be configured.

resolution

A pointer to an unsigned 8-bit integer that receives the resolution value.

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully retrieved the Pulse counter module resolution.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

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

Remarks

The DlnPlsCntGetResolution() function is defined in the dln_pls_cnt.h file.

DlnPlsCntGetValue() Function

The DlnPlsCntGetValue() function retrieves the current timer and counter values of the specified Pulse Counter port.

Syntax
C/C++
DLN_RESULT DlnPlsCntGetValue(
  HDLN handle, 
  uint8_t port, 
  uint32_t *timerValue, 
  uint32_t *counterValue
);
Parameters
handle

A handle to the DLN-series adapter.

port

A number of the port.

timerValue

A pointer to an unsigned 32-bit integer that receives the timer value.

counterValue

A pointer to an unsigned 32-bit integer that receives the counter value.

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully retrieved the timer and counter values.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

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

Remarks

The DlnPlsCntGetValue() function is defined in the dln_pls_cnt.h file.

DlnPlsCntReset() Function

The DlnPlsCntReset() function resets the timer and/or counter on the Pulse Counter port.

Syntax
C/C++
DLN_RESULT DlnPlsCntReset(
  HDLN handle, 
  uint8_t port, 
  uint8_t resetTimer, 
  uint8_t resetCounter
);
Parameters
handle

A handle to the DLN-series adapter.

port

A number of the port.

resetTimer

Defines whether the timer needs to be reset. To reset the timer, specify any value greater than 0 to this parameter.

resetCounter

Defines whether counter need to be reset. To reset the counter, specify any value greater than 0 to this parameter.

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully reset the timer and/or counter values.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

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

Remarks

The DlnPlsCntReset() function is defined in the dln_pls_cnt.h file.

DlnPlsCntResume() Function

The DlnPlsCntResume() function resumes the pulse counter operation state on the Pulse Counter port.

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

A handle to the DLN-series adapter.

port

A number of the port.

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully resumed the pulse counter operation state.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

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

Remarks

The DlnPlsCntResume() function is defined in the dln_pls_cnt.h file.

DlnPlsCntSuspend() Function

The DlnPlsCntSuspend() function suspends pulse counter operation state on the Pulse Counter port.

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

A handle to the DLN-series adapter.

port

A number of the port.

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully suspended the pulse counter operation state.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

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

Remarks

The DlnPlsCntSuspend() function is defined in the dln_pls_cnt.h file.

DlnPlsCntIsSuspended() Function

The DlnPlsCntIsSuspended() function informs whether a port is currently suspended.

Syntax
C/C++
DLN_RESULT DlnPlsCntIsSuspended(
  HDLN handle, 
  uint8_t port, 
  uint8_t *suspended
);
Parameters
handle

A handle to the DLN-series adapter.

port

A number of the port.

suspended

A pointer to an unsigned 8-bit integer that receives the current port configuration.

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully retrieved the current port configuration.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

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

Remarks

The DlnPlsCntIsSuspended() function is defined in the dln_pls_cnt.h file.

DlnPlsCntSetEventCfg() Function

The DlnPlsCntSetEventCfg() function defines the event configuration for the specified Pulse Counter port.

Syntax
C/C++
DLN_RESULT DlnPlsCntSetEventCfg(
  HDLN handle, 
  uint8_t port, 
  uint8_t eventType, 
  uint32_t repeatInterval
);
Parameters
handle

A handle to the DLN-series adapter.

port

A number of the port.

eventType

Defines the event type parameter. There are 4 possible event types.

  • DLN_PLS_CNT_EVENT_NONE - 0

  • DLN_PLS_CNT_EVENT_OVERFLOW - 1

  • DLN_PLS_CNT_EVENT_MATCH - 2

  • DLN_PLS_CNT_EVENT_REPEAT - 4

repeatInterval

Defines the repeat interval parameter.

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully configured events for the specified port.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

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

DLN_RES_INVALID_EVENT_TYPE (0xA9)

The specified event type is not valid.

DLN_RES_INVALID_EVENT_PERIOD (0xAC)

The specified event period is not valid.

Remarks

The DlnPlsCntSetEventCfg() function is defined in the dln_pls_cnt.h file.

DlnPlsCntGetEventCfg() Function

The DlnPlsCntGetEventCfg() function is used to get event configuration of the specified Pulse Counter port.

Syntax
C/C++
DLN_RESULT DlnPlsCntGetEventCfg(
  HDLN handle, 
  uint8_t port, 
  uint8_t *eventType, 
  uint32_t *repeatInterval
);
Parameters
handle

A handle to the DLN-series adapter.

port

A number of the port to get configuration.

eventType

A pointer to an unsigned 8-bit integer. Defines the current event type parameter.

repeatInterval

A pointer to an unsigned 32-bit integer. Defines the current repeat interval parameter

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully retrieved the current event configuration.

DLN_RES_INVALID_PORT_NUMBER (0xA8)

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

Remarks

The DlnPlsCntGetEventCfg() function is defined in the dln_pls_cnt.h file.