Newbie designing a freq counter from scratch - Page 1
Forum section: electronics / projects

author: Praxis
author_rank: Contributor
timestamp: May 01, 2011, 07:51:15 am
content: So, hi. Long-time listener/watcher, first time board-poster here. I'm someone who always was interested in electronics, but only within the last couple of months have I actually started building things and experimenting. I'm one of those geeks who got sucked in by the Arduino explosion. Finally, a cheap, easy-to-program microcontroller with a decent amount of RAM! (The last time I seriously looked at playing with electronics, the BASIC stamp was the only comparable option, and I hated many things about it, including the fact that I'd be using BASIC.)I've decided to try to design a frequency counter/event counter, from scratch, avoiding looking at frequency counter schematics as much as possible. It's my first really complex design, and sort of a test of my ability, in addition to being a very useful piece of test equipment. At this point, I still haven't laid down any circuits.I want it to be able to measure at least 30 MHZ, with an accuracy of within a few PPM. As much as possible, I want to avoid SMD parts. I do plan on sending out to have the PCB made.The input signal will be fed through an input module, which will use comparators to convert the signal to digital logic levels. The module will have settable low and high trigger levels.The pulses will get fed into a 25-bit counter circuit made out of flip-flops. I think I'm going to use CD74HCT4024E chips for the basic building blocks.The outputs from the counter logic will be fed into some transparent latches, and I'd also like to split off each line to a LED binary counter, with each line driving an LED through a FET for blinkenlights bling. Anyone know if driving an LED at 30 MHz is a Bad Idea? For the latches, I think the SN74LVC373AN will work.I'm going to use an AVR chip running Arduino for the brains of the project, mostly because I have a bunch of ATMEGA 328s on-hand, and I know what I'm doing with Arduino. No, I won't be slapping an actual Arduino board in there.It'll do all the math, control the latches, control the display, and any other administrative functions.I know that I'm not going to have enough data lines. I think I'm going to use one or two MCP23016 chips for more IO lines. I2C is easy-mode.The meter will use 7-segment LEDs for its display, driven by the uC. I'm highly tempted to use a bunch of Nixies I have on hand, but that'd double or triple the parts-cost of the project, so, no, I'm not going to do that, no matter how cool it'd look.I could use some help with a few aspects. I'm operating at the edge of my knowledge of electronics, here, so please feel free to yell "OH GOD NO YOU'RE DOING IT WRONG," so long as you tell me why. Suggestions for cheaper or more suited logic would also be helpful, keeping in mind I'd like to stick with 5v logic in DIP packages. I should also note that at the moment the only test gear available to me is a good multimeter and a cruddy little pocket O-Scope. (I'm in the process of searching for a cheap/free analog oscilloscope, but still haven't acquired one yet. Actually, I don't have the multimeter yet, but that should be here in a couple of days. I bit the bullet and bought an Amprobe 37XR-A off ebay when my $10 meter stopped working without applying percussive engineering.)I also need some sort of precision clock source and timer. Ideally, this would output time-between-events on a trigger signal, with timings available of up to one Hz, but something which can output pulses at a user-defined frequency would also be fine. It's got to be precise to within a few ppm. I'm not really even sure what to plug in to get the searches for what I want. But I do want varied and preferably widely adjustable timebases.Also, do you think the circuit as I describe it will throw out an inordinate amount of RF hash when running at high speed, if I take common-sense measures like keeping high-frequency lines as short as possible and using shielded input cables?Anyway, I'd be immensely thankful for any input you folks might want to throw my way, and I look forward to documenting the whole process I'm going through designing and building this thing.

author: vk6zgo
author_rank: Super Contributor
timestamp: May 01, 2011, 08:07:44 am
content: It sounds immensely complex for a frequency counter based around a microcontroller,especially considering the modest performance you are expecting.I'm not a "computer person",but I have seen quite a few projects of similar performance using a PIC with one or twoadditional chips in magazines & on the net.I feel that you are handicapping yourself unduly by following this "re-invent the wheel" approach.VK6ZGO

author: Mechatrommer
author_rank: Super Contributor
timestamp: May 01, 2011, 08:48:31 am
content: your proposal seems logical, including the flip flop, but i dont have experience on that, i believe you made more study on that.i dont think driving 30MHz LED is a bad idea, but for what? all you see is a contionously lit LED during operation.i dont think your tools is a problem, with conditon your o-scope can display 30MHz BW as you've spec'ed.why you need accuracy to some PPM figure? for a frequency counter project? noob here.

author: Zero999
author_rank: Super Contributor
timestamp: May 01, 2011, 10:33:00 am
content: It does seem silly to use all those external ICs when you should be able to do the whole thing with a single microcontroller. All you need is one with a built-in event counter module which is capable of running at 30MHz. External counter ICs are used to divide down a higher frequency to enable the MCU to count it - I remember seeing a MCU based counter which works up to 2GHz with less parts than the project you're proposing.

author: tnt
author_rank: Regular Contributor
timestamp: May 01, 2011, 11:02:20 am
content: For a 1 ppm precision as you said you're gonna need a very precise clock reference.The two "easiest" are :* GPS : A GPS module will provide a 1 PPS (1 pulse per second) output with high precision. But you need a GPS lock where you plan to use the counter* Rubidium reference: It will often output both a 10 MHz signal and a 1 PPS output. You can find those on ebay but they're not that small.To know the frequency, at each 1PPS pulse, you reset a counter, increment it as each event and at the next PPS, you read the counter. Obviously the counter needs to go high enough.To read the counter you can also use shift register that will latch the value and then read it. Something like the 74165.You can then even have the reset of the counter and the latch of the shif tregister tied together at the PPS signal directly.

author: Unknown
author_rank: Unknown
timestamp: May 01, 2011, 11:52:08 am
content: Quote from: tnt on May 01, 2011, 11:02:20 amLong term stability is great, short term stability (which is critical for a counter) depends on the oscillator.Quote from: tnt on May 01, 2011, 11:02:20 amI don't see the need to go crazy on the oscillator, even a TCXO should be able to (just) meet the 1ppm spec, and will be a lot smaller, cheaper, easier and lower power than GPSDO/Rb.

author: scrat
author_rank: Frequent Contributor
timestamp: May 01, 2011, 12:15:39 pm
content: Few things...Why do you need an external timer to generate the "trigger" event (which reasonably will be every second, so the counter value at that time will already be the frequency), while you can generate it precisely into the microcontroller? Worst case you can use an external counter fed by a slow PWM output from the MCU, to enlarge the period.About accuracy...All is based on the reference clock accuracy, and an accurate oscillator is expensive.Then, to have enough resolution, you need two different counting techniques, depending on the frequency: low freq needs counting time between period starting and ending (high freq ref source to be counted), while high freq needs counting number of periods in a fixed time lenght (low freq source to start-stop counting).Quote from: Hero999 on May 01, 2011, 10:33:00 amThat's the most compact (and flexible) solution, IMHO, if the internal peripheral counters count up to 30MHz and there is more than one, to be cascaded (many small MCUs have max 16bit counters).Quote from: tnt on May 01, 2011, 11:02:20 amSince I think you don't need to update the measurement so frequently (you can miss some narrow time windows), you can simply use the counter's enable input to stop and freeze the count at the "triggering" event and read output (e.g. at every second), then read the output, reset the counter and re-enable the counter.

author: Mechatrommer
author_rank: Super Contributor
timestamp: May 01, 2011, 12:18:40 pm
content: Quote from: Hero999 on May 01, 2011, 10:33:00 amthat could be a problem with atMega328 he's proposing.

author: Bored@Work
author_rank: Super Contributor
timestamp: May 01, 2011, 03:50:12 pm
content: .

author: Praxis
author_rank: Contributor
timestamp: May 01, 2011, 06:25:18 pm
content: Quote from: vk6zgo on May 01, 2011, 08:07:44 amYep. I know I could drop a high-speed PIC or something in there but I have zero experience with PICs, and a good chunk of this project is getting to know how to work with things like flip-flops, multiplexed I/O, and such things. I'm pretty confident with the Arduino environment, and don't want to add in the complexity of learning a new processor and environment while also adding on all this other stuff. I'm just starting learning how to deal with raw AVR programming.I also want the ability to take a full 1-Hz sample without adding error due to sampling delays, which is why I'm using a ripple counter with enough stages to not overflow with a full 1-sec sample at 30 MHz. I don't trust my ability to do complex, speed-efficient code on an arduino, or an Arduino's ability to execute it if I did, which is why as much as possible I'm eliminating the uC from anything that requires precision and speed.QuoteOnly if my goal was to create a frequency counter quickly using a microcontroller -- which is, of course, the normal and logical thing to do.

author: Praxis
author_rank: Contributor
timestamp: May 01, 2011, 06:31:38 pm
content: Quote from: Mechatrommer on May 01, 2011, 08:48:31 amWell, I'm not deliberately going to drive it at 30MHz all the time. It's just that with the least significant bit toggling at max speed, with the LEDs coupled directly to the counter outputs, I could drive it up to 30 MHz in practice.QuoteMy O-Scope is a POS, and can't do nearly 30 MHz.I don't really -need- such high accuracy, though it could be useful when I start doing some amateur radio projects. I do want to see how much precision I can manage to work into the thing. To some extent it's a wank, and complication for complication's sake.

author: Praxis
author_rank: Contributor
timestamp: May 01, 2011, 06:36:19 pm
content: Quote from: tnt on May 01, 2011, 11:02:20 amThanks! I'd forgotten about GPS references; I have a spare GPS module kicking around and that might prove useful. However, I don't think I want to use such an expensive part (or a Rubidium source) in this thing. I don't need 1 ppm accuracy, but I want to get as close as I can without being quite that ridiculous.QuoteI was thinking of an arrangement like this, actually, thanks!

author: Praxis
author_rank: Contributor
timestamp: May 01, 2011, 06:41:14 pm
content: Quote from: alm on May 01, 2011, 11:52:08 amThanks for the input. I'd forgotten about TXCOs; I'll go out and do some studying.

author: Zero999
author_rank: Super Contributor
timestamp: May 01, 2011, 07:24:01 pm
content: Why have you made four posts one after another when one would do? It's hard to read and is just annoying, please don't do it again!A Googlesearch finds loads of MCU frequency counter projects.http://www.google.co.uk/search?client=opera&rls=en&q=Microcontroller+frequency+counter.&sourceid=opera&ie=utf-8&oe=utf-8&channel=suggestHere's one which does it using two ICs: a PIC and a quad NAND gate.http://www.guidecircuit.com/Circuit-Microcontroller-Frequency-counter-0-50MHz.htm

author: Praxis
author_rank: Contributor
timestamp: May 02, 2011, 12:41:15 am
content: Quote from: Hero999 on May 01, 2011, 07:24:01 pmIt's the way I roll, baby. Blame it on Usenet.It would have been nice if you'd actually read the posts so that your reply wouldn't have been exactly what I don't want, so I'll give your suggestion the same respect you gave my explanations.

author: Bored@Work
author_rank: Super Contributor
timestamp: May 02, 2011, 05:32:46 am
content: Quote from: Praxis on May 02, 2011, 12:41:15 amYou are an idiot. You selectively thanked the people which pampered you, but ignored the one, like mine, which were clearly not spoon feeding you. So talk about "respect". You'll note I have deleted my answer, because you didn't show any respect and are clearly not worth wasting my time with you. You are not willing to learn, you just want to be spoon feed.

author: Zero999
author_rank: Super Contributor
timestamp: May 02, 2011, 07:55:14 am
content: Yes, I often see trolls like this on forums. You answer their questions but they just tell you to piss off if they don't like the answers.

author: Mechatrommer
author_rank: Super Contributor
timestamp: May 02, 2011, 09:36:05 am
content: not to mentioned "their" wasted time, effort and energy to google it for us. think about thatps: and about multiple posts, i've seen stricter rule on it on another forum, you can get banned by doing that. but not in this forum, but use it wisely. cheers.

author: Zad
author_rank: Super Contributor
timestamp: May 04, 2011, 04:07:17 am
content: Chill guys. The OP replied to several posts in a logical manner. Does it matter that they were posted individually and not edited into one? Forums always tend to get to a certain stage where long-time posters feel they are police, judge and jury. I think we just reached that point.He did right to point out that people were just complaining and not adding anything useful, and so were themselves trolling. Yes, he could have Googled, and probably did, but he was asking our opinion. Instead, all he got in return was a set of self-righteous indignation. As Jeri might put it, p*ssing contests.Anyway, to avoid being 100% troll myself, I am going to say that Farnell / Element 14 sell 1PPM and 0.5PPM TCXOs for £13:32. They also sell divide-by-10 prescaler chips for £6:49.

author: Bored@Work
author_rank: Super Contributor
timestamp: May 04, 2011, 05:50:28 am
content: Quote from: Zad on May 04, 2011, 04:07:17 amHe got useful stuff, he ignored some and argued about some.QuoteUnlikely, he indicates he wants to be spoon-feed. And regarding getting opinions, he was rejecting or ignoring those he didn't like. Why do these people go out in public, ask for opinions and then shit all over themselves, because they can't handle opinions they didn't expect? In the particular case that his design is shit.QuoteWrong. He got useful information. E.g. I provided a complete breakdown of the architecture of a counter, in small building blocks, complete with hints where people typically make mistakes and point to a special feature of AVRs which might be useful. That little prick decided that this was not to his liking. Too much own thinking required, ehh? So he ignored it. This is disrespectful. But he had the guts to talk about "respect". He wants to be treated like a little prince, but treats us like shit. I say good riddance to such people.QuoteYou are just gullible, maybe with a helper complex. There are always some in forums who, instead of doing the right thing, are eager to please.

author: Mechatrommer
author_rank: Super Contributor
timestamp: May 04, 2011, 08:11:50 am
content: Quote from: BoredAtWork on May 04, 2011, 05:50:28 amit could be me.Quote from: BoredAtWork on May 04, 2011, 05:50:28 amwell Bored, why you deleted that usefull info? he neglected it, thats a "good" thing for him already. sure other viewers will learn from your schematic/info later, who choose to accept.

author: scrat
author_rank: Frequent Contributor
timestamp: May 04, 2011, 08:38:32 am
content: I'm surprised of the way this thread has taken...It could also be that he was thinking on some of the replies, and waited to understand/search information on himself before answering.