7:55:24 pm on 5/17/12

Menu
» Home
» About Scott
» VD Labs
» QRSS VD
» Old Stuff
» Archive
» Publications
» Contact

Categories
» C/C++
» Circuitry
» DIY ECG
» General
» high altitude balloon
» Linux
» Microcontrollers
» Molecular Biology
» My Website
» PHP
» Prime Numbers
» Python
» Radio
» UCF Lab
» Everything
» RF Links

Writings
» MD Labels
» Streamrip
» AIM Thoughts
» WindowsXP?
» Partitioning
» CD/DVD Repair
» Monitor Info
» CRT Deflection
» Venomcrack
» Flash Thing
» Heart/Brain
» Diabetes
» Triops
» Biomed

Friends
» Mike
» Fred
» Kyle W
» Nick
» Louis
» Tom
» Kyle H




Archives
» August 2011
» July 2011
» June 2011
» March 2011
» February 2011
» January 2011
» December 2010
» November 2010
» September 2010
» August 2010
» July 2010
» June 2010
» May 2010
» April 2010
» March 2010
» February 2010
» January 2010
» December 2009
» September 2009
» August 2009
» July 2009
» June 2009
» May 2009
» April 2009
» March 2009
» February 2009
» January 2009
» December 2008
» November 2008
» October 2008
» September 2008
» September 2007
» December 2006
» August 2006
» January 2006
» August 2005
» July 2005
» June 2005
» May 2005
» April 2005
» March 2005
» February 2005
» January 2005
» December 2004
» November 2004
» October 2004
» September 2004
» August 2004
» July 2004
» June 2004
» May 2004
» April 2004
» March 2004
» February 2004
» January 2004
» December 2003
» November 2003
» October 2003
» September 2003
» August 2003
» July 2003
» June 2003
» May 2003
» April 2003
» March 2003
» February 2003
» January 2003
» December 2002
» November 2002
» October 2002
» September 2002
» June 2001
« Half-Hearted DIY Logic Analyzer Works, a Little
PC/microcontroller “wireless” data transfer (part 1) »


Frequency Counter Gen2
667 words | Posted on July 24th, 2011
Scott was 25.83 years old when he wrote this!
Filed under: C/C++, Circuitry, General, Microcontrollers, Python, Radio

I’m working to further simplify my frequency counter design. This one is simpler than my previous design both in hardware and software! Here’s a video to demonstrate the device in its current state:

I utilize the ATMega48’s hardware counter which is synchronous with the system clock, so it can only measure frequency less than half of its clock speed. I solve this issue by dividing the input frequency by 8 and clocking the chip at 12mhz. This allows me to measure frequencies up to about 48MHz, but can be easily adapted to measure over 700MHz (really?) by dividing the input by 128. Division occurs by a 74HC590 8-bit counter (not a 74HC595 as I accidentally said in the video, which is actually a common shift register), allowing easy selection of input divided by 1, 2, 4, 8, 16, 32, 64, or 128. The following image shows the o-scope showing the original signal (bottom) and the divided-by-8 result (top)
DSCN1630

The device outputs graphically to a LCD simply enough. That LCD is from eBay and is only $3.88 shipped! I’m considering buying a big box of them and implementing them in many more of my projects. They’re convenient and sure do look nice!
DSCN1634

The signal I test with comes from an oscillator I built several months ago. It’s actually a SA612 style receiver whose oscillator is tapped, amplified, and output through a wire. It’s tunable over almost all of 40m with a varactor diode configuration. It was the start of a transceiver, but I got so much good use out of it as a function generator that I decided to leave it like it is!
DSCN1637

THIS IS HOW THE PROGRAM WORKS: I don’t supply a schematic because it’s simple as could be. Divide the input frequency to something relatively slow, <1MHz at least. Configure the 16-bit counter to accept an external pin as the counter source (not a prescaled clock, as I often use in other applications). Then set the timer value to 0, _delay_ms() a certainly amount of time (1/10th second), and read the counter value. Multiply it by 10 to account for the 1/10th second, then multiply it by 8 to account for the divider, and it’s done! It will update 10 times a second, with a resolution down to 10*8 = 80 Hz. It’s well within the range of amateur radio uses! If you’re considering replicating this, read up on how to use hardware counters with ATMEL AVR microcontrollers. That should be enough to get you started! Here’s the code I used…

For the LCD, this code requires LCD library.

#include <stdlib.h>
#include <avr/io.h>
#include <avr/pgmspace.h>
#include <util/delay.h>
#include "lcd.h"
#include "lcd.c"

int main(void)
{
	TCCR1B=0b00000111; // rising edge trigger
    char buffer[8];
	long toshow=0;
	char mhz=0;
	int khz=0;
	int hz=0;
    lcd_init(LCD_DISP_ON);
	for(;;){
    	lcd_clrscr();

    	lcd_gotoxy(0,0);
		itoa(mhz , buffer, 10);
		lcd_puts(buffer);
		lcd_puts(".");

		if (khz<100){lcd_puts("0");}
		itoa(khz , buffer, 10);
		lcd_puts(buffer);

		itoa(hz/100 , buffer, 10);
		lcd_puts(buffer);

		lcd_puts(" MHz");

		TCNT1=0;
		_delay_ms(99);
		_delay_us(312);
		toshow=TCNT1;
		toshow=(long)toshow*16*10; // tenth second period
		mhz=toshow/1000000;
		toshow=toshow-mhz*1000000;
		khz=toshow/1000;
		toshow=toshow-khz*1000;
		hz=toshow;
	}
}




This entry was posted on Sunday, July 24th, 2011 at 5:07 pmand is filed under C/C++, Circuitry, General, Microcontrollers, Python, Radio. You can follow any responses to this entry through the RSS 2.0 feed. You can skip to the end and leave a response. Pinging is currently not allowed.



6 Responses to “Frequency Counter Gen2”

Anon wrote the following at 08:30:14 PM on July 24th, 2011

In the video you said you used a 74hc595 8 bit counter, I thought that the 74hc595 was a 8 bit shift register, could you explain how that is used as a counter?

Scott wrote the following at 09:38:39 PM on July 24th, 2011

You’re right Anon, I meant to say a 74HC590, an 8-bit binary counter! I use 74hc595s all the time so it must have just slipped out…

Anon wrote the following at 10:03:45 PM on July 26th, 2011

I figured, for a second I was thinking wow, is there some way you can use 74hc595’s as a counter? heh.

Have you considered adding in a AD8307 to measure signal strength as well?

Check out: http://www.webx.dk/oz2cpu/radios/miliwatt.htm

David S wrote the following at 12:19:01 AM on August 3rd, 2011

Scott,great projects, love the idea of simple builds using common parts and substitutions.

Would you please consider releasing the full schematics for Frequency counter 1 and Gen2.

I’m trying to use arduino to determine what frequencies my vhf super-regen is receiving.

You have been blessed with talent and the drive to attempt things not been tried before, keep it up, great job.

Tony wrote the following at 03:36:17 AM on February 27th, 2012

I am trying to build one of these to measure from 10Hz to 30kHz. I have a Atmega168 that I’m using to do other things. It has an LCD connected to it. I am an analog design engineer trying to dabble in digital. The problem I have it that it seems the timer port I need is being used by my LCD. I’m using the LCD and LCD setup that comes with a NerdKit. Are you interested in re-writing your code for me in C+ for my micro for a fee? Please let me know.

Alex wrote the following at 12:50:54 PM on May 17th, 2012

Maybe I’m missing something simple, but the 74HC590 can only count up to 61MHz according to the datasheet. How do you manage to get it up to 700 MHz?

Leave a Reply




copyright © 2006 swharden@gmail.com