Category Archives: Uncategorized

DG5 mounted and ready to go!

I ordered up a 2″x4″x 5″ extruded aluminum chassis off of eBay, and mounted the DG5 and the LCD display.



It’s looks good, and the metal shielding eliminated some slight RFI from the board.  There are multiple, HF signals on the board being amplified and switched – a metal chassis is recommended!


Looks good on top of the TS-520S!

Strange dreams about VFO drift.

I have strange dreams.  I often awake with new ideas on something that I am working on, which really isn’t all that strange, but when I try to explain my dreams to my wife, well…. they’re strange.

Yesterday morning I woke up thinking about other things I could do with the DG5 shield, and one of the things I dreamed about was making VFO drift measurements.  Using the DG5 emulator and the USB communications with the computer, I could log the calculated VFO frequency over time, and see how my VFO drifted during warmup.  This was pretty straight forward, instead of scanning thru three frequencies to measure, I just locked the board to the VFO and increased the gate time to 1 second, and took a measurement every 6 seconds.  I printed these results to the serial port and captured them with my computer.

Now, there’s another source of drift in this setup, and that’s the crystal oscillator on the Arduino itself.  The crystal’s I have used for other ATMega328 based project boards are rated at 20ppm at 16Mhz – the clock frequency the Arduino uses. 20ppm works out to be +/- 320 Hz = quite a bit of potential measurement error!  But crystals don’t usually drift all over the place in short periods of time, with relativity stable temperatures.  I had the Arduino and the shield powered up overnight with the TS-520S off, so I figured it would be pretty stable for a measurement of the TS-520S VFO drift during warm-up.


Here’s the drift plot over about 3 hours of warmup.  I suspect most of the calculated drift is the TS-520S VFO, and not the Arduino. But we can actually eliminate the Arduino’s error using one of the DG5’s other inputs.

By using an external frequency reference, we can eliminate the Arduino as a source of the error.  The DG5 emulater can select from 3 inputs for measuring (2 direct, 1 prescaled by a divide by 8 counter), so I used my HP 8924C as an external frequency reference. It uses an OCXO (Oven Controlled Crystal Oscillator) for it’s frequency source, which is much better than the $0.39 Arduino crystal. I don’t have the spec’s in front of me, but if I remember correctly, it’s something like 0.05 ppm or better.  I have used it to obtain sub 1 Hz measurements in the ARRL Frequency Measurement Test (, so it’s pretty good at these frequencies.

This time I had the program select the VFO input, make a measurement, then select the external frequency reference (which was set to 5.000000 Mhz) , and make another measurement, Since we know the input frequency is 5.000000 Mhz we can calculate the error, then apply that error to the measured VFO frequency.  The data of the Arduino looks like this:


That’s the fist minute or so of data out of the Arduino.  The columns are VFO (the raw measured frequency), the Ref (the 5 Mhz reference frequency as measured by the Arduino), The calculated error (REF – 5,000,000), the corrected VFO frequency (Measured VFO + ERROR), and lastly the millis() function out of the Arduino which gives us the Millis counter value – how many milliseconds we’ve been running.

Put this in to Excel, and we get this:


Here’s the calculated error in Hz over about 7 1/2 hours (I left it running overnight).  Looks like the Arduino is -59.512 Hz low on average, but drifted only about 5Hz during the test.  Not bad, and perhaps I should add a frequency error compensation factor in the DG5 code.

Here’s the corrected VFO drift over 7 1/2 hours:



Even after running all day, the TS-520S’s VFO continues to drift appreciably – about 40Hz over this time frame.  No big deal – it’s amazingly stable for the technology – but it’s sure nice to be able to characterize it!

Points learned:

  • It looks like the Arduino frequency stability is about 10x better than the TS-520’s VFO in this setup, which is good since we’re looking to the Arduino to measure the VFO.
  • I have only measured the VFO so far, I’ll probably do a similar exercise with the BFO (which mixes with the VFO to obtain the IF frequency) and the Hetrodyne oscillator (HET) to see how stable they are.

The DG5 shield can be a useful tool as well as a frequency display!


DG5 Emulator Version 1.5 PCB’s have arrived!

Got the boards in yesterday, was feeling pretty confident about the design, so I ordered 20 this time.  Lucky, the boards look good, and the first one I built fired up right away – whew!


Here it’s fully populated and mounted on an Arduino Duemilanove.



The new boards are a bit more packed than version 1 as they have a few more features.  There’s a 5V 7805 regulator option, 2, 6-pin headers for an external LCD (with a contrast pot), and 4 mounting holes that match up to the Arduino boards.  Quality looks good, these are from Accutrace here in the US – see for info.  Only 2 weeks as opposed to 4 or so from China.





With the boards packed, the clearances between the Arduino and the DG5 shield are tight – too tight in areas as is a usual issue with shields.  I put a piece of electrical tape over the top of the USB connector, and trimmed the mounting tabs for the RCA connectors that protruded thru a little too far.  I also covered the ICSP connector to keep it from touching.


Here’s the layout.



The 6 pin jumper cables I had are a little long, 12″ I think.  I’ll be ordering up some 4″ jumpers that will make it easy to mount in a case.

If you’re interested in a board, leave me a note here and I’ll get in touch with you!  I am working on the Bill of Materials for the complete kit – I had a lot of parts in my parts bin so I haven’t sourced everything, but most parts are available from Mouser, and a couple are from SparkFun (RCA connectors, LCD Jumpers, shield headers).

A DDS VFO for the TS-520S

While I am waiting for the new DG5 boards to arrive (they shipped yesterday – yay!), I decided to see if I could get the AD9850 DDS module I got on eBay to work as an external VFO.  If you search “DDS AD9850” on eBay you should find lots.

This is mine.


The module is being controlled with an Arduino UNO – it sends the desired frequency serially to the DDS chip.  The Arduino is also attached to a rotary encoder for frequency input, as well as an LCD display.  In this prototype, the LCD display is showing the DDS frequency, not the VFO frequency.  I don’t really need a display on the VFO since the DG5 emulator already displays the dial frequency.  An additional advantage to this is I don’t have to worry about the radio Carrier/BFO and Heterodyne oscillators warm-up drift as the dial frequency is being calculated using these actual frequencies by the DG5 emulator.

I put a 0.01uF cap between the output of the DDS and the VFO signal input on the TS-520 to block any DC component present on the output from the module.   The stock output was a little low, but worked – signals were a bit low- 3-4 S units as compared to my K3.  Looking at the datasheet for the DDS module, there is a 3.9k ohm resistor called “Rset”, which sets the DAC’s full scale output current.  I put a 2.2k resistor in parallel with it (just soldered it on top of the existing 3.9k SMD part, you can see it in the pic above) to lower the Rset value and increase the DAC output – bingo!  Signals are on par with the K3, and signal reports are good.  I’ll need to make sure I am not saturating the output or causing any distortion – I might need a buffer amplifier if there are any problems. Looked OK on the scope.



Next steps will be to get it in a case on a protoboard, and establish communications between the DG5 emulator and the VFO – the DG5 is connected to the computer, and I can have the computer tell the DDS what frequency to go to, and I might be able to use one display.  At this point I am leaning to independent boxes as the DG5 box is best on top of the TS-520, and the VFO would be best off to the side with the VFO knob and at the same general height as the existing VFO knob.  The rotary encoder I am using is a cheap mechanical type with detents, I’ll need to get a higher resolution, smoother encoder (probably optical) for the final design.

Let me know what you think!

Steve – KV6O

P.S. – I have been in touch with Todd at ToddFun, I sent him a couple of the first run PCB’s for the DG5 emulator – he’s building it and will be posting a new video with the DG5 emulator soon!  Keep your eye out for it!

DG5 emulator version 1.4 ready to go!

I finished up on the changes and tweaks I wanted to make to the design, new schematic below.  I think I have found a US based PCB house (in Nor Cal, no less!) that can do a run for not much more that what I would pay for the China based house I used last time.  I should have the boards in less than 2 weeks as opposed to close to 4 weeks.  Since I just finished it up today, and it’s Friday, I’ll wait till Monday to submit the design, giving me 2 days to look it over for any problems.


Few things I addressed in this version:

  • Rotated the board on the shield so the inputs are on the same side as the Arduino USB port.
  • Fixed 3 wiring errors.
  • Added headers for attaching an LCD display with contrast potentiometer and optional dropping resistor for LED back-light. This will use 2, 6 pin jumpers to connect to the LCD.
  • Corrected some of the cap and resistor solder pads, should be easier to solder.
  • Fixed silkscreen errors on shield headers.
  • Added optional 7805 regulator and 2.1mm power jack for running standalone (no USB power). 7805 WILL need heatsink as it’s dissipating around 2W, almost twice what the board, LCD and Arduino uses since it’s dropping 14V (from the back of the TS-520) down to 5V.

I looked at using a triple gang RCA jack, but couldn’t find one with an Eagle footprint, so I am sticking with the single jacks from Sparkfun for now. There is too much risk designing the footprint off the datasheet, part unseen.

Download (PDF, 34KB)

New schematic.  Only difference from the one below should be the addition of the 7805 and supporting components.

DG5 emulator Version 1 PCB’s have arrived

Yippie!  The boards arrived last week and it was a few day’s before I could get to them.  They sure looked nice!


I was working on version 1.1 of the layout before these boards even arrived as I realized that the inputs for the VFO/CAR/HET were on the opposite side of the board from the USB connector – not convenient if you want to mount the assembly in a chassis.  But I was anxious to get this first version up and running to see if I got the schematic correct in Eagle.  And as is usual, I found a couple of minor problems.


Here’s a view of the bottom of the populated board – note the 3 jumpers. Turns out I made a few mistakes – one was bringing a NET on the Eagle schematic over the pin and near the chip – missing the intended connection to the pin.  Another one was missing an air wire – a ground “island” was created without a connection to ground.  And lastly, I wired to the wrong output pin on the 74LS93 counter, winding up dividing by 4 rather than 8.  All three errors were corrected with jumpers.

There is also some silkscreen mistakes, I somehow incorrectly labeled the Arduino shield pins in two areas – not critical.


Here’s the board fully populated from the top.

Few other issues with this version that I have corrected with version 1.1:

  • Some of the Eagle parts used solder pads that are pretty small, making soldering a little more difficult.
  • I had 2 LED’s for showing which input was selected on the LS74153, which I have removed in version 1.1 to save board space, they weren’t really necessary.

As I work on the new version in Eagle, I am trying to keep in mind a few other things now that I have an actual, working shield.

  • Arduino to shield clearance – putting the RCA connectors on the same side as the USB connector makes it easy to short things out.  A little bit of electrical tape on top of the USB connector should prevent this.
  • Need to keep the PLL output signals as short as possible as they are 5V TTL level representations of the original, low level signals – a potential RFI issue.  Using the shield design this isn’t really possible as the signal exits the shield to the main Arduino board on Pin 5.  A better design would put everything on one PCB, keeping HF signals nets as short as possible. Another way of reducing this issue as a good, shielded enclosure.
  • Might need to add an LM7805 so it can run without being connected to the computer via USB.  I added one to my original prototype since it has an LCD display and isn’t dependent on a computer.  The LCD’s backlight and the Arduino draw enough current that a good heat sink is required to drop the 13.8VDC (provided at the back of the TS-520 for the DG5) to 5VDC.

Arduino’s with shields don’t lend themselves well to enclosures, so one possibility might be to make a larger shield that an Arduino plugs into that can slide into an extruded aluminum enclosure.  The Arduino would be a “daughter card” in this scenario, plugged in up side down on the main board.

My TS-520 still uses the prototype shown below since it’s already mounted in an enclosure and has the LCD display added, which was something I added after I sent in the version 1.0 PCB design.

Download (PDF, 31KB)

My current schematic, with 2, 6-pin jumpers to go to a 16-pin LCD display (only the first 6, and last 6 pins are used on the display).

Latest Arduino code with LCD support (note the pins used for the LCD):

Note – I have only tested this with the Arduino UNO and Duemilanove boards.  There are probably issues with other Arduino boards, such as the Leonardo, as they use the internal TIMERs for USB emulation.

If you’re interested in the eagle files, drop me a line.


Arduino based Kenwood DG5 emulator for my TS-520S

Here’s a quick video of my DG5 emulator prototype buttoned up in a project box.

Still waiting on my PCB’s to arrive on the slow boat from China.  I already have changes to make – the first version PCB has the 3 RCA jacks for the 3 signals from the TS-520S on the opposite side from the Arduno’s USB – not exactly the best for mounting in a box.  And I also have added the display since I sent in the design, so I’ll have to add that in as well.  The “shield” is getting a bit tight with the DIP IC’s and new requirements, I might either go to SMD devices (for the IC’s at least) or just make the shield bigger that an Arduino.  This might actually be an advantage, as a bigger shield would allow me to slide it in a Hammond type aluminum extrusion chassis, with the Arduino plugging in on top, upside down.

Got myself one of the AS9850 DDS modules that are available on eBay for around $10.  Looking at making an external VFO for the TS-520 with one of these, so a bigger box might be a good idea.

DG5 Update – now with LCD display!

Today I added a display, so now my the DG5 emulator actually emulates a DG5 in function – a digital display of your frequency.  I also built some Arduino shield PCB’s using Eagle and have sent them off to Itead in China, should have them back in a couple of weeks.

Here’s the display in action:

Using a parallel LCD display because the frequency counter code uses an 8 bit Timer and the only 16 bit Timer on the 328 – most of the serial based libraries use the 16 bit timer as well, causing a conflict.

A Kenwood DG-5 emulated on Arduino

A few months ago, I bought a Kenwood TS-520S. The Kenwood hybrid’s are beautiful radios, and the TS-520 is the first radio I was on the air with (on amateur HF bands) while I was in High School in the early 80’s.  So when I had an opportunity to pick one up locally, I jumped at it.

I have had a great time playing around with it and ragchewing. It takes a bit more work than my K3 or TS-2000 (tuning, calibrating) but that’s the beauty – it’s like an older car with points, condensers, and a carburetor – takes some more tweaking, but you can fiddle with it easily. I replaced the HV caps, adjusted the calibrator, and cleaned the switches and pots, but that’s about it. It just works.

I came across a site called while doing some TS-520 searches, and found a series of very well documented posts (with in depth videos) about  building a Kenwood DG-5 type display for the TS-520.  The Kenwood DG-5 was an optional digital display for the TS-520/820, and on the used market they go for more than I paid for the radio!  He was using the Arduino platform, something I have been using for a few years here.  I thought, “I can do this!”, but instead of a display, I wanted to have it talk to my computer so my logging program (DXLab) could read the frequency of the radio.

There’s lots I could do better, and the Mega 328 isn’t the best platform to be doing frequency counting, updating a display, and servicing a serial port at the same time.  The frequency counter needs the limited internal timers on the 328 which limits use of I2C, SPI, and software serial libraries as far as I can see.  Nevertheless, getting the TS-520 to talk to my computer is what I set out to do, and it works beautifully!

A quick and dirty demo of it:

I don’t have a schematic for it, if you watch Todd’s video’s you can figure it out.  Basically, the signals are buffered and conditioned by the TI PLL’s, the (HFO frequency needs to be pre-scaled as it’s outside the range of the Arduino counter), and the 3 are mux’ed into the Arduino on pin 5.

Arduino DG-5 code:


Kenwood DG5 digital display emulator, sort of.

Stephen Leander, KV6O
August 22, 2014

No display in this revision, outputs Kenwood Commander commands on the Serial/USB port for a logging program (DXLab's Commander)
No idea if it will work with other programs because I haven't tested anything else!

Got the idea from Todd Harrison's website,, where he outlined and built an Adrunio DG-5 emulator, with the plans of using this to display
the frequency, just like the DG-5.

Counter code based on Arduino timer code by Nick Gammon

Emulates a TS-790 for DX Commander, based on input from Dave, AA6YQ:

 From Dave AA6YQ, DXLab's author:
 From: [] Sent: Tuesday, August 05, 2014 10:42 PM To: Subject: [dxlab] Kenwood

 >>>If your emulator responds to the ID; command with 


 >>>Commander will think its controlling a TS-790. The only other commands to which your emulator will then have to respond are IF; and FB;

 >>>Note: Commander pays attention to the following bytes of the radio's response to an IF; command:

 3-13: VFO A frequency
 29: RX vs TX status
 30: Mode
 31: VFO selection
 33: split status

 >>>Operation won't be convenient unless your emulator can correctly report the radio's mode.

See for more on Kenwood command set.

8/22/14 - Version 1.0 Prototyped the circuit using 3 TI PLL's (74HC4046A's), a 74HC93 counter for prescaling the HFO, and 74HC153 for selecting the
signal (VFO, BFO, or HFO) to be counted by the Arduino on pin 5.


//#define DEBUG //Uncomment for debugging

volatile unsigned long timerCounts;
volatile boolean counterReady;

// internal to counting routine
unsigned long overflowCount;
unsigned int timerTicks;
unsigned int timerPeriod;

unsigned long vfo = 0;
unsigned long bfo = 0;
unsigned long hfo = 0;

void startCounting (unsigned int ms)
 counterReady = false; // time not up yet
 timerPeriod = ms; // how many 1 mS counts to do
 timerTicks = 0; // reset interrupt counter
 overflowCount = 0; // no overflows yet

 // reset Timer 1 and Timer 2
 TCCR1A = 0;
 TCCR1B = 0;
 TCCR2A = 0;
 TCCR2B = 0;

 // Timer 1 - counts events on pin D5
 TIMSK1 = bit (TOIE1); // interrupt on Timer 1 overflow

 // Timer 2 - gives us our 1 mS counting interval
 // 16 MHz clock (62.5 nS per tick) - prescaled by 128
 // counter increments every 8 µS.
 // So we count 125 of them, giving exactly 1000 µS (1 mS)
 TCCR2A = bit (WGM21) ; // CTC mode
 OCR2A = 124; // count up to 125 (zero relative!!!!)

 // Timer 2 - interrupt on match (ie. every 1 mS)
 TIMSK2 = bit (OCIE2A); // enable Timer2 Interrupt

 TCNT1 = 0; // Both counters to zero
 TCNT2 = 0; 

 // Reset prescalers
 GTCCR = bit (PSRASY); // reset prescaler now
 // start Timer 2
 TCCR2B = bit (CS20) | bit (CS22) ; // prescaler of 128
 // start Timer 1
 // External clock source on T1 pin (D5). Clock on rising edge.
 TCCR1B = bit (CS10) | bit (CS11) | bit (CS12);
 } // end of startCounting

 ++overflowCount; // count number of Counter1 overflows
 } // end of TIMER1_OVF_vect

// Timer2 Interrupt Service is invoked by hardware Timer 2 every 1ms = 1000 Hz
// 16Mhz / 128 / 125 = 1000 Hz

 // grab counter value before it changes any more
 unsigned int timer1CounterValue;
 timer1CounterValue = TCNT1; // see datasheet, page 117 (accessing 16-bit registers)
 unsigned long overflowCopy = overflowCount;

 // see if we have reached timing period
 if (++timerTicks < timerPeriod)
 return; // not yet

 // if just missed an overflow
 if ((TIFR1 & bit (TOV1)) && timer1CounterValue < 256)

 // end of gate time, measurement ready

 TCCR1A = 0; // stop timer 1
 TCCR1B = 0; 

 TCCR2A = 0; // stop timer 2
 TCCR2B = 0; 

 TIMSK1 = 0; // disable Timer1 Interrupt
 TIMSK2 = 0; // disable Timer2 Interrupt

 // calculate total count
 timerCounts = (overflowCopy << 16) + timer1CounterValue; // each overflow is 65536 more
 counterReady = true; // set global flag for end count period
 } // end of TIMER2_COMPA_vect

String inputString = ""; // a string to hold incoming command date
boolean stringComplete = false; // whether the string is complete

void setup ()
 pinMode(2, OUTPUT); // for signal select on the 74HC153. Using Pins 2 and 3.
 pinMode(3, OUTPUT);

 // reserve 200 bytes for the inputString:

 // end of setup


void loop ()
 for (int x=0; x < 3; x++){ // Loop thru the 3 signals to count the signals.
 if (x==0) { //Select VFO
 digitalWrite(2, LOW);
 digitalWrite(3, HIGH);
 if (x==1) { //Select BFO
 digitalWrite(2, HIGH);
 digitalWrite(3, LOW);

 if (x==2) { //Select HFO
 digitalWrite(2, LOW);
 digitalWrite(3, LOW);

delay (20); //settle time

 // stop Timer 0 interrupts from throwing the count out
 byte oldTCCR0A = TCCR0A;
 byte oldTCCR0B = TCCR0B;
 TCCR0A = 0; // stop timer 0
 TCCR0B = 0; 

 startCounting (100); // how many mS to count for

 while (!counterReady)
 { } // loop until count over

 // adjust counts by counting interval to give frequency in Hz
 float frq = (timerCounts * 1000.0) / timerPeriod;

// Serial.print (" freq: ");
// Serial.print ((unsigned long) frq);

 if (x==0)vfo=frq; // load frequency's into vfo, bfo, and hfo.
 if (x==1)bfo=frq;
 if (x==2)hfo=(frq*8);

#ifdef DEBUG // for debugging and monitoring the results.
Serial.print("VFO: ");
Serial.print (vfo);
Serial.print(" BFO: ");
Serial.print (bfo);
Serial.print(" HFO: ");
Serial.print (hfo);
Serial.print (" FREQ: ");
Serial.println (hfo-(bfo+vfo));


 // restart timer 0
 TCCR0A = oldTCCR0A;
 TCCR0B = oldTCCR0B;


 // Check serial port to see if we have a command
 if (stringComplete) {

 if (inputString == "ID;") { //ID the radio as a "ID007" - Kenwood TS790. There is no TS-520S. ;-)
 else if (inputString == "FB;"){ // Probably not needed as Commander uses the "IF" command, used for debugging..
 else if (inputString == "IF;"){

 if ((hfo-(bfo+vfo)) > 9000000){ // Used 9Mhz as the cutoff so I could properly format the string with the additiona digit returned above 10Mhz.
 Serial.print ("IF000");
 Serial.print (hfo-(bfo+vfo));
 Serial.print ("000000000000000020000000;"); // The "2" is the mode, above 9Mhz it returns "USB"
 Serial.print ("IF0000");
 Serial.print (hfo-(bfo+vfo));
 Serial.print ("000000000000000010000000;"); // Mode set to 1 for "LSB".

 // clear the string:
 inputString = "";
 stringComplete = false;

 // end of loop


 SerialEvent occurs whenever a new data comes in the
 hardware serial RX. This routine is run between each
 time loop() runs, so using delay inside loop can delay
 response. Multiple bytes of data may be available.

void serialEvent() {
 while (Serial.available()) {
 // get the new byte:
 char inChar = (char);
 // add it to the inputString:
 inputString += inChar;
 // if the incoming character is a newline, set a flag
 // so the main loop can do something about it:
 if (inChar == ';') { // Look for ";" - this is the Kenwood command terminator.
 stringComplete = true;