Class CounterJNI
public class CounterJNI extends JNIWrapper
- See Also:
- "hal/Counter.h"
-
Nested Class Summary
-
Field Summary
Fields Modifier and Type Field Description static int
EXTERNAL_DIRECTION
static int
PULSE_LENGTH
static int
SEMI_PERIOD
static int
TWO_PULSE
-
Method Summary
Modifier and Type Method Description static void
clearCounterDownSource(int counterHandle)
Disables the down counting source to the counter.static void
clearCounterUpSource(int counterHandle)
Disables the up counting source to the counter.static void
freeCounter(int counterHandle)
Frees a counter.static int
getCounter(int counterHandle)
Reads the current counter value.static boolean
getCounterDirection(int counterHandle)
Gets the last direction the counter value changed.static double
getCounterPeriod(int counterHandle)
Gets the Period of the most recent count.static int
getCounterSamplesToAverage(int counterHandle)
Gets the Samples to Average which specifies the number of samples of the timer to average when calculating the period.static boolean
getCounterStopped(int counterHandle)
Determines if the clock is stopped.static int
initializeCounter(int mode, IntBuffer index)
Initializes a counter.static void
resetCounter(int counterHandle)
Resets the Counter to zero.static void
setCounterAverageSize(int counterHandle, int size)
Sets the average sample size of a counter.static void
setCounterDownSource(int counterHandle, int digitalSourceHandle, int analogTriggerType)
Sets the source object that causes the counter to count down.static void
setCounterDownSourceEdge(int counterHandle, boolean risingEdge, boolean fallingEdge)
Sets the down source to either detect rising edges or falling edges.static void
setCounterExternalDirectionMode(int counterHandle)
Sets directional counting mode on this counter.static void
setCounterMaxPeriod(int counterHandle, double maxPeriod)
Sets the maximum period where the device is still considered "moving".static void
setCounterPulseLengthMode(int counterHandle, double threshold)
Configures the counter to count in up or down based on the length of the input pulse.static void
setCounterReverseDirection(int counterHandle, boolean reverseDirection)
Sets the Counter to return reversed sensing on the direction.static void
setCounterSamplesToAverage(int counterHandle, int samplesToAverage)
Sets the Samples to Average which specifies the number of samples of the timer to average when calculating the period.static void
setCounterSemiPeriodMode(int counterHandle, boolean highSemiPeriod)
Sets Semi-period mode on this counter.static void
setCounterUpdateWhenEmpty(int counterHandle, boolean enabled)
Selects whether you want to continue updating the event timer output when there are no samples captured.static void
setCounterUpDownMode(int counterHandle)
Sets standard up / down counting mode on this counter.static void
setCounterUpSource(int counterHandle, int digitalSourceHandle, int analogTriggerType)
Sets the source object that causes the counter to count up.static void
setCounterUpSourceEdge(int counterHandle, boolean risingEdge, boolean fallingEdge)
Sets the up source to either detect rising edges or falling edges.
-
Field Details
-
TWO_PULSE
- See Also:
- Constant Field Values
-
SEMI_PERIOD
- See Also:
- Constant Field Values
-
PULSE_LENGTH
- See Also:
- Constant Field Values
-
EXTERNAL_DIRECTION
- See Also:
- Constant Field Values
-
-
Method Details
-
initializeCounter
Initializes a counter.- Parameters:
mode
- the counter modeindex
- the compressor index (output)- Returns:
- the created handle
- See Also:
- "HAL_InitializeCounter"
-
freeCounter
Frees a counter.- Parameters:
counterHandle
- the counter handle- See Also:
- "HAL_FreeCounter"
-
setCounterAverageSize
Sets the average sample size of a counter.- Parameters:
counterHandle
- the counter handlesize
- the size of samples to average- See Also:
- "HAL_SetCounterAverageSize"
-
setCounterUpSource
public static void setCounterUpSource(int counterHandle, int digitalSourceHandle, int analogTriggerType)Sets the source object that causes the counter to count up.- Parameters:
counterHandle
- the counter handledigitalSourceHandle
- the digital source handle (either a HAL_AnalogTriggerHandle or a HAL_DigitalHandle)analogTriggerType
- the analog trigger type if the source is an analog trigger- See Also:
- "HAL_SetCounterUpSource"
-
setCounterUpSourceEdge
public static void setCounterUpSourceEdge(int counterHandle, boolean risingEdge, boolean fallingEdge)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:
counterHandle
- the counter handlerisingEdge
- true to trigger on risingfallingEdge
- true to trigger on falling- See Also:
- "HAL_SetCounterUpSourceEdge"
-
clearCounterUpSource
Disables the up counting source to the counter.- Parameters:
counterHandle
- the counter handle- See Also:
- "HAL_ClearCounterUpSource"
-
setCounterDownSource
public static void setCounterDownSource(int counterHandle, int digitalSourceHandle, int analogTriggerType)Sets the source object that causes the counter to count down.- Parameters:
counterHandle
- the counter handledigitalSourceHandle
- the digital source handle (either a HAL_AnalogTriggerHandle or a HAL_DigitalHandle)analogTriggerType
- the analog trigger type if the source is an analog trigger- See Also:
- "HAL_SetCounterDownSource"
-
setCounterDownSourceEdge
public static void setCounterDownSourceEdge(int counterHandle, boolean risingEdge, boolean fallingEdge)Sets the down 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:
counterHandle
- the counter handlerisingEdge
- true to trigger on risingfallingEdge
- true to trigger on falling- See Also:
- "HAL_SetCounterDownSourceEdge"
-
clearCounterDownSource
Disables the down counting source to the counter.- Parameters:
counterHandle
- the counter handle- See Also:
- "HAL_ClearCounterDownSource"
-
setCounterUpDownMode
Sets standard up / down counting mode on this counter.Up and down counts are sourced independently from two inputs.
- Parameters:
counterHandle
- the counter handle- See Also:
- "HAL_SetCounterUpDownMode"
-
setCounterExternalDirectionMode
Sets directional counting mode on this counter.The direction is determined by the B input, with counting happening with the A input.
- Parameters:
counterHandle
- the counter handle- See Also:
- "HAL_SetCounterExternalDirectionMode"
-
setCounterSemiPeriodMode
Sets Semi-period mode on this counter.The counter counts up based on the time the input is triggered. High or Low depends on the highSemiPeriod parameter.
- Parameters:
counterHandle
- the counter handlehighSemiPeriod
- true for counting when the input is high, false for low- See Also:
- "HAL_SetCounterSemiPeriodMode"
-
setCounterPulseLengthMode
Configures the counter to count in up or down based on the length of the input pulse.This mode is most useful for direction sensitive gear tooth sensors.
- Parameters:
counterHandle
- the counter handlethreshold
- The pulse length beyond which the counter counts the opposite direction (seconds)- See Also:
- "HAL_SetCounterPulseLengthMode"
-
getCounterSamplesToAverage
Gets the Samples to Average which specifies the number of samples of the timer to average when calculating the period. Perform averaging to account for mechanical imperfections or as oversampling to increase resolution.- Parameters:
counterHandle
- the counter handle- Returns:
- SamplesToAverage The number of samples being averaged (from 1 to 127)
- See Also:
- "HAL_GetCounterSamplesToAverage"
-
setCounterSamplesToAverage
Sets the Samples to Average which specifies the number of samples of the timer to average when calculating the period. Perform averaging to account for mechanical imperfections or as oversampling to increase resolution.- Parameters:
counterHandle
- the counter handlesamplesToAverage
- The number of samples to average from 1 to 127- See Also:
- "HAL_SetCounterSamplesToAverage"
-
resetCounter
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:
counterHandle
- the counter handle- See Also:
- "HAL_ResetCounter"
-
getCounter
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:
counterHandle
- the counter handle- Returns:
- the current counter value
- See Also:
- "HAL_GetCounter"
-
getCounterPeriod
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:
counterHandle
- the counter handle- Returns:
- the period of the last two pulses in units of seconds
- See Also:
- "HAL_GetCounterPeriod"
-
setCounterMaxPeriod
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:
counterHandle
- the counter handlemaxPeriod
- the maximum period where the counted device is considered moving in seconds- See Also:
- "HAL_SetCounterMaxPeriod"
-
setCounterUpdateWhenEmpty
Selects whether you want to continue updating the event timer output when there are no samples captured.The output of the event timer has a buffer of periods that are averaged and posted to a register on the FPGA. When the timer detects that the event source has stopped (based on the MaxPeriod) the buffer of samples to be averaged is emptied.
If you enable the update when empty, you will be notified of the stopped source and the event time will report 0 samples.
If you disable update when empty, the most recent average will remain on the output until a new sample is acquired.
You will never see 0 samples output (except when there have been no events since an FPGA reset) and you will likely not see the stopped bit become true (since it is updated at the end of an average and there are no samples to average).
- Parameters:
counterHandle
- the counter handleenabled
- true to enable counter updating with no samples- See Also:
- "HAL_SetCounterUpdateWhenEmpty"
-
getCounterStopped
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:
counterHandle
- the counter handle- Returns:
- true if the most recent counter period exceeds the MaxPeriod value set by SetMaxPeriod
- See Also:
- "HAL_GetCounterStopped"
-
getCounterDirection
Gets the last direction the counter value changed.- Parameters:
counterHandle
- the counter handle- Returns:
- the last direction the counter value changed
- See Also:
- "HAL_GetCounterDirection"
-
setCounterReverseDirection
Sets the Counter to return reversed sensing on the direction.This allows counters to change the direction they are counting in the case of 1X and 2X quadrature encoding only. Any other counter mode isn't supported.
- Parameters:
counterHandle
- the counter handlereverseDirection
- true if the value counted should be negated.- See Also:
- "HAL_SetCounterReverseDirection"
-