PIC - timer0 up to 100MHz - Page 1
Forum section: electronics / general

author: 0xFFF0
author_rank: Regular Contributor
timestamp: September 28, 2021, 09:28:33 am
content: Are there modern PICs whose timer0/1/etc. can count up to the range of 100MHz or is this a MCU domain only?

author: iMo
author_rank: Super Contributor
timestamp: September 28, 2021, 09:58:11 am
content: The vintage 16F84A/628 did 50MHz easily (timer0), so chances are the modern one PICs will do the double..

author: Tagli
author_rank: Contributor
timestamp: September 28, 2021, 01:43:43 pm
content: I doubt you can count 50 MHz signals with PIC16F628A which runs at 20 MHz max.Synchronous counters can't count faster than MCU frequency. Timer0 falls into this category.Asynchronous counters can be faster.The values are available on datasheets. This is from PIC16F628A datasheet, where you can see that min period for async input for Timer1 needs to be 60 ns, so it's ~16.66 MHz signal.PIC16F18444, which is suggested by Microchip to replace PIC16F628A, runs at 32 MHz but has similar values.For comparison, a STM32F407 running at 168 MHz can count up to 84 MHz signals, which seems to be fTIMxCLK/ 2.So, finding a MCU that can count signals faster than 100 MHz is probably hard if not impossible.

author: mikeselectricstuff
author_rank: Super Contributor
timestamp: September 28, 2021, 02:06:16 pm
content: Even the PIC32MZ, which has 200MHz CPU clock, shows a 50Mhz limit for async external clock.If you really neeed that speed, an external CPLD is probably the simplest solution

author: ledtester
author_rank: Super Contributor
timestamp: September 28, 2021, 02:33:28 pm
content: The "50 MHz PIC Frequency Counter" originally created by Wolfgang "Wolf" Büscher, DL4YHF:https://www.qsl.net/dl4yhf/freq_counter/freq_counter.htmland available on alix/ebay/bg/etc. uses the 16F628 prescaler which is an asynchronous series of JK flip-flops.In practice it seems you can measure greater than 50 MHz.This video has a good explanation of the prescaler in the 16F628 and its use in the "50 MHz Frequency Counter" design:- PIC Frequency Counter: Fixing the pulse-width problem (and getting beyond 100 MHz) - TheHWCavehttps://youtu.be/HVVcTv75RFsIf you just want to see how greater than 100 Mhz is achieved, skip to timestamp 12:53.Btw - that youtube channel has other nice videos on modifying the frequency counter.

author: iMo
author_rank: Super Contributor
timestamp: September 28, 2021, 02:58:24 pm
content: Yep, I built aprx 5 counters with 16F84A and 628.Timer0 does 50MHz easily. It has got an async prescaler - and you _can_ read out its content as well - that is the trick.. So something like 51.234567MHz on the display with 1 sec gate time (gating in a sw loop)..

author: ledtester
author_rank: Super Contributor
timestamp: September 28, 2021, 03:05:53 pm
content: Quote from: imo on September 28, 2021, 02:58:24 pmHow do you do that? Inquiring minds want to know!(ok - I think I just figured it out, but I'm interested in your answer.)

author: iMo
author_rank: Super Contributor
timestamp: September 28, 2021, 03:11:01 pm
content: That is an old trick since ever (around 2000)..470ohm resistor into the Timer0 (into the78bits 50+ MHz prescaler). The frequency is fed in via that 470ohm (the resistor works as a "tristate buffer").Also an additional pin wired to the Timer0 input (normally input).After the 1sec gate measurement is done you set the pin to output and you clock-in pulses until the prescaler overruns.Now you know the content of the prescaler..Thus counting the instructions in a loop such you get 1sec (or other) gate time, then you read out78 bits off the prescaler (high byte) then Timer0 (mid byte) and afaik you can increment Timer1 when Timer0 overflows (lowest byte)..

author: Zero999
author_rank: Super Contributor
timestamp: September 28, 2021, 03:33:04 pm
content: Is there no room for the 74LVC1G74, which can be configured as a divide by two counter to generate 50MHz, from your 100MHz signal?

author: iMo
author_rank: Super Contributor
timestamp: September 28, 2021, 03:43:40 pm
content: Quote from: imo on September 28, 2021, 03:11:01 pmActually the prescaler is (8bits) the lowest byte, timer0 the mid byte, and timer1 the highest byte.The prescaler counts till 256, you clocked-in say 68 pulses till the prescaler overan (->timer0 increments by 1), therefore the lowest byte is 256-68 (plus minus 1, as usual).Edited the prescaler number of bits.. It is long time ago I messed with it. There is asm for that counter available, google for it..

author: PCB.Wiz
author_rank: Super Contributor
timestamp: September 28, 2021, 09:22:42 pm
content: Quote from: 0xFFF0 on September 28, 2021, 09:28:33 amIt's not a PIC but it is a small flash MCU - I connected a EFM8BB1 to a Si5351A clock generator, and that bench tested fine to the 200Mhz limit on the Si5351A, with a suitable SysCLK prescaler value.Flash limit is 25MHz or 50MHz on SiLabs MCUs so a /8 or more is needed to get to 200MHz.ie the pin and the Logic divider tested ok to 200MHz, which is an indication of the typical 'newish' 8b MCU process.The Config Logic inside many new MCUs can also divider faster than sysclk, I also tested thisEFM8LB1 using Async CLU/16 can Clock right up to 200MHz test limitYou could use any small MCU as a pin-selectable prescaler, with a few lines of code.Other LOGIC family divider choices are parts like 74AHC1G4208 series - specs > 125MHz at 3v3 and > 165MHz at 5vThese are like tiny-package 4060 parts, and include the Unbuffered inverter preamp.Addit: Another 'process indicator' for low cost 8 bit MCUs can be found in the MG82F6D17That specs 144MHz clock ability on the PCA counter, usually generated from a PLL, but the data does not clearly state if the external pin ECI choice, is SysClk sampled, or not.Addit2: This is the 200MHz i2c clock generator used to test the examples above.https://www.adafruit.com/product/2045Web code can run this : Operation range from 10kHz to 225MHz

author: ledtester
author_rank: Super Contributor
timestamp: September 28, 2021, 11:40:58 pm
content: Quote from: ledtester on September 28, 2021, 02:33:28 pmSpotted this in the comments of that video about determining the value of the prescaler counter:Quote

author: iMo
author_rank: Super Contributor
timestamp: September 28, 2021, 11:58:43 pm
content: Setting the timer0 input pin to output and toggling the T0SE may work as the fixed level (set to 0 or 1 before you set the timer0 pin to output) is then xored with T0SE. Nice..PS: I saw in past they toggled it with the internal pullup too..