Hi all, I'm requesting some help.=A0 I need to measure a frequency range of apporximately 700hz to 4000hz.=A0 The frequency will be in the form of a squarewave.=A0 It is fed into RC2 (CCP1) on a PIC16F876A connected to a 20Mhz crystal.=A0 I need this to be accurate to 1/25Hz or better.=A0 If possible I prefer to read 512 cycles to keep the aquisition time to a minimum.=A0 I tried to write a routine but=A0the accuracy is not quite there and it doesn't work below about 1200hz.=A0 I am using basic but I wrote a routine in assembly to imbed in the basic program for this.=A0 I have issues in this routine but I have been unable to figure out where.=A0 I have searched for sample routines but haven't been able to find anything quite close to what I'm trying to accomplish or any explanations that I can understand.=A0 I'm using 1:1 on timer1 and capturing every 16th rising edge.=A0 Any help or code is greatly appreciated.=A0 I need to solve this quickly. Thanks, Fran =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D '*** Variables used in math ASM subroutine ******** Dim accu as longint absolute 0x35 'test0,test1,test2 Dim count As Word absolute 0xA4 'count is the same as Dim tmr1tmpl As byte absolute 0xA4 'tmr1tmpl used to store first capture Dim tmr1tmph As byte absolute 0xA5 'tmr1tmph used to store second capture for j=3D1 to 32 ASM BCF STATUS,RP0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0;Bank 0 CLRF T1CON=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0 ;clear t1con MOVLW 0x07=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0 ;w =3D 07h MOVWF CCP1CON=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 ;Enable= ccp1 for 16 rising edges BCF PIR1,2 ;clear flag CCP1 INI: BTFSS PIR1,2 ;testing flag GOTO INI BSF T1CON,0 ;timer 1 enabled BCF PIR1,2 ;clearing flag CCP1 X: BTFSS PIR1,2 ;flag =3D 1? GOTO X BCF T1CON,0 ;turn off timer1 BCF PIR1,2 ;clear flag CCP1 CLRF TMR1L ;clear register TMR1L CLRF TMR1H ;clear register TMR1H END ASM tmr1tmpl=3DCCPR1L ' These 2 lines put the counter value= in tmr1tmph=3DCCPR1H ' the variable count accu=3Daccu+count next j ' here accu variable holds total timer ticks for 512 cycles -- = http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist