Tuesday, 23 October 2012

For those of you wondering what that trigonometry you learnt in school has to do with circuit bending, read on....

Amplitude Modulation, as in AM radio, is a real world application of trigonometry, and AM radio has been with us for over 100 years.

Some of you may recall the trigonometric identity for multiplying two sinewaves.

Here is how this trigonometric identity can be used to modulate a hypothetical radio frequency carrier signal (a sine wave) with an audio tone (the information signal - also a sine wave):

So, we have shown mathematically how to amplitude modulate a radio wave carrier signal of amplitude A with an audio signal.

This results in the final equation with upper and lower sidebands of amplitude +1/2 and -1/2, and the carrier sine wave of amplitude A.

If we were to look at the results on a spectrum analyser, we would see something like this:

(Thanks to Wikipedia for the graphics)

From this diagram, it becomes obvious how the three terms of the equation arising from the original trigonometric identity relate to the lower sideband, upper sideband, and carrier in an AM broadcast.

In case you don't believe the mathematics, here's a sneak preview of what comes later... note the upper and lower sidebands (the vertical bars) on the spectrum scope and the central carrier shown on the kit built SDR cube receiver receiving a single AM audio tone centred on 1230.20kHz....

As an aside, if you have heard the term "lower sideband", "upper sideband", or perhaps "double sideband" transmission in amateur radio, these modes should make a bit more sense now - they are transmissions missing one or two of the above three terms to save on transmitter power.

So, how do we use this theory for circuit bending?

Simple, we use an existing LC oscillator generating a radio frequency (RF) carrier, and we then feed an audio tone into the early stages of the RF output amplifier, to modulate the amplitude of the final RF output.

This VK5JST antenna analyser is a handy piece of test equipment which can serve as a source of RF from 1.3MHz to 31MHz (and sometimes more, i.e. 200khz to 50MHz, if you do the necessary mods...), usually used to tune antennas to resonance for your desired frequency range (a.k.a. band) of radio activities.

So, how do we circuit bend this source of RF into an AM chiptune transmitter?

Well, the antenna analyser uses a PicAXE microcontroller for frequency and SWR readout on an LCD display.

The software driving the frequency counter and analyser circuit is easily modified and uploaded to the analyser, making it an eminently hackable piece of benchtop test equipment...

It also just so happens that 28X1 and newer PicAXE chips can squirt an audio tone out, including RTTTL music formats, on a spare pin if asked nicely.

So, we have access to the software, which we can modify to add chiptune audio outputs, and we have a soldering iron, which we used to build the analyser in the first place, and we have access to the circuit diagram, so....

First, we install the optional serial port header, so that we can install cabling from the PCB to a stereo 3.5mm audio jack. This is done in keeping with the standard PicAXE convention of ground (tip), PicAXE serial data in (ring), and PicAXE serial out (shaft).

Having done so, we now have the ability to upload modified code to the analyser....

Next, we need to pick a spare pin on the pickaxe that we can use for the chiptune output. From perusal of the circuit diagram, found on the designer's website

Next, we need to decide which bit of the circuit to squirt the audio into, to amplitude modulate the RF signal generation portion of the analyser.

Perusal of the LC oscillator and subsequent buffer and amplifier portions of the circuit, we find a control loop feeding back to the Q5 transistor base connected to a 680 ohm resistor controlling oscillator output amplitude:

Somewhere around here should do.

First, we try jumpering a lead from pin 21 to the base of Q5, via a 1uF DC blocking capacitor and a current limiting resistor. Remember, this is a quick and dirty hack... but most circuit bending is. Although the hack is likely to affect phase and frequency stability a little, it shouldn't be noticeable with AM reception.

We start with an test audio tone of around 800 hertz, using a squarewave to mimic what the PicAXE will be providing in due course.

Here are pictures of a dual trace CRO (oscilloscope) showing the audio tone on the lower trace, and the AM modulated RF waveform on the upper trace.

Each picture shows the increasing modulation and increasing waveform distortion arising from reductions in the value of the series resistor going to Q5.

In the last CRO picture, we see over-modulation, and the RF waveform goes to zero for a proportion of each cycle. This confused the frequency counter in the antenna analyser and it reads low, so it's best to use a higher value resistor and to not overmodulate.

The modulation also appeared to be subject to the increasing correction by the AGC loop, and although the tone could be heard on a nearby radio, cleaner modulation was desirable in order to reduce "splatter" and harmonic generation.

To fix this, another approach was needed, and after contemplating various schemes, one requiring minimal modification of the PCB was chosen.

Here's the circuit:

The audio transformer had been gutted from a radio many years ago, as had the33nF capacitor, and these were used in conjunction with a 10k multi-turn potentiometer.

The effect of the potentiometer and capacitor was to form a voltage divider that directed current into the transformer at lower frequencies, but shunted higher frequencies straight to ground through the capacitor. This is also known as a low pass audio filter. This circuit could be interposed between ground and the 680 ohm resistor (also shown in the circuit diagram).

Here's the prototype:

The modulation improved a lot. See how it is much less "jagged":

And here's the circuit being patched into the analyser more permanently.
Note the red wire going to pin 21 of the PicAXE, and the shielded lead interposed between the groundplane and the "earthy" end of the 680 ohm resistor on the PCB. The keen eyed will also note the additional RF chokes added to the rotary switch during analyser kit construction giving extended frequency ranges to the analyser:

And finally, to complete the hack, additional code was added to the antenna analyser's PicAXE micro to make it play ring tone music, squirting the audio out on pin 21.

The resulting AM can be listened to on any old AM radio, in this case an FT817 which happened to be nearby:

In summary, we have used trigonometry to circuit bend a kit built antenna analyser into an AM radio transmitter, and we have even managed to Rickroll it while we were at it.

Here's the subroutine code. It expects a 16MHz clock, and may need slowing down for slower processors. Feel free to use it to rickroll anything with a PicAXE:

'Rickrolling
- uses B.0 which is pin 21 on the PicAXE, 16 is the speedtune B.0,16,($47,$49,$50,$49,$14,$4C,$14,$4C,$02,$42,$0C,$4C,$47,$49,$50,$49,$12,$4C,$12,$4C,$10,$4B,$09,$49,$47,$49,$50,$49,$D0,$12,$0B,$09,$07,$47,$4C,$07,$D2,$C0,$00,$0C,$47,$49,$50,$49,$14,$4C,$14,$4C,$02,$42,$0C,$4C,$47,$49,$50,$49,$12,$4C,$12,$4C,$10,$4B,$09,$49)

PAUSE 6000

goto playitagainsam

It just goes to show, if you can't modify the software in the box, you don't own it....

And in case you think this is a pointless hack, we are just a few lines of code away from turning the antenna analyser into a Morse practice beacon, and just some pullup resistors on some remaining spare PicAXE pins from being able to use a Morse paddle to practice Morse code on any AM radio.....

For the AVR fans, there is nothing to stop similar mischief being perpetrated with an Arduino....

About Me

Licensed radio amateur - That doesn't mean I wait for floods and tornadoes with a battery and a radio, it means I like to pull stuff apart, put stuff together, and hack stuff generally, while avoiding electric shock, thermal burns, RF burns, fire, lightning and falls from heights.