Saturday, September 13, 2025

Automatic Antenna Selector Project

Auto Antenna Selector under test.
Some projects are years in the making. October 2020, I ordered the KK1L 2x6 Antenna Switch board. I assembled it and by December I rigged up a manual antenna selection switch. Two years later, I mounted the KK1L to an aluminum panel to create a Single Point Ground (SPG). While all that work was beneficial from a bonding and grounding standpoint, antennas were selected manually. If I changed bands and forgot to change the antenna selection, trouble could ensue.

The purpose in buying the KK1L 2x6 Antenna Switch was fully automatic antenna selection. I needed a controller that could communicate with the Elecraft K3 and select the right antenna. 

A PIC microcontroller seemed suitable. I'd had success using one of these chips to build a K9AY Controller. For that project I had used a PIC16F1503. After that, I picked up the PIC16F18426 and PIC16F18446 chips -- these offered more features than the '1503, including a serial port and way more program memory. The Microchip tools were free, and I had a PICkit3 programmer.

I sketched out three designs.

Design A - 1 radio, 1 set of relays

The most basic design - it does little more than replace the manual switch. A single DE-15 jack brings the BAND0-3 information from the K3 into the PIC. Three outputs drive a 74LS145 BCD decoder to select one of the six relays through a 2N3906 driver transistor. Two other outputs allow selection of the 160 or 80/75m shunt matching networks.

Total I/O required nine pins, which any of the three chips could provide.

Design B - 1 radio, 2 sets of relays

A limitation with Design A is that a K3 with the KAT3 has two antenna jacks, but the selector only chooses one antenna. Design B reads BAND0-3 from one radio, and selects the best antenna on port A of the switch, which is connected to ANT1, and the second best antenna on port B, which is connected to ANT2. The operator can then use the ANT button on the K3 to switch between the two antennas. 

This design retained the four inputs for the BAND0-3 information, plus six outputs feeding two separate 74LS145 BCD decoders, and two additional outputs for the 160 or 80/75m shunt matching network. 

That's exactly 12 pins -- still possible using any three of the chips.

Design C - 2 radios, 2 sets of relays

I liked Design B, but along the way I purchased a second Elecraft K3. If I were trying to use both radios, what would I need to switch the antennas?

Two DE-15 jacks facilitate the BAND0-3 data from each radio, requiring eight inputs. The selector could then choose the best antenna for both Radio A and Radio B, unless that choice caused a conflict, in which case Radio B would get the second-best choice.  Outputs were the same as in Design B. 

This required the 20-pin '18446, because the 14-pin controllers don't have enough I/O available. 

It occurred to me I might want to switch the antenna selection priority sometimes, so Radio B gets the best antenna in a conflict and Radio A gets second best. That required an input pin for a pushbutton and an output to light an LED. This used all the 18 pins available on the '18446. 

Design Choice - B/C - 1 or 2 radios, 2 sets of relays

First look with front panel assembled
The end design combines Design B and C features. Two DE-15 jacks are used, and the PIC software decides if a K3 is connected or not based on the pattern of BAND0-3. Unconnected pins are pulled up, so a value of all ones indicates no connection. If only one radio is connected, the software acts like Design B, if both radios are connected, it acts like Design C. 

The front panel has LEDs for the six relays on port A and B, so you can visually see which antenna is selected for each radio. An LED each for the 160 and 80/75m shunt selection, and a pushbutton and LED for the mode selection rounds out the front panel. A power switch and a switch to choose between the 80 and 75m shunt network round things out.

Power requirements are simple. A port relays take 88 mA, and B port relays require 44 mA. Selecting one relay for both ports is less than 140 mA. The 160m shunt relay requires 120 mA and 80m relay requires less. The power requirements of the PIC, 74LS145 and LEDs are negligible by comparison -- 300 mA covers everything. 

Construction

A look at the guts of the box. The relay
drive transistors dominate the board
I searched for a smart-looking cabinet for this project fitting the dimensions of the station. I found a reasonably priced enclosure on Amazon.com. I took lot of care drilling the front panel so that everything lined up correctly. I figured I might be staring at it for years. In retrospect, the rear panel doesn't look so pretty.

With the cabinet in hand, how to construct the hardware? I considered developing a PC board, but I was eager to build. I ended up using a bit of perfboard and some 3M Scotchflex prototyping sockets. The Scotchflex system is now obsolete, mainly because everything is surface mount, but I had most of this in the junk box. I had to engineer a 20-pin 0.3 inch socket -- which I accomplished with two 14-pin sockets back to back.

The downside to this approach is all the wiring required for the relay and LED driver transistors -- there are fourteen 2N3906s, three 2N3904s and a bunch of related resistors. A PC board would have taken more design work ahead of time, but the construction would have gone quickly and taken less space.

I worked on this project off and on in six different locations - Gwinnett county, Fulton county, Warren county, two locations in Gordon county and finally from Floyd county. For a while, I carried the whole project with me in a small cardboard box wherever I was.

Software

Like the K9AY controller, everything is interrupt-driven. The '18466 CPU is configured with a 500 kHz clock speed, and a timer interrupt occurring every 5 ms. 

During the interrupt, we sample the A and B ports from the radios, plus the mode button. All of these values go through debounce logic - the value must hold for 10 interrupts (50 ms) before taking action.

If either the A or B values change, or the mode selection changes, then the antenna selection logic is followed. If either port is all ones, it indicates a radio isn't connected, so the Design B rules are used to select the antenna. If neither port is all ones, we assume two radios are connected, and Design C rules are used to make the selection. 

Debugging

Unlike the K9AY controller, I had a bit of trouble getting the software working. Part of the struggle was knowing if a problem was a wiring problem or a software issue.

At first, nothing seemed to work. In the end, I wrote really simple firmware that just blinks the mode LED based on the timer. Nothing. Setting up the chip on a solderless protoboard, still nothing. After some experiments, I got the timer interrupt straightened out and had a blinking LED on the protoboard. 

Then came the wiring issues on mode LED. One issue was the transistor drivers for the LED didn't have proper pull-ups. Eventually, I settled on a one second startup routine that would blink the mode LED briefly once, then twice. After that, the chip would be looking at the input ports and selecting antennas.

In the next phase, I wrote an additional startup routine that selected the antenna for ports A and B. Every second or so, it selected a different relay, and hence light the LED. I coded it to go in a pattern so I could verify that each relay driver and LED worked correctly. Of course, it didn't work.

Several wiring problems became apparent. First, the 74LS145 chips weren't getting any +5 volt power, so they weren't doing anything. They had been wired, but one of the wires broke. Once fixed, the LEDs lit. Then it was apparent they were going in the wrong order. 

The wiring between the PIC16F18466 and the 74LS145 chips had two problems. First, the pins for the A port and B port had been reversed. Second, outputs from the 74LS145 were reversed. Putting out a value of 001 into the 74LS145 selected antenna 0, and a value of 110 selected antenna 5. Rather than doing a massive amount of re-wiring, it was easier to change the software and re-draw that part of the schematic. 

Then we finally come to the business end -- hooking up the K3 BAND0-3 inputs. That's when I found my last wiring error. Turns out, I had swapped the pins between rig A and rig B. Another problem solved with a software change.

It Works! Now What?

Even with the basic software running, I felt the need for change. I've disassembled my station in Gwinnett county, and the antenna configuration I programmed, even designed this Automatic Antenna Selector for no longer exists.

The antenna selection logic originally was a bunch of switch statements embedded inside if / else statements -- not very easy to change. I re-coded to use a short table of eleven rows and four columns. The rows represent each band, 160 through 10m, including 60m. The columns are the first, second, third and fourth choices of antennas. Much easier to understand and update.

I expanded on the idea about the Mode button. Originally, it was just primary / secondary. To allow for up to four antenna choices, perhaps there are more than two modes. How does one tell which mode you are in? The mode LED was programmed as just on or off. I could have it be off for primary, blink once for secondary, twice for tertiary, and three times for quaternary.

The last issue was how to test the relay action without having to program a new antenna configuration.  Currently, there's nothing programmed for relay position 4. If one wanted to hook an antenna there to test it, how do we do that without burning a new chip? 

Holding down the mode button could select a special mode that selects ports A0 ad B5. Then, each time you tap the mode button, it would switch: A1 and B4, A2 and B3, etc. In this way, each port can connect to each antenna. And the mode LED would indicate this with a solid on condition. Hiding the mode button again would switch back to the to the normal program.

How about using a radio other than the K3? Maybe I want to use the Novice Transmitter, or perhaps my trusty Elecraft K2/100. Perhaps we re-purpose the seven-position manual selection switch to encode K3 band values. A simple diode matrix would work, and I have a bunch of 1N270 diodes, 

This project is now working, but it is far from done.

No comments:

Post a Comment