WPILibC++ 2027.0.0-alpha-2
Loading...
Searching...
No Matches
Counter Functions

Functions

HAL_CounterHandle HAL_InitializeCounter (int channel, HAL_Bool risingEdge, const char *allocationLocation, int32_t *status)
 Initializes a counter.
 
void HAL_FreeCounter (HAL_CounterHandle counterHandle)
 Frees a counter.
 
void HAL_SetCounterEdgeConfiguration (HAL_CounterHandle counterHandle, HAL_Bool risingEdge, int32_t *status)
 Sets the up source to either detect rising edges or falling edges.
 
void HAL_ResetCounter (HAL_CounterHandle counterHandle, int32_t *status)
 Resets the Counter to zero.
 
int32_t HAL_GetCounter (HAL_CounterHandle counterHandle, int32_t *status)
 Reads the current counter value.
 
double HAL_GetCounterPeriod (HAL_CounterHandle counterHandle, int32_t *status)
 Gets the Period of the most recent count.
 
void HAL_SetCounterMaxPeriod (HAL_CounterHandle counterHandle, double maxPeriod, int32_t *status)
 Sets the maximum period where the device is still considered "moving".
 
HAL_Bool HAL_GetCounterStopped (HAL_CounterHandle counterHandle, int32_t *status)
 Determines if the clock is stopped.
 

Detailed Description

Function Documentation

◆ HAL_FreeCounter()

void HAL_FreeCounter ( HAL_CounterHandle counterHandle)

Frees a counter.

Parameters
[in]counterHandlethe counter handle

◆ HAL_GetCounter()

int32_t HAL_GetCounter ( HAL_CounterHandle counterHandle,
int32_t * status )

Reads the current counter value.

Reads the value at this instant. It may still be running, so it reflects the current value. Next time it is read, it might have a different value.

Parameters
[in]counterHandlethe counter handle
[out]statusError status variable. 0 on success.
Returns
the current counter value

◆ HAL_GetCounterPeriod()

double HAL_GetCounterPeriod ( HAL_CounterHandle counterHandle,
int32_t * status )

Gets the Period of the most recent count.

Returns the time interval of the most recent count. This can be used for velocity calculations to determine shaft speed.

Parameters
[in]counterHandlethe counter handle
[out]statusError status variable. 0 on success.
Returns
the period of the last two pulses in units of seconds

◆ HAL_GetCounterStopped()

HAL_Bool HAL_GetCounterStopped ( HAL_CounterHandle counterHandle,
int32_t * status )

Determines if the clock is stopped.

Determine if the clocked input is stopped based on the MaxPeriod value set using the SetMaxPeriod method. If the clock exceeds the MaxPeriod, then the device (and counter) are assumed to be stopped and it returns true.

Parameters
[in]counterHandlethe counter handle
[out]statusError status variable. 0 on success.
Returns
true if the most recent counter period exceeds the MaxPeriod value set by SetMaxPeriod

◆ HAL_InitializeCounter()

HAL_CounterHandle HAL_InitializeCounter ( int channel,
HAL_Bool risingEdge,
const char * allocationLocation,
int32_t * status )

Initializes a counter.

Parameters
[in]channelthe dio channel
[in]risingEdgetrue to count on rising edge, false for falling
[in]allocationLocationthe location where the allocation is occurring (can be null)
[out]statusError status variable. 0 on success.
Returns
the created handle

◆ HAL_ResetCounter()

void HAL_ResetCounter ( HAL_CounterHandle counterHandle,
int32_t * status )

Resets the Counter to zero.

Sets the counter value to zero. This does not effect the running state of the counter, just sets the current value to zero.

Parameters
[in]counterHandlethe counter handle
[out]statusError status variable. 0 on success.

◆ HAL_SetCounterEdgeConfiguration()

void HAL_SetCounterEdgeConfiguration ( HAL_CounterHandle counterHandle,
HAL_Bool risingEdge,
int32_t * status )

Sets the up source to either detect rising edges or falling edges.

Note that both are allowed to be set true at the same time without issues.

Parameters
[in]counterHandlethe counter handle
[in]risingEdgetrue to trigger on rising
[out]statusError status variable. 0 on success.

◆ HAL_SetCounterMaxPeriod()

void HAL_SetCounterMaxPeriod ( HAL_CounterHandle counterHandle,
double maxPeriod,
int32_t * status )

Sets the maximum period where the device is still considered "moving".

Sets the maximum period where the device is considered moving. This value is used to determine the "stopped" state of the counter using the HAL_GetCounterStopped method.

Parameters
[in]counterHandlethe counter handle
[in]maxPeriodthe maximum period where the counted device is considered moving in seconds
[out]statusError status variable. 0 on success.