mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-23 01:21:42 +00:00
[hal] Convert DutyCycle Raw output to be a high time measurement (#4466)
The existing raw time has an issue where it jumps around, as in the FPGA if the frequency is not a multiple or divisor of 25 Mhz it jumps around by 1 every second. While waiting on an FPGA change, update the API to make raw output give nanoseconds rather then a scaled value. This does a longer read cycle to get the correct value, but in the future if a fast FPGA function is added this can be easily changed.
This commit is contained in:
@@ -84,6 +84,7 @@ int32_t HAL_GetDutyCycleFrequency(HAL_DutyCycleHandle dutyCycleHandle,
|
||||
}
|
||||
return SimDutyCycleData[dutyCycle->index].frequency;
|
||||
}
|
||||
|
||||
double HAL_GetDutyCycleOutput(HAL_DutyCycleHandle dutyCycleHandle,
|
||||
int32_t* status) {
|
||||
auto dutyCycle = dutyCycleHandles->Get(dutyCycleHandle);
|
||||
@@ -93,20 +94,29 @@ double HAL_GetDutyCycleOutput(HAL_DutyCycleHandle dutyCycleHandle,
|
||||
}
|
||||
return SimDutyCycleData[dutyCycle->index].output;
|
||||
}
|
||||
int32_t HAL_GetDutyCycleOutputRaw(HAL_DutyCycleHandle dutyCycleHandle,
|
||||
int32_t* status) {
|
||||
|
||||
int32_t HAL_GetDutyCycleHighTime(HAL_DutyCycleHandle dutyCycleHandle,
|
||||
int32_t* status) {
|
||||
auto dutyCycle = dutyCycleHandles->Get(dutyCycleHandle);
|
||||
if (dutyCycle == nullptr) {
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return 0;
|
||||
}
|
||||
return SimDutyCycleData[dutyCycle->index].output *
|
||||
HAL_GetDutyCycleOutputScaleFactor(dutyCycleHandle, status);
|
||||
|
||||
if (SimDutyCycleData[dutyCycle->index].frequency == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
double periodSeconds = 1.0 / SimDutyCycleData[dutyCycle->index].frequency;
|
||||
double periodNanoSeconds = periodSeconds * 1e9;
|
||||
return periodNanoSeconds * SimDutyCycleData[dutyCycle->index].output;
|
||||
}
|
||||
|
||||
int32_t HAL_GetDutyCycleOutputScaleFactor(HAL_DutyCycleHandle dutyCycleHandle,
|
||||
int32_t* status) {
|
||||
return 4e7 - 1;
|
||||
}
|
||||
|
||||
int32_t HAL_GetDutyCycleFPGAIndex(HAL_DutyCycleHandle dutyCycleHandle,
|
||||
int32_t* status) {
|
||||
auto dutyCycle = dutyCycleHandles->Get(dutyCycleHandle);
|
||||
|
||||
Reference in New Issue
Block a user