;
; new count operation
;
NewCount
clrf TMR0 ; clear TMR0 and prescaler |B0
clrf CountL ; clear 24 bit counter var |B0
clrf CountH ; |B0
clrf CountU ; |B0
movlw 200 ; |B0
movwf msctr ; gate timer = 200 msecs |B0
movlw TRISIO ; |B0
movwf FSR ; setup TRISIO indirect access |B0
bsf INDF,2 ; counter "on" (T0CKI = input) |B0
;
; count T0CKI input for precisely 200-msecs (isochronous loop)
;
GateOn
setz ; set Z=1 |B0
btfsc INTCON,T0IF ; tmr0 overflow? no, skip, else |B0
incf CountU,F ; bump CountU (Z=0) |B0
skpz ; tmr0 overflow? no, skip, else |B0
bcf INTCON,T0IF ; clear T0IF interrupt flag |B0
DelayCy(1*msecs-8) ; delay 1 msec minus 8 cycles |B0
decfsz msctr,F ; 200 msecs? yes, skip, else |B0
goto GateOn ; loop again |B0
GateOff
bcf INDF,2 ; counter "off" (T0CKI = output) |B0
btfsc INTCON,T0IF ; tmr0 overflow? no, skip, else |B0
incf CountU,F ; bump CountU |B0
bcf INTCON,T0IF ; clear T0IF interrupt flag |B0
;
; add 8-bit TMR0 and 8-bit prescaler to the 24 bit result
;
movf TMR0,W ; |B0
movwf CountH ; add TMR0 value to result |B0
Flush
bsf STATUS,RP0 ; bank 1 |B1
bcf OPTION_REG,T0SE ; pulse TMR0 edge select bit |B1
bsf OPTION_REG,T0SE ; |B1
bcf STATUS,RP0 ; bank 0 |B0
decf CountL,F ; decrement counter LSB |B0
movf CountH,W ; |B0
xorwf TMR0,W ; prescaler overflow into TMR0? |B0
bz Flush ; no, clock it again |B0
;
; CountU:CountH:CountL = 0..10000000 (frequency/5) result
;
Dear Sir,timing requirements are 30ns high, 30ns low..
What is the period of a 16MHz sine wave?Dear Sir,
can you explain what is the mathematical meaning of above
please advice
There were plenty of PIC based freq meter designs in the "old days" that used the externally clocked TMR1 to read up to 50MHz, even with a 20MHz PIC xtal on old PICs like 16F84.Mark is correct. You should be able to count frequencies up to around 16 MHz using Timer 1 and the code is perhaps a little simpler, but beware of an anomaly with Timer 1 where you miss the very first count when using it in asynchronous counter mode...
Dear AllMicrochip PIC16F87XA Data Sheet (DS39582B), Page 185, parameters 45 and 46.
Can you point me to one of those please Roman? I've seen a lot of examples over the years but I haven't seen a 50 MHz counter that used TMR1 and so I wonder if you may be mistaken?There were plenty of PIC based freq meter designs in the "old days" that used the externally clocked TMR1 to read up to 50MHz, even with a 20MHz PIC xtal on old PICs like 16F84.
Thanks for replyMicrochip PIC16F87XA Data Sheet (DS39582B), Page 185, parameters 45 and 46.
I googled for "50MHz freq meter with PIC 16F84" and there are a few there, like this;Can you point me to one of those please Roman? I've seen a lot of examples over the years but I haven't seen a 50 MHz counter that used TMR1 and so I wonder if you may be mistaken?
Cheerful regards, Mike
If you are stuck with Timer0 then it is back to a limitation of 4MHz if the XTAL is 20MHz.Thanks for reply
Dear sir,
that is related to timer1
so I am still stuck with timer0
as per data sheet in counter mode Q2 to Q4 renaming (TtoH and Tt0L) for the sync purpose . let me know , will it be happens every clock that insert to T0CKI
Please advice
Yes, that's what I was referring to... I had never seen a 50 MHz counter that used TMR1...That uses TMR0 (I said TMR1 sorry!) so that might make a difference?
by Duane Benson
by Duane Benson
by Jake Hertz