Friday 11 February 2022

16 - Software, not Ham radio

This started as a post about my view on software development and turned into my memoirs...

Each of us has undertaken a journey that colours our perspective. My journey in writing software began 50 years ago when I was 15 and took a class at school in Computer Science -  a very new option then (1969).

I began with the ALGOL programming language, this was one of the big three languages of the time, the others being COBOL and FORTRAN. We wrote our code on special A4 sheets of paper on a Tuesday and our teacher took them to a local technical college a few miles away on Friday and we got computer printouts the following Tuesday. If you had made a simple typing error like omitting a comma then you had to wait a week for the syntax to be corrected. you have to be careful when writing programs, they can't be approximately right.

Nonetheless, I found the creative part of programming very satisfying, my earliest program found all the primes in the first thousand numbers, I still remember the algorithm, it was mostly inefficient although my version was smart enough to only search up to the square root of a thousand plus 1.

I left school at 18 and went to the local university to study engineering, after 6 weeks there I was approached by a government department who asked me to undertake an industrial sponsorship scheme - one of their entrants had dropped out and I had mentioned to my entrance tutor I would maybe have liked a year off. The sponsorship scheme was a brilliant way to do engineering, 12 months working in a company, then the university degree with summers spent working in the company and then an obligation to work in the company for a couple of years after finishing, described as a moral obligation and not a legal one. The sweet spot was you got paid throughout all this so I never had to ask my parents for money when I was a student. I ended up with a very high tech company that made microprocessor based medical instruments. They also produced minicomputers to be used in hospital laboratories as well as bespoke software solutions for businesses and labs. Early on they brought in microcomputers from the states and became dealers for the Commdore PET and Apple machines. Early geek heaven.

I remember being handed two thick books and told to write a mastermind program on a microprocessor development board. The books were the Motorola data book and the application manual for the M6800 8 bit microprocessor. A happy 2000 pages that I devoured with intensity. The development board had 256 bytes of ram and had a simple monitor program that allowed entering hex bytes into memory (a "M" command) and to pass control to an address where you had placed your program (a "G" command). The monitor also allowed reading and writing the contents of memory to paper tape - if your terminal was a teletype. These beasts were old and very noisy printers and keyboards with attached paper tape punches and readers, 2000 moving parts and three feet wide using rolls of paper. No glass screens. 

After writing mastermind (also called bulls and cows I think) I went on to write my own monitor, memory test routines and even a disassembler  I also wrote a crude semicompiler that could process BASIC like statements and produce assembly language. Didn't quite get it finished but it did cause me to be interested in compiler writing although it would take me 10 years to get back to it (with the MIPs 32 bit microprocessor)

Mainly I wrote bits of code to talk to bits of hardware that we were building and interfacing to our microprocessor systems. These were card based, it took several cards to make up a system in the 19 inch wide racks we used, a power supply card, a processor card, an eprom card, a ram card, a serial communication card and a parallel interface card. A modular system was easy to debug and repair. single sided 43 way edge connectors and only a few chips per PCB, this worked well and allowed low cost PCBs to be made in-house, double sided but with soldered thru links.. 

Funny how you learn the laws of unintended consequences. The company had 3 or 4 young bright things of which I suppose I was one. I tended to do microprocessor hardware design which also involved some software. Others focused on repair, (Aubrey Sayers) manufacture/production (Helen Hall) or pure software (Nigel Young). After me came Ivan Bell, Alan Watts and Angela - memory fails here... but the company changed direction a bit in later years. 

When I joined the company it did bespoke microprocessor interfacing, bespoke small scale electronic production as well as being a software house and its medical instrumentation product. (a computerised interface to laboratory blood analysers). Aubrey, the young undergraduate/graduate doing repair got fed up replacing a particular chip on the boards - it always seemed to be the one to go faulty. A 74LS133 chip that looked at a lot of address lines and was used to map boards to particular address ranges (the M6800 had a 16 bit address bus - 64k of space but we only 2k eprom board and 256 byte memory RAM boards at first). The reason why the 74LS133 chips broke was interesting, an education.

The 43 connections had +12v pin adjacent to one of the address lines and when you pulled a board out and reinserted it, if you were at a slight angle the gold finger momentarily connected the +12v to the address line blowing up the '133. This happened because, even with the power switched off the +12v was still present on the smoothing capacitor that was on the 12 volt output, it decayed very slowly. It had been this way for several years before Aubrey's smart thinking tracked down the fault (more a feature I suppose). Adding a 10k resistor across the cap ensured its voltage died away quickly and the number of faults reduced dramatically - we had supplied spare boards to 30 or 40 hospitals across the UK and encouraged user repair by board swapping. Nice one Aubrey!

We also brought in (SWTPC) M6800 systems from the states and these even had floppy disks, this was the start of the home computer revolution, at least in the states and we were in the vanguard of bringing it into the UK. We also brought in software libraries such as floating point maths routines and simple BASIC interpreters, tinybasic (3.5k of code), integer BASIC(4k) and a powerful floating point basic that took up 8k of space. I recall wiring code for a system to be used on television for a quiz game - basically snakes and ladders. It was one of the summers when I worked at MSCS as an undergraduate. I had to load the BASIC interpreter into RAM and then load my code as well - both using paper tape. It took 40 minutes unless there was an i/o loading error when I had to reload the portion of paper tape and try again, I remember one day having to load three times and it took to lunchtime to get the system up. Then there was a power fail and I burst into tears and went home. It is not often an 19 year old man cries...

I learnt a lot at this company, then called MSCS Ltd. When microcomputers arrived we were quick to do smart things with them, I recall having a Commodore PET interfaced to a parallel interface board and using BASIC and machine code to drive parallel voltages to DAC chips to set the gain in a really complex data acquistion system that involved making a fast ADC out of three or four chips and having the ADC feed its data into 16k of dynamic RAM, I built the circuitry to access and refresh the RAM in hardware. This memory meant we could do time travel...

We had been commissioned to make a system that monitored faults in power stations, monitoring many voltages and storing 1/5th of a second of data in memory - in a circular buffer. A separate board detected a power station fault and after a short delay (say 1/10th of a second) stopped sampling voltages and outputted the data into a UV paper chart recorder - which took 60mSec to get up to speed. The buffer had the data both before and after the fault and you could go back in time nearly a 1/5th second to see which voltage went wrong first.

My circuit board had scores and scores of chips, my boss Ken Richey had designed most of the digital parts although I had to modify it to get the timing just right to get the dynamic RAMs to work. The full system went into a wardrobe sized cabinet and was an impressive bit of work. It spawned a company that sold them into the Americas and went on to great things (Power Automation Products and then CSD Ltd).

When the Apple microcomputer came along I was fascinated by it, this was the Apple 2 (Apple ][ and then the ][e) and not the later Apple Macs though I did get to play with the Apple Lisa a bit. The Apple ][ came with an orange book that gave complete design details and a complete industry was spawned making add on interfaces. The back of the microcomputer had 8 slots which allowed adding lots of extra boards to interface to external equipment - really handy for MSCS which was interfacing microprocessors to all sorts of industrial devices

I designed and built lots of plugin boards; serial boards, parallel boards, even bank switched memory boards. These all required software written in assembly language for the Rockwell 6502 which was very similar to the Motorola M6800 I had started with. I made many complete systems, my favourite was used in a lab in the Department of Agriculture in Belfast. It controlled three bomb calorimeters. These had relays that caused a heater to burn all the oxygen in a sealed container that contained pig shit I think. The computer had to wait for a stable initial temperature, trigger the burn and wait for a final stable temperature, the more "fuel" (calories) the higher that final temperature. A human had weighed the sample and had to enter a serial number into the computer.

One of the unique things about the Apple ][ visual display was that not only was it completely memory mapped, there were routines were you specified the coordinates of a box within the display and you could scroll it by calling a routine in the Apple firmware. I wrote a system that split the screen into 4 or 5 and included three vertical columns that showed data for the three calorimeters. These scrolled independently and the various numbers changed and flashed, displayed inverse video etc as the state of each machine changed. Remember this all predates windows!

I recall avidly reading the Byte magazine and Dr Dobb's journal every month and soaking up what was going on in microcomputers. I taught myself USCD Pascal which really replaced all the Apple innards with a new operating system, very interesting. As MSCS was a selling lots of different stuff, the development engineers often got to "test" (play with) things before we shipped them. Hence I also played with the CP/M operating system and some of the other languages it could support. Colleagues used Forth and Fortran, my boss even played with LISP. Often we could use the new technology to deliver a solution to a customer - we got to stay on the bleeding edge of technology and the customer got a product that performed well or could do extra things, 

I also had an introduction to minicomputer programming as we had some bigger systems, bit like the DEC PDP range of machines. I also recall the first 16 bit microcomputer arriving at the factory for evaluation, this was the predecessor to the IBM PC. In fact it ran CPM/86, the first MSDOS was yet to arrive. I remember laughing when the machine beeped and said "ERROR: Keyboard missing, hit [F1] key to continue"

An IBM Dealer manager arrived to assess whether we could sell IBMs. An interesting guy, I had little experience of very (very) big companies and the strict all encompassing culture of IBM was amazing, though not my cup of tea. He said that IBM often setup two factories to make something, at opposite sides of the world sometimes. The job of one factory manager was to make it cheaper than the other one. They also did not add up the manufacturing cost of a product and just add a margin (multiply by a ratio is actually more accurate) to set the selling price. No, IBM had decided they could afford a chunk of money to make PCs (actually only one day of IBM's annual turnover got invested at the start). So to set the price they asked the marketing department, "what is the highest we can charge for these computers so demand is suppressed and we only manage to sell x million of them" This is why the IBM PC was twice the price of anybody else and a large clone market appeared. 

It was a salutary less in business methods that this was a brilliant strategy, "Make it for as cheap as you can and sell it for as much as you can" There are a lot of smart people at IBM.

However the time came for me to move on. Developing products all the time is stressful and can have very long hours, particularly in very small companies. I had been a part time tutor for the Open university and an opportunity came up to apply for a lecturing post in the University of Ulster - actually called the Ulster Polytechnic at the time but the name change was planned for the following year. I successfully entered academia on a "Fresh Blood" appointment and stayed there until I retired.

I never fully embraced the academic side of things, the traditional career route of churning out papers . These sometimes came so fast, one had to doubt their value, but it is part of the game. Besides by doing lots of consultancy I got to play with interesting things and enhanced my salary too - academic research grants got you money too, but you could only spend it on certain things, going to conferences, hiring PHd students and sometimes getting equipment. I also enjoyed the teaching and specialised in embedded microprocessors, both digital hardware and software. In fact as new technology came along I was able to amend teaching curriculums to suit my own interests and got to learn and lecture on Linux as an embedded operating system, 32 bit microprocessors, Internet Socket programming and Real time operating systems (FreeRTOS). To really know something, you should teach it. Geek heaven again!

In the early days you were left alone to become an expert in something and the freedom to study what you wanted was fantastic. I tended to work 60 hour weeks until the Summer and then disappeared with my computer and with a few interesting textbooks to the caravan in Donegal and latterly away abroad in our cruising yacht, France and the Baltic. I set many interesting final year projects for students to undertake; most of colleagues found this a hindrance to their own work but I loved it as an outlet for some of my more outlandish ideas. I was involved with dozens of industrial consultancy schemes; Teaching company projects, Fusion schemes with companies over the border where I mentored young bright things in industry in specific projects for the companies they worked in, usually a new product or product line/area and occasionally new processes. This certainly kept my brain alive!. There were also one week Innovation Voucher schemes where I worked with entrepreneurs on their own, sometimes, outlandish ideas. There were a couple of longer term projects too. All good fun, really good fun.

My interests in Ham radio and Sailing are listed elsewhere, but this is where I came from... so far ok...

15 - Taking Measurements of the modules of an SSB Transceiver

A transceiver has 4 basic modules, repeated in various guises. Oscillators, mixers, Amplifers and filters. I will describe how I tested the modules of my sctratchbuilt uBitx

The list of some of my ham shack test gear that could be used is; 

DVM (even a simple, cheap one - £10 is useful but even better  is to have  2 or 3)

NanoVNA (under £50 this can be used as an antenna analyser and is very useful)

SWR Meter that can measure Power can be useful once the power gets above 1W

Signal Generator - though you can use the transmitter part of a working transceiver. You could make your own but it is probably better to pick up a second hand unit as it will probably be much more stable with more accurate level attenuators. £50 to £100

Oscilloscope, even a cheap 20MHz one (£20 second hand) is useful but the more recent Digital types that pass data to a PC using the USB interface is much better - they sometimes have a very slow Spectrum display. I have a 200MHz one that cost £200.

Component testers; in the old days these might have been a substantial RLC bridge. There are some very cheap modules available on EBAY - the GM328 or LC-100A cost under £15.

Frequency Meter, older units are now available second hand form EBAY for £50 to £100. But there are new uncased PCB modules that cost under £10. They work well provided the input is at a suitable level. At a pinch you could use a working receiver.

Spectrum Analysers, old substantial units are available second hand from £300 upwards (new ones could set you back £1500+) As an alternative you can use a SDR with spectrum analyser software - I use a RSP1a from SDRPlay (£92) although you will need to build an attenuator, The SDRPLay SDR's have properly calibrated input stages that allow display of signals with accurate display of levels to within 1dB but are easily damages at inputs much above 1mW (0dBm) and distort slightly if the input is above -10dBm so keep inputs low for the most accurate readings. They are superb if you do this.

Attenuator - you will need two or three fixed ones and a switched one - I made one with 8 slide switches that can bring in 20dB, 20dB, 20dB, 10dB, 6dB, 3dB, 1dB and 1dB  allowing any values from 0dB to 81dB. fixed attenuators are made up of three resistors so you knock them up as and when you need one. Be careful above 30MHz and check your homemade devices.

Return Loss bridge -If you don't have a NanoVNA you should make a simple one of these  -they only have 4 components and will cost you about 50p plus a couple of connectors - I try to standardise on BNC and use adaptors to convert to and from these if needs be.

An RF Two Tone oscillator is vital for certain types of measurement such as IMD. Slightly more tedious to make, mine has a pair of two transistor crystal oscillators, each built in its own metal Altoids mint tin along with 7 pole filters, the output of each is put into a 3dB combiner/isolator and the whole assembly put in another metal case, made up spare PCB material soldered into a box shape, still only under £10 for the bits

A testbench amplifier - a broadband, well screened unit that can provide 15 to 20dB of gain, at lowish levels of under 50mW output, you might want a higher power one to drive and test 1W and 10W amplifiers - but you will be building these anyway as you build your transceiver - provided you build in the right order! you can build a couple of extra units so you will have them for later projects.

Power amplifier sampler will allow easier testing of the output of driver and PA stages. A high power attenuator would be handy too.

Of course you will also need a soldering iron or 3, desoldering braid, flux and cutters, pliers and probably a couple of magnifiers, one of which should be an illuminated light. - unless you have young eyesight!

I have more than this of course as I hoard stuff and have 2,3 or 4 of everything, but if you were setting up your own lab in the shack using this list you would probably spend £350 to £500. You should make your own gear as much as possible, but you should be prepared to spend money on your hobby. Some people spend much more than this playing golf (per year).

Now to the tests;

Filters, you will be making lowpass filters, as well as crystal filters. Some designs require bandpass filters although the uBitx does not. It has some LC circuits used as matching circuits. The things needing measured are corner frequency, passband loss, passband ripple and Slope in the stopband. All of these can be done using NanoVNA and it can also measure the inductance of any coils you need to wind. Crystal filters are a bit special in that you need to buy more than you need and then to select a group with frequencies that are very close to each other. With care the NanoVNA will suffice but you may need to make a couple of jigs (costing under £1 each) as it is quicker to use a jig and a frequency counter.  

Ampifiers Most of these are low level but the transmit chain might have 4 stages of gradually increasing power, maybe 10mW, 100mW, 1W and 10W (most amplifier designs use gains of 10 or so in each stage - better to be conservative to reduce the chance of instability).  We will want to measure Gain vs Frequency, input and output Impedances (i.e return loss or SWR in a 50 Ohm environment). NanoVNAs are handy for this - provided you use an attenuator on the amplifier output - taking account of the power coming out of the amp - every attenuator has a maximum power rating. Also for the higher power amplifier you will want bench amplifiers to boost the NanoVNA output as most models can only manage 1mW. Protect the NanoVNA input too, using attenuators.

The other parameters you will want to measure is the harmonic content of the amplifier output when amplifying a single signal (you can use a signal generator and spectrum analyser) and also what is the distortion when two signals close together in frequency and amplitude are fed to the amplifiers inputs. This distortion is called Intermodulation distortion or IMD. It indicates non-linearity and the biggest is nearly always due to the third order mixing of (2 * f1 - f2) or (2 * f2 - f1) . This is also known as OIP3 - When the distortion is equal to the desired signal. You look at the spectrum on a spectrum analyser and interpolate the OIP3 as you can never get the output as high as the OIP3 level. This can be a bit tedious and you also need an RF two tone signal generator and attenuators and amplifiers. As an alternative to measuring and calculating the OIP3 you can use a rule of thumb that a drop in the gain of 1dB over what the expected output happens about 13 to 15dB below OIP3 (for amplifiers made of BJTs, ordinary transistors). So we measure  P(-1dB) also known as "Gain Compression" It is easier to do than measuring OIP3 directly - though not as accurate it will give ball park figures. you can use a single signal generator with an attenuator and a oscilloscope (or a simple diode probe and a DVM to measure gain

Actually the OIP3 is usually about the same as the DC power that the amplifier stage takes from the power supply - this is why increasing the current passing through the amplifier devices, either by using bigger transistors or paralleling  4 transistors is sometimes done in the early stages of a receiver - to provide better strong signal handling, important on 40m but it does reduce battery life when operating portable and may make more noise (or less!)

The remaining amplifier parameter is concerned with noise and the minimum discernable signal, (MDS). Measurement of Noise figure (NF) is difficult, current methodology is to use a calibrated noise source and you make noise measurements with it switched on and off, the ratio of these two can be used to calculate the Noise figure using the "Y-Factor" method.

Calibrated noise sources are expensive. Alternatively if you know the NF is low you can use the Hot and Cold method were you heat and cool a resistor and take two readings. Best done with boiling water and Liquid Nitrogen but Ice would do at a pinch, particularly if the expected NF is below 2, not clear (yet) how accurate noise figures of 5 or 6 will fare. One problem with this method is that you need to have the resistance keep its value as the temperature changes - a 0% temperature coefficient. Or maybe that can be fixed using mathematics - if we know the tempco. I haven't done this yet so I am being a bit theoretical.  Another way to measure noise is to use a microwave dish that is good enough quality to be sure of a tightly focused beam path, you can point this at a "cold" sky. 

I will leave noise measurements to the last. I may buy a preamplifer with a known NF (or send it off the someone and get it measured. Once I have that I can make a noise source and test the amplifier using a guessed Equivalent Noise Ratio (ENR) and then amend the guess until I get the right answer!. To be scientific about it I would need to calculate all the expected errors, sum the RMS errors, think about the accuracy of everything and see what the upper and lower limits are or maybe I will keep monitoring EBAY and hope (forlornly) that a dirt cheap Noise Source with a calibration certificate becomes available. By the way, there are uncalibrated noise sources that are useful accessories to a spectrum analyser - if you pass wideband noise through a filter you can see the shape of the filter's response. Such general purpose noise sources only have a few components and can be bought or built for under a tenner.  Mediocre proper noise sources start at £200

Mixers In an ideal world we measure the loss, the noise and the distortion behaviour. Mixers have three ports, low-level RF is applied to one port and a mid-level oscillator is applied to another. Mixing takes place and the sum and difference of the two input frequencies appears at the third port, This describes how they are used on receivers with the RF and Local Oscillator(LO) ports combine to present an output to the IF port, When used as a transmitter the roles of the RF and IF ports are swapped. Noise is usually taken as the loss, this will be close.

To test a mixer we can use two signal generators; one strong, one weak. Then by using a switchable attenuator between either signal generator and its mixer port you can do a series of tests to prove basic functionality - using a Spectrum analyser on the IF port, the IF port must have a 50 Ohm load on it, most SAs have this built in. As well as observing the mixing process on the spectrum you can see the insertion loss, probably about 6dB below the applied RF. A lot of mixers use 7dBm LO levels but higher is better, the OIP3 is close to the power level of the LO and the IIP3 being higher by 6dB or so. Of course you mustn't overdrive the diodes. LTSpice can offer up values to try.

Measuring Distortion is a bit harder, I will focus on 3rd order IIP3 and OIP3 (they differ by the insertion loss) To measure IIP3 you need three signal generators, the Local Oscillator and a RF two tone generator for the RF port, The Spectrum analyser is used to measure the signal levels at the IF Port, there are 4 frequencies generated at the Additive frequency and 4 at the difference frequency. for example the Additive 4 are displayed as two middle signals of ToneF1+LO and ToneF2+LO and the lowest and highest of the 4 are the third order IMD products of (ToneF1*2 -ToneF2) + LO and (ToneF2*2-ToneF1) + LO.

Mixers only work when properly terminated otherwise any signals reflected from the IF port go back into mixer and get mixed with all the signals present, so a smorgsbord of signals come out the IF port where they reflect back to the mixer. This rapidly growing list of spurious tones gives the mixer the opportunity to create more IMD products near our desired signals which will be heard, or at least have an effect on the quality of the final audio signal, clearly undesirable. To get a 50 Ohm load for the mixer will require a diplexor or an amplifier with a broadband Zin of 50 Ohms. The ubitx uses Termination Insensitive Amplifiers designed with the correct Zin. A mixer's output should never feed a crystal directly as the Zin of (any) filter varies such a lot. A diplexor is a filter that passes the desired signal without attenuation and passes any other frequency into 50 Ohm resistors.