This page last updated on Thu, 19 Jan 2017 00:45:44 +0000

-----------------------------------------------------------------------------------------------
A FREQUENCY COUNTER PROJECT - Part-2
(from concept to a finished product)
Dieter (Diz) Gentzow -- W8DIZ                                             w8diz@tampabay.rr.com
-----------------------------------------------------------------------------------------------

PREFACE:
In this Article, we will design a Frequency Counter and create a schematic using free tools from 
http://expresspcb.com and http://atmel.com.  We will assume that you are using Linux Mint
for this project but you may also follow the project using Microsoft Windows XT or Vista.
For these series of articles, it is assumed that you have built qrp kits, can solder and have used 
a text editor.  You should also have access to a high speed internet connection because
the size of the PDF document files you need to download are one to two megabytes.  It is the intent
of these series of articles that anyone having the above tools and knowledge should be able to
follow the articles and produce schematics, create a PCB layout and write/copy code and upload the
code to a hardware platform, producing a fully functioning Frequency Counter.  Note that
addendums and/or corrections to this project are available at http://w8diz.com/qq-fc-project/
 
DOWNLOAD TOOLS AND DOCUMENTS:
If you are running Linux, go to http://w8diz.com/qq-fc-project/part-2/ and install WINE first,
followed by EXPRESSPCB.  If you are on a Windows machine, go to
http://expresspcb.com and download and install their free CAD software package. In both cases,
install EXPRESSPCB using all the default settings.
Download Documents to your Desktop.

THE HEART OF THE PROJECT:
The ATmel AVR ATtiny2313-20 is a powerful microcontroller.  One of it's features is the ability
to count external clock pulses at a rate of 45 percent of the internal clock frequency.  If we use
an internal clock frequency of 20.48 MHz, we can count an external clock source up to about 9 MHz.
Officially, ATmel recommends 40 percent of the internal clock frequency, or about 8 MHz.
Since we want to be able to count up to at least 30 MHz, we need to add a prescaler.
The 74HC4040 chip has selectable prescale outputs and a maximum guaranteed operating frequency of
30 MHz.  We will use the divide by 4 output (Q2) on PIN-7 of the chip.  A 30 MHz external clock
is divided by 4 for a maximum frequency input of 7.5 MHz to the AVR chip.
See http://w8diz.com/qq-fc-project/MM74HC4040.pdf for more detail.  The input of the 4040 chip
requires a 5 volt peak-peak signal level.  To achieve this level, we need to amplify the input
signal.  A simple way to accomplish the amplification is to use the input amplifier from a
74HC4046 phase lock loop chip.  PIN-14 (Signal In) on the 74HC4046 chip has a special DC bias
network that enables AC coupling of input signals.  Input sensitivity is better (lower) than
100 mVolts P-P RF.  See http://w8diz.com/qq-fc-project/MM74HC4046.pdf

LEARNING TO USE EXPRESSPCB SCHEMATIC CAPTURE PROGRAM:
Double-click the ExpressSCH.desktop icon on your desktop. Ref http://w8diz.com/qq-fc-project/expressSCH.gif

Click on Help in the Menu Bar and review the User Manual and the Quick Start guide.
Play with all the buttons and try the examples and suggestions in the guides.  When you think
you can move around the schamtic program, close the program and restart it. We will now create
an IC component, the ATtiny2313.  Ref http://w8diz.com/qq-fc-project/ATtiny2313.gif

Start by maximizing you expressSCH window on you Desktop.  Zoom-In by clicking the PLUS-SIGN
magnifier button in the menu bar twice.  Left click on the ADD RECTANGLE button on the left button bar.
Place the CROSS CURSOR over one of the DOTS in the upper part of the window and press the LEFT mouse
button while draging the mouse lower and to the right to form a rectangle on the screen and then
release the mouse button.  Now lets resize the rectangle by left clicking on the ARROW button on the left
menu bar.  Place your ARROW CURSOR tip anywhere on the rectangle line (perimeter) and left-click it.
The rectangle should now be colored BLUE and display 4 resizing points.  Left-click on the points and drag
your mouse at the same to resize the rectangler to 3 DOTS wide and 10 DOTS high.  Note that the DOTS
aka GRID is configured by clicking on View and then Options in the menu bar.
Ref http://w8diz.com/qq-fc-project/options.gif

Left-click themouse pointer on EXACTLY the upper-left corner of the rectangle and drag the rectangle to
co-ordinates X: 4.700 and Y: 1.800 and then center the rectangle on the screen using the scroll bars.
We will now add 20 PIN connections.  Left-click the PLACE PIN button on the left tool bar and place a pin
at co-ordinates X: 4.600 and Y: 1.900 and then left click on the ARROW button on the left menu bar.
Now double click the PIN dot to set it's properties.  Ref http://w8diz.com/qq-fc-project/setpin.gif

Change the PIN Number to 1, the PIN name to Reset and both Text Heights to 0.050 inches. Click OK.
CLick on the ADD LINE button on the left tool bar.  Place your CURSOR ARROW TIP on the PIN dot,
click the left mouse button and move the mouse to the right, up to the body of the rectangle and then
click the left mouse button again and then finally click the right mouse button to disable the LINE.
Click the ARROW button on the left menu bar and then click on the Reset tag name, keeping the mouse
button down and drag the Reset tag word to match the picture below. Do the same with the pin number 1.
Ref http://w8diz.com/qq-fc-project/pin1.gif

Now we will replicate (copy) PIN-1 to pins 2 thru 10.  Left-click on PIN-1 once to turn it BLUE.
Type CONTROL-C on your keyboard.  The type CONTROL-V on the keyboard.  A copy of PIN-1 will display
in the center of your window.  Drag the PIN to the PIN-2 position.  Repeat this step 8 more times
to create all 10 PIN positions for the IC on the left side.  The component should look like this:
Ref http://w8diz.com/qq-fc-project/copypins.gif

Also copy the LINE form PIN-1 to the other PINS,  Select (click on) the line at PIN-1.
Type CONTROL-C on your keyboard.  The type CONTROL-V on the keyboard.  A copy of the line will display
in the center of your window.  Drag the LINE to connect PIN-2 to the body of the component.
Repeat for the remaining 8 pins.
Now click on each PIN and renumber and rename then per http://w8diz.com/qq-fc-project/ATtiny2313.gif
Note that some of the PINS of my component have 2 names. You can add additional text at any time by
clicking on the PLACE TEXT button on the left tool bar, entering your text in the input field at the
top of the window and setting the text height to 0.050 inches and then placing the text by moving
the mouse to the desired text position and left clicking the mouse.  Once all the text has been
added to the part/component, you may need to reposition/align the text on the component part.
Repeat the above for PINS 11 thru 20 until your part looks like this:
Ref http://w8diz.com/qq-fc-project/2313.gif

We are now ready to SAVE the component and assign it a real name.  click on the ARROW button on the
left menu bar.  Place the mouse cursor to the left and top of PIN-1, click the left mouse button
and then drag the mouse to the lower right of the component beyond PIN-11 to create a rectangle
that encompases the entire component and then release the mouse button. The component should now be BLUE.
In the MENU bar, click on COMPONENT and then click on GROUP TO MAKE COMPONENT.  Set the properties
of the new component and click OK.  Ref http://w8diz.com/qq-fc-project/new2313.gif

You have now created your first component for the QQ Freq Counter Project.  Save your schematic by
clicking on FILE, then SAVE AS and then select the ExpressPCB directory, then name your file "learning".
TIME TO DRAW THE SCHEMATIC:
Ref http://w8diz.com/qq-fc-project/QQ_FC_sch.gif

You now have the option of downloading the schematic that I created or create your own.  May I suggest
that you download my schematic from http://w8diz.com/qq-fc-project/QQ.sch and try and re-create it using 
your new skills. Place the file QQ.sch into your ExpressPCB directory.

CIRCUIT DESCRIPTION:
The LCD is 16 character by 2 line with LED backlight made by Hantronix and sold by Mouser.
A PDF document for the LCD is available at http://w8diz.com/qq-fc-project/hantronix.pdf
The LCDs backlight draws about 75 mA while the rest of the circuit draws about 10 mA.
The backlight current is controlled by R7. To reduce current and brightness, change to 18 or 22 ohms.
I use a 78L05 5 volt 100 mA voltage regulator and feed the regulator from a 9 volt source.
If you wish to run the FC project from a 12 volt source, you must use a full size voltage
regulator like the 7805, which can handle at least 1 amp and can dissipate more heat.
The purpose of R1 in the power circuit is to drop 1 volt and limit the heat dissipated by the 78L05 regulator.
Using a 20.48 MHz crystal, we can directly measure (count) up to about 9 MHz without using a prescaler.
I use a 74HC4040 binary counter to prescale by 4 and allow measurement up to about 36 MHz.
The prescaler selection is 1,2 or 4, jumper selectable.
A PDF document for the HC4040 is available at http://w8diz.com/qq-fc-project/MM74HC4040.pdf
The input to the prescaler is 5 Volts P-P, so we need a preamp.  I use a 74HC4046, which will amplify
less than 100 mVolts P-P to the required 5 Volt level.
A PDF document for the HC4040 is available at http://w8diz.com/qq-fc-project/MM74HC4046.pdf
Overvoltage protection is provided by 1N4148 back-to-back diodes on the input.
The R2/C4 network is a noise suppressor.
I have included D3 on pin-8 of the CPU, an LED that we will use to test the operation of the CPU.
J3 is the header connection that connects to the AVRISP programmer.

BUILDING THE PROTOTYPE:
We are now ready to build a prototype Frequency Counter and here you have four or more options:
1. Order a PCB from http://kitsandparts.com
2. Order a complete kit from http://kitsandparts.com
3. Design and order your own PCBs from your favorite PCB house.
4. Create an ugly construction project using vector board or other techniques.
This project started out at my QTH using option 4.  Pictures of the proto construction are available
at http://w8diz.com/qq-fc-project/proto1.jpg and http://w8diz.com/qq-fc-project/proto2.jpg
I use wire-wrap-wire (available from Radio Shack in multiple colors) to interconnect all the components on the prototype.
If you strip off about 3/16 inch of insulation from the wire, you can wrap it around an IC socket pin
using a jewelers screwdriver to push/wrap the wire around the pins.
A complete kit of parts, including 2 CPUs, PCB and a backlit LCD is available for $28 from http://kitsandparts.com
A picture of the PCB can be seen at http://w8diz.com/qq-fc-project/QQ_FC_pcb.gif
Let's build the prototype in two phases; the first is to complete the prototype with all components to control the LED, D3.
Build the prototype using all the parts shown in the schematic except all the components that connect up to pin-9 of the CPU.
After phase one is built, with the CPU and the LCD both NOT installed, 
apply 9 volts to the power connection and verify that you have 5 volts +/- 0.1V
available at pin-2 of the programming header, J3. Once the 5 volts is verified, 
we can connect the LCD to the PCB and insert the CPU.
Again, DO NOT use a 12 volt power source UNLESS you are using a 7805 regulator.
Power up the FC and adjust R6, the blue pot so that you can see the character display.
This will most likely be black squares for each character position.
Now install all remaining parts per the schematic.
Install the LED so that the body of the LED matches the patern on the PCB.

At this point, we will review the QQ-FC project environment and requirements.
Ref http://w8diz.com/qq-fc-project/block-diagram.gif

The LED source code is available at http://w8diz.com/qq-fc-project/led-code/led.asm
The FC source code is available at http://w8diz.com/qq-fc-project/fc-code/fc.asm
You will also need http://w8diz.com/qq-fc-project/fc-code/tn2313def.inc used by both asm files
Make sure that you have the AVRISP available for the next article.

NEXT ARTICLE:  Making it all work together

ABOUT THE AUTHOR:
Dieter (Diz) Gentzow, W8DIZ, aka WB8QYY before April 2000, has been a licensed ham since 1973.  
Past employment include Honeywell as an Industrial Sales & Systems Engineer,
AC Nielson, Electrical Engineer designing black boxes that monitor TV viewing habits and 
a handful of other hardware and/or software jobs.  
Currently semi-retired, living in sunny Palm Harbor, Florida.  
You can contact Diz, W8DIZ via eMail at w8diz@tampabay.rr.com

NOTES:
Addendums and/or corrections to this project are available at http://w8diz.com/qq-fc-project/