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…
DSCN1367
DSCN1372





I’m ecstatic! Finally I built something that worked the first time. Well… on the 3rd attempt! The goal was to develop a minimal-cost, minimal complexity frequency counter suitable for amateur radio. Although I think I can still cut cost by eliminating components and downgrading the microcontroller, I’m happy with my first working prototype.

I haven’t tested it rigorously with anything other than square waves, but I imagine that anything over 1PPV is sufficient (the input is through a bypass capacitor, internally biased right at the trigger threshold). Counting is accomplished by a 74LV8154N (dual 16-bit counter configured as 32-bit) which displays the count as four selectable bytes presented on 8 parallel pins. The heart of the device is an ATMega16 which handles multiplexing of the display and has a continuously-running 16-bit timer which, upon overflowing, triggers a reset of the counter and measurement of the output. Software isn’t perfect (you can see the timing isn’t accurate) but I imagine its inaccuracy can be measured and is a function of frequency such that it can be corrected via software. Here are some photos…IMG_5209IMG_5222IMG_5221

A PCB is DESPERATELY needed. I’ll probably make one soon. Once it’s a PCB, the components are pretty much drop-in and go! No wires! It’ll be a breeze to assemble in 5 minutes. I wonder if it would make a fun kit? It would run on a 9V battery of course, but a calculator-like LCD (rather than LED) display would be ultra-low-current and might make a good counter for field operation (3xAAA batteries would last for months!)

UPDATE: I found out that the ATMega16 donation was from my friend Obulpathi, a fellow Gator Amateur Radio Club member! He also gave me a pair of ATMega32 chips. Thanks Obul!





This is the current state of my receiver. Unlike earlier designs this one uses NO VARIABLE CAPACITORS! This helps because (a) it reduces cost, (b) makes it easier to build for anyone (it’s hard to hunt down identical variable capacitors), and (c) allows it to be totally voltage controlled so microchip or PC control of frequency becomes trivial. Tuning over the entire 40m band is achieved with 3 LEDs reverse biased acting as varactors (wow!). The knobs are potentiometers. The whole circuit runs on 5v.





In the spirit of furthering my knowledge of AC circuity, I’m trying to build a 100% homebrew transceiver. Yeah, QRSS and ultra-weak signal, ultra-narrowband communications is still fun, but it’s not the same thrill as actually engaging in real time communication with somebody! My goal is a transmitter / receiver in a box. The basic features I desire are (1) multiple bands (at least 40m, 30m, 20m), (2) FULL-band coverage, (3) direct conversion receiver, (4) 10W transmitter, (5) digital frequency display, (6) common standard components (nothing mechanical, no air variable capacitors, everything must be easily obtainable on sites like Mouser and DigiKey), (7) SMT capability, (8) inexpensive ($20 is my goal, but that’s a tough goal!). My designs are changing daily, so I’m not going to waste time posting schematics every time I write on this blog, but here are some photos and videos of the product in its current state.

IMG_4994IMG_5013
(I just found that last video – it was one of my favorite songs as a teenager, performed live!)

UPDATE: I got a cool dual 16-bit counter IC made by TI, a SN74LV8154N – very cheap, and can be configured as a 32-bit counter. It seemed like a better option than multiple 8-bit counters, and this chip is about $0.60 so if I can make it work I’ll be happy! I breadboarded it up (see circuit diagram) and it seemed to work. I started wiring it on the perf board, but haven’t written software for it yet…

IMG_5042IMG_5039IMG_5041

UPDATE – I just found this video on youtube I never posted on my blog, so this seems like an appropriate location for it:





Today is a very special day, as it’s the day I first made a contact with a radio transmitter I built completely on my own! The plans were copied from no where (although the concepts were obviously learned elsewhere), so it’s somewhat of a unique design (likely because it’s not very good!). I’ll be the first to admit there is MUCH room for improvement, but my goal was to design and build a multi-band transmitter which would produce RF (not necessarily efficiently) at multiple bands by dropping in crystals of different frequencies.

My first QSO was with Bob, KC8MFF in West Virginia at 5pm today on 7MHz. He heard me calling CQ and replied! He gave me a 559 which made my happy. I was sending about 8 watts at the time into a Mosley Pro 67 Yagi at 180FT and receiving from a 40m dipole at 150FT at the W4DFU Gator Amateur Radio Club station in Gainesville, FL. Although he’s was about 650 miles away, I hope to make a more significant contact as the band opens up later tonight. It’s such an exciting feeling! The aluminum plate gets very hot (even with the fan) and there’s a slight smell of smoke whenever I transmit, but it adds to the fun I guess! Here’s some information about the build, though I’m confident it’s less than optimal.IMG_4946

I’ll preface this by stating that my goal was to produce an experimental platform which I could use to investigate construction techniques of small moderate-power transmitters. This is by no means a finished product! Much work (and some math) must be done to calculate the best number of turns on each coil for each band, including the RF choke on the power (resulting in class C amplifier behavior), the RF transformer, and the inductor/capacitor values of the low pass filter – all of which were determined empirically (watching output on an oscilloscope while adding/removing turns on a toroid). At 10W, it’s not QRP, but it’s easy to tone down to QRP (5W levels). 30m_40m_80m_transmitter_10watt_aj4vd

One of my desires was to create a transmitter which could be built at minimal cost (total value of this is probably about $10). The microcontroller (ATTiny2313) was what I had on hand ($2), the buffer chip acts as a small amplifier ($0.50), and the power amplifiers are IRF510 MOSFETs ($1). The rest of the components are junkbox, and their values aren’t really significant! The power supply is a 19V 3.6A power supply from an old laptop – small, convenient, awesome! Hopefully with some tweaking I’ll have a nice transmitter which I’m proud to share and have replicated…IMG_4928

The overall schematic represents a crystal clocking a microcontroller at the transmit frequency, where the CKOUT fuse has been set, producing 5PPV square waves. These trigger an inverting buffer which (a) amplifies the current of the signal and (b) provides an easy source of inverted signal. The two (inverse) signals then fire a pair of IRF510s in tandem, each acting as a Class C amplifier producing about 60PPV waves (not quite as square-ish). The output is low-pass filtered with a Pi filter (3 pole Chebyschev), then sent to an antenna. Nothing special has been done to match the output to the antenna, so SWR with a 50ohm load is currently a bit high, but I imagine a variable capacitor on the output LPF would give me something to adjust to improve this. I should probably go back to square 1 and re-do the math from start to finish and follow my impedance values more closely.IMG_4939

Future work will be invested into adding an iambic keyer property to the microcontroller, as well as a button to send CQ at various speeds. It may be interesting to clock this from a Si570 digital synthesizer, allowing me to transmit on any frequency and no longer be crystal-bound. Additionally, using the same oscillator source to power a direct conversion receiver would yield obvious benefit, allowing transmit/receive from a home-brew device at minimal cost. Currently, I’m locked into using a commercial rig as a receiver. We’ll see how it goes… IMG_4940

Anyhow, that’s that. I wanted to document this because I know I’ll look back in the future and laugh at how poorly designed this project is. I’m just amazed it works, and for now this represents a gigantic step step in my learning and growth as an engineer. As poorly designed as it may be, it’s something I’m very, very proud of!

Great inspiration has come from Wes Hayward’s Experimental Methods in RF Design text. I’ve been checking it out from the library every few weeks (Interlibrary Loan, from Vanderbilt University to the University of Florida) but I finally got my own copy for Christmas. It’s such a great resource! The IRF510 push-pull idea came from figure 2.101.

PS: The image below is of a MOSFET I exploded in the development process. Too much current… oops!mosfet_die