How to deal with a wrapping counter in embedded C

后端 未结 11 877
时光取名叫无心
时光取名叫无心 2021-02-05 14:23

I need to deal with a counter that gives me ticks for my application. The counter is 32bits so what i need to know is how to deal with it when it wraps. for example:

I h

11条回答
  •  失恋的感觉
    2021-02-05 14:57

    One of the possibilities is to cast both variables to 64-bit long and then do sum. After that compare with maximum 32-bit value to identify if it's wrapped.

提交回复
热议问题