Hi Roman, > Peter, I think you may have misunderstood the > system? Why add the extra tick?? The beauty of > the system is that you only need one 24bit number > which is as accurate as timer0 tick. I don't think that I misunderstood the system. I think I improved it. And I don't think that the mistake is there. It could be something else. I am asking because I am looking for new ideas (having run out of my own). I only need a 16 bit counter because the 24 bit value that expresses 1,000,000 ends in 0x40. (1 mil is 0x0F 0x42 0x40). Then we notice that the number of ticks to substract is 512 per interrupt, which is 0x200, or 0x02 0x00 in my notation. The substraction leaves the l.s.byte unchanged all the time, it only needs to be added in when the constant is added at the unedrflow time (every second). So I do not use the last byte, the initial counter is 16 bits and loaded with 0x0F 0x44 (0x44 = 0x40 + 0x200), and I have an auxiliary counter that is loaded with 8 and decrements every interrupt. When it reaches zero I add 0x200 to 0x44 which causes the next 'second' to be 512 T cycles longer, and provides the correction, and is reloaded with 8. The effect is exactly the same as a 24 bit accumulator where the 0x40 LSB would add up to 0x200 after 8 additions. Obviously I compare the accumulator with 0x200 not 0 to detect when the time has come, as you have pioneered. This is not so usefull in assembly where one has direct access to the carry flag, but it is essential in portable ANSI C where one has not (most of the time). My ISR is very short, and sets a flag that is used and cleared by the main code. The main code just spins waitong for the flag and checks some keys. There is no way the ISR could spend 'too much time' and miss an interrupt. The code is in C but I assume the ISR takes less than 50 T cycles all together worst case. I will read the code but I do not think that this is necessary in this case. I could have used a 24 bit accumulator but I did not need it here, the code is simpler like this. If I'd use a crystal with a strange frequency maybe I'd use a proper 24 bit accumulator. There has to be something that oopses me and I can't find it. thanks for the ideas, Peter -- http://www.piclist.com#nomail Going offline? Don't AutoReply us! email listserv@mitvma.mit.edu with SET PICList DIGEST in the body