lpcware

StopWatch_DelayXs doesn't bear in mind timer overrun?

Discussion created by lpcware Employee on Jun 15, 2016
Content originally posted in LPCWare by 1234567890 on Thu Jan 01 04:31:41 MST 2015
Because LPCOpen contains no 'StopWatch' for LPC11xx yet I started to implement it with code from LPC17xx. Just adapting the used timer and so on.

But: StopWatch_DelayXs uses 32 bit unsigned integers.
For convinience let's have a look with 4 bit unsigned integers. The variable 'ticks' to delay has been calculated to uint4_t 0x9.

StopWatch_DelayXs starts with reading the actual timer value as reference. Let's assume a current timer value of startTime = uint4_t 0xF.

In the while-loop the expression 'current timer value - startTime < ticks' is evaluated.
Let's assume  'current timer value' is now uint4_t 0x0.
Then '0x0 - 0xF < 0x9' is evaluated. This should be evaluated to 'FALSE' and the whille loop is terminated much too early.

Did I have too much Champagne last night or is this the case?

Outcomes