Quadcopter Take Off

A couple of years ago, I put together a quadcopter, but haven’t gotten a chance to play around with it. I decided to dig it out of the closet and hope to learn how to fly it this summer. It’s a 250 mm size quadcopter that is suitable for racing and acrobatics. The parts are the cheapest I could find on Ebay and Hobbyking:

Total$204.53 CAD
Glass/Carbon Fibre 250 mm Mini Quadcopter Frame Kit$25.21
EMAX MT1806 2280 KV Motors$46.54
4 EMAX 12A ESCs with SimonK Firmware$51.05
8 pairs of GemFan 5030 Propellers$17.36
CC3D Flight Controller$20.11
Turnigy Nano-Tech 2200 mAh 35-70C 3S LiPo Battery$26.01
ZIPPY Flightmax 2200mAh 35C 3S LiPo Battery$18.25

I also got the Turnigy 9X 9-channel transmitter ($140.16 CAD). It got the mode 2 version, but it’s not too difficult to convert to mode 1 controls, as I did. The mode refers to the mapping of throttle, pitch, roll, and yaw to the controls.

LibrePilot’s easy configuration.

Assembling the quadcopter was not too difficult. As seen in the pictures below, I have the battery strapped to the top for now. LibrePilot is the open-source software I used to set up the flight controller. It has a very nice UI and makes calibration easy for someone like me who knows very little about these flying machines.

Did I mention that this thing is suited for racing and acrobatics? Because it’s not stable and very difficult to pilot! Larger quadcopters are typically more stable. I only managed to get it off the ground for a number of seconds today, and broke one of the props. I have a lot to learn!

Op-Amp Design and Fabrication

For one of my courses (ELEC 4609 at Carleton University), a major project was the design and fabrication of a CMOS circuit. While a digital circuit such as a pseudorandom sequence generator was a popular choice for other students, I elected to make an op-amp. I started this project with having just studied analyzing BJT op-amps, and now I set out to design a CMOS op-amp. I had little exposure to CMOS at the start of the project so it was fairly ambitious.

The topology I chose was an NMOS-input differential pair followed by a common-source amplifier, with a class-AB output buffer. This is a fairly standard circuit. However, rather than using traditional Miller compensation, I used a form of indirect compensation. As explained by V. Saxena and J. Baker, this solves the problem of the right-half plane (RHP) zero in Miller compensation, which decreases the phase margin and ultimately reduces the unity-gain bandwidth when because a larger compensating capacitor is required. I implemented the indirect compensation using split-length transistors for the PMOS differential pair load and feeding the signal from C_c in between.

Op-amp Circuit

The two-stage op-amp with a class-AB output buffer.

Note that the compensation capacitor is implemented as a MOSFET (M14) with source and drain tied, and operating in inversion. This was used since real capacitors were not available in the CMOS process. I won’t go into the details of the rest of the schematic as it is fairly standard.

Speaking of the CMOS process, most of the fabrication steps were done at Carleton University. It is uncommon for a university to have a fab due to the cost. At Carleton, the minimum gate length is about 4.8 μm, although test have shown that smaller devices can work. This is very large compared to modern CMOS; nevertheless, it’s neat to be able to fabricate on-site. For this project, a silicon-on-insulator (SOI) process was used. While this is more costly than ordinary bulk CMOS, it was used since it can be done with less processing steps. Time was a concern for the project, since only part of the semester was available for fabrication. I was not involved with the fabrication.

SOI has some important advantages over bulk SOI. For example, there is reduced source/drain capacitance (speed improvement), arbitrary biasing of individual transistors (no body effect), and complete immunity to latch-up (since there is an insulator below). In the design, there are no body connections made. The channel region is essentially left floating, but this is OK; remember that it’s insulated from all the other devices. Since the “well” is very shallow, it is nearly or completely depleted, and the gate might not have to modulate a depletion charge at all: V_{Tn}\approx -(E_g/2 - \phi_B) + \Delta V for NMOS and V_{Tp}\approx -(E_g/2 + \phi_B) + \Delta V for PMOS. \Delta V is due to a threshold adjustment implant that is used to adjust the threshold voltages; it is usually used to make them equal in magnitude.

Back to the circuit in question, the final schematic (with device sizes) is shown below. Note that the layout included input protection, which is shown in this schematic (devices M15 and M16). These don’t seem reasonable here, but make sense in the layout.

The op-amp circuit, showing device sizes. Also shown is the input protection, which comprises of devices M15 and M16. M14 is the compensating MOSFET capacitor.

After putting together the schematic, simulating it, and much revision, I moved onto the layout. This was done in L-Edit, which is a tool from the 90s. This is still used since the design rules are available in a format that was made for this software. Throughout the design, I used matching techniques like common-centroid layout and using dummy poly. Long devices were implemented with multiple fingers. See below. To ensure functionality, the circuit was extracted and compared to the schematic using a tool called Tanner Layout Versus Schematic (LVS). This software is able to combine split devices and check that that the layout truly implements the desired schematic.

The final testing of the op-amp was brief, but it was found to be functional. A DC sweep comparing the simulation to reality is shown below.

A DC sweep over the 3 V supply voltage.

Taking the derivative, the DC gain is plotted below. The gain is about 376.6 V/V (51.5 dB), which is less than the simulated value of 958.9 V/V (59.6 V/V). Also, there is an input-referred offset of about 26 mV.

The simulated gain and measured gain.

Lastly, the stability of the op-amp was tested by configuring it as a unity-gain buffer, producing the oscilloscope capture shown below. Since is a replica of the input (as expected for a buffer), the circuit is stable. Note that the oscilloscope is incorrectly calculating the amplitude on Ch4 (1.740 V). By considering that both traces are displayed at 1.00 V/div and both traces have the same height, it is clear that the gain is truly unity.

An oscilloscope capture showing the input and output of the unity-gain buffer.

While the testing verified the basic functionality of the op-amp, much more extensive testing is left to be desired. Perhaps of most importance would a Bode plot indicating the response of the op-amp at different frequencies, and also showing the unity-gain bandwidth product. Other tests should be done to find the common-mode input range and quiescent power dissipation. Nevertheless, the successful testing of the op-amp was a good opportunity to gain experience working in a lab environment and provided satisfying closure to the project.

Cascode Amplifier

For one of my analog electronics courses (ELEC 3509 at Carleton University), one of the lab projects was the design of a cascode amplifier. As shown in the schematic below, it is composed of a BJT in the common-emitter (CE) configuration (Q1) followed by a transistor in the common-base (CB) configuration (Q2). While the basic CE emitter amplifier has good gain and input impedance, it suffers from a poor frequency response due to the Miller effect.

Cascode Amplifier Schematic

A schematic of the cascade amplifier.

The cascode amplifier improves upon the frequency response of the CE amplifier, as will be discussed below. For the project, the given specification was:

Midband voltage gain(32.72 ± 1.64) V/V
Load resistance22 kΩ
Low cutoff frequency (-3 dB)60 Hz to 200 kHz
High cutoff frequency (-3 dB)> 600 kHz
Minimum output swing (peak-to-peak)2 V
Maximum total power dissipation50 mW
Collector current(1.0 ± 0.1) mA
Supply voltage15 V

The design process began by producing the small signal model, shown below. The hybrid-pi model was used to model Q1 while the T-model of the BJT was used for Q2. The internal capacitances of the BJTs were included for determining the high-frequency response.

Cascade Amplifier Small Signal Model

A small signal model of the cascode amplifier.

Component Values

One of the most important points in designing the component values was ensuring that the signal swing at the emitter of Q2 (v_{\pi 2} in the small signal model) was small – below 10 mV peak-to-peak. This is because r_{e2} is small (about 25 Ω), so a small signal is required to keep within the linear region of Q2. Since the parallel combination of R_C and R_L determined the voltage gain of the second stage, the 2 V output swing requirement and maximum 10 mV swing of v_{\pi 2} required that R_C be at least 6.47 kΩ. The closest available nominal resistance of 8.2 kΩ was selected.

Since the transistors were to operate at 1 mA, the emitter of Q2 was at 8.2 V with the selection of R_C. 2 V was allocated for the V_{CE} of Q2, to allow for 1 V of swing while leaving room to prevent saturation. The remaining voltage was divided between V_E and the V_{CE} of Q1. This was a tradeoff between better operating point stability (if more voltage were allocated to V_E) or a better high-frequency response. (Increasing V_{CE} for Q1 increases the base-collector depletion region width and thus decreases internal capacitance). 0.47 V was allocated to the emitter resistor, allowing an available 470 Ω resistor to be used.

Lastly, R_4 forms a voltage divider at the input and could be used to control the gain of the overall filter. Note that the magnitude of the gain of the amplifier is

    \[|A| &= \frac{\beta}{\beta + 1} g_m (R_C||R_L)\frac{R_1||R_2||r_{\pi 1}}{R_1||R_2||r_{\pi 1} + R_4} \]

This was solved for R_4, which was found to be 12.3 kΩ.

The coupling capacitors were selected so that the low frequency -3 dB cutoff would be at about 100 Hz, within the 60-200 Hz requirement. This requirement was likely imposed so that AC power noise would not be amplified.


Before prototyping, the circuit was simulated in LTSpice. It was found that the signal swing was too great at the emitter of Q2. The overall gain was found to be about 36.5 V/V, which was also too great. R_4 was increased to decrease the gain at the first stage, which resolved the first issue; however, the simulated gain became slightly too small. This was temporarily accepted, since it was expected that poor tolerances on components available for implementation would require changing component values anyways. The coupling capacitor values were also modified. The simulation also indicated a high-frequency -3 dB cutoff of 3.5 MHz, which was well above the required 600 kHz.

Simulated Gain

The simulated frequency response of the cascode amplifier, before component value modifications.


The circuit was implemented on a breadboard, as shown below.

The implementation of the amplifier on a breadboard. I tried to reduce the parasitic capacitances added by the breadboard.

After fine-tuning the circuit, the final component values were:

ComponentDesign valueActual value
$R_1$ (kΩ)5.65.54
R2 (kΩ)2214.83
R3 (kΩ)4755.5
R4 (kΩ)1517.53
RC (kΩ)8.29.81
RE (kΩ)470472
RL (kΩ)2222
CE (μF)2233
CB (μF)110
CIN (μF)2222
COUT (μF)1022

The operating characteristics of the circuit were then measured to ensure compliance to the specification. the midband gain was found to be 31.74 V/V, which was within the specified (32.72 ± 1.64) V/V. The input impedance was measured to be 21.2 kΩ and the output impedance 9.76 kΩ. The low-frequency cutoff was found to be 112 Hz, which is close to the designed 100 Hz. Lastly, the high-frequency cutoff was about 600 Hz, just barely meeting the specification. This is far less than the simulated 3.5 MHz, and is likely due to the capacitances introduced by the breadboard and components, which are not ideal for testing this circuit. Nevertheless, this is an improvement over the single-transistor CE amplifier that was tested in another experiment, which had a high frequency cutoff of 220 kHz.

The measured frequency response of the amplifier was within the specification, which is indicated by the dashed lines. The theoretical (calculated) response calculated before implementation is also shown.

The improvement is thanks to Q2, which acts as a current buffer. The single-transistor CE amplifier suffers from the Miller effect, which causes its internal base-collector capacitance to be multiplied by the gain, which results in a large capacitance and a low high-frequency cutoff. The current buffering of Q2 causes the base-collector voltage gain of Q1 to be small, so the Miller effect does not significantly increase the effective internal capacitance of Q1. Since Q2 acts as current buffer, it also has a good high output resistance. Thus, adding Q2 to the simple CE amplifier with direct coupling produces an an amplifier with significantly better performance.  This is in exchange for the increased complexity of an extra BJT, several resistors, and a capacitor.

Overall, the design met or exceeded all of the specifications.

Reverse Engineering of a Tent Peg

During my first year of engineering, I completed an “Introduction to Engineering” course (ECOR 1101) that sampled various topics from mechanical CAD to engineering ethics. For the CAD portion, we were tasked in groups to redesign a simple mechanical component. As a past Scout and backcountry camper, one thing that I thought could be improved is the humble tent peg that is used to prevent a camping tent from shifting around during the night (or blowing away if it’s windy!).

Tent Peg Solid Model

A solid model of the tent peg exported from PTC Creo

My group decided to improve the tent peg by adding a handle for easier removal from the ground. We also added notches along the length of the peg in order to increase the force required to remove it from the ground. I was tasked with modelling the peg, using a parametric CAD software called PTC Creo.

The complex shape of the peg made it a difficult first modelling project. The handle portion presented the greatest challenge in order to make it ergonomic. I decided to make it hollow in order to reduce the amount of material required to manufacture the peg.

If the peg were to be manufactured in large quantities, injection moulding with ABS plastic would be used. For prototyping, 3D printing was used instead. Thus, some constraints were given: maximum dimensions of 5″ x 5″ x 5″ and a maximum volume of 1 cubed inch. Thus, a scale version of the original 10-inch tent peg was produced. The schematic below shows compliance to the size specification. This was successfully 3D-printed using the STL file exported from Creo.

Tent Peg Size Compliance

Compliance to the maximum size was satisfied.

CruiseControl: a 2D Javascript Sidescroller

Play the game here!

Throughout high school, I was very interested in programming, likely due to its accessibility since only a computer is required. (Also required: a curious mind and perseverance when debugging.) During my final year in 2013, I put together a simple 2D side-scroller using Javascript and HTML.

My goal was not to create an addictive game (although I’m happy with the result); rather, I wanted to learn about how game frameworks work. Thus, I wrote the game from scratch, creating my own “game engine”. One of the most interesting parts of this project was implementing a collision detection algorithm. The code is available here if you’re interested. Keep in mind that I wrote this a long time ago when I was naive and didn’t comment my code very much.

Lab Power Supply Soldering

I received the boards towards the end of October 2016, but school was unfortunately very busy and I didn’t have time to devote to the project. I finally got around to doing some soldering over Christmas break.

For some reason, not all of the silkscreen got printed. Specifically, the outlines of the components were present but none of the component names were printed. This was probably something I did when generating the Gerber files for fabrication; I’ll have to look into it for my next layout.

This board gave me plenty of practice in SMD soldering! There were a lot of 0603 resistors and capacitors. I found this video tutorial particularly helpful. At first, a lot of my joints were ugly, but I got better at it. I found that the solder would stick to the soldering iron, even though I was using a fine point tip with solder containing flux, in addition to applying rosin flux paste to the PCB. I hope that this is just a matter of inexperience. In any case, I am much more confident in my soldering skills now.

This was my first PCB layout, so I had no expectation of it working on the first revision. So far, I have gotten the display working. This required fixing some missing wires for the display by soldering directly to the SOIC microcontroller (not very pretty – see the picture). It was so reliving and rewarding when I was able to successfully program the microcontroller to get a blinking LED and a test message on the display. Next, I have to finish writing the firmware and test the rest of the circuit.

Fixing the missing data lines

Added the missing data lines for the display.

Initial testing

A beautiful sight: a blinking LED and a test message on the display.

Lab Power Supply Schematic & Layout

During the summer of 2016, I started building a lab power supply. At the time, I didn’t have one at all, so I just wanted a general purpose one. I decided to base it on the open-source EEVBlog µSupply, which is capable of 0-20.48 V output with current limiting from 0-1 A. It also has some fancy features like an ethernet interface, which I decided not to include in my design. Some vague specifications that I decided on were:

Output voltage0-20.48 V
Output current0-1 A
Input voltage12 V DC
Display16 x 2 Character LCD
ConnectivityBluetooth (serial)

Voltage Control

I designed the schematic in Eagle. The voltage and current control is identical to that in the EEVBlog µSupply and is based around the LT3080 linear regulator from Linear Technology. There are some videos explaining the design available from EEVBlog, but I will briefly summarize here.

LT3080 Block Diagram

A block diagram of the LT3080 linear voltage regulator.

The LT3080 OUT voltage is typically set by connecting SET to ground via a resistor, which generates a voltage at the SET pin due to the 10 µA reference current. The output tracks the SET voltage via negative feedback.

To adjust the output voltage with a microcontroller, the SET voltage needed to be controlled. This is taken care of by U6 (refer to the schematic below), which is a 10-bit DAC with a 2.048 V reference voltage (U7). U8A is in the non-inverting configuration with a gain of 10, so the DAC output is scaled up to the desired 0-20.48 V range. Note that T2, which is used for current limiting, is normally off and does not affect the circuit when the output is not drawing too much current. Thus, the output voltage can be set by controlling the DAC via its I2C interface.

On the output, IC3 is a current source that takes care of the minimum output current required by the LT3080. There are also some protection diodes.

Power Supply Schematic - LT3080

The portion of the schematic that adjusts the voltage and limits the current.

Current Limiting

U4A and U4B form a difference amplifier that measures the current across the 1 Ω shunt resistor composed for R11-R20, with an output of 1 mV per 1 mA. U3B compares this to ISET_3V3, which is generated by filtering the ISET PWM signal from a microcontroller. If the current is too much, T2 shorts SET nearly to ground via R39, causing the output voltage/current to drop.

U1 is a current/power monitor that also measures the current across the shunt resistor. It allows the microcontroller to monitor the power use of the supply.

The Rest of the Circuit

The rest of the circuit includes the microcontroller, 5 V and 3.3 V voltage supplies, a 16 x 2 character LCD display, and rotary encoders along with some buttons for navigating the menu. See the schematics below. Many of the signals are available on headers for debugging, and I made the TX and RX connections configurable in case I wired them up the wrong way around (I had a bad experience with this in the past!). There is also some level shifting with R28, R31, D6, and D8, since the microcontroller runs at 5 V while the Bluetooth module uses 3.3 V logic levels. SW1 and SW2 are the rotary encoders, while S2 and S3 are pushbuttons. The headers JP4, JP5, JP8 and JP9 are present to allow these signals to be connected to external hardware rather than the footprints on the PCB.

The PIC microcontroller and the 3.3 V and 5 V supplies.


Rotary encoders, a 16 x 2 character LCD display, and the connection to the Bluetooth serial module. JP6 allows the RX and TX connections to be configured, so that I don’t wire them up wrong permanently.

PCB Layout

After finishing the schematic, I designed the PCB in Eagle. Because there were so many passive components in the design, I decided to use 0805 components. I do not have much experience with surface mount soldering, so I decided not to use 0603, even though this size is still fairly large.

Power Supply Layout

The power supply layout created with Eagle. It is about 95 mm x 80 mm.