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 Toddfun.com 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, Toddfun.com, 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.

http://www.toddfun.com/2013/02/07/arduino-frequency-display-for-kenwood-ts-520s-hf-ham-radio-part-1/

Counter code based on Arduino timer code by Nick Gammon
http://www.gammon.com.au/forum/?id=11504

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

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

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

 ID007;

 >>>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 http://www.kenwood.com/i/products/info/amateur/ts_480/pdf/ts_480_pc.pdf 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

ISR (TIMER1_OVF_vect)
 {
 ++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

ISR (TIMER2_COMPA_vect)
 {
 // 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)
 overflowCopy++;

 // 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);

 Serial.begin(9600);
 // reserve 200 bytes for the inputString:
 inputString.reserve(200);

 // 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));

#endif

 // 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. ;-)
 Serial.print("ID007;");
 }
 else if (inputString == "FB;"){ // Probably not needed as Commander uses the "IF" command, used for debugging..
 Serial.print("FB00014195000;");
 }
 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"
 }
 else
 {
 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)Serial.read();
 // 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;
 }
 }
} 

[wpdm_file id=2 title=”true desc=”true”]

 

5 thoughts on “A Kenwood DG-5 emulated on Arduino

      1. Tom sides

        Thanks for the reply. I looked thru the Web page for documentation . A schmatic for lcd but none for the led or nixie.. being a little lazy I guess. Thanks for supporting this neat project.

        Reply
        1. admin Post author

          No problem, I haven’t posted the LED or Nixie data yet. The Nixie schematic is pretty straight forward – it just daisy-chains the TaylorEdge modules to make a display using I2C, and uses the I2C ports on the Arduino, A4 and A5.

          Steve
          KV6O

          Reply
  1. Moe

    Hi Steve !
    I have been following this interesting project through Toddfun ended up by you, you did very good job, I always wanted to built something like this kit to do the math for the old receivers, I have a question, would this project be able to do the math for other receivers ? may some modification of the code ?
    I wanted to use nixies instead of LCD display, by driving nixies directly using I2C is a much better way instead of the old conventional way, there’s an interesting video on you tube titled ( DIY nixie tube frequency counter ) using this way but the counter didnt have the three input to do the math, the builder also provided the code for who is interested, sounds nice.
    I will keep an eye open when post the next of your projects of nixie counter, that will be interesting.
    73s
    Moe

    Reply

Leave a Reply to admin Cancel reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.