improve timer compare register calculation