The personal website of Scott W Harden
June 19th, 2011

Using Timers and Counters to Clock Seconds

My current secret project involves cramming a bunch of features into a single microcontroller. The chip I chose to use is an ATMega48. The ATMega 48 is $1.40 each in small quantities and comes crammed packed with features. The chip will be quite busy performing many functions, but its main loop will be executed at least every 50ms (required for USB, did I mention I'm bit-banging USB?!). I desire to have a bit of RTC (real time clock) functionality in that I need to precisely measure seconds, although I don't need to actually know the time or date. I desire to execute a function once per second, consuming a minimum of resources. The solution was quite simple, but I'm choosing to document it because it's somewhat convoluted in its explanation elsewhere on the net.

In summary, the way I accomplished this is using the built-in 16-bit timer (most AVRs have such a timer, including the ATTiny series). If I'm clocking the microcontroller at a known rate (determined by my selection of crystal, 12 MHz in my case), I can set the chip to continuously increment a register (timer1) and execute a function every time it overflows. Timer1 overflows at 2^16 (65,536). I enabled a prescaler value of 256 so that it takes 256 clock pulses to increment the timer. 12MHz/256 = 46,875 Timer1 increments each second. Since Timer1 overflows at 65,536, if I initiate Timer1 at 18,661 (65,536-46,875), it will take 1 second exactly to overflow. Upon overflowing, I do something (maybe flip a LED on or off), and reset the Timer1 back to its starting value 18,661. Done! Without using an external RTC module or even an external crystal or asynchronous timer, we managed to execute a function every second on the second with minimal overhead, allowing the chip to do everything it wants in the rest of the time!

The following example is a little more specific, executing a function exactly 15 times a second, and executing another function (to flash an LED) exactly every 1 second. It should be self explanatory:

// This function is called every second on the second
volatile int count; // this should be global
ISR(TIMER1_OVF_vect){
    TCNT1=62411;//Initialize our varriable (set for 1/15th second)
    count++; //increment 1/15th second counter
    if(count==15){
        statusTOGGLE(); // do your event (flash a LED in my case)
        count=0;//reset global variable
        }
    }
// This is for ATMega48, consult datasheet for variations for different chips
// place this just inside main(), before your primary loop
TCCR1B|=(1<<CS12);// prescaler 256
TIMSK1|=(1<<TOIE1); //Enable Overflow Interrupt Enable
TCNT1=62411;//Initialize our varriable (set for 1/15th second)
count=0; //Initialize a global variable
sei(); // enable interrupts

I'm having a lot of fun spending time going through the datasheet of this chip. It has a lot of features, and some I didn't really dig deeply into. Without giving away too much of my project, I'll show some photos I'm excited to share. My project interfaces the PC through USB directly attached to 2 pins using no intermediate chips (wow!). The photos demonstrate various steps in the temperature measurement and calibration tests...

Markdown source code last modified on January 18th, 2021
---
title: Using Timers and Counters to Clock Seconds
date: 2011-06-19 23:06:41
tags: circuit, microcontroller, old
---

# Using Timers and Counters to Clock Seconds

__My current secret project involves cramming a bunch of features into a single microcontroller.__ The chip I chose to use is an [ATMega48](http://www.swharden.com/blog/images/atmega48pinout.png). The ATMega 48 is $1.40 each in small quantities and comes crammed packed with features. The chip will be quite busy performing many functions, but its main loop will be executed at least every 50ms (required for USB, did I mention I'm bit-banging USB?!).  I desire to have a bit of RTC (real time clock) functionality in that I need to precisely measure seconds, although I don't need to actually know the time or date. I desire to execute a function once per second, consuming a minimum of resources. The solution was quite simple, but I'm choosing to document it because it's somewhat convoluted in its explanation elsewhere on the net.

__In summary, the way I accomplished this__ is using the built-in 16-bit timer (most AVRs have such a timer, including the ATTiny series). If I'm clocking the microcontroller at a known rate (determined by my selection of crystal, 12 MHz in my case), I can set the chip to continuously increment a register (timer1) and execute a function every time it overflows. Timer1 overflows at 2^16 (65,536).  I enabled a prescaler value of 256 so that it takes 256 clock pulses to increment the timer. 12MHz/256 = 46,875 Timer1 increments each second. Since Timer1 overflows at 65,536, if I initiate Timer1 at 18,661 (65,536-46,875), it will take 1 second exactly to overflow. Upon overflowing, I do something (maybe flip a LED on or off), and reset the Timer1 back to its starting value 18,661. Done! Without using an external RTC module or even an external crystal or asynchronous timer, we managed to execute a function every second on the second with minimal overhead, allowing the chip to do everything it wants in the rest of the time!

__The following example__ is a little more specific, executing a function exactly 15 times a second, and executing another function (to flash an LED) exactly every 1 second. It should be self explanatory:

```c
// This function is called every second on the second
volatile int count; // this should be global
ISR(TIMER1_OVF_vect){
    TCNT1=62411;//Initialize our varriable (set for 1/15th second)
    count++; //increment 1/15th second counter
    if(count==15){
        statusTOGGLE(); // do your event (flash a LED in my case)
        count=0;//reset global variable
        }
    }
```

```c
// This is for ATMega48, consult datasheet for variations for different chips
// place this just inside main(), before your primary loop
TCCR1B|=(1<<CS12);// prescaler 256
TIMSK1|=(1<<TOIE1); //Enable Overflow Interrupt Enable
TCNT1=62411;//Initialize our varriable (set for 1/15th second)
count=0; //Initialize a global variable
sei(); // enable interrupts
```

__I'm having a lot of fun__ spending time going through the datasheet of this chip. It has a lot of features, and some I didn't really dig deeply into. Without giving away too much of my project, I'll show some photos I'm excited to share. My project interfaces the PC through USB directly attached to 2 pins using no intermediate chips (wow!). The photos demonstrate various steps in the temperature measurement and calibration tests...

<div class="text-center img-border">

[![](DSCN1367_thumb.jpg)](DSCN1367.jpg)
[![](DSCN1372_thumb.jpg)](DSCN1372.jpg)

</div>
June 5th, 2011

Permeability Tuned Oscillator (PTO) Working Nicely

My last entry described my accidental discovery of the PTO for QRP purposes. I breadboarded it and was amazed at the results! I went ahead and built this carefully in an enclosure and the output is wonderful. It's strong, it's stable, and it tunes effortlessly over the same range it did before (about 1MHz). The video describes details of the action, and demonstrates the stability of the oscillator by letting you hear it audibly on a nearby receiver.

The fundamental concept and hardware is straightforward. Two nuts are soldered into an Altoids tin providing much-needed grounding for the screw (reduces shift when it's touched). Also the wire soldered over the screw is pinched firmly at the base to apply constant pressure to the screw to make it hard to turn and therefore more stable while turning. The inductor is a bunch of turns (no idea how many, about a meter of magnet wire) around a McDonalds straw.

Alltogether it's a simple colpitts oscillator with a MPF102 JFET at its heart, using a 74hc240 CMOS buffer as an amplifier. There's a voltage regulator in there too.

The result? Pretty darn stable (by CW QSO standards). That's without any regard to thermal isolation or temperature compensation. I'm quite pleased! I look forward to MUCH more experimentation now that I'm starting to feel good about designing and building simple, tunable, stable oscillators. It's always hard to nail all 3 in a single device!

Markdown source code last modified on January 18th, 2021
---
title: Permeability Tuned Oscillator (PTO) Working Nicely
date: 2011-06-05 02:21:40
tags: circuit, amateur radio, old
---

# Permeability Tuned Oscillator (PTO) Working Nicely

__My last entry described my accidental discovery of the PTO__ for QRP purposes. I breadboarded it and was amazed at the results! I went ahead and built this carefully in an enclosure and the output is wonderful. It's strong, it's stable, and it tunes effortlessly over the same range it did before (about 1MHz). The video describes details of the action, and demonstrates the stability of the oscillator by letting you hear it audibly on a nearby receiver.

![](https://www.youtube.com/embed/jm3a1OqNFVI)

__The fundamental concept and hardware is straightforward.__ Two nuts are soldered into an Altoids tin providing much-needed grounding for the screw (reduces shift when it's touched). Also the wire soldered over the screw is pinched firmly at the base to apply constant pressure to the screw to make it hard to turn and therefore more stable while turning. The inductor is a bunch of turns (no idea how many, about a meter of magnet wire) around a McDonalds straw.

<div class="text-center img-border">

[![](DSCN1350_thumb.jpg)](DSCN1350.jpg)

</div>

__Alltogether it's a simple colpitts oscillator__ with a MPF102 JFET at its heart, using a 74hc240 CMOS buffer as an amplifier. There's a voltage regulator in there too.

<div class="text-center img-border">

[![](DSCN1356_thumb.jpg)](DSCN1356.jpg)

</div>

__The result?__ Pretty darn stable (by CW QSO standards).  That's without any regard to thermal isolation or temperature compensation. I'm quite pleased!  I look forward to MUCH more experimentation now that I'm starting to feel good about designing and building simple, tunable, stable oscillators. It's always hard to nail all 3 in a single device!

<div class="text-center img-border">

[![](DSCN1357_thumb.jpg)](DSCN1357.jpg)

</div>
June 2nd, 2011

Screwy Oscillator Idea

Can you believe it's been almost 3 months since my last post? A lot's been going on since then, namely the national board dental exam. I'm happy to report I prepared for it and performed above and beyond my expectations on the exam, and I'm quite satisfied. The last few weeks were quite a strain on my life in my aspects, and during that time I realized that I didn't appreciate the little things (such as free time) that I would have loved to experience instead of studying. I guess it's the feeling you have when you're really sick and think to yourself "remember this moment so that when you're well again, you can appreciate feeling well". Now that it's all behind me, what do I do? I sit at my work station, play some light music, grab an adult beverage, turn on the soldering iron, and make something special.

I'm resuming work on my simple transmitter/receiver projects, but I'm working at the heart of the device and experimenting with oscillator designs. I built various Colpitts, Hartley, Clapp, and other oscillator designs, and I think I landed on a design I'm most comfortable with replicating. I'm actually creating a voltage controlled oscillator (VCO or VFO), with a frequency that can be adjusted by rotating a dial or two. It's always a balance between stability and tunability for me. I don't want to use polyvaricon variable capacitors (expensive!), and LED-based varactor diode configurations only give me a swing of about 20pf. What did I come up with?

I had tremendous success using a variable inductor for coarse tuning! The inductor is nothing more than a screw entering and exiting the center of an air core inductor. I can't claim all the credit, because I got the idea from this photo on one of the coolest websites on the planet, Alan Yates' Lab. It looks like Alan got the idea from this page... This is so useful! Is this common HAM knowledge? Why am I, someone who's been into RF circuitry for a couple of years now, JUST learning about this? I'm documenting it because I haven't seen it out there on the web, and I feel it should be represented more! Here's a video of it in action:

This is the circuit I was using:

This is what it looked like before the glue or screw:

Here's the variable inductor enveloped in hot glue before it cooled and turned white:

At the end of the day, it looks nice!

Band changes can be accomplished by swapping the capacitor between the inductor and ground. It couldn't be any easier! I'll see if I can build this in a more compact manner...

UPDATE (2 days later): Apparently this is called a "Permeability Tuned Oscillator", or PTO. It's an early design for radios (earlier than variable capacitors) and I guess therefore not described often on the internet. Knowing it's official title, searching yielded a few pages describing this action: Dave, G7UVW did some analytical measurements using a mercury core!The Tin Ear uses a PTO as its primary tuning method (also McDonalds straw?) This guy made a PTO out of PVC with a nice screw handle! This PTO kit seems to be used in many projects.The Century 21's VFO is a PTO! I love that rig and had no idea it tuned like that... This guy used a PTO in his MMR-40 radio.

Someone on Hackaday recommended This ARRL Challenge winner with an almost identical design as mine!I guess this bright idea was so bright, it was thought of by many people long ago...

Markdown source code last modified on January 18th, 2021
---
title: Screwy Oscillator Idea
date: 2011-06-02 21:18:47
tags: circuit, amateur radio, old
---

# Screwy Oscillator Idea

__Can you believe it's been almost 3 months since my last post?__ A lot's been going on since then, namely the national board dental exam. I'm happy to report I prepared for it and performed above and beyond my expectations on the exam, and I'm quite satisfied.  The last few weeks were quite a strain on my life in my aspects, and during that time I realized that I didn't appreciate the little things (such as free time) that I would have loved to experience instead of studying. I guess it's the feeling you have when you're really sick and think to yourself "remember this moment so that when you're well again, you can appreciate feeling well". Now that it's all behind me, what do I do?  I sit at my work station, play some [light music](http://www.youtube.com/watch?v=7nmTRZLLO2M), grab an adult beverage, turn on the soldering iron, and make something special.

__I'm resuming work on my simple transmitter/receiver projects,__ but I'm working at the heart of the device and experimenting with oscillator designs. I built various [Colpitts](http://en.wikipedia.org/wiki/Colpitts_oscillator), [Hartley](http://en.wikipedia.org/wiki/Hartley_oscillator), [Clapp](http://en.wikipedia.org/wiki/Clapp_oscillator), and other oscillator designs, and I think I landed on a design I'm most comfortable with replicating. I'm actually creating a voltage controlled oscillator (VCO or VFO), with a frequency that can be adjusted by rotating a dial or two. It's always a balance between stability and tunability for me. I don't want to use polyvaricon variable capacitors (expensive!), and LED-based varactor diode configurations only give me a swing of about 20pf. What did I come up with?

<div class="text-center img-border">

[![](DSCN1335_thumb.jpg)](DSCN1335.jpg)

</div>

__I had tremendous success__ using a variable _inductor_ for coarse tuning! The inductor is nothing more than a screw entering and exiting the center of an air core inductor. I can't claim all the credit, because I got the idea from [this photo](http://www.vk2zay.net/article/45) on one of the coolest websites on the planet, [Alan Yates' Lab](http://www.vk2zay.net). It looks like Alan got the idea from [this](http://www.wa6otp.com/pto.htm) page... This is so useful! Is this common HAM knowledge? Why am I, someone who's been into RF circuitry for a couple of years now, JUST learning about this? I'm documenting it because I haven't seen it out there on the web, and I feel it should be represented more! Here's a video of it in action:

![](https://www.youtube.com/embed/5JjF8-hjL9E)

This is the circuit I was using: 

<div class="text-center img-border">

[![](DSCN1334_thumb.jpg)](DSCN1334.jpg)

</div>

This is what it looked like before the glue or screw: 

<div class="text-center img-border">

[![](DSCN1307_thumb.jpg)](DSCN1307.jpg)

</div>

Here's the variable inductor enveloped in hot glue before it cooled and turned white: 

<div class="text-center img-border">

[![](DSCN1316_thumb.jpg)](DSCN1316.jpg)

</div>

At the end of the day, it looks nice! 


<div class="text-center img-border">

[![](DSCN1339_thumb.jpg)](DSCN1339.jpg)

</div>

__Band changes can be accomplished by__ swapping the capacitor between the inductor and ground. It couldn't be any easier! I'll see if I can build this in a more compact manner...

**UPDATE (2 days later):** Apparently this is called a "Permeability Tuned Oscillator", or PTO. It's an early design for radios (earlier than variable capacitors) and I guess therefore not described often on the internet. Knowing it's official title, searching yielded a few pages describing this action: [Dave, G7UVW](http://webshed.org/wiki/Mercury_PTO) did some analytical measurements using a mercury core!The [Tin Ear](http://www.amqrp.org/kits/tin_ear/index.html) uses a PTO as its primary tuning method (also McDonalds straw?) [This guy](http://www.geocities.ws/k7hkl_arv/PTO_Simplified_Mechanicals.html) made a PTO out of PVC with a nice screw handle! [This PTO](http://www.wa6otp.com/pto.htm) kit seems to be used in many projects.The [Century 21's VFO](http://www.io.com/~n5fc/c21_pto.htm) is a PTO! I love that rig and had no idea it tuned like that... [This guy](http://kd1jv.qrpradio.com/ARRLHBC/ARRL_MMR40.html) used a PTO in his MMR-40 radio.

Someone on Hackaday recommended [This ARRL Challenge winner](http://www.arrl.org/files/file/QST/Homebrew%20Challenge/HBC%201%20Winner-KD1JV.pdf) with an almost identical design as mine!I guess this bright idea was so bright, it was thought of by many people long ago...
March 14th, 2011

$10 Frequency Counter Finished!

Wow, what a cool project start to finish. Simple, cheap, and absolutely useful! ... and not to mention big green numbers which make it look more impressive than it actually is! This is my super-simple frequency counter designed to be used for amateur radio, all for about $10. It was a project I developed over the last few months and documented all along the way. It's finished I guess, so this will probably be the last post about it! Now for some vids and pics:

Sure there's room for improvement,but that's the fun part! This is a solid start and it's cheap as can be. Simply improving software would greatly improve its accuracy. This doesn't use any time-averaging at all! If you had it average 20 readings, it'd probably be much smoother, update every second, and have a higher precision. Also, there's ample room left in the case to build in a transmitter or receiver!

There's the finished project! It looks pretty good, considering it was built mostly out of junk box components, and everything it's made from can be purchased cheaply online. I'm happy with it! I could improve my metal cutting, but that was the first time I ever cut a square window in aluminum so I'm still proud of myself.

As you can see the enclosure is made from sheet metal bent and cut into 2 pieces. The enclosure was from RadioShack, and was $2.99! Yeah it might be cheaper online, but when you add shipping it's pretty convenient to get it locally. My local RadioShack didn't carry these metal ones (they have stupid plastic ones), but I found these in Orlando and after asking the workers I learned that anyone can find any product online (such as the case I used) and request that their local store order them. When they arrive, you can buy them with no extra charge!

Here are some of the internals after being mounted. Heck, these are ALL the internals! You can tell I could have gotten away with a case one third this size if I had one available. Oh well, it's still cool.

There are a few random photos of the build. It's just a microcontroller reading (and resetting) a counter a bunch of times a second and displaying the result on the multiplexed display. That's it! It was a lot of work, but a truly simple concept. The micro-controller is an ATMEL Atmega 16 AVR which is a little costly (around $5) but I had it on hand. I imagine you could accomplish the same thing with a far less intricate microcontroller! I'll bet you could pull it off with an ATTiny2313, especially if you had a LCD display rather than a multiplexed LED like mine. The counter is a 74lv8154 chip, a 32-bit (dual 16-bit) counter IC at a bargain $0.50 - why when I google for home made frequency counters do I not see people using these? They daisy-chain multiple 8-bit counters! What a shortcut I stumbled upon...

Thinking of making your own? Go for it! Here are some of my other posts which describe the development of this thing (including stuff I tried that didn't work). Everything I ordered should be stocked at mouser.com.

I guess that sums it up! What a fun hack. If you have any questions feel free to contact me (link in the menu on the right), and if you make one of these of your own I'd LOVE to see it! I'll even slap a photo of yours on my site to share with everyone. I had fun working on this project. If you're at all into radio, I recommend you try attacking a project like this too! It's more efficient at determining frequency than turning on a commercial radio receiver and spinning the dial until you hear your transmitter ^_^

SUPPLEMENTAL VIDEO

Upon request here's the code! It's nothing special, and certainly not very efficient, but it's quite functional. If you re-create this project, I recommend writing your own code rather than flat copying mine. You'll learn a heck of a lot more... and my code for this is really crap XD

#include <avr/io.h>
#include <avr/delay.h>
#include <avr/interrupt.h>

#define A PC5
#define B PC0
#define C PC6
#define D PC7
#define E PC2
#define F PC4
#define G PC1
#define P PC3

char sendDigit(char row, char num, char dot){
    char val=0;
    if (num==0) {val|=(1<<A)|(1<<B)|(1<<C)|(1<<D)|(1<<E)|(1<<F);}
    if (num==1) {val|=(1<<B)|(1<<C);}
    if (num==2) {val|=(1<<A)|(1<<B)|(1<<D)|(1<<E)|(1<<G);}
    if (num==3) {val|=(1<<A)|(1<<B)|(1<<C)|(1<<D)|(1<<G);}
    if (num==4) {val|=(1<<B)|(1<<C)|(1<<F)|(1<<G);}
    if (num==5) {val|=(1<<A)|(1<<C)|(1<<D)|(1<<F)|(1<<G);}
    if (num==6) {val|=(1<<A)|(1<<C)|(1<<D)|(1<<E)|(1<<F)|(1<<G);}
    if (num==7) {val|=(1<<A)|(1<<B)|(1<<C);}
    if (num==8) {val|=(1<<A)|(1<<B)|(1<<C)|(1<<D)|(1<<E)|(1<<F)|(1<<G);}
    if (num==9) {val|=(1<<A)|(1<<B)|(1<<C)|(1<<F)|(1<<G);}
    if (dot==1) {val|=(1<<P);}
    PORTC=val;
    PORTD=(0b10000000>>row);
    _delay_ms(1);
}

void showNumber(unsigned long val){
    if (val==0) {return;}
    int i;
    int array[6]={10,0,0,0,0,0}; // NUMBER OF DIGITS
    int dly=10;
    i=6-1;
    while (val>0){
      array[i--]=val%10;
      val /= 10;
    }
    sendDigit(1,array[0],0);
    sendDigit(2,array[1],1);
    sendDigit(3,array[2],0);
    sendDigit(4,array[3],0);
    sendDigit(5,array[4],0);
    sendDigit(6,array[5],0);
    sendDigit(0,0,0);
}

#define byte1 PB4
#define byte2 PB3
#define byte3 PB2
#define byte4 PB1

unsigned long val=123456;
void readFreq(){
    unsigned long b4,b3,b2,b1;
    PORTB=255-(1<<byte1);b1=PINA;
    PORTB=255-(1<<byte2);b2=PINA;
    PORTB=255-(1<<byte3);b3=PINA;
    PORTB=255-(1<<byte4);b4=PINA;
    PORTB=0;PORTB=255;//RESET
    val=b1+b2*256+b3*65536+b4*16777216;
    val=val/3355;
}

int cnt=0;
ISR(TIMER1_OVF_vect)
{
   cnt++;
   readFreq();
}

int main(){
    DDRA=0;
    DDRB=255;
    DDRC=255;
    DDRD=255;

    TIMSK|= (1 << TOIE1); // Enable overflow interrupt
    sei(); // Enable global interrupts
       TCCR1B|=(1<<CS11); // Set up timer at Fcpu/8

    while(1){showNumber(val);}
}

... and I know it's unrelated, but:

(I watched this four times - it's so random I love it!)

Update

This project was featured on a couple of my favorite sites, Hack-A-Day and Electronics-Lab!

Markdown source code last modified on January 18th, 2021
---
title: $10 Frequency Counter Finished!
date: 2011-03-14 10:29:21
tags: amateur radio, circuit, microcontroller, old
---

# $10 Frequency Counter Finished!

__Wow, what a cool project start to finish.__ Simple, cheap, and absolutely useful! ... and not to mention big green numbers which make it look more impressive than it actually is! This is my super-simple frequency counter designed to be used for amateur radio, all for about $10.  It was a project I developed over the last few months and documented all along the way. It's finished I guess, so this will probably be the last post about it! Now for some vids and pics:

![](https://www.youtube.com/embed/KduEGjvXaeY)

__Sure there's room for improvement,__but that's the fun part! This is a solid start and it's cheap as can be. Simply improving software would greatly improve its accuracy. This doesn't use any time-averaging at all! If you had it average 20 readings, it'd probably be much smoother, update every second, and have a higher precision. Also, there's ample room left in the case to build in a transmitter or receiver!

<dev class="center border">

[![](IMG_5452_thumb.jpg)](IMG_5452.jpg)

</dev>

__There's the finished project!__ It looks pretty good, considering it was built mostly out of junk box components, and everything it's made from can be purchased cheaply online. I'm happy with it! I could improve my metal cutting, but that was the first time I ever cut a square window in aluminum so I'm still proud of myself.

<dev class="center border">

[![](IMG_5429_thumb.jpg)](IMG_5429.jpg)

</dev>

__As you can see the enclosure is made from sheet metal__ bent and cut into 2 pieces. The enclosure was from RadioShack, and was $2.99! Yeah it might be cheaper online, but when you add shipping it's pretty convenient to get it locally. My local RadioShack didn't carry these metal ones (they have stupid plastic ones), but I found these in Orlando and after asking the workers I learned that anyone can find any product online (such as [the case I used](http://www.radioshack.com/product/index.jsp?productId=2062217)) and request that their local store order them. When they arrive, you can buy them with no extra charge!

<dev class="center border">

[![](IMG_5425_thumb.jpg)](IMG_5425.jpg)

</dev>

__Here are some of the internals after being mounted.__ Heck, these are ALL the internals! You can tell I could have gotten away with a case one third this size if I had one available. Oh well, it's still cool.

<dev class="center border">

[![](IMG_5209_thumb.jpg)](IMG_5209.jpg)
[![](IMG_5222_thumb.jpg)](IMG_5222.jpg)
[![](IMG_5221_thumb.jpg)](IMG_5221.jpg)

</dev>

__There are a few random photos of the build.__ It's just a microcontroller reading (and resetting) a counter a bunch of times a second and displaying the result on the multiplexed display. That's it! It was a lot of work, but a truly simple concept. The micro-controller is an ATMEL Atmega 16 AVR which is a little costly (around $5) but I had it on hand. I imagine you could accomplish the same thing with a far less intricate microcontroller! I'll bet you could pull it off with an ATTiny2313, especially if you had a LCD display rather than a multiplexed LED like mine. The counter is a 74lv8154 chip, a 32-bit (dual 16-bit) counter IC at a bargain $0.50 - why when I google for home made frequency counters do I not see people using these? They daisy-chain multiple 8-bit counters! What a shortcut I stumbled upon...

__Thinking of making your own?__ Go for it! Here are some of my other posts which describe the development of this thing (including stuff I tried that didn't work). Everything I ordered should be stocked at mouser.com.

* [this post demonstrates it in action](http://www.swharden.com/blog/2011-02-12-wideband-receiver-works/)

* [this post shows it being used too](http://www.swharden.com/blog/2011-02-09-minimal-radio-project-continues/)

* [this post shows the first time I really got it working](http://www.swharden.com/blog/2011-02-04-frequency-counter-working/)

* [this post has the SCHEMATIC for the counter!](http://www.swharden.com/blog/2011-01-28-home-brew-transceiver-taking-shape/)

__I guess that sums it up!__ What a fun hack. If you have any questions feel free to contact me (link in the menu on the right), and if you make one of these of your own I'd LOVE to see it! I'll even slap a photo of yours on my site to share with everyone. I had fun working on this project. If you're at all into radio, I recommend you try attacking a project like this too! It's more efficient at determining frequency than turning on a commercial radio receiver and spinning the dial until you hear your transmitter ^_^

## SUPPLEMENTAL VIDEO

![](http://www.youtube.com/embed/B0pj717UJPo)

__Upon request here's the code!__ It's nothing special, and certainly not very efficient, but it's quite functional. If you re-create this project, I recommend writing your own code rather than flat copying mine. You'll learn a heck of a lot more... and my code for this is really crap XD

```c
#include <avr/io.h>
#include <avr/delay.h>
#include <avr/interrupt.h>

#define A PC5
#define B PC0
#define C PC6
#define D PC7
#define E PC2
#define F PC4
#define G PC1
#define P PC3

char sendDigit(char row, char num, char dot){
    char val=0;
    if (num==0) {val|=(1<<A)|(1<<B)|(1<<C)|(1<<D)|(1<<E)|(1<<F);}
    if (num==1) {val|=(1<<B)|(1<<C);}
    if (num==2) {val|=(1<<A)|(1<<B)|(1<<D)|(1<<E)|(1<<G);}
    if (num==3) {val|=(1<<A)|(1<<B)|(1<<C)|(1<<D)|(1<<G);}
    if (num==4) {val|=(1<<B)|(1<<C)|(1<<F)|(1<<G);}
    if (num==5) {val|=(1<<A)|(1<<C)|(1<<D)|(1<<F)|(1<<G);}
    if (num==6) {val|=(1<<A)|(1<<C)|(1<<D)|(1<<E)|(1<<F)|(1<<G);}
    if (num==7) {val|=(1<<A)|(1<<B)|(1<<C);}
    if (num==8) {val|=(1<<A)|(1<<B)|(1<<C)|(1<<D)|(1<<E)|(1<<F)|(1<<G);}
    if (num==9) {val|=(1<<A)|(1<<B)|(1<<C)|(1<<F)|(1<<G);}
    if (dot==1) {val|=(1<<P);}
    PORTC=val;
    PORTD=(0b10000000>>row);
    _delay_ms(1);
}

void showNumber(unsigned long val){
    if (val==0) {return;}
    int i;
    int array[6]={10,0,0,0,0,0}; // NUMBER OF DIGITS
    int dly=10;
    i=6-1;
    while (val>0){
      array[i--]=val%10;
      val /= 10;
    }
    sendDigit(1,array[0],0);
    sendDigit(2,array[1],1);
    sendDigit(3,array[2],0);
    sendDigit(4,array[3],0);
    sendDigit(5,array[4],0);
    sendDigit(6,array[5],0);
    sendDigit(0,0,0);
}

#define byte1 PB4
#define byte2 PB3
#define byte3 PB2
#define byte4 PB1

unsigned long val=123456;
void readFreq(){
    unsigned long b4,b3,b2,b1;
    PORTB=255-(1<<byte1);b1=PINA;
    PORTB=255-(1<<byte2);b2=PINA;
    PORTB=255-(1<<byte3);b3=PINA;
    PORTB=255-(1<<byte4);b4=PINA;
    PORTB=0;PORTB=255;//RESET
    val=b1+b2*256+b3*65536+b4*16777216;
    val=val/3355;
}

int cnt=0;
ISR(TIMER1_OVF_vect)
{
   cnt++;
   readFreq();
}

int main(){
    DDRA=0;
    DDRB=255;
    DDRC=255;
    DDRD=255;

    TIMSK|= (1 << TOIE1); // Enable overflow interrupt
    sei(); // Enable global interrupts
       TCCR1B|=(1<<CS11); // Set up timer at Fcpu/8

    while(1){showNumber(val);}
}
```

__... and I know it's unrelated, but:__

![](https://www.youtube.com/embed/_0NIDVJWo0U)

(I watched this four times - it's so random I love it!)

## Update

This project was featured on a couple of my favorite sites, [Hack-A-Day](http://hackaday.com/2011/03/14/frequency-counter-for-10-worth-of-parts/) and [Electronics-Lab](http://www.electronics-lab.com/blog/?p=10093)!

<dev class="center border">

[![](counter_EL_thumb.jpg)](counter_EL.jpg)
[![](counter_HAD_thumb.jpg)](counter_HAD.jpg)

</dev>
February 20th, 2011

RF Workshop Launched

The Radio Active Workshop kicked off a couple weeks ago in the engineering department of the University of Florida led by yours truly! Jimmy Lin (an aerospace engineering graduate student) set up the group, and together we're trying to provide an open environment for engineering students (or anyone who's interested) to meet, share ideas, and get some practical hands-on experience building stuff. We made gave it a radio theme so it meshes nicely with the Gator Amateur Radio Club. I brought a lot of my equipment from home (components, o-scope, tools, etc) and we all started building right away!

This was the first time many students worked on copper boards, as most of them spend their time working with breadboards and/or computer simulations. For a couple it was the first time picking up a soldering iron (how exciting!). My goal is to start everybody off building the same thing (an ultra-simple multi band radio receiver) with a modular design, then turn everyone loose to modify it to their liking. There are a lot of possibilities, from computer control, micro-controller interaction, frequency measurement, stability testing and compensation, audio processing, and of course making it transmit (which should be trivial!). I'm very excited, but still a bit cautious - I think it's too early to tell whether or not this will be a worthwhile success, or misdirected enthusiasm! I'll give it my all and see where it goes...

One thing that struck me as a challenge is the difference in levels of experience of the group. We have everything from undergraduate freshmen to experienced graduate students all working on the same project. You can imagine how each of us look at the same circuit differently! I hope that some of the more experienced students can help those less experienced (I fit in that group!) gain some knowledge and come up with some ideas to improve the project.

There are many other projects which would be fun to work on! A cheap and simple frequency counter would be a fun project, especially for the micro-controller gurus out there. Then there's the enclosure problem - I hope to get a mechanical engineering student to help me out in that department. It would be nice to have a design for an inexpensive HF receiver that can be produced in a small quantity and made available for check out from school radio clubs to let new hams (or those interested in radio) the ability to listen to HF, learn CW, or decode some digital signals! When I got home my wife and I were talking about it and she gave me a hard time for my devices looking so sloppy, specifically commenting on my soldering. Can you believe it? A nursing student ripping on a dental student's soldering skills -- what a funny life I stumbled into =o) Anyhow, I challenged her to make a circuit (switch-controlled LED with filtering capacitor for smooth fade-off) look pretty, and she did! Although it's not pictured, I got a snapshot of her building it...

Details of the board won't be published quite yet. I wish to improve it and finalize the design. A PCB would be nice, but I'm very very very hesitant to go in that direction. PCBs imply "finished" circuits, and I don't want to give the impression that any circuit I design shouldn't be tinkered with to try to improve it! We'll figure that out as it goes. Here are a couple photos of the modules I'm providing as a starting point for the students to make. So far they've only made the center board, and next week I imagine we'll start on (maybe even complete) the rest...

And of course a video - it's a bit on the long and redundant side, but it clearly demonstrates what we're working on at the workshop. Again, note that this board is purely for educational purposes, and the amount of exposed copper in the critical sections (antenna/oscillator) obviously needs to be minimized in more finalized designs.

Here's my most recent schematic:

WARNING: This schematic has a couple problems. First and foremost, pins 2 and 3 are ACTUALLY pins 1 and 2 (antenna). Pin 3 should be GROUDNED. Also, the series capacitor between the two ICs was replaced by a 22uF capacitor.

Markdown source code last modified on January 18th, 2021
---
title: RF Workshop Launched
date: 2011-02-20 00:13:37
tags: circuit, amateur radio, old
---

# RF Workshop Launched

__The _Radio Active Workshop_ kicked off a couple weeks ago__ in the engineering department of the University of Florida led by yours truly! Jimmy Lin (an aerospace engineering graduate student) set up the group, and together we're trying to provide an open environment for engineering students (or anyone who's interested) to meet, share ideas, and get some practical hands-on experience building stuff. We made gave it a radio theme so it meshes nicely with the [Gator Amateur Radio Club](http://www.GatorRadio.org). I brought a lot of my equipment from home (components, o-scope, tools, etc) and we all started building right away!


<div class="text-center img-border">

[![](rag1_thumb.jpg)](rag1.jpg)

</div>

__This was the first time__ many students worked on copper boards, as most of them spend their time working with breadboards and/or computer simulations. For a couple it was the first time picking up a soldering iron (how exciting!). My goal is to start everybody off building the same thing (an ultra-simple multi band radio receiver) with a modular design, then turn everyone loose to modify it to their liking. There are a lot of possibilities, from computer control, micro-controller interaction, frequency measurement, stability testing and compensation, audio processing, and of course making it transmit (which should be trivial!). I'm very excited, but still a bit cautious - I think it's too early to tell whether or not this will be a worthwhile success, or misdirected enthusiasm! I'll give it my all and see where it goes...

<div class="text-center img-border">

[![](rag2_thumb.jpg)](rag2.jpg)

</div>

__One thing that struck me as a challenge__ is the difference in levels of experience of the group. We have everything from undergraduate freshmen to experienced graduate students all working on the same project. You can imagine how each of us look at the same circuit differently! I hope that some of the more experienced students can help those less experienced (I fit in that group!) gain some knowledge and come up with some ideas to improve the project.

<div class="text-center img-border">

[![](rag3_thumb.jpg)](rag3.jpg)

</div>

__There are many other projects__ which would be fun to work on! A cheap and simple frequency counter would be a fun project, especially for the micro-controller gurus out there. Then there's the enclosure problem - I hope to get a mechanical engineering student to help me out in that department. It would be nice to have a design for an inexpensive HF receiver that can be produced in a small quantity and made available for check out from school radio clubs to let new hams (or those interested in radio) the ability to listen to HF, learn CW, or decode some digital signals!  When I got home my wife and I were talking about it and she gave me a hard time for my devices looking so sloppy, specifically commenting on my soldering. Can you believe it? A nursing student ripping on a dental student's soldering skills -- what a funny life I stumbled into =o)  Anyhow, I challenged her to make a circuit (switch-controlled LED with filtering capacitor for smooth fade-off) look pretty, and she did! Although it's not pictured, I got a snapshot of her building it...


<div class="text-center img-border">

[![](angelina_harden_2_thumb.jpg)](angelina_harden_2.jpg)

</div>

__Details of the board__ won't be published quite yet. I wish to improve it and finalize the design. A PCB would be nice, but I'm very very very hesitant to
go in that direction. PCBs imply "finished" circuits, and I don't want to give the impression that any circuit I design shouldn't be tinkered with to try to improve it! We'll figure that out as it goes. Here are a couple photos of the modules I'm providing as a starting point for the students to make. So far they've only made the center board, and next week I imagine we'll start on (maybe even complete) the rest...


<div class="text-center img-border">

[![](DSCN1256_thumb.jpg)](DSCN1256.jpg)
[![](DSCN1251_thumb.jpg)](DSCN1251.jpg)

</div>

__And of course a video__ - it's a bit on the long and redundant side, but it clearly demonstrates what we're working on at the workshop. Again, note that this board is purely for educational purposes, and the amount of exposed copper in the critical sections (antenna/oscillator) obviously needs to be minimized in more finalized designs.

![](http://www.youtube.com/embed/6rSC0JMR0fs)

__Here's my most recent schematic:__

<div class="text-center img-border">

[![](sa612_rx_thumb.jpg)](sa612_rx.jpg)

</div>

WARNING: This schematic has a couple problems. First and foremost, pins 2 and 3 are *ACTUALLY* pins 1 and 2 (antenna). Pin 3 should be GROUDNED.  Also, the series capacitor between the two ICs was replaced by a 22uF capacitor.
Pages