Locating Where a Sound is Coming From

For my masters year, half the marks came from one module, the masters project. Being a team effort, we were in a group of three. Putting our heads together, and taking ideas from lecturers, we made a list of potential projects. We knew for one that I wanted to be making hardware, and the other two wanted to use/learn machine learning and maybe FPGA’s. After much deliberation we decided to make a project that listened for a sound, and using time difference of arrival worked out where the sound came from. This post is mostly about the hardware and circuitry designed for the project.

The final board for our masters project. Contains four amplifier sections for the microphones and a micro controller with USB interface.

With a world with a big focus on safety in public places, we thought it would be a good product for the security industry, potentially with links to smart cities. Imagine a shopping center, somewhere with lots of security already. They tend to have lots of security cameras, alarm systems and a dedicated guard. This isn’t uncommon in big public places/attractions, especially in the UK. Sports stadiums, train stations and museums are always looking for new ways to protect themselves and isolate problems. The example that inspired us was the horrendous shooting in Las Vegas at a concert in October 2017, just as we were picking projects. The main problem was that the security services did not know where the shooter was, meaning it took longer to get to him. If they had a system like we envisaged, the microphones would pick up the sound and triangulate it. The location could then be sent to relevant authorities to use.

The front page of the New York times just days after the Las Vegas shooting

To start with we needed microphones. We didn’t need to reinvent the wheel, and microphones can be easily bought off the shelf. For ease we used standard stage microphones, that had 3-pin XLR outputs. Although we had been warned that they would not work they had a good omnidirectional pattern, and had lots of good documentation. One issue with them is the output is balanced, which means it needs to go through a pre-amp. To get an idea of what a balanced signal is, imagine a ground connection and two signals. The two signals are the same, but one is inverted. This means when it travels down the cable it is much less susceptible to interference. This is part of the reason we liked using stage rated equipment, as sound engineers have already worked out issues with transporting sound signals long distances through noisy situations. We concluded from research that the signals could reach over 100m, which was the number we were aiming for.

One of the pre-amplifier sections used on the board, using four operational amplifiers.

Once the signal got to the box it needed to be converted to a signal that could be read by an ADC. To do this we used an INA217, a pre-amp designed for basically this purpose. An instrument amplifier, it measures the difference between the signals and amplifies them, outputting a voltage with reference to ground. The signal from the microphone is tiny, in the tens of milivolts range, so it needed some dramatic amplification to get it near the 5V ADC. The INA217 did a good job but we put a second stage amplifier to give it the extra push, as very large gains can sometimes be bad for a number of reasons. We used an OP07D but if we were to do it again we would get a rail-to-rail to get better results. This amp had a pot as one of the gain resistors so that we could easily trim the gain depending on test. Finally, the signal at this point sat between -2.5V and +2.5V so we needed to shift it up so it was between 0 and 5V. This was done with a simple shift circuit and an amplifier. We used another OP07D to make buying easier.

Me manufacturing the PCB, at this point I was inspecting to see how well it had been soldered.

From here the signal gets read by the 12 bit ADC in an STM32 microcontroller. It then streams the data via the USB to a PC where MATLAB picks it up. This is where my knowledge is a bit lacking as I did not make it. In essence MATLAB uses a machine learning algorithm that had listened to over 1000 gunshots, screams and explosions. It has categorized them, and used a number of features to notice the difference. Then when playing a new sound of one of these things (not heard by it before) it categorizes it and outputs it to the user. It also used a selection of sounds from the background to know when there is not one of these events happening, else there will false negatives.

One of our set ups to get a useful output and test the amplifiers were working properly.

All in all the project did actually work. It detected gunshots and screams being played into the microphone, and the triangulation algorithm worked, just not in real time. We managed to win the best masters project, mainly because we had good quality hardware, a partially working system and a good business case behind it. There is a lot of scope of where this project could go, and many things that could be improved, but we were happy with how it came out. I may be able to use some of the circuitry on other projects, who knows. If you are interested in more of the project, maybe some more detail about the hardware or manufacture, comment or message on Twitter. Thanks for reading.

A good example of how much difference there is between the microphones when a big sound was made. Minute distances made a big time difference.

Semi Autonomous Robotic Platform

As part of my degree I had to complete a project as part of the third year in the field of robotics and electronics. I chose to make a robotic platform, a simple idea that could be completed to a high quality with the right amount of effort. What is a robotic platform I hear you ask? well it essentially is a small buggy/rover that that moves around an assigned area completing simple jobs such as transporting goods, picking up parcels or any job that needs a moving vehicle. Usually autonomous, and very expensive, the majority of systems are very application specific. Some simple systems without any sort of control system can cost tens of thousands of pounds, and are not easy for the average employee to operate. Tackling the problem of expensive, application specific robotic platforms was the basis of my project.

4WD robotic platform
The Nexus 4 wheeled drive mecanum robot has an arduino based control system, and mecanum wheels, but will set you back $1500

Named the Semi Autonomous Robotic Platform, the idea was very simple, make a modular system, with building blocks that could be easily interchanged, and didn’t cost the world. These modules were things like motor controllers, sensors and power systems. If a user had a working platform built from this system, it would take minimal effort to swap out any of these modules to bigger motors or better sensors. This means a user can make a robot and only buy the bits they need, and even make their own modules, as long as they fit to the standard written as part of the project.

system block diagram
The initial block diagram of the system, showing how the modules can be controlled in hierarchy structure.

In most robotic systems, mainly to keep costs cheap, there is one controller that controls everything. This idea makes sense for small integrated systems that don’t need to change, but doesn’t really work when systems need to be dynamic. For instance, say you decide that your DC motors driving your robot aren’t giving you the control you want. You source some stepper motors, but this means completely changing the motor controller and therefore the software that controls it. Because one controller is in charge of everything, the software for the whole system needs to be re-written, and re-tested. That small change could have affected any of the other systems that that controller is in charge of. Make a change that breaks something important, you could set back a project weeks. This shows how painful a setup like this can be, especially when it starts to become a complex robot. Add on top of that the potential for computer intensive algorithms being used on the robot, like route planning or SLAM, and that controller suddenly has a lot to do. My system design separates these jobs out to a selection of individual controllers, such as a system specifically for motor control, or power systems. These controllers can deal with the nitty gritty hardware, and leave the master controller to orchestrate a higher level version of control.

Final Year Project
My design, near the end of the project, with the mecanum wheels, ultrasonic sensors and multiple controllers.

The added benefit of separating out all these jobs means that multiple engineers can work on the same robot, at the same time on different areas and not be worried about breaking the other person’s design. The system specification defines how the modules interact in terms of communication speeds/type, the way to alert other modules and how those communications are scheduled. The master controller (shown in the system block diagram in green) schedules all these communications and decides which modules need specific information. Warnings, control signals and user inputs are all calculated and scheduled, then communicated to and from the required modules. A power system doesn’t care that a user has pressed a button to scroll through an LCD screen, and the master controller means it doesn’t see it.

The above video shows how the robot moves with its mecanum wheels, and how it can easy move around environments. I will explain the more technical parts of the project in a later post, but this simple idea became a very heavy hardware based project, rather than the software project it started as. I learnt about mechanical design, PCB design and good techniques associated with electronic design. For these reasons, the robot won the “Best Project” award for 2017. Thank you to: Cubik Innovation for help with electronic design, and providing PCBs, VEX Robotics for donating the wheels, and Altium Designer for providing their electronic design software. I would not have been able to produce the robot I did without them.

Four Bit Carry Adder/Subtractor Circuit

After creating my 1 bit full adder design found in a previous post, I decided to go for something a little more complicated. I wanted to prove to myself that the ripple carry system worked, so the obvious choice is to make a multi bit device. 4 bits seemed like a good amount, it’s a value used in some early ALU’s so it can be used in a future project. To make it more interesting I added in the ability to make the device a Subtractor at the same time. When you look at the schematic, it only requires one more device per adder, so it’s not even an expensive thing to implement, but adds lots of functionality. As with the 1 bit adder, I have attempted to build this adder using only single logic chips.

4 bit adder-subtractor circuit

The first stage is to know the logic circuit, its widely known and can be found pretty easily all over the web. I’m not going to explain how it’s created (I can always make a separate post on that) but I can describe how to use it. The aim is for the device to take two 4 bit inputs (0 – 15), along with a carry from another adder. So the adder needs to be able to output a value between 0 and 31. In binary this can be shown as 5 bits, so we have 2 outputs. This the S output is a 4 bit bus, and the Co output bumps this up to the 5 bits we need to make 31. A truth table can be made for this but it would be 32 lines long, so too much for this post. You could regard it as a personal challenge if you want to attempt it on your own.

So I got onto Altium and made a schematic of this circuit using some of the low voltage 7400 LVC series individual logic gates that I used on the previous adder I made. They come in SOT23-5 packages which are leaded a nice size to solder. Plus they are a size where it’s possible to probe the pins fairly easily. Luckily Altium shows the components as their logic symbols. Below I have shown the first two adders, the third and fourth are basically the same as the second one, which is the idea of the ripple carry adder.

The first two adders of the four found on the board

I also added a few LEDs to show what parts are on and off. This means the user can see the inputs and outputs. These LEDs run off the 5V input voltage, and have 220Ω current limiting resistors in series with them. Also, I have put in some 0.1 inch header pins so it can be attached into a breadboard and maybe even a micro.

The LEDs for the carry bits and outputs
The LEDs for the input bits

As a base of my circuit, I have decided on a double sided 100mm x 100mm board. This is quite big as you can see for the circuit I have made, but gives plenty of space for a soldering iron to get access. As well as this, it gives a nice amount of space for multimeter probes. I also tried to keep the individual logic chips in a similar arrangement as the schematic. This is meant to be used as a learning device, so it’s useful for the chips to line up with the diagram. The header pins for the inputs and outputs are placed on opposite sides of the board to make it more obvious for the user to see it. And the pins have designators written on the board so the user can see what each pin does. The input and output busses are placed in fairly logical places, and grouped together. There is no point having all the A inputs intertwined with the B inputs. The pins for the power and ground are on opposite sides with their own headers, only one needs to be connected for it to work. The LEDs that are directly attached to the pins are placed closer to the logic circuitry, but labeled clearly on the silkscreen. Most of the routing to the LEDs is on the underside of the board, else the top could get confusing. All the designators for components have been made half the normal size due to the small amount of parts used in the project. The below images show the PCB layout I created with the top copper being red, bottom copper being blue, and the silkscreen shown in yellow.

Top Copper

As you might be able to see, I have tried to keep all the power on the bottom side of the board. This leaves lots of space for the logic signals on the top, where the user is more likely to see. As you can see, most of the inputs and outputs of the circuit are also on the bottom side. This is because the way the busses work and input into the adder needs lots of crossing over and would add confusion into the design. This is why labels were used instead.

Bottom Copper

To make it easier to see, I made a larger image of the first and last adder in the series. As you can see, the only real difference in them is that the first has the add/subtract input shown by an LED, whereas the last shows the carry from the previous adder (C0). This is because the A/D bit is attached to all the adders, but the first bit doesn’t have a carry bit input. The carry on that adder is the input for the A/S. It serves the function of inverting the first bit, so that it works like 2’s complement when in subtract mode.

The layout of the first adder in the series
The layout of the last adder in the series

As noted above I used 7400 LVC series logic gates. The SOT23-5 package chips have the suffix of “BVD”. See the datasheets for each of the devices for more information. I have written a simple bill of materials below:

12x SN74LVC1G86DBVT – XOR gate
8x SN74LVC1G08DBVT – AND gate
4x SN74LVC1G32DBVT – OR gate
17x DO-214 LED’s
17x 0805 220Ω resistors
6x 5-pin 0.1″ header pins

The main downside to this type of adder is that is is very slow. Especially when you get to high bit amounts that you are trying to add. This adder will take at least 4 times as long as a single adder to add the two numbers together because the signal has to propage through 4 full adders. This problem is known as propagation delay, each logic chip will take a very short time to compute the output. Although this time is not perceivable by the human eye, if there are 100’s of logic gates in a row, then the delays start to add up and be a problem. If this circuit is to be used in a computer, it could need to make calculations thousands, or maybe millions of times a second, and a carry bit adder is not generally good at that. There are other, faster adders that I will show in a future post.

One Bit Adder Project

One thing that has always been interesting to me is using logic circuitry in electronics. It’s easy to implement something on a microcontroller in just a few lines of code, but the real challenge comes from making a boolean project using real logic gates. It’s something we all learn about if you have taken a basic computer science class, or even digital electronics. One of the first circuits you ever learn about is the adder. It’s pretty simple, teaches you how to cancel down boolean equations, and only has a few inputs and outputs. I have decided to try and make the circuit using real components, and see if I can get it to work.

full adder layout

The first stage is to know the logic circuit, its widely known and can be found pretty easily all over the web. I’m not going to explain how it’s created (I can always make a separate post on that) but I can describe how to use it. The aim is for the device to take two 1 bit inputs, along with a carry from another adder. So the adder needs to be able to output a value between 0 and 3. In binary this can be shown as 2 bits, so we have 2 outputs. The S output represents bit 1, and the Co output represents bit 2. Below is the truth table I used, if you want a little challenge, try and get the above circuit using boolean algebra.

A B Ci Co S
0 0 0 0 0
0 0 1 0 1
0 1 0 0 1
0 1 1 1 0
1 0 0 0 1
1 0 1 1 0
1 1 0 1 0
1 1 1 1 1

So I got onto Altium and made a schematic of this circuit using some of the low voltage 7400 LVC series individual logic gates. They come in SOT23-5 packages which are leaded and a nice size to solder. Plus they are a size where it’s possible to probe the pins fairly easily. Luckily Altium shows the components as their logic symbols.

1 bit adder 1 schematic

I also added a few LEDs to show what parts are on and off. This means the user can see the inputs and outputs. These LEDs run off the 5V input voltage, and have 220Ω current limiting resistors in series with them. Also, I have put in some 0.1 inch header pins so it can be attached into a breadboard and maybe even a micro.

1 bit adder 1 schematic

As a base of my circuit, I have decided on a double sided 50mm x 50mm board. This is quite big as you can see for the circuit I have made, but gives plenty of space for a soldering iron to get access. As well as this, it gives a nice amount of space for multimeter probes. I also tried to keep the individual logic chips in the same arrangement as the schematic. This is meant to be used as a learning device, so it’s useful for the chips to line up with the diagram. The header pins for the inputs and outputs are placed on opposite sides of the board to make it more obvious for the user to see it. The pins for the power and ground are on the same side on both headers. The LEDs that are directly attached to the pins are kept close to them, and the track is fairly obvious to show where the signal is from. The silkscreen labels which LED designates which input/output. All the designators have been made half the normal size due to the small amount of parts used in the project. The below images show the PCB layout I created with the top copper being red, bottom copper being blue, and the silkscreen shown in yellow.

1 bit adder 1 PCB top

As you might be able to see, I have tried to keep all the power on the bottom side of the board. This leaves lots of space for the logic signals on the top, where the user is more likely to see. As you can see, not all signals are on the top side due to circuit constraints, but signals that do swap over are generally short jump, and straight lines, This makes it more obvious where the tracks go without having to flip the board.

1 bit adder 1 PCB bottom

As noted above I used 7400 LVC series logic gates. The SOT23-5 package chips have the suffix of “BVD”. See the datasheets for each of the devices for more information. I have written a simple bill of materials below:

2x SN74LVC1G86DBVT – XOR gate
2x SN74LVC1G08DBVT – AND gate
1x SN74LVC1G32DBVT – OR gate
5x DO-214 LED’s
5x 0805 220Ω resistors
2x 5-pin 0.1″ header pins