> Hello :-) > > I've been reading this list via the archive on www.infosite.com for a few weeks > now. It's been VERY USEFUL ! > > Does anyone have experience of getting wrong values from the lower byte of the > timer 1 counter on a 16F877 ? > > I'm clocking tmr1 at 3.5 - 3.6Mhz (Those with a Ham Radio background will > quickly realise what I'm trying to do!) > The processor clock is 3.2768Mhz and I'm genterating 100 interrupts a second. > > So Timer1 should advance by 350000 to 360000 between each Tmr0 interrupt. > To get around the problems of reading the high and low bytes I used this method > > Step1 Read High byte > Step2 Read Low byte > Step3 Reread High byte > > If the two high bytes are the same then low byte did not overflow while > reading the values. > > If the two high bytes are different then look at the low byte to decide if > the overflow happened between Steps 1 and 2 or Steps 2 and 3. > > If lowbyte > 0x80 then the overflow happened after reading the low byte so > use the second high byte value > > If lowbyte <= 0x80 then the overflow happened before reading the low byte so > use first high byte value > > This seemed to work as expected except once in a while it produced the wrong > result. > > Note I can't afford to do the normal method of rereading the low value again if > the high bytes differ as I'm trying to measure the frequency as accuratly as I > can. Timer 1 is being clocked at about 4 times the instruction rate so going > back to reread the values will introduce an unacceptable error. > > > It seems that sometimes the value read from the timer low byte was wrong! > How did I come to this conclusion ? Well I have a DAC on PORTB and I just > replace my main loop with on the read the low byte and writes it to the DAC. > > I expect to see a nice ramp on the scope increasing by about 4 DAC steps between > each sample. But every so often the value skips by a much larger value (And > yes I had stopped the 100Hz interrups when I tested this). > > In the end I found another way to get an accurate count (*) but this does seem > like a hardware bug to me. > Hi It wasn't clear to me: Are you using timer 1 as an assynchronous counter ???? I have used many times the timer1 module of the F872 and F876 and never saw this (in fact, only synchronous mode !) Fabio Pereira -- http://www.piclist.com hint: PICList Posts must start with ONE topic: [PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads