Olin Lathrop wrote: >Ake Hedman wrote: > =20 > >>My fosc is 32 MHz. >>By using a 32 bit prescaler i get 1MHz >> =20 >> I meant that the prescaler was set to 32 of course.... >You don't have anywhere near 32 bits of prescaler. > > =20 > >>I let the timer fire an interupt on overflow and reload it with >>0xffff - 0x3E8 >> >>But this give the wrong result. Instead if I change the prescaler to 4 >>the timing is OK. This indicates that I have a 4MHz clock in to the >>timer!? If it was 8MHz I could guess whats up but 4 MHz...? Im lost? >> >>Anyone see *the fault* in my thinking. >> =20 >> > >The descriptions of your prescaler settings are muddled, which probably >indicates the thinking behind them is too. One thing to keep in mind is >that timer 0 increments on the instruction clock, not the oscillator. T= he >instruction clock is Fosc/4, which is 8MHz in your case. > >However, you will have some error creep into your timing due to interrup= t >latency, a few instructions needed after the interrupt to reload timer 0= , >that timer 0 stops incrementing for a few cycles after it's modified, an= d >that the prescaler gets cleared on a write to timer 0. All in all this = is >not a good way to get a 1mS clock. > >An easier and more reliable way is to use one of the timers with built i= n >period registers. That's what they are for. You set it up once then yo= u >automatically get periodic interrupts. > =20 > I can live with the error introduced by this method. That is not *the=20 problem*. What I did not know was that the timer is updated with the=20 instruction clock. Thats good information . So I have 8 MHz into the timer. Set the prescaler to 4 (where I get the=20 correct result) which give me 2 MHz. 1000 countes I would expect half=20 the time of which I measure..... Regards /Ake --=20 --- Ake Hedman (YAP - Yet Another Programmer) eurosource, Brattbergav=E4gen 17, 820 50 LOS, Sweden Phone: (46) 657 413430 Cellular: (46) 73 84 84 102 Company home: http://www.eurosource.se =20 Kryddor/Te/Kaffe: http://www.brattberg.com Personal homepage: http://www.eurosource.se/akhe Automated home: http://www.vscp.org -- http://www.piclist.com hint: The list server can filter out subtopics (like ads or off topics) for you. See http://www.piclist.com/#topics