William At MyBlueRoom
New Member
Assume Timer0 (8bit traditional for frequency counters) is not available is Timer1 16bit fine. I assume it fine.
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Mike said:And if you've been lookin' at the various example frequency counters out there, you might think you need to use a "gate" pin to freeze the counter input but that's not the case. It's easily accomplished simply with the single T0CKI or T1CKI pin.
Hi Nigel,Nigel Goodwin said:Assuming you're referring to the interconnected I/O pins?, it's NOT for gating, it's for manually clocking the pre-scaler so you can read it's value (as it can't be read by the PIC). This allows you to get a 16 bit value from the 8 bit timer!.
;
; the counter input is gated off after 200-msecs, now finalize
; our 32-bit count accumulator
;
; ACCA+0, Most significant byte (TMR0 overflows)
; ACCA+1, Next significant byte (TMR0 overflows)
; ACCA+2, copy of TMR0 register
; ACCA+3, prescaler, Least significant byte
;
movf TMR0,W ; get TMR0 value |B0
movwf ACCA+2 ; |B0
;
; empty the 1:256 prescaler by toggling the TMR0 edge select
; bit and decrementing ACCA+3 (initially 00) until detecting
; the prescaler overflow into TMR0.
;
FLUSH bsf STATUS,RP0 ; select Bank 1 |B1
bcf OPTION_REG,T0SE ; clock on rising edge |B1
bsf OPTION_REG,T0SE ; clock on falling edge |B1
bcf STATUS,RP0 ; select Bank 0 |B0
decf ACCA+3,f ; decrement counter LSB |B0
movf TMR0,W ; compare TMR0 to saved value |B0
xorwf ACCA+2,W ; prescaler overflow? |B0
bz FLUSH ; no, clock it again |B0
;
Mike said:Hi Nigel,
I believe you may be mistaken.
(3) I have seen designs that used another pin in addition to a "gate" pin that was used for clocking the prescaler, but why bother when software can provide the same capability?
What do you suppose most of us newcomers are using Nigel? Is a 16F84 or 16F84A really that 'modern'?Nigel Goodwin said:Perhaps so, on 'modern' PIC's.
I guess I haven't come across the 'original' design, or a design that uses an "interconnected pin" to clock the prescaler. Is it a Microchip Application Note? Anyway, I'd love to study the design and software if you happen to come across it.The original design was based on an old OTP PIC, which presumably didn't have that capability?, most modern conversions just used the old code.
I put those bank reminders into the comment field manually. I suspect it seems silly but it's the method I found that works best for me to help keep track of banking at-a-glance while debugging.eblc1388 said:Hi Mike,
Clever use of the T0SE bit to toggle the prescalar and save one PIC pin.
One OT question: How do the bank "|B0|" comment in your code comes about? Do you manually place them after the comment using a key macro?
Mike said:What do you suppose most of us newcomers are using Nigel? Is a 16F84 or 16F84A really that 'modern'?
I guess I haven't come across the 'original' design, or a design that uses an "interconnected pin" to clock the prescaler. Is it a Microchip Application Note? Anyway, I'd love to study the design and software if you happen to come across it.
Mike said:Nigel,
Thanks for the link. I see how they're using the RA0 pin to clock the T0CKI input to advance the prescaler (the cover page and schematic says RA2 but the code is using RA0).
The RA0 output will easily overpower the signal generator output (through that 470 ohm series resistor) to prevent additional unwanted counts while RA0 pumps the T0CKI input to advance the prescaler.
I wonder if they could have used the 16C54 T0SE bit on this older device the same way we're using it on more recent devices to read the prescaler value?