This project has been asleep since 2007 when I published Part 1 and Part 2 of the $10 ATA series. However for a couple of reasons I was inspired at lca.conf.au 2011 to go back to work. So for the past few weeks I have been working on this project for a few hours each day, and have been making steady progress. I now have a really low cost prototype “hybrid” (2 to 4 wire converter) circuit running, which uses an Arduino as the “sound blaster” for audio I/O.
This project is useful the following reasons:
- A way to lower the Bill of Materials (BOM) cost and hence sales price for the Mesh Potato. This means more poor people get telephones.
- It makes the Mesh Potato design more portable to other Wifi System on a Chips (SoC), i.e. any router with a serial console port (pretty much all of them) can be converted into a Mesh Potato. This allows us to migrate the Mesh Potato design to lower cost or more modern (802.11n) SoCs, “future proofing” the design.
- I am intrigued by the idea of recycling old OpenWRT-capable routers into useful mesh telephony devices. More on that below.
- It’s a stepping stone to some other low cost Wifi router + micro-controller projects I would like to see happen, like the Louder Router, small automated AM/FM radio transmitters for villages, and HF Mesh Radio.
- I want to know if it can be done. Geeky curiosity. Can we really build a FXS port with a few $ of analog components and a micro-controller?
- I kicked off the idea 4 years ago so I feel committed to finishing it. One day.
The Mesh Potato project absorbed a lot of the ideas I originally had for the $10 ATA. For example using RS232 serial for SoCs that don’t have a TDM or USB port, and signal processing (echo cancellation, DTMF detection) on low end router CPUs. One nice outcome is that we now have many of the software components, e.g. a low latency serial port kernel mode device driver, an Asterisk channel driver, and user mode echo cancellation. On the Mesh Potato project I gained a lot of experience with the approach of using RS232 serial for PCM audio, so we know it can be done.
RS232 Serial or USB?
Although a bit “old school”, I like the idea of using RS232 between the micro-controller and the host router. The reasons were discussed in some detail in the Part 1 $10 ATA blog post. One big advantage is every OpenWRT capable router has a serial port. This makes it possible to turn any router into a Mesh Potato. In particular we know how to use a router’s serial port without SoC vendor support (e.g. detailed data sheets). Vendor support for the AR2317 SoC was a big problem with the Mesh Potato – the full data pack and support package for this chip costs $100,000 which we just couldn’t afford. So sticking to SoC peripherals like RS232 serial ports that are well understood can make life a lot easier.
However USB is also a great idea. Angelos Varvitsiotis was inspired by the $10 ATA idea to develop his very cool Open USB FXS dongle. This uses a Silicon labs chip set for the FXS port, and a PIC microcontroller with internal USB support for the interface to the host PC. Angelos has worked hard on this design for some time and it has recently been featured in Elektor magazine. A neat output of this project is a micro-controller based USB back end for FXS ports (USB drivers, Asterisk drivers etc).
To access the RS232 on OpenWRT routers you need to open them up. However modern routers have external USB, and USB can also be used to connect with any PC.
So it’s possible to take the low cost FXS circuits based I am developing here and fit them to either a RS232 serial or USB back end. I’ll be starting with RS232 as that’s what I am interested in, but I also look forward to seeing a USB version developed (maybe by some one else) one day.
Telephone Hybrid Requirements
As discussed in Part 1, telephones have a DC path (loop current), and an AC audio signal path for transmit and receive audio. All on the same pair of wires. The hybrid works with the AC audio signals. Some of the functions are:
- Take unbalanced (signal plus ground) transmit audio from a DAC and send it down the telephone line to the telephone. The transmit signal must be balanced, so when one side of the pair goes up to V volts, the other must go down to -V.
- Extract the balanced receive signal from the telephone line and convert to an unbalanced signal ready for ADC conversion.
- Two to four wire conversion. This needs a little explanation. In analog telephony the transmit and receive signals are both present on the same pair of wires. So the receive circuit must try to separate them and recover just the receive signal alone. This is done by subtracting the transmit signal and sending what’s left to the ADC. Separating the combined transmit plus receive signals into separate signals is known as two to four wire conversion. This separation is never perfect, so you always get a little transmit audio in your receive audio. That’s where echo cancellation comes in. As long as the hybrid can make a good attempt at separating the signals the echo canceller can take it from there, removing the remaining transmit signal. So 6-12dB suppression of the transmit signal in the receive audio is usually good enough.
This figure illustrates the hybrid in action. It’s from an earlier series of posts I wrote on echo cancellation.
Open Hardware to the Rescue
I am a weak in analog design. However over the past few years a couple of very nice guys have sent me circuits for low cost SLIC (FXS port) designs. This was just what I needed, some people who know more about analog design that me to step in and give me a few tips. This is one of the great things about Open Hardware – you meet all sorts of really smart people who have the skills and motivation to help. One great side effect is learning about analog design from guys much cleverer than me. Just like I can learn about software by looking at open source code.
I have used a circuit sent to me by Ken Boak, which was developed by Ken and Radu Constantinescu. I have also received another design from Manoj Desai, thanks Manoj. Details of Manoj’s design are in the “Open FXS & SLIC Designs” section of my Open Hardware page. Either design would have been fine for this project, I just happened to try Ken’s design first. Thanks Ken for kindly answering my many questions via email.
How the $10 ATA Hybrid works
Here is a PDF of the current hybrid circuit.
Gyrator 1 and 2 are like electronic inductors. They block any AC signals (like phone audio). The operation of the Gyrators was described here. A useful side effect is biasing each side of the telephone a few volts away from AGND and VBATT. This means the balanced audio voltages to and from the phone stay a few volts away from the AGND and VBATT rails. In the previous $10 ATA design, I didn’t have Gyrator 2, this side of the phone was just grounded. So this version was unbalanced and susceptible to picking up hum, plus half the signal would be lost as one side wasn’t being driven.
During transmission onto the telephone line U1C and U1D drive the line differentially. C6 and C7 decouple us from the negative DC voltage developed across the telephone handset.
The 560 ohm resistor R13 sets the transmit and receive line impedance (nominally 600 ohms). During receive the telephone sends balanced audio to our hybrid via C6 and C7. The low impedance output of U1D means the voltage on pin 14 will not change in response to AC signals, it is like an AC ground. So due to the C6/C7 capacitive coupling the entire audio signal from the telephone will be developed across R13. So the AC equivalent circuit is like this:
Zl is the impedance of the phone (roughly 600 ohms, but in some countries there is a reactive component as well), and Vl is the AC voltage the phone is sending. There is a detailed explanation of the telephone model in the Part 1 blog post.
A difference amplifier (U1A) is used to perform 2 to 4 wire conversion. It subtracts the line voltage across R13 from the transmit signal to give us the single ended receive signal that is sent to the micro-controller ADC. R19 and R20 form a voltage divider that samples the balanced transmit output. Another voltage divider is formed by R13 and the telephone’s AC impedance, Zl.
D3 and D4 provide some protection for large input signals, for example 20Hz ringing at 100 volts peak-peak.
When I built this circuit I experienced AM radio break through. I could listen to the news about the February 2011 Egyptian demonstrations quite clearly on the telephone handset. This stumped me for a few days. Adding small capacitors to the input nodes of the circuit had no effect. I even rebuilt the circuit “dead bug” style on a piece of PCB to give better grounding. Eventually, more through luck than engineering, I found that adding C14 and C15 removed the AM radio pick up. I guess the phone lines were picking up strong local radio stations that were being demodulated (“detected”) by p-n junctions inside the op-amp. After describing this to Ken he also suggested series RF chokes in the wires leading to the phone connector .
Audio Record and Playback with an Arduino
Now that we have four wire transmit and receive audio I needed a way to sample the signals. So over a few days I wrote this uart2analog Arduino program. Actually it’s standard C code, not an Arduino project. I wanted to use Arduino hardware (they are ubiquitous now), but not the Arduino GUI. This project pushes the capability of the Atmel microcontroller so we need to get close to the bare metal. There is a Makefile to take care of compiling and download instructions are in the project README.
I am used an Arduino Duemilanova which sports an ATMEGA368P. Trivia – Duemilanova means 2009 in Italian, thanks Rosemary for the translation!
The uart2analog program takes RS232 samples from a Host PC and “plays” them out the PWM port. It simultaneously samples using the ADC and sends the samples to the Host PC via RS232 serial. There is some crude averaging to handle sample rate conversion. Combined with the hybrid circuit it actually works quite well, here is some recorded audio. This is another sample recorded while simultaneously playing the previous sample, to demonstrate full duplex audio. You can hear the effect of the hybrid suppressing the “played” (transmit) signal, only a little bit of it comes back as echo. I can also hear some effects of the coarse (8 bit) quantisation.
Eight bit linear sampling is unlikely to sound as good as a custom FXS chip set (like the Silicon Labs chip set we use for the Mesh Potato). The current hardware layout is rough, with long unshielded analog lines and poor power supply filtering on the ADC. A proper PCB should help that. But it’s a good start, and should improve with some hardware and software tweaks. In Part 2 I recorded this sample, using different software and hardware. This sample sounds cleaner to my ears, with a better high frequency response. I’ll need to track down the differences in these two samples some day. But it’s actually it’s quite amazing how good 8 bit linear audio can sound. Good enough for my purposes, anyway (developing world telephony).
I used a x86 laptop as the host, and a user mode host program to record and play samples to/from disk files. User mode PC programs suffer from big delays (10’s of ms) between Serial I/O system calls as the PC swaps between tasks. This means the RS232 output from the PC will be bursty. It sends nothing, then a big burst every several 10’s of ms. So I found that a large FIFO buffer was required on the Arduino program (1800 bytes) to get good quality audio with no gaps through RS232 serial. This is almost all of the micro-controllers 2k RAM.
For real world VOIP use we need to hack the kernel mode serial driver to have low latency response to serial port activity. This is also necessary to get a constant, known delay between the transmit and receive sample stream, a requirement for echo cancellation. Anyway, I did all that for the Mesh Potato so it will be straight forward for the $10 ATA. In the mean time the user mode host sampling code is OK for basic testing, and lets me focus on the hardware rather than recompiling kernels and developing on embedded boxes.
The ATMEGA368P chip I am using can do 10 bit PWM and ADC, we could use this if we implement mu-law companding on the micro-controller with look-up tables or some C code.
Open Hardware and Local Manufacture
One key feature of the $10 ATA is the use of easy to find, “garden variety” analog components. With the exception of the micro-controller they could even be recycled from e-waste. No special chip sets, no surface mount.
A cool project for your hacker-space might be recycling old routers into Mesh Potatoes, then using them for local free telephone networks or shipping boxes of them to developing countries to build mesh telephony networks. Some more details on this idea at the bottom of the lca.conf.au 2011 post.
I would also like to try building $10 ATAs in developing countries. This is a meme of Open Hardware that I have dreamed about for years but never tried until now. In the Dili Village Telco project there was some local assembly of the Mesh Potatoes (drilling boxes, soldering cables), and the Timorese guys absolutely loved it. So I think their is a big appetite for local assembly in the developing world. Recycling e-waste, low end user cost, and local manufacture could be very empowering compared to importing expensive 1st world goods. I have this vision of people in developing countries recovering analog components from old TV sets, CFL Light bulbs and PCs, then hacking old routers into Mesh Potatoes, or maybe other useful devices.
- Design a micro-controller based DC-DC converter that can supply -24 to -48V VBATT and ringing voltages. I made some progress on that in Part 2, but there is still a lot of work to do. I am intimidated by control system design so need to think about this some more. Last time I worked on this I blew up my micro-controller by putting -100V into an ADC input! So I might pay a little more attention to protecting inputs this time around….
- On and off hook detection hardware and micro-controller logic. Detecting off hook during ringing can be tricky.
- Develop a way to send hook detection and ringing commands thru RS232 serial, multiplexed with voice data. This will save some GPIOs, and the bandwidth is trivial, a few bits/s.
- Develop OpenWRT patches for common routers that include the low latency serial driver, chan_mp channel driver and Asterisk, Batman, and config files.
- Design a full schematic and PCB for the $10 ATA, including the micro-controller. For the PCB design we need to pay attention to good analog layout, like single point grounding, and isolation of hybrid and DC-DC converter sections.
- Organise some trial workshops in developed or developing countries to try building some $10 ATAs and fitting them to routers. To support this maybe publish a Wiki with debugging and step by step testing information.
- $10 ATA Part 1
- $10 ATA Part 2
- $10 ATA SVN, circuits, source code, Makefiles, simulations, notes on downloading to Arduinos.
- Project Google Group Mailing List which has been dead for years. I’ll answer questions on it or via comments on this blog post.
- Gyrator DC Characteristic
- How echo cancellers work