AKA Interface Considerations

A couple months ago, Ben, NN9S, suggested developing a morse code keyer that would run on android devices (see his write up and video). Since then, we’ve been designing hardware and software to get the job done. The software lives in a repository on the Google Code site, and is moderately functional, but far short of ready for general release. On the hardware side, we’re still batting around ideas. Here is a brief history of the ground we’ve covered with regard to hardware design, and some idea of what’s coming next.

Phone, AKA, paddles and a transmitter - the most common configuration.

We considered all sorts of options such as having the device’s left and right channels run into a standard keyer, using the USB port directly, and some other more exotic alternatives (bluetooth anyone?), but we eventually settled on the idea of having the android device output a sound, which could be used directly to modulate a signal, or could drive a switch of some sort.  The simplest configuration would be the device plugged into the androidomatic keying adapter (AKA), and the AKA plugged into the radio’s key  jack. Presumably, most people would want to be able to also key their rig using a straight key, paddle, or bug, so we assumed that the AKA and some other sending device would connect to the key jack via a Y adapter of some sort.

Android devices encompass a gamut of hardware platforms including phones, pads, netbooks, and dishwashers. Well, soon. At home, my only android devices were a Nexus S phone and an Optimus T phone, so that’s where I started in terms of characterizing the platform. Two essential tools were the android app “FuncGen” and the multiplatform audio editor “Audacity“. FuncGen runs on the android device and can generate various waveforms with all sorts of parameters, whereas Audacity test files (e.g., *.wav files) can be generated on a desktop computer and transferred to the android device for playback using apps like media player or winamp. The phone’s output can also be recorded via Audacity to analyze fine timing events (for those of us without fancier equipment).

Using FuncGen at full media volume to generate a 1000hz sine wave, the Nexus S put out about 1.85V peak-to-peak (654 mVrms) into a 20-100k load, and the Optimus T put out 1.9V peak-to-peak (671 mVrms). The output impedance of the Nexus S was about 14 ohms, and the Optimus T was near 17 ohms. I calculated the maximum power transfer at around 7.9mW per channel for the Nexus S, and 6.4 mW for the Optimus T.

Output voltage at maximum volume into a fixed (20k) load was flat for the Nexus S from 20Hz to 3000 Hz, with only slight attenuation (down less than half a decibel) at 10kHz, and down almost 2 dB at 20kHz. The Optimus was more sensitive to frequency and was ideally flat from 300-3000 kHz, with more marked attenuation at 10kHz (less than 1 dB) and 20 kHz (down almost 5 dB). Both phones demonstrated a log-linear relationship between the number of clicks on the media volume scrollbar and the rms voltage output (e.g., for the Nexus, if full volume was 707 mV, one detent down was 477 mV, the next was 317 mV, 224, 150, 100, 70, etc.) — meaning that the voltage drops off fairly quickly to relatively low levels.

The first hardware design considered was literally a VOX keyer circuit. A quick websearch turned up a nice design by N1HFX. This straightforward circuit is based on a 1458 op amp, which is essentially two 741C op op amps in one package. The circuit was meant to work from very low voltages generated by a microphone, so the first op amp acts as an inverting amplifier, and the second as a comparator. The 741C op amp is a dual voltage op amp, so to run this from a battery, the positive input of the first amplifier is raised to half Vcc by a voltage divider; likewise, the set point for the negative input is a bit above half Vcc. The output from the second amplifier will be a square wave at the same frequency as the input wave, and ranging from about 1V to (Vcc-1V). Since this drive would only be half-duty cycle, some smoothing is necessary before driving a transistor. A simple RC circuit sets the degree of smoothing, and a diode prevents back-discharge of the capacitor into the amplifier. Since the circuit was designed for voice, the RC values were chosen for a relatively long time constant; however for purposes of keying a rig for fast CW or even Hellscreiber transmission, a low time constant is preferable.

Based on the N1HFX design, we prototyped a similar circuit, with the following exceptions – for cost/availability, we used an RC 4558 op amp, which is a workalike to the 1458. Because the phone’s volume is adjustable, and the output is relatively high, we used a fixed resistance ratio for the comparator set point. The smaller RC values used were just large enough to smoothen output wave. We added some bells and whistles including a power indicator LED, and another LED to indicate when the keying circuit was closed. It was probably overkill, but to further protect the phone, we stuck an optoisolator between the rig and the rest of the circuitry. In retrospect, all of these LEDs are nice looking, but consume many orders of magnitude more power than the keying circuit itself, and they might as well be omitted — in our final designs, we just key the rig from the switching transistor.

Another design that we considered was based on a circuit described by Robots Everywhere in their implementation of an earphone jack-based serial port on android devices. Their write up made us wonder if android phones could put out digital levels through the ear phone port — boy, that would certainly make our job easy. As it turns out, some can and some cannot.  The Nexus S can sustain a very flat positive or negative voltage without breaking a sweat: at 20Hz, the output waveform is very square, at 1000Hz, there is some ringing. The Optimus T, however, looks like it’s output is capacitively coupled. At low frequencies, it’s not very square at all — the output capacitor bleeds voltage until the next half cycle. The take home is that around 1000Hz and above, both phones can generate some semblance of a square wave.

The Robots Everywhere design centered on an LM324 single voltage source quad op amp, but used only two of the four op amp subunits. Our next design was aimed at getting away from timing issues related to signal rectification and need for a “filler” capacitor prior to the switching transistor.

Since the phone can generate a stereo output, our next circuit used the left and right channel to generate square waves180 degrees out of phase — effectively get a halfwave rectifier for free by doing it in the software. These waveforms were fed into op amps like in the first design, with amplification occurring in the first stage and inversion in the second stage for each channel. When the positive portions of two channels are then brought together through diodes, the result is just about a flat positive voltage, about about 1V under Vcc (due to the diode drop). This voltage is applied to the gate of a 2N7000 enhancement mode N-channel FET, which has a threshold voltage of just under 3V. The gate capacitance itself further smooths the small defect at the edges of the two square waves. The 2N7000 could be directly connected to the rig, but we again used an optoisolator, since the design required the use of a battery anyhow.

Both the dual and quad op amp designs resulted in some prolongation of tone sent out the phone’s earphone port. The best we got with the dual was about 4-5ms, and the quad op amp design yielded around 3ms extra duration. We could compensate in software, ending the signal earlier, but it would be preferable to avoid that complication. For morse code, this extra delay would probably be unremarkable, as a single code element at 30 wpm is 40 milliseconds, so +/- 10% is probably tolerable. At fast code, it becomes significant, though — at 60 wpm, a single element is 20 milliseconds. Since we had plans to implement Hellscreiber keying as well, with a minimal on-time of 8.163 milliseconds, this delay was not acceptable.

In addition to the timing issue, we realized that it would be preferable to not require a power source for the adapter. Luckily, one solution address both problems — using a transformer to step up the voltage enough to directly bias a switching transistor. This approach was inspired by the interesting work done by the “HiJack” team exploring power harvesting from the iPhone’s earphone port. They designed a miniature power supply using the AC from the iPhone’s audio output as driving voltage. A similar approach was taken by Wolphi, in connecting the iPhone to microphone input for his excellent PSK31 appplication for android. His circuit was, in turn, based on a circuit proposed by KH6TY.  Similar solutions have also occurred to hams in the past developing interfaces for sound-based keying of Hellscreiber, including a design by K9JRI that includes a voltage doubler.

In considering transformers for stepping up voltage, we did try the nearly microscopic one employed by the HiJack team. Unfortunately, it was too far off in terms of impedance matching to function well. We ended up going for the most accessible transformer, a 8:1000 ohm audio transformer from Radio Shack. This transformer gives about an 11-fold voltage step-up, so some losses in rectification are tolerable. In principle, germanium diodes or even synchronous rectification could reduce these losses, but there is enough head room to not worry about it. The currents involves are minuscule, so there is no problem is using tiny (read: cheap and available) signal diodes like a 1n914. A 0.01 uF capacitor does not entirely smooth the wave, but it ensures that the voltage is never below about five volts, and the 2n2222a transistor remains saturated when the transformer is energized. The additional duration introduced by this circuit is around 300 microseconds. I tried adding a voltage doubler per the K9JRI circuit mentioned above; the voltage was marginally increased and the duration increased slightly as well to around 1 millisecond. Since the extra complexity did not add much, I’ve opted to stick to the simpler design, which can be built from easily obtained parts for less than ten dollars (much less, if you mail order and/or buy in bulk).

The transformer-based designs have the benefit of providing galvanic isolation between the android device and the the keying circuit and rig. One downside to transformer-based designs is that they need relatively high volume output from the phone. The design above required that media volume be set within three clicks of maximum on the Nexus S. The dual op amp design worked down to 9 clicks below max, and the quad op amp design worked down to 12 clicks below max.  Both devices tested put out about the same voltage and power, and hopefully most android devices are in the same ballpark, but if there were a particularly underpowered device, or if this circuit was used in some other context where lower output were available, a design with active components might be necessary. The other drawback to

We are now trying to figure out ways to miniaturize the design, and of course, the most limiting factor is the transformer. If anyone spots a suitable transformer let me know. I guess the idea one would be 16 ohm on the primary, and 2000 on the secondary (or 4000 on the secondary, with a center tap — allowing us to get rid of two diodes).

[Update 17 May 2016]

The androidomatic keyer has not had a lot of love lately; Ben and I have been busy with other projects and developing for android requires more sustained attention than we can afford for now. However, I’d still like to see this work preserved. When the GoogleCode repository blinked out of existence, I moved the software archive over to github, where it now resides: https://github.com/dhakajack/androidomatic-keyer

Digital Restoration Day

I hereby declare Thursday, April 21st was Digital Restoration Day.  The moment I walked in the door after work, Lara pounced on me and told me that she had shut down her computer because a window had popped up indicating that she had fifty or so horrible viruses on it. As she guessed, it was a fake message produced by adware of some sort. Starting with the usual, I ran microsoft security essentials, which identified and quarantined the adware. I did a manual update of the malicious software removal tool and gave that a run as well. After a reboot, the machine ran normally, and Lara went back to her online projects.

My next project was my cell phone. I live on my android phone, but it had been getting quirky for the last few months — long latency when switching apps, unexplained crashes, general orneriness. Last year, I had gotten tired of waiting for T-mobile to upgrade my HTC Magic 32b (i.e., T-mobile MyTouch) from it’s original (v 1.5?) android install. Mainly, I wanted tethering ability and some of the bells and whistles of the later versions. T-mobile kept promising over the air upgrades, but after a few months, that got old — particularly when all of their new and shiny phones were being sold with the new operating system, but I was stuck with my dinosaur.

Last year, I rooted the phone and installed a then-current version of the Cyanogen Mod. The HTC Magic followed the Google G1, so it was the second android phone on the market. Although it supports a 8 GB sdcard, the onboard memory is limited, so I had to install the “tiny” version of the Google apps, and otherwise be careful about memory allocation. Over time, the phone slowed down and became buggy. It got quite annoying. Tonight, I grabbed the highest version 6 cyanogen stable release, did a factory wipe/reset, and installed the updated operating system. It booted without a problem, grabbed my settings from the cloud, and I’m back in business today with a phone that is not only more stable, but a lot perkier.

Now to reload some apps.

Android App du jour: PDAnet

PDAnet

It would be nice if Wifi access were everywhere, but that’s not quite the case. It’s not a big deal for me, because I can get to my email or browse the web via my phone over a 3G connection, but sometimes it’s nice to be able to connect with your computer. I knew that I’d be in a location without any Wifi access all day today, so I took a chance an plunked down about $20 for an application, PDAnet, that would allow me to tether my non-rooted MyTouch phone from T-mobile. I was skeptical that this would work well, but it does.

The browser on the MyTouch (“G2”) phone is a little sluggish, but I had always assumed it was I/O-bound. It turns out that T-mobile’s throughput is not the limiting factor and that connecting via the tethered connection gives a quite usable connect — better, in fact, than I have had at most hotels via Wifi. I was able to connect to work via the VNC, and the connection was reasonably responsive.

PDAnet is an application that runs on the host PC (in my case, an intel MacPro with OS X 10.5), and another app on the mobile device. The computer and the phone can then be connected either via USB or bluetooth. This software is available on a 15-day try-it basis, and then requires registration to unlock. There are a few flavors, including one for Palm Treo devices (where I think it must have started). The host application is downloaded from June Fabrics, and the android part of the app is downloaded from the android market.

This opens up a whole new level of connectivity. I had been thinking of buying a verizon dongle for the computer, but I’m much happier to not have to cart around another piece of hardware and, more to the point, pay another monthly fee. The only advantage the verizon dongle would now offer would be choice of provider, but I’ve found T-mobile’s coverage to be excellent.

So, five thumbs up. Posted via Android and Mac.