Hello, I've made a routine to make frequency counting with CCS. Code snipet follow: uns16 interrupt_counter; #INT_TIMER1 void interrupt(void) { interrupt_counter++; } uns16 get_freq(void) { uns8 x; uns8 counter; float total; PIR1.TMR1IF =3D 0; PIE1.TMR1IE =3D 1; INTCON.PEIE =3D 1; INTCON.GIE =3D 1; T1CON.T1CKPS1 =3D 0; T1CON.T1CKPS0 =3D 0; // T1CON.T1OSCEN =3D 1; T1CON.NOT_T1SYNC =3D 1; T1CON.TMR1CS =3D 0; T1CON.TMR1ON =3D 0; interrupt_counter =3D 0; TMR1H =3D 0; TMR1L =3D 0; // Esperando final da onda atual while(!PORTC.B0); while(PORTC.B0); // Contagem do tempo necess=E1rio para fechar 32 ciclos T1CON.TMR1ON =3D 1; while(!PORTC.B0); while(PORTC.B0); for (x=3D0; x < 30; x++) { while(!PORTC.B0); while(PORTC.B0); } while(!PORTC.B0); while(PORTC.B0); T1CON.TMR1ON =3D 0; total =3D ((float)interrupt_counter * 65536) + ((float)TMR1H * 256) + ((float)TMR1L); total /=3D 32; total =3D 2500000 / total; return total; } The idea here is to measure the time it takes to complete 32 cycles, then divide it by 32 to get the period of one wave. Then divide the numbe= r of instructions by second the PIC executes (here 2500000 with a 10MHz clo= ck) to get the frequency. But this method isn't working very reliably. Someone got a better ide= a? Also, I have to implement a timeout on this routine. Best regards, Brusque ----------------------------------- Edson Brusque Research and Development C.I.Tronics Lighting Designers Ltda (47) 323-2685 / (47) 9993-6453 Blumenau - SC - Brazil www.citronics.com.br ----------------------------------- -- http://www.piclist.com hint: To leave the PICList mailto:piclist-unsubscribe-request@mitvma.mit.edu