Skip to content

Commit

Permalink
fix(PeriphDrivers): Improve accuracy of timer stop watch (#1187)
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Perkins <michael.perkins@analog.com>
  • Loading branch information
perkinsmg committed Sep 24, 2024
1 parent ace41b2 commit c8cd2cb
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions Libraries/PeriphDrivers/Source/TMR/tmr_reva.c
Original file line number Diff line number Diff line change
Expand Up @@ -235,15 +235,15 @@ int MXC_TMR_RevA_GetTime(mxc_tmr_reva_regs_t *tmr, uint32_t ticks, uint32_t *tim
((tmr->cn & MXC_F_TMR_REVA_CN_PRES) >> MXC_F_TMR_REVA_CN_PRES_POS) |
(((tmr->cn & MXC_F_TMR_REVA_CN_PRES3) >> (MXC_F_TMR_REVA_CN_PRES3_POS)) << 3);

temp_time = (uint64_t)ticks * 1000 * (1 << (prescale & 0xF)) / (timerClock / 1000000);
temp_time = (uint64_t)ticks * 1000000 * (1 << (prescale & 0xF)) / (timerClock / 1000);

if (!(temp_time & 0xffffffff00000000)) {
*time = temp_time;
*units = MXC_TMR_UNIT_NANOSEC;
return E_NO_ERROR;
}

temp_time = (uint64_t)ticks * 1000 * (1 << (prescale & 0xF)) / (timerClock / 1000);
temp_time = (uint64_t)ticks * 1000000 * (1 << (prescale & 0xF)) / timerClock;

if (!(temp_time & 0xffffffff00000000)) {
*time = temp_time;
Expand Down
4 changes: 2 additions & 2 deletions Libraries/PeriphDrivers/Source/TMR/tmr_revb.c
Original file line number Diff line number Diff line change
Expand Up @@ -512,15 +512,15 @@ int MXC_TMR_RevB_GetTime(mxc_tmr_revb_regs_t *tmr, uint32_t ticks, uint32_t *tim
return timerClock;
}

temp_time = (uint64_t)ticks * 1000 * (1 << (prescale & 0xF)) / (timerClock / 1000000);
temp_time = (uint64_t)ticks * 1000000 * (1 << (prescale & 0xF)) / (timerClock / 1000);

if (!(temp_time & 0xffffffff00000000)) {
*time = temp_time;
*units = MXC_TMR_UNIT_NANOSEC;
return E_NO_ERROR;
}

temp_time = (uint64_t)ticks * 1000 * (1 << (prescale & 0xF)) / (timerClock / 1000);
temp_time = (uint64_t)ticks * 1000000 * (1 << (prescale & 0xF)) / timerClock;

if (!(temp_time & 0xffffffff00000000)) {
*time = temp_time;
Expand Down
4 changes: 2 additions & 2 deletions Libraries/PeriphDrivers/Source/TMR/tmr_revc.c
Original file line number Diff line number Diff line change
Expand Up @@ -293,15 +293,15 @@ int MXC_TMR_RevC_GetTime(mxc_tmr_regs_t *tmr, uint32_t ticks, uint32_t *time, mx
uint32_t prescale = (((tmr->cn & MXC_F_TMR_CN_PRES) >> MXC_F_TMR_CN_PRES_POS) |
((((tmr->cn & MXC_F_TMR_CN_PRES3) >> (MXC_F_TMR_CN_PRES3_POS)) << 3)));

temp_time = (uint64_t)ticks * 1000 * (1 << (prescale & 0xF)) / (timerClock / 1000000);
temp_time = (uint64_t)ticks * 1000000 * (1 << (prescale & 0xF)) / (timerClock / 1000);

if (!(temp_time & 0xffffffff00000000)) {
*time = temp_time;
*units = MXC_TMR_UNIT_NANOSEC;
return E_NO_ERROR;
}

temp_time = (uint64_t)ticks * 1000 * (1 << (prescale & 0xF)) / (timerClock / 1000);
temp_time = (uint64_t)ticks * 1000000 * (1 << (prescale & 0xF)) / timerClock;

if (!(temp_time & 0xffffffff00000000)) {
*time = temp_time;
Expand Down

0 comments on commit c8cd2cb

Please sign in to comment.