Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
11 years, 10 months ago.
Why not use 64bit int type?
Just an question/idea... if this timer was updated (or extended) to use a 64bit integer (eg. int64_t), the timer would overflow every after about 292277 years instead of after 2147.48365 seconds. Would this be a significant performance hit? Is simple arithmetic on the mbed with these large integers types significantly slower?
Question relating to:
1 Answer
11 years, 10 months ago.
The timer uses a hardware timer, which is 32 bits, so you cannot simply make that a 64 bit hardware timer. Of course you could add a 32-bit software timer which provides the 32MSBs, and only has to increment every 2147 seconds, so it wouldnt be too bad a performance hit. It could maybe be noticed at short intervals, since it will need to read 64-bit instead of 32-bit.
In the end you could also make it yourself, but the problem isnt as much that it would give a large performance hit, but more that it isnt required. When would you possible need timer functions that take more than 2100 seconds, arent solved by using the RTC, and aren't trivial to make yourself? (For example by just setting a ticker every 2000 seconds, add a counter to interrupt routine, and you easily can make it call a function every 10000 seconds).
Hey Erik, thanks for the comments. I forgot to mention I was on the mbed LPC11U24, which doesn't have RTC. I like the idea of storing the extra 32MSBs with an intermittent service routing. I guess I'll try that route. For the record I don't actually need 64 bits... but I need to have a good relative accuracy for the duration of the life of the unit. I don't need absolute accuracy, which is why getting an extra RTC peripheral for the LPC11u24 mbed doesn't make sense.
posted by 25 Jan 2013