Hello, I am working with a friend on a system wich is able to give the datation=20 of an event with a precision of ms. For that we use the PPS (pulse per=20 second) coming from a GPS receiver. we have write a small program to=20 test the timer2 ability to give a 1ms interupt. We know that the precision of the PPS is better than 5=B5s (precision=20 check with the atomic clock of Paris Observatory). So when the PPS come,=20 we write 0 in the register of the timer2 (for information Timer2 has=20 been initialized with a prescaler of 16, a postcaler of 1, and 249 in=20 PR2, wich give us an interupt every 1ms for a quartz of 16 MhZ). Then we=20 wait for the next PPS, when it comes, we write on rs232 the number of=20 1ms interupt and the residual value in Timer2 register. We should get=20 something like 1000 and a very smal value, or 999 and a value near 249.=20 But we get a value of 1000 and 34 for my system, and 1000 plus 42 for my=20 friend. We don't know why! The error for me is about 34*4=3D136=B5s, whic= h=20 is far away of the mean error of a quartz!! My friend has tried with=20 other quartz, and it's strange because the value are allways 1000 plus=20 something quite high. If it was a problem of the quartz, we will have=20 values under and over 16MHz, but we allways have a value over 16MHz!?! I think we make a mistake in the use of the Timer2, but I don't know wher= e. I have also make a test with a prescaler of 1, a postscaler of 16; and I=20 get 1000 plus 34, the same thing than previous test, it's impossible I=20 should have got something like 1000 plus (34*16) modulo 250 because the=20 register of timer2 run 16 times faster! I have also join the small program that my friend has written to perform=20 these tests, it's in C but very simple: /* Test Timer_2 et PPS ------------------- prescaler :16 postscaler =3D 1 PR2 =3D 250 - 1 an interrupt every 1 mSec. */ #include <16F876A.h> #device *=3D16 #use delay(clock=3D16000000) #define CRYSTAL_FREQ 16000000 #fuses HS,NOWDT,PUT,BROWNOUT,NOWRT,NOLVP #use rs232(baud=3D9600,parity=3DN,xmit=3DPIN_C6,rcv=3DPIN_C7,stream=3DPC,= errors) #use fast_io ( A ) #use fast_io ( B ) #use fast_io ( C ) #priority EXT , TIMER2 //TIMER1 static long lmSecCount, lmSecCountOld, Timer2count; static char Pulse, x; /**** Interrupts ******************************************/ #INT_TIMER2 void Timer2Interrupt ( void ) { lmSecCount ++; } #int_ext // PPS sur B0 void intRB0 () { Timer2count =3D get_timer2(); set_timer2(0); lmSecCountOld =3D lmSecCount; lmSecCount=3D0; Pulse ++; } /********* Main *************************************************/ void main ( void ) { /* INITIALIZE */ port_b_pullups(TRUE); setup_adc_ports ( NO_ANALOGS ); set_tris_b(0xff); set_tris_a(0x20); set_tris_c(0b10011010); setup_timer_2(T2_DIV_BY_16,249,1); set_timer2(0); fprintf(PC,"Event "); /* INTERRUPTS */ enable_interrupts ( INT_EXT ); // PPS interrupt enable_interrupts (INT_TIMER2); // enable timer2 interrupts enable_interrupts ( GLOBAL ); // enable all interrupts output_high(PIN_A2); Pulse =3D 0 ; while (Pulse < 3) { } fprintf(PC,"ready : "); Pulse =3D 0 ; output_low(PIN_A2); // a LED is switch on to show that PPS is=20 Ok now /* MAIN LOOP */ while ( TRUE ) { if (Pulse =3D=3D 1) { fprintf(PC,"%04lu %04lu ",lmSecCountOld, Timer2count); Pulse =3D 0; } } } Thank you to have write me, and also for your help if you have an idea. Best Regards Michel Meunier PS: sorry for my bad english!! --=20 http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist