StopWatch_DelayXs doesn't bear in mind timer overrun?

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

StopWatch_DelayXs doesn't bear in mind timer overrun?

647件の閲覧回数
lpcware
NXP Employee
NXP Employee
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?

ラベル(1)
0 件の賞賛
返信
0 返答(返信)