Skip to content

Commit

Permalink
Merge pull request #147 from skliper/is76-usec-conversion
Browse files Browse the repository at this point in the history
Fix #76, Microsec conversion lost resolution
  • Loading branch information
astrogeco authored Apr 21, 2020
2 parents c7e4ce4 + 6ddf6fd commit c8bde97
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion fsw/mcp750-vxworks/src/cfe_psp_timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,21 @@ void CFE_PSP_GetTime( OS_time_t *LocalTime)
DecCount = DecCount & 0x7FFFFFFF;
DecCount = ((uint32) 0x0D6937E5) - DecCount;
LocalTime->seconds = DecCount / 8333311;

/* Get subseconds (discard seconds) */
DecCount = DecCount % 8333311;
LocalTime->microsecs = (DecCount/8333) * 1000;

/* Microsecond conversion
* If speed really matters, recommend testing the following
* options on hardware being used (all should give the exact same answer):
* - long long to avoid overflow: (DecCount*1000000ULL)/8333311
* - Double w/ divide: DecCount/8.333311
* - Approximation: ((300 * DecCount) + (DecCount / 1244)) / 2500
* At cost of up to 2us error (at max value):
* - Approximation: (DecCount * 3) / 25
*/
LocalTime->microsecs = ((300 * DecCount) + (DecCount / 1244)) / 2500;

}/* end CFE_PSP_GetLocalTime */

/******************************************************************************
Expand Down

0 comments on commit c8bde97

Please sign in to comment.