Frequency counter  - Page 1
Forum section: electronics / projects

author: cleanworkbench
author_rank: Regular Contributor
timestamp: June 08, 2019, 12:28:10 pm
content: Hi there , i,m researching into building a frequency counter for the bench . Been looking at PIC chips ie 16f628 and the 16F886 as the system and displaying onto an LCD. Looking at a pre scaler to go up to 432 or even 1296Mhz. So i have never used or programmed PICs before . I watched the you tube on the pickit 2 vs the pickit3 programmer and might be leaning toward finding a pickit 2 as a tool for this project yet another consideration. Or build a programmer with open source capability ?.Like ive said , never done programming so it could be a work up?I could go and use ICs i think 74 CMOS series , but that could involve quite a lot more work but i dont mind , what i am looking for is a bullet proof design that gives accurate readout .So can anyone chip in , no pun intended, with some comments please

author: Brutte
author_rank: Frequent Contributor
timestamp: June 08, 2019, 12:37:58 pm
content: Noob + 1296Mhz =I do not want to discourage you but you are just too ambitious.Start from something simpler.

author: HB9EVI
author_rank: Frequent Contributor
timestamp: June 08, 2019, 03:50:30 pm
content: A simple gate timed counter isn't a big thing to program, but nevertheless it needs the basic programming skills to do so - to start as a newbie into programming a counter is quite something.handling the 23cm band isn't impossible but has to be seen as a separate task which requires more knowledge about rf-friendly pcb design and smd soldering; with a MB506 as prescaler its no big thing.By saying a 'gate timed counter' isn't a big thing, I don't want so say that this is the type of counter you still want to use these days in your lab; reciprocal counters are a much better target as counter, but requires again different knowledge in mcus hardware and programming it.

author: cleanworkbench
author_rank: Regular Contributor
timestamp: June 08, 2019, 06:00:44 pm
content: Thanks for the replies , just wanted to see opinions , looks like i,m going to have try something simpler then to learn on .

author: MosherIV
author_rank: Super Contributor
timestamp: June 08, 2019, 06:03:45 pm
content: Using the counter/timer of a microcontroller is indeed a simple way to make a freq counter.As hb9evi says, simple time gated counter is not that good or flexible for a freq counter.As Brutte says, trying to count GHz is no easy task. Even the instrument designers have difficulty at that range.Another thing to consider is the stability of the crystal oscillator of the micro itself. It needs to be very very stable. Your standard xtal is not going to cut it!Best is a ovened crystal (ocxo).

author: HB9EVI
author_rank: Frequent Contributor
timestamp: June 08, 2019, 06:58:30 pm
content: with today's readily available TCXOs, at least that should be the choice, but wont be enough for GHz; an external input for e.g. a gps disciplined clock should be state of the art nowadays

author: bd139
author_rank: Super Contributor
timestamp: June 08, 2019, 07:02:40 pm
content: By the time you've paid out for the bits to make one you could have picked up a half decent one on ebay that does what it says on the tin.Some of the older Thurlby, Racal, Marconi and Philips ones turn up regularly in Europe and will count up to that. Grab one and retrofit a cheap Bliley OCXO from Aliexpress and you're done. HP ones turn up as well but they tend to be a lot more expensive. I'm using a Racal 9915 which is good to 520MHz (which is fine for me) with an aftermarket OCXO in it and it cost me total 40GBP including the OCXO! A far more manageable project. Thread here:https://www.eevblog.com/forum/testgear/repairing-off-frequency-racal-9442-ocxo/Incidentally there's a "fit for purpose" counter project here to illustrate what is involved:http://lea.hamradio.si/~s53mv/counter/history.htmlBear in mind a PIC will only count to about 50MHz if you are lucky so you need prescaler, amplifier, buffers, all sorts of crap above about 100MHz or so. It's not worth it as a project IMHO.

author: HB9EVI
author_rank: Frequent Contributor
timestamp: June 08, 2019, 07:37:20 pm
content: there's imo nothing wrong about building your own counter; it's an overseeable project; sure there is more than just programming the mcu, but also building an analog frontend with a high speed comparator is a task you can learn something the same goes for a GHz prescaler. You should just not fall for the conclusion that self made is a way to save $$$if you want to do it properly, it will cost in the end more than a buckpersonally I'm not a big fan of PICs but they have a big pro for a gate timed counter - the asynchronous prescaler for timer0 on the PIC16/PIC18 series what allows a rather high frequency input without the need for external prescalers/dividers.

author: Ian.M
author_rank: Super Contributor
timestamp: June 09, 2019, 01:54:44 am
content: On many PIC18 parts the T0CKI (Timer 0 external clock) input is good for up to 50MHz, given an exact 50% duty cycle squarewave. Add a single fast D type flipflop configured as /2 in front of it, to guarantee that 50% duty cycle, and connect a CCP module output pin to the flipflop /Reset input, to provide the gateing and you've got the makings of a 100MHz frequency counter. If you connect an I/O pin to the flipflop's /Set input, you can pulse the Q output independently of the input signal while /Reset is held low, which allows you to clock through the count stuck in the Timer 0 prescaler at the end of the gate period, effectively increasing the Timer 0 resolution to 24 bits. Given an accurate enough system clock source, (better than +/- 0.05 ppm) that's enough for a 7 digit frequency counter.If you use a 'classic' midrange PIC16, the max T0CKI frequency is generally considerably lower and you only get an 8 bit timer 0. T1CKI has a lower frequency limit than T0CKI, so using timer 1 to get a 16 bit timer isn't a particularly good option (vs using a PIC18), as its prescaler is smaller so you can only get a total of 19 bits + you need it for the CCP module to produce the gate waveform.However as others have mentioned designing an analog front end for it to get reasonable sensitivity, and adding an external prescaler for operation up to even 1 GHz requires considerable RF design experience for a reasonable chance of success.

author: cleanworkbench
author_rank: Regular Contributor
timestamp: June 09, 2019, 10:34:32 am
content: Ok thanks for the replies , looking at buying and constructing as options paths here , i take all you have suggested as good advice, well maybe i,m going to limit my upper freq to say 50 mhz , lower my sights and not be too ambitious !!!.I like the idea of analog construction with 7 segment displays as there is no programming but also like the PIC route as there is possibly less to build but it has a programming learning curve or just buy one second hand and take the risk of it being out of cal.Any other comments please ?.Are there any examples of homebrew on the EEV site for counters, i,d be interested to see .

author: bd139
author_rank: Super Contributor
timestamp: June 09, 2019, 10:40:37 am
content: If you want a relatively simple one I built one of these a few years back because there was nothing on ebay and I had the bits lying around:http://www.hamradio.in/circuits/freq_counter_lcd.phpIt worked but I had to futz with the LCD code as I only had a 2x16 display handy. No prizes for construction here as it was a rush job just to solve a couple of problems on a radio. It has computation ability so you can add/remove IF frequencies with it which was rather neat.Edit: don't use polyester caps on the input like I did. That was a stupid idea... worked up to about 45MHz I think. It got recycled for parts since.7 seg displays are harder to work with IMHO. Best bet is a large character 8x1 LCD module these days with backlight

author: Theboel
author_rank: Frequent Contributor
timestamp: June 09, 2019, 11:01:11 am
content: what about read this thread and made as much as modification You like without to much worry about choose the right hardware.https://www.eevblog.com/forum/projects/ten-dollar-pic-100khz-2-4ghz-frequency-counter/

author: HB9EVI
author_rank: Frequent Contributor
timestamp: June 09, 2019, 11:04:45 am
content: I built longer time ago one based on Atmega328 with a OCXO running @ 20MHz and 74HC variable software presetable divider ratios on the input, but with 8 7seg multiplexed by a MCP23017I used it now for quite a while but I'm actually working on a reciprocal counter based on a STM32F429 running @ 180MHz locked either by a OCXO or GPSDO; no more 7seg but a 3,5" TFT

author: Ian.M
author_rank: Super Contributor
timestamp: June 09, 2019, 11:29:29 am
content: 7 segment displays with up to eight digits are pretty easy to work with if you use aMAX7219LED driver. 8 digit MAX7219 LED display modules are cheap and readily available from many suppliers including EBAY.If you've done any low level programming on 8 bit computers, or for any MCU, and you can program in 'C', then getting into Microchip PICs is pretty easy. I no longer recommend the PICkit 2 - its just too obsolete and limits your choice of chips severely, especially if you stick to the subset that it can both program and debug. A PICkit 3 is a much better choice. The PICkit 4 is still a bit too new and flaky - its more or less where the PICkit 3 was when Dave made his famous bashing video. To get started, all you need is MPLAB + XC8 (both free downloads), a PICkit 3 programmmer (or reputable clone), six short Dupont pin to pin jumper wires to hook up the programmer, a solderless breadboard and a suitable PIC. You'll probably also need an 100nF ceramic cap for decoupling, (2x for 40 pin PICs), a 10K resistor to pullup the PIC's /MCLR (reset) pin, and a LED + a 330R resistor to hang off an I/O pin for your first 'Hello World' LED blinkie test program.If you haven't done *ANY* MCU development before, you may do better to start off with Arduino rather than Microchip PICs. At least you can dip your toes in the water really cheaply and find out if you have any aptitude for 'C' programming. Unfortunately the AVR microcontroller used in entry level Arduinos doesn't support anything near as high an external counter/timer clock frequency as PICs do, and also genuine Arduinos and many clones use a rather inaccurate 16MHz ceramic resonator for the MCU clock so you cant build a very good frequency counter easily with one, but it would do to get you started with a 'proof of concept' project build.If you cant program in 'C', you need to learn!

author: HB9EVI
author_rank: Frequent Contributor
timestamp: June 09, 2019, 12:22:58 pm
content: Sure, today the MAX7219 is readily available - wasn't the case at that time I built that counter...My advise'd be to start AVR on the direct way, without arduino hard/software; especially for a counter fast routines are a must, so all these bitWrite() routines should be avoided; even some inline assembler can be thought about for a counter.

author: Ian.M
author_rank: Super Contributor
timestamp: June 09, 2019, 01:02:00 pm
content: Certainly the Arduino libraries are fairly bloated, and many third party ones are of dubious quality, but there's nothing to stop you using the Arduino hardware and its easy to install GCC toolchain as a dirt cheap and readily available way of getting your toes wet with bare-metal AVR development. You can even mix & match - use Arduino libraries for stuff that's not time critical and hit the bare-metal ATmega registers for the critical stuff, dropping into inline assembler if you really need it. However, if your frequency counter design is fairly sane with hardware gateing, there should be absolutely no need to resort to assembler.The Arduino hardware does have a few design issues - a clone with a real crystal is vastly preferable, and that idiotic Reset via a coupling cap concept requires you to cut a track link if you want to debug with a debugWIRE compatible AVR ISP programmer.When you get to that level, getting a ATmega328P Xplained Mini board from MicrochipDirect (or major distributers) would probably be the cheapest/easiest option. Its Arduino header footprint compatible with the same MCU and an on-board debugger so is an easy path to real AVR development and debugging.

author: Kleinstein
author_rank: Super Contributor
timestamp: June 09, 2019, 01:11:40 pm
content: LED display with multiplexing is a beginner project on it's own, though not that difficult. Ready made LCD modules with 8 or 16 digits are usually a little easier to use.Building a counter with just 74HC... takes quite some effort. So from the HW side the µC is definitely easier.Besides the PIC and AVR one could also consider an ARM based µC - these often don't need an extra programmer. relatively cheap test board can often directly be programmed via USB.

author: HB9EVI
author_rank: Frequent Contributor
timestamp: June 09, 2019, 01:21:13 pm
content: never bothered using that kind of hardware; there was no arduino yet when I started using AVRs, however I like the nucleo boards since it spares you from designing a pcb for every purpose; but they have similar limitations for example with clock sources like arduino boards.for many projects no big thing, but a counter without proper reference clock is quite uselessI wrote some minor fractions of code inline asm, didn't even try if it makes a point compared to plain C; just seemed to be convenient.lcds are indeed easy to set up; personally for a counter a 16x2 seems to me a bit too tinywhen I mentioned 74HC I didn't want to say to build the whole counter from it; just e.g. use some binary counter as a prescaler; the 74HC393 still triggers on 80MHz signals, so I can be quite useful.

author: cleanworkbench
author_rank: Regular Contributor
timestamp: June 09, 2019, 07:55:13 pm
content: Thanks again for the replies , lots of food for thought there , going to look at each suggestion .

author: mino-fm
author_rank: Regular Contributor
timestamp: June 10, 2019, 08:45:51 am
content: I can give you some examples of reciprocal counters but with german description only. They offer full resolution at any input frequency from mHz to MHz.Designed 20 years ago the oldest one used an AT90S2313 up to ATtiny4313 today. Up to 7 digits/s and serial transmission:http://mino-elektronik.de/fmeter/fmeter.htm.There are .hex-files for using 20 MHz crystal or cheap 16,3676 MHz TCXO:http://mino-elektronik.de/download/fmeter20.zipLater on I used ATmega48 and ATmega88/168/328:http://mino-elektronik.de/fmeter/neue_versionen.htm#c2Another solution uses 6 digits of 13 mm 7-segment displays incl. sourcecode and layout:http://mino-elektronik.de/7-Segment-Variationen/LCD.htm#led2Further examples are shown here:http://mino-elektronik.de/fmeter/fm_software.htm.All are based an AVR-controllers. One simple version, one of them uses GPS 1pps signal for high stability, there is code for Arduino Uno R3, code for using BASCOM and so on. Please look and try to understand, why reciprocal counting is the best ;-)If anybody likes to reactivate an older STM32F429-Discovery board, here is an example for a 7 digit counter from 0,05 Hz to 80 MHz:http://mino-elektronik.de/FM_407/fmeter_407.htm#c1Following this link there are further examples for STM32F4xx controllers even using 4,3" displays.

author: HB9EVI
author_rank: Frequent Contributor
timestamp: June 10, 2019, 09:00:35 am
content: Hi MichaelI was kind of hoping you'd write some lines.It was your work presented in a different thread here which made me resuming my works on a reciprocal counter. After almost having completed the work on the code, it's quite evident to me that the STM32F4 series is a suitable alternative to a FPGA. Even the STM32F411 clocked at 100MHz i used for the first breadboard-like tests showed good results.