Author Topic: Newbie designing a freq counter from scratch  (Read 9318 times)

0 Members and 2 Guests are viewing this topic.

Offline PraxisTopic starter

  • Contributor
  • Posts: 22
Newbie designing a freq counter from scratch
« on: May 01, 2011, 07:51:15 am »
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.
 

Offline vk6zgo

  • Super Contributor
  • ***
  • Posts: 7653
  • Country: au
Re: Newbie designing a freq counter from scratch
« Reply #1 on: May 01, 2011, 08:07:44 am »
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 two
additional chips in magazines & on the net.

I feel that you are handicapping yourself unduly by following this "re-invent the wheel" approach.

VK6ZGO
 

Offline Mechatrommer

  • Super Contributor
  • ***
  • Posts: 11700
  • Country: my
  • reassessing directives...
Re: Newbie designing a freq counter from scratch
« Reply #2 on: May 01, 2011, 08:48:31 am »
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.
Nature: Evolution and the Illusion of Randomness (Stephen L. Talbott): Its now indisputable that... organisms “expertise” contextualizes its genome, and its nonsense to say that these powers are under the control of the genome being contextualized - Barbara McClintock
 

Offline Zero999

  • Super Contributor
  • ***
  • Posts: 19672
  • Country: gb
  • 0999
Re: Newbie designing a freq counter from scratch
« Reply #3 on: May 01, 2011, 10:33:00 am »
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.
 

Offline tnt

  • Regular Contributor
  • *
  • Posts: 241
Re: Newbie designing a freq counter from scratch
« Reply #4 on: May 01, 2011, 11:02:20 am »
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.
 

alm

  • Guest
Re: Newbie designing a freq counter from scratch
« Reply #5 on: May 01, 2011, 11:52:08 am »
* 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
Long term stability is great, short term stability (which is critical for a counter) depends on the oscillator.

* 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.

I 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.
 

Offline scrat

  • Frequent Contributor
  • **
  • Posts: 608
  • Country: it
Re: Newbie designing a freq counter from scratch
« Reply #6 on: May 01, 2011, 12:15:39 pm »
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).

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.
That'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).

To read the counter you can also use shift register that will latch the value and then read it. Something like the 74165.
Since 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.
One machine can do the work of fifty ordinary men. No machine can do the work of one extraordinary man. - Elbert Hubbard
 

Offline Mechatrommer

  • Super Contributor
  • ***
  • Posts: 11700
  • Country: my
  • reassessing directives...
Re: Newbie designing a freq counter from scratch
« Reply #7 on: May 01, 2011, 12:18:40 pm »
All you need is one with a built-in event counter module which is capable of running at 30MHz.
that could be a problem with atMega328 he's proposing.
Nature: Evolution and the Illusion of Randomness (Stephen L. Talbott): Its now indisputable that... organisms “expertise” contextualizes its genome, and its nonsense to say that these powers are under the control of the genome being contextualized - Barbara McClintock
 

Offline Bored@Work

  • Super Contributor
  • ***
  • Posts: 3932
  • Country: 00
Re: Newbie designing a freq counter from scratch
« Reply #8 on: May 01, 2011, 03:50:12 pm »
.                                                                      
« Last Edit: May 02, 2011, 05:34:46 am by BoredAtWork »
I delete PMs unread. If you have something to say, say it in public.
For all else: Profile->[Modify Profile]Buddies/Ignore List->Edit Ignore List
 

Offline PraxisTopic starter

  • Contributor
  • Posts: 22
Re: Newbie designing a freq counter from scratch
« Reply #9 on: May 01, 2011, 06:25:18 pm »
It sounds immensely complex for a frequency counter based around a microcontroller,especially considering the modest performance you are expecting.

Yep.  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.

Quote
I feel that you are handicapping yourself unduly by following this "re-invent the wheel" approach.

VK6ZGO

Only if my goal was to create a frequency counter quickly using a microcontroller -- which is, of course, the normal and logical thing to do. ;) 
 

Offline PraxisTopic starter

  • Contributor
  • Posts: 22
Re: Newbie designing a freq counter from scratch
« Reply #10 on: May 01, 2011, 06:31:38 pm »
i dont think driving 30MHz LED is a bad idea, but for what? all you see is a contionously lit LED during operation.

Well, 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.

Quote
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.

My 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.
 

Offline PraxisTopic starter

  • Contributor
  • Posts: 22
Re: Newbie designing a freq counter from scratch
« Reply #11 on: May 01, 2011, 06:36:19 pm »
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.

Thanks!  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. ;)

Quote
You can then even have the reset of the counter and the latch of the shif tregister tied together at the PPS signal directly.

I was thinking of an arrangement like this, actually, thanks!
 

Offline PraxisTopic starter

  • Contributor
  • Posts: 22
Re: Newbie designing a freq counter from scratch
« Reply #12 on: May 01, 2011, 06:41:14 pm »
I 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.

Thanks for the input.  I'd forgotten about TXCOs; I'll go out and do some studying.
 

Offline Zero999

  • Super Contributor
  • ***
  • Posts: 19672
  • Country: gb
  • 0999
Re: Newbie designing a freq counter from scratch
« Reply #13 on: May 01, 2011, 07:24:01 pm »
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=suggest

Here'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


 

Offline PraxisTopic starter

  • Contributor
  • Posts: 22
Re: Newbie designing a freq counter from scratch
« Reply #14 on: May 02, 2011, 12:41:15 am »
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!


It'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.
 

Offline Bored@Work

  • Super Contributor
  • ***
  • Posts: 3932
  • Country: 00
Re: Newbie designing a freq counter from scratch
« Reply #15 on: May 02, 2011, 05:32:46 am »
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!


It'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.

You 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.
« Last Edit: May 02, 2011, 05:37:29 am by BoredAtWork »
I delete PMs unread. If you have something to say, say it in public.
For all else: Profile->[Modify Profile]Buddies/Ignore List->Edit Ignore List
 

Offline Zero999

  • Super Contributor
  • ***
  • Posts: 19672
  • Country: gb
  • 0999
Re: Newbie designing a freq counter from scratch
« Reply #16 on: May 02, 2011, 07:55:14 am »
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.
 

Offline Mechatrommer

  • Super Contributor
  • ***
  • Posts: 11700
  • Country: my
  • reassessing directives...
Re: Newbie designing a freq counter from scratch
« Reply #17 on: May 02, 2011, 09:36:05 am »
not to mentioned "their" wasted time, effort and energy to google it for us. think about that ;)
ps: 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.
Nature: Evolution and the Illusion of Randomness (Stephen L. Talbott): Its now indisputable that... organisms “expertise” contextualizes its genome, and its nonsense to say that these powers are under the control of the genome being contextualized - Barbara McClintock
 

Offline Zad

  • Super Contributor
  • ***
  • Posts: 1013
  • Country: gb
    • Digital Wizardry, Analogue Alchemy, Software Sorcery
Re: Newbie designing a freq counter from scratch
« Reply #18 on: May 04, 2011, 04:07:17 am »
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.

Offline Bored@Work

  • Super Contributor
  • ***
  • Posts: 3932
  • Country: 00
Re: Newbie designing a freq counter from scratch
« Reply #19 on: May 04, 2011, 05:50:28 am »
He did right to point out that people were just complaining and not adding anything useful,

He got useful stuff, he ignored some and argued about some.

Quote
Yes, he could have Googled, and probably did, but he was asking our opinion.

Unlikely, 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.

Quote
Instead, all he got in return was a set of self-righteous indignation.

Wrong. 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.

Quote
Anyway, to avoid being 100% troll myself,

You 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.
I delete PMs unread. If you have something to say, say it in public.
For all else: Profile->[Modify Profile]Buddies/Ignore List->Edit Ignore List
 

Offline Mechatrommer

  • Super Contributor
  • ***
  • Posts: 11700
  • Country: my
  • reassessing directives...
Re: Newbie designing a freq counter from scratch
« Reply #20 on: May 04, 2011, 08:11:50 am »
In the particular case that his design is shit.
:D it could be me.

I provided a complete breakdown of the architecture of a counter
well 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.
Nature: Evolution and the Illusion of Randomness (Stephen L. Talbott): Its now indisputable that... organisms “expertise” contextualizes its genome, and its nonsense to say that these powers are under the control of the genome being contextualized - Barbara McClintock
 

Offline scrat

  • Frequent Contributor
  • **
  • Posts: 608
  • Country: it
Re: Newbie designing a freq counter from scratch
« Reply #21 on: May 04, 2011, 08:38:32 am »
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.
One machine can do the work of fifty ordinary men. No machine can do the work of one extraordinary man. - Elbert Hubbard
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf