Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

We talked about this in my microcontrollers class today! Not this exact incident but about the problems associated with using the system clock in a micro for precise timing.

Our micro (Freescale HC9S12) is clocked by a 24 MHz crystal quartz oscillator and if you use the timing module to clock the micro, you cannot get exactly 1ms, 10ms, etc. This makes summing the time over a long period tricky.



What was the solution proposed in your class?

Of the top of my head, I can only think of keeping time values in units of clock-ticks (equivalent to the Linux "jiffy") and only converting to/from milliseconds when turning programmer or user input into internal values.


This. There is almost no reason to put time back into ms when absolute clock ticks will do. Never sum low precision values, etc.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: