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.

Considerations When Making a Current Shunt Sensor

For battery powered projects, current consumption is a really important consideration when designing the circuitry. While designing my final year project I spent a huge amount of time researching how to put together a simple current sensor. Considering most applications for me are DC, fairly low current and low voltage, the most obvious design is to make a current shunt. The basic idea of a current shunt is that you put a very low value resistor between the circuit you want to measure and ground, and measure the voltage across it. When one side is of the shunt resitor is ground it is low side, there are also high side versions but are mlre complex. As the resistor has a small resistance, there will be a low voltage drop (usually mV) across it meaning it shouldn’t affect the load circuitry. The voltage will also be proportional to the current running through it, meaning if you measure it, and do the right maths you can get a consistent and reliable current reading. This post is about how to get that tiny voltage into 1’s and 0’s, while thinking about the considerations that have to be made about the design to make it accurate and reliable in the environments you want.

Final Year Project
My final year project needed current sensors on the motors as well as monitoring the drain on the battery.

The first thing that needs to be decided is the shunt resistor itself. A shunt resistor is basically a low value resistor, with very tight and known tolerance usually with a fairly high power rating. It can be used in AC and DC circuitry, with the concept behind it being that as a current flows  though it, a voltage is induced across it. The voltage can then be measured and using a simple calculation (based on ohms law) converted into a value for current. The value of the resistor depends on what it is measuring and what is measuring it. Start with what is measuring it. If you are like me, it is likely that it will be read by an ADC, probably on a 5V or 3V3 microcontroller. The voltage across the resistor is going to be amplified between 10 and 100 times (we will get to why in a moment) so pick a maximum voltage within that range. I tend to go with 100mV maximum voltage drop, which for a 5V ADC would require an amplification of 50. Then, take the maximum value of current you want to be able to measure. You can then use ohms law to figure the resistance you need. For example if I wanted to measure 1A, the resistor would be 100mV/1A = 100 mohm. Now we know the resistor value, use the power equation to work out the power eating we want. For this example we would need P = I V = 1 x 0.1 = 100mW. This is the minimum power rating you need, I personally would get a 250mW or even a 500mW just to keep the temperature of the circuit down.

The simple equation to work out what sizesunt resistor to use. Credit: Texas Instruments 

Now we have a voltage that will be somewhere between 0 and 100mV with reference to ground. We want this value to be scaled up to 0 to 5V. To do this we are going to use an operational amplifier. There are plenty out there, and most people have their favourites and I’m not here to convince you otherwise. I tend to use an op amp that I am using somewhere else in the circuit to make life easier. There are a few things you do need from an op amp in this circuit though, it needs to be rail to rail, and have a low input offset voltage. Offset voltage in an op amp is the voltage difference on the inputs, and even though they are tiny differences they can have a big effect because we are amplifying small voltages, and any noise or offset will be amplified too. The op amp needs to be in a simple non inverting configuration. The equations needed to design this are in most first year textbooks and there are plenty of calculators online. I have set a gain of 50 in my calculation, which is in the fairly common range. The output of the amplifier can then go straight straight into an ADC to be measured.

The basic layout of a current shunt sensor showing where the shunt resistors and gain resistors go in the circuit. Credit: Texas Instruments 
The first version of my current sense test circuit, using an OP170 made by TI.

Now let’s look at a few places where errors can come into a design like this. There are two types of errors that occur in a circuit like this, gain error and offset error. A gain error is one where the output error gets further away from the ideal output as the current gets higher. An offset error is one that has the same amount of error whatever the input, just like an offset. The only common source of offset error in a circuit like this is from the offset error in the op amp discussed previously, solved with an improved choice of amplifier. The gain errors are usually due to a difference in resistance from the ideal. Many things can cause this, one is the tolerance of the resistor used, we want to use a precision resistor of 1% or less tolerance. Another cause could be temperature changes in the resistor itself, it may be next to a large MOSFET or other hot component, or could have too low of a power rating making it heat up, wither way a change in temperature means change in resistance. Layout can also be an issue, if tracks are too thin or too long they can add extra unwanted resistance.

Great graphs showing the difference between gain an offset error. Credit: Texas Instruments.

If you want to add a bit of fancyness into the project, or really need to measure down to low currents, you need to tackle the zero-current error. The problem is that when using an op amp, even a rail to rail one, it never quite reaches the power rails. Even the best ones can only get within 100mV or so of the power rails, this is known as saturation. Solving this involves moving the power rails slightly so the saturation point is less than ground. If you have a negative voltage rail you can use that but home projects tend to be single supply, so we need another power source. This can be made using a voltage inverter (a type of charge pump). Usually only needing an external capacitor to work, they are cheap and easy to integrate into a project. I used a LTC1983, which creates a negative 5V rail, but there are plenty of others such as the LM7705. Research what fits your circuit and cost point, and just attach the negative output to the negative supply rail of the op amp.

 A great graph showing how the zero current error occurs, and what it would look like if you tested it. Credit: Texas Instruments.

Most issues with error can be fixed during the hardware design phase. You can pick better op amps, such as ones designed to combat offset voltage. Some amplifiers have internal calibration procedures, and some such as chopper stabilizers are specifically designed to correct these problems. You can also use a potentiometer instead of a power resistor, but they are more susceptible to temperature and can be knocked. Another way is to fix issues in software by creating a calibration procedure. Using a calibrated precision current source and a multimeter, measure the reading of the ADC and compare the value to the reading from the instruments. You should get an offset and gain value that can then be used to calibrate the sensor.

A simple set up that I used to calibrate an early sensor, with a big power resistor as the load and a variable power supply to change the current. Marked down to put into calibration.

I would suggest trying out a few of these sensors in future projects, they don’t cost too much, and can be a valuable addition to a design. Especially for power sensitive devices, or smart sensors, this could be a better solution than an off the shelf or breakout board solution. If you want to hear more about my current sensor designs, and how well the testing and calibration went then comment or tweet at me. I already have some documentation that I may release at some point.

Follow @TheIndieG
Tweet to @TheIndieG

Getting Ugly, Dead Bugs, and Manhattan Style

If you are anything like me, you love to build small circuits. I like to try and get my head around how things work by making it in front of me. This is usually in the form of breadboarding, but sometimes that doesn’t cut it, and soldering is needed. Veroboard tends to be my go to for building a simple circuit as something a bit more permanent, but it doesn’t always lend itself to certain designs. Take a design with lots of grounding points in the design, like an RF circuit, it can be difficult to have lots of ground strips everywhere, and the extra capacitance can mess with those high frequency signals. Also, designs with lots of different separate signal traces going round the board can make for a real pain. lots of slicing the traces, which tend to lead to mistakes. With my constant desire for order and straight lines, and pretty layouts this can get annoying quickly. Recently I have found a few new and simpler ways to throw together simple circuitry. For any budding electronic engineer, they are good skills to add to an arsenal.

A veroboard design of a hybrid microphone amplifier and level shifter I made for a recent project, prototyped on veroboard, many mistakes were made.

Ugly Circuits

As the name suggests, ugly circuits are not always the prettiest of designs. There are a few different definitions of what makes an ugly circuit, but my favourite is any circuit where the components are not completely mechanically connected to the substrate. The substrate usually being a copper clad board, but not always. This method can be a tricky one to master, as it is literally a balancing act. The prefered method that I see this being used is having a single copper clad board as a giant unobstructed ground plane. Two wire passives are usually the easiest to start with (standard resistors/capacitors), soldering one side to ground, then soldering the other side to another component in the air. This means any point that is not grounded is usually floating physically in the air (but depending on how good you are it could have floating voltage too). This can be a big benefit to RF circuitry or circuits that need good solid grounding. The unobstructed copper clad board means anything connected to it has a great connection to ground. It is fairly easy to build simple passive filters, but gets very fiddly and fragile if you aren’t careful.

A very “haywire” circuit constructed in the ugly style by Rick Anderson – KE3IJ in 2006. An experimental stage of his AGC-80 Regan receiver.
Not sure on the origin of this one, but it is more chaotic rather than ugly. It is definitely in the ugly style.

Technically ugly circuits don’t have to have a substrate at all, although it makes life easier. There are plenty of examples out there of ugly circuitry that just connects pins to pins via small wires. As said before, it can be very fiddly to make a circuit like this, but it is much cheaper to make singles as there is no need for expensive copper clad board. Plus after plenty of practice one can get very good at doing it. The wires connecting the parts together can be part of the structure of the unit, and if designed correctly could be very strong. The construction method can be useful in certain circumstances, and as long as you have the components, it can be build easily with just a soldering iron and solder. Although there are some amazing looking circuits made from this method, the majority do earn the name of an ugly circuit. If you can make a pretty one I would love to see.

Nathanxl at the Electro music forums creates some amazing almost artistic music project using the ugly style, but they look incredibly hard to make.
An Arduino Uno made without any substrate, just wires and components. Made by Kimo Kosaka, it is not an ugly, but it uses an ugly style of construction.

Dead Bugs

No, this method does not actually use dead insects as a manufacturing material, but it may look like it. The idea is to take an IC, traditionally in a DIP package, and place it upside down on the substrate. Usually glueing, but not always, with the pins facing upwards, so it has the look of a dead bug. The pins can be bent to attach to the substrate if required, but they tend to be facing up. Taking many methods from ugly, the pins are usually directly connected to passives or wires to other chips. This means the mechanical connections are usually in the air. The benefit to this method is that you don’t have to waste time drilling holes in in the substrate, and can integrate IC’s into an ugly design fairly easily. If trying to use this method, just be weary that all the pins on the chip will be the wrong way round as it gets flipped when placed upside down. I recommend making your own diagram to go from to make life easier.

As you can see in this use of dead bug mixed with ugly construction made by JCHaywire is the chip flipped over and the pins moved about with all the connections floating in the air

Although not really dead bugs, the concept can be seen in many modifications of PCB’s. It is easy to order the wrong package or get sections of pins wrong when designing and ordering PCB’s, especially if you have manually made the part. So it is not uncommon to find upside down IC’s on prototype PCBs or even sometimes on short runs. That being said, anything smaller than a DIP or SOIC package can get very fiddly, and is difficult to hand solder, and will need some extra magnification. Don’t be deterred though, there are many examples of even QFN and even BGA devices being hand soldered in the dead bug form, with very thin gauge jumper wires. With plenty of practice and spares, it can be a useful method of saving money without having a new run of PCB’s.

A bodge on a PCB before the real chip arrives, a 6650 is being used in dead bug style to get the circuit working by Dave Curran.

Manhattan Style

This one is my favourite styles of circuit design on the cheap and quick, and if done right can be very pretty and efficient. The big issue with the ugly method is that it is difficult to create, and often difficult to follow, and horrible to document. Manhattan is an upgrade, using cut out sections of copper board as small islands, much like manhattan. This method means there are no connections floating in the air, as all points on a component are mechanically connected to copper clad in some way, even if it is only a small bit. This leads to generally a much nicer laid out board, that can easily be followed and replicated. It also allows for use of SMD components, which is possible with ugly, but very difficult. The small pads don’t have to be separate, they can simply be cut outlines on the same backplane, making the process cheaper, but get it wrong and it can get messy. I much prefer manhattan as a quick construction method, due to its neat look and ease of use. Another reason for the name Manhattan is the fact the capacitors and resistors tend to line up and are perpendicular to the substrate, looking a bit like tower blocks and skyscrapers like Manhattan itself.

A great example of Manhattan style soldering by Dave Richards. Solid copper substrate with QRPme pads to attach components together. 
Another impressive circuit in the Manhattan style by Dave Richards, this one is a high performance regen receiver, with a full write up on his blog.
An example by VE7SL – Steve of making his own pads for his amateur radio transmitters and receivers, using an Ebay punch to make the pads.

One step on from Manhattan style, and the final step before fully fledged PCB’s is a little known style called Pittsburg, much like the steak. I have also seen it be called muppet style, and I am sure there are many other names for it. It is very similar to an actual PCB, usually etched, a layout is carved into the board, with traces and pads. The difference from a PCB is the fact there are no holes anywhere to be seen. Meaning you get the benefit of being able to etch a nice looking layout at home, and the benefit of not needing expensive routers/drills that quickly break. To allow for the pads to be soldered to as the main mechanical connection they are much bigger to allow for more solder on a bigger surface area. These pads would be overkill for a thru hole project, but also allows for easy use of SMD components. You can sometimes see specialist pads like Pittsburg to use SMD chips on a Manhattan style board. It is a matter of taste and confidence. These methods are obviously not suitable for all prototypes, but could come in useful for your next project. 

A Pittsburgh style PCB at one point sold by Joe Porter, unsure if they are still sold.

A good source of the small pads used in Manhattan can be found here. Reasonable price, and if you are doing lots of prototyping you can even buy the tools to make it yourself!

Thank you for reading, take a look at my other posts if you are interested in space, electronics, or military history. If you are interested, follow me on Twitter to get updates on projects I am currently working on.


How the Type G Gate Worked

apollo 3 input NOR gate
An image of the silicon die inside the Type G 3 input NOR gate used to power the Apollo Guidance computer.

Previously I went through the three input NOR gate that ran the Apollo Guidance Computer and how the circuit works. Previous to that I also told the story of how this chip partially funded Silicon Valley as we know it today. This post builds on that and goes through how the silicon works, and the simplicity of the circuit. Quite a famous image of the chip, fairly detailed image of the silicon inside the device spurred on this post, and taught me lots about silicon that I want to pass on.

apollo 3 input NOR gate schem annotated
The schematic of the 3 input NOR gate. From the schematic of the Apollo Guidance Computer. Annotated with my own designators for reference.

The above schematic of the 3 input NOR gate is also shown in previous posts. It is from the NASA Apollo Guidance Computer schematic, but I have annotated it so that I can reference to specific parts. It is a handy schematic considering it was right at the start of the development of semiconductors. The first image in the post is the best image of the silicon, but is not very big. The biggest image I can find is not quite as sharp, but is much better to annotate, it is the same chip. The first annotation shows the pinout of the device, and how those pins actually connect to the pins.

apollo 3 input NOR pin out
The silicon of the 3 input NOR gate with annotations to show which pin is connected. The pin numbers are from the schematic.

Showing how pins are connected
An image showing how the pins coming off of the silicon are connected into pins of the flat pack.

The noted parts of the above images are pins 5 and 10, and are the starting points to deciphering the layout. If you look at pin 5 and 10 on the schematic, they correspond to GND and power respectively. They are the only pins that are shared between both NOR gates. Apart from that the two sides look remarkably similar, and are basically a mirrored version. To figure which is ground and which is power, the resistors need to be taken into account.

apollo 3 input NOR gate resistors
The resistors on the silicon of the device. Shown above as brown lines they are P doped silicon that act like a resistor.

The above image shows the resistors found on the device. They tend to just be a thin section of P doped silicon, and above connect two sections of aluminum to form a resistor. It is also noted that there is big section of brown surrounding the whole circuit. Although it functions like a resistor and is made in the same way, it is puterly for ESD purposes, protecting the circuit. This big ring also is a big hint that it is connected to ground (pin 5). the second hint is that GND has no resistors attached to it on the schematic, but power has two. They are R1 and R2, connecting to pin 9 and 1 respectively, and are pull up resistors. Pin R3 to R8 are simply the base resistors for the transistors. They are all roughly the same size, and are there are 6 of them. The transistors are also fairly obvious in the centre of the silicon.

apollo NOR gate transistors
The centre silicon from the Apollo 3 input NOR gate. The transistors have been shown, and the collector, base and emitter also shown,

The above image is showing the heart of the device. the 6 transistors that make it resistor-transistor logic. As you can see in the above image, all the collectors are connected together, connected to pins 1 and 9. If you look closely, the base and emitter of each transistor sit inside a brown section like the resistors. This is P doped silicon and forms the base-emitter junction. This allows the base and emitter to sit anywhere within that P doped silicon detection to work. This means that the transistors do not conform to the standard Collector-base-emitter topology. All of the emitters are also connected together via the aluminium placed on the top, but the P doped sections of each device are seperate. As all the transistors of each device have common emitters, it doesn’t matter that they are all connected together, by design, only one of the transistors needs to be on for it to function.

Ken Shirriff transistor side view
A great image showing how the transistor works from a side view by Ken Shirriff.

The above image found on Ken Shirriff’s blog shows how the transistor works with the emitter and base in the P doped silicon. I may do some more posts about it, but his blog is a great place to find more information on silicon reverse engineering.

Electronics world 1963
A cutout from electronics world in 1963 showing the new process of planar technology. This method was used to make the NOR gate.

The above image is an interesting one I found while researching this chip. A section in electronics world 1963 showing how micrologic is made. The type G chip was part of the second batch of micrologic circuits. This section was useful to see how silicon was actually manufactured, and in some ways, still is today.

The NOR Gate That Got Us To The Moon

Type G micrologic
The Fairchild Type ‘G’ Micrologic gate for the Apollo Guidance Computer – this is the flat pack verison

In a previous post I talked about how the going to the moon kick started the silicon age. If you haven’t read it, it is short but really interesting story about how NASA made Integrated circuits cheap, and partially funded what we now know as Silicon Valley. In this post I am going to take a slightly closer look at the circuit that ran the famous type “G” Micrologic gate that ran the Apollo Guidance Computer.

apollo 3 input NOR gate
The official NASA schematic of the Type G micrologic gate found in the Apollo Guidance Computer

As you can see in the above image, the circuit was not particularly complicated. You have to remember that this is very early logic, before CMOS or NMOS or any other fancy IC technologies. This is basically two 3 input NOR gates, they both run off the same power, with pin 10 at the top, and the negative which was likely ground being shared on pin 5. The output for the left NOR gate is pin 1, and the output for the right is pin 9. The three inputs for the left are pins 4, 2 and 3, with the right having pins 6, 7, and 8 as inputs. Simply put, the output is “pulled” high to power when all the inputs are OFF. The resistor between pin 10 and pin 1 (or 10 and 9) are a simple pull up resistor as you would find in most electronic circuits. As expected with a NOR gate, the output will be only be ON when all the inputs are OFF. When any of the inputs are ON the output of that gate will be pulled to ground. One two, or all the inputs can be on, but it just needs one to turn OFF the output. The resistors going into the base of the transistor are just to limit the current.

3 input NOR
My breadboarded version of the 3 input NOR gate, it is made with BC547 transistors and a DIP switch. the output has been inverted with the LED.

I made a simple recreation of this circuit using BC547 NPN transistors, but most NPN transistors would work, these were ones I found in my parts box. As you can see in the image above, I have made it on a breadboard, with the inputs being a DIP switch attached to the power (5V in this case). The base resistors for the transistors are 1K and the pull-up to 5V is a 10K. I recommend making up this circuit if you want to learn a bit more about logic, and is a cheaper method than going out to buy 74 series logic chips! As you can see in the images there are a number of states that I showed the circuit in, and notice that if any of the switches are on, the circuit turns on, this is slightly against what I mentioned earlier, but thats due to the output LED using the transistor as a current sink, not a source, so the output is inverted. Basically, when the output is 0 the LED turns on. The only time the LED is off (output high) is when no switches are on, meaning all the transistors are off.

apollo 3 input NOR gate
An image of the silicon die inside the Type G 3 input NOR gate. We will be going through how the layout works in a future post.

The final point for this post is why the circuit is actually quite inefficient. Modern logic is amazingly low power compared to this. One of the biggest issues is that it is always taking power in some way. When the inputs are off, there is still some leakage through the pull up resistor, when an input is on, then there is current going through the resistor to ground. Also, by the nature of the transistors there is always parasitic leakages, and inefficiencies in the process. They are only small numbers, but the AGC used over 3000 of these circuits, so the small leakages soon add up to draw some hefty power needs, especially for battery powered operations.

If you enjoyed this post, take a look at the rest of my blog, there is lots about space, electronics and random history. I am always open to ideas and feedback, and where is best to post links to my posts.

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.

How Going To The Moon Kick-started the Silicon Age

In the late 1950’s, there were three people who were at the epicenter of a huge breakthrough in the world of electronics, the invention of the Integrated Circuit (IC). Jack Kilby of Texas Instruments, Kurt Lehovec of Sprague Electric Company, and Robert Noyce of Fairchild Semiconductor. In August 1959, Fairchild Semiconductor Director of R&D, Robert Noyce asked Jay Last to begin development on the first Integrated Circuit. They developed a flip-flop with four transistors and five resistors using a modified Direct Coupled Transistor Logic. Named the type “F” Flip-Flop, the die was etched to fit into a round TO-18 packaged, previously used for transistors. Under the name Micrologic, the “F” type was announced to the public in March 1961 via a press conference in New York and a photograph in LIFE magazine. Then in October, 5 new circuits were released, the type “G” gate function, a half adder, and a half shift register.

The Type F flip flop
Junction-isolated version of the type “F” flip-flop. The die were etched to fit into a round TO-18 transistor package

Type F life image
Physically-isolated Micrologic flip-flop compared to a dime from LIFE magazine March 10, 1961

These first few integrated circuits were relatively slow, and only replaced a handful of components, while being sold for many times the price of a discrete transistor. The only applications that could afford the high prices were Aerospace and Military systems. The low power consumption and small size outweighed the price drawbacks, and allowed for new and more complex designs. In 1961, Jack Kilby’s colleague Harvey Craygon built a “molecular electronic computer” as a demonstration for the US Air Force to show that 587 Texas Instruments IC’s could replace 8,500 discrete components (like transistors and resistors) that performed the same function. In 1961, the most significant use of Fairchild Micrologic devices were in the Apollo Guidance Computer (AGC). It was designed by MIT and used 4,000 type “G” three input NOR gates. Over the Apollo project, over 200,000 units were purchased by NASA. The very early versions were $1000 each ($8000 today) but over the years prices fell to $20-$30 each. The AGC was the largest single user of IC’s through 1965.

apollo guidance computer logic module
Apollo logic module assembled by Raytheon to be used in the AGC

Type G micrologic
Philco Ford also produced the Fairchild Type ‘G’ Micrologic gate for the Apollo Guidance Computer – this is the flat pack verison

Note that although Fairchild designed and owned the type “G” device, they were mostly made by Raytheon and Philco Ford under licence from Fairchild. Over this time many semiconductor manufacturers such as Texas Instruments, Raytheon and Philco Ford were also making large scale silicon production for other military equipment. These included the LGM-30 Minuteman ballistic missiles, and a series of chips for space satellites. This major investment from the government and the military kick started the development of the increasingly complex semiconductor, and eventually forced the prices low enough for non military applications. The processes improved and by the end of the Apollo program, hundreds of transistors could be fitted into an IC, and more complex circuits were being made. Eventually the costs of adding more transistors to a circuit got extremely low, with the difficulty being the quality of manufacturing. It could be argued that NASA and the Pentagon paved the way for silicon device production as we know it today.

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

How a Voltage Regulator Works: LM7805

Voltage regulators are one of the first electronic components you get introduced to as a hobbyist. Really useful when starting out, it simply takes a voltage that is too high, and reduces it down to a set voltage that you want, usually defined by the component. Solves the problem of having batteries or power supplies being a different voltage to the thing you are powering (such as your Arduino), and at as little as 50p from ebay they are easily acquired. Sounds like a great solution, but there is an issue, they are terribly inefficient. They are known to get very hot when used at high currents, and often need hefty heatsinks to stop the magic smoke from being released. To demonstrate why they get so hot we need to think about what happens during use. Remembering Kirchoff, the current going into a system is the same as the current going out of the system. If we use a simplified version of the regulator, the only thing this device changes is the voltage of the output. Due to the minimal current lost powering the circuit we assume the vast majority of power lost is in heat. Using the basic equation of:

Power (W) = Voltage (V) x Current (I)

So if we use an example of the LM7805 made by On Semiconductor (previously Fairchild) that can regulate 5V at 1A. It’s a pretty standard component, and is very typical of a voltage regulator.

If we use a 9V input the power going in is 9V x 1A = 9W.

The output power is 5V x 1A = 5W.

This means that there is 4W of power being dissipated from the regulator as wasted heat. This is a large amount when considering the size of the packages available. When thinking about problems excessive heat can cause in a circuit, it can quite easily damage itself and other components around it when not designed properly. It is why there are often big chunks of aluminium attached to the back of the components to act as a heat sink.

7805
7805 chip in a TO-220 package. Notice the heat sink on the rear with a screw mount.

This post isnt meant to dissuade you from using regulators, they have their place in electronic circuits, and are a great starting point. All electronic engineers need to have a broad understanding of the advantages and disadvantages of linear voltage regulators to be able to handle them properly.

How it Works

LM78xx schematic 2 coloured
Schematic of the silicon inside an LM78xx device, coloured relating to the function of each area.

The above schematic can be found on the datasheet, but it’s been coloured in to show the different sections of the circuit.

The most important component in the above schematic is Q16 (Red), it controls the current between the input and output, therefore the voltage. It is placed in a darlington pair configuration with Q15 (Orange). In this configuration Q16 is amplifying the current amplified by Q15. This means that Q15 can be used to introduce error feedback. The Blue section contains a voltage divider that scales the output voltage so that it can be used by the bandgap circuit. This bandgap circuit is found in the yellow section (Q1 and Q6). This bandgap reference produces an error signal that is fed into Q7 (orange). A bandgap is used because it can provide a stable output even when the temperature of the device changes.

The orange section takes this error and amplifies it through Q15 and the darlington configuration described earlier. The purple section has overheating protection (Q13) and excessive output current protection (Q14). Occasionally on these schematics you also find excessive input voltage protection marked as Q19 in this section. These shutdown the regulator in fault conditions like overcurrent or getting too hot. The Green section is known as the “start up” circuit, because it provides the initial current needed to power the bandgap circuitry. This gives a jumpstart to the circuit when it needs it.

I chose the LM7805 because 5V is a common value to be used, but the LM78xx series has many different preset voltage versions. The bandgap circuit is trying to get its input to 1.25V, this is from the voltage divider found in the blue section. As R20 is a variable resistor, the voltage divider can be calibrated during manufacture to output exactly 1.25V at any chosen output voltage. This is great for a manufacturer because they make lots of the same chip, and it can be made to suit any voltage output they want. This is also similar to the way some adjustable voltage regulators work, such as the LM317. In adjustable chips, the voltage divider is made by the designer externally, meaning it can be applied to any situation with a simple change of resistors.

Basic Configuration

Looking at the datasheet, there are many applications for the device. but the simplest one is just an input and an output. All that’s needed is a couple of decoupling capacitors to smooth out AC signals and random noise. Voltage regulators work best with clean, smooth power. There is also the need, due to the voltage drop across the transistors, for the input voltage to be at least 2V above the required output. This is always a good rule of thumb to go by when it comes to regulators.

LM78xx basic configuration
LM78xx basic configuration

I would recommend people read the datasheet and have a play with different voltage inputs and current outputs, see how easy it is for it to get hot. In that datasheet there are some other good applications using the device, you can turn it into an adjustable voltage output, constant current supply and high current supply. These are also good projects for learning more about transistors and op amps. Equally, there are other types and brands of regulator out there, some cheap, and some quite expensive, it is worth shopping around for  the ones that suit you.