Venturing into 250cm quadcopters

20141116_233219

My quadcopter

Hey all sorry it’s been so long! I promise I’ve got a tutorial on the way for a super simple and easy to build nixie clock that I’ve designed. Anyway I thought I’d share my quadcopter build. This isn’t a tutorial! I’ve included a BOM at the end, and I encourage anyone who’s experienced in putting electronics together to give it a shot! If you’re interested but intimidated, I’d be up for building and tuning a quadcopter for you for a very reasonable price! If you want to get into this hobby, I highly recommend you to buy a cheap toy quadcopter like this one and learn to fly — I guarantee it will save you money and frustration in the long run. I’m also rank 1 jet/heli pilot in BF4 and I can say it flies similar to a small chopper when using the FPV system (wireless camera First Person) :P

Inspiration

and of course racing mini quads

Legality

20141116_233356

Better view of electronics and camera

Please respect the FAA rules — Note: The goggles are now considered illegal. The ones included in my BOM have a video out that allows you to easily connect classic RCA composite screen to put you back in the legal field. Darren from Hak5 talked a bit about this.

BOM

The BOM is what/where I bought parts. Don’t forget that multirotors need ESCs that don’t do any input filtering. Get an ESC (like in the BOM) flashed with SimonK firmware or an equivalent.

My BOM

Overall my quad is flying like an absolute champ! Unlike the QAV250, it doesn’t have a battery hanging way out the rear, which has caused the QAV250 to have some notoriously bad flight characteristics due to poor weight distribution. The only thing I’d change are the 20A escs which are overkill on 3s maybe get a 12A esc, but a 20A esc compatible with a 4s battery would really put this quad into overdrive — I’ve read the motors can handle 4s but may fail if pushed to hard.

Some terms

What is this ‘s’ mentioned above? It stands for the number batteries in series in a battery pack:  4s = 4*4.2v = 16.8v, 3s = 3*4.2 = 12.6v. A fully charged lipo = 4.2v per cell.

Also in my BOM I have a high ‘C’ battery. C determines how much current the battery is rated for. To find this max current take the C*mAh/1000 = max continuous amps. So a 1300mAh, 45-90C battery can do 45*1300/1000 = 58.5 amps continuously, but can handle a spike of 90*1300/1000 = 117 amps. In this field a spike is generally less than 10 or 5 seconds.

Bode Plot on an Oscillscope

intropicMaybe you’re learning about filters and want to see the how your filter responds in the 10Hz to 1MHz range. This guide will show you how to make a low frequency ‘spectrum analyzer with tracking generator’ using a few cheap modules and an oscilloscope — Based off of a video done by Dave Jones over at EEVBlog. Dave does a great job going into the theory, so check out the video if you want to see how it works! He will also show you how to set up the scope. Check out my video below for the reader’s digest version.

Some important notes

For the audio crowd — the vertical scale is still in volts, not decibels. There is also no information on phase shift.

Arduino math

Arduino math

Brief Theory

The circuit from this guide generates a sine wave and the frequency of this sine wave ramps up exponentially. This creates a logarithmic axis on the horizontal axis of your scope. The filter under test will then react differently as the frequency is ramped up. Finally everything will be displayed on the oscilloscope which is synced via the external trigger. The oscilloscope and the arduino will also need  the same time settings.

a

15Hz-10Khz sweep with simulation

a

15Hz-1Mhz sweep with simulation. marker at 50Khz (approx peak)

One major problem is that the oscilloscope’s horizontal axis markings aren’t going to be placed correctly all the time. To solve this the microcontroller will calculate where the axis bars should be and generate a 1ms pulse at 10Hz, 100Hz, 1000Hz, etc… The two screenshots show different generated axis and there are some simulations to compare results.

Hardware

For this project I used an arduino (breadboard friendly) to do the timing/math/markings, but the star of the show here is the AD9850 DDS sine wave generator. It’s easiest if you are using a breakout for the AD9850. Luckly they can be found on ebay for about 5$ with free shipping! This seems to be the breakout specs from the original creator — EIM377_AD9850 (pdf)

Schematic

Schematic, add some decoupling caps as in the next photo

The AD9850 also needs a buffer amplifier. I decided to use the TS922IN from adafruit as a unity gain amplifier. Many op amps will do the job just fine, but get one that doesn’t require a dual power supply and has a high current output. If you want to do any impedance matching or if your filter is low impedance, be sure to add an appropriate terminating resistor.

Wire everything up and get you scope hooked up!

Completed circuit

Completed circuit (with filter on the right)

Code

What a mess! I coded this pretty quick and fudged a few things =P You’ll want to jump down to sweepTime_mS and get ready to input the correct values — I’ll cover these in the video.

https://github.com/thefatmoop/bode

Why did I have a bunch of these DDS modules floating around? They had something to do with an LCR meter I built ;p — more on that hopefully soon!

Xbee hive

xbee

xbee galore!

Well summer is over! I ended up doing my internship at Caterpillar and had a delightful time! I especially loved the cafe there! The D11, D7E, and 735 articulated truck were cool too.

I really hope to post some more how-to guides probably related to RF modules… I’ve been working with some ultra low cost RF modules from sparkfun and just starting to do some work with XBees after an awesome donation! I have around 60 pro/standard series 1/prototype (mostly standard) xbee modules!

wireless wii nunchuck mouse

I just haven’t had the time to write about many of my other projects. Here’s a wireless wii nunchuck mouse, and it uses a 5v limited joule theif for the power supply. This is great since it runs down to 1v. The receiver acts as a HID device with basic error detection and those low end modules are only a one way link, so it would just throw out the reading if any error was calculated.

As far as my next guide topics i’m certainly open to suggestions. Possibly a part 2 mosfet guide that goes into more detail about calculating current, power dissipation, resistive feedback, and triode regions. Maybe a BJT intro guide or something else…

Self balancing robot

Ugly! Accelerometer in wii nunchuck, Gyro in Wii motion plus (right side)

In the near future I really want to build a quadrocopter, and would possibly need to do this for two of the interns I’ve been pursuing (NASA JPL or OSF). I was trying to figure out a good place to start and actually get some tests in. After doing some thinking I assume that a quad’s control system is similar to a self balancing robot only in two axis. On a quad I would read the pulses coming from a tx/rx system to adjust the target balancing angle. So far I’ve only put in two days into this robot, yes I am aware that I may not be approaching this the best way! please leave advice! So far it’s been 1 day to get the wii motion plus working with the wii nunchuck (they have the same I2C address…), and 1 day writing the software and building the robot. Everything is very rough so far, so I’m going to wait to post the source code! If you want a copy please leave a comment and I’ll send you the three versions! Once I get more familiar, I’ll surely write a very detailed guide!

Control system:

My current control system. Edit: I calculate angle from the accelerometer right after the offset and scaling.

I’m using a complementary filter, which is used to combine a gyro (accurate but drifts over time) and an accelerometer (not so accurate but doesn’t drift). Anyway look at the control picture to see exactly how I’m doing the calculations. Everything underlined in blue I want to get rid of/move. Possibly I will want to keep the MA so that I can do a standard deviation. The standard deviation could help the platform tune the complementary filter. A high standard deviation for the accelerometer would tune the complimentary filter constants to .999(gyro)/.001(accel) where as a low standard deviation may set it to .95(gyro)/.05(accel) and make it a continuous tuning function.  I’ve also been brainstorming on methods that would allow robot calculate the balancing angle for the platform. As far as phase shift: I’m not too worried about the accelerometer’s phase shift due to the filters, but the gyro needs the phase shift to be an absolute minimum!

Talking to two I2C devices with the same address. Had to include my new tool - saleae logic analyzer

How I would improve results:

The wii motion plus is a ~20$ three axis 2000deg/sec gyro with a plastic case, sockets, PCB, and a I2C pass through chip. This really isn’t the right type of gyro for this type of robot, and I seriously question the quality of the gyros on board. I can say the same for the accelerometer on the wii nunchuck too. I’ve also thought of a few ways to calibrate the system and get the gyro/accel units to match up with each other. Regardless the results are pretty good and I may just need to tune everything. Those servos are also slow as beans! My plans are to replace the gyros with less than 500deg/sec gyros, clean up the algorithm and work on perfecting it! I also need to put the IMU on the pivoting point of the platform.

Code:

segway05 – I probably won’t get around to taking another wack at this till summer, so here’s the most recent code. Not many comments other than the blatant mistakes pointed out.

Great resources:

Complementary filter by MIT

Tilt with accelerometer

Calculating angles with accelerometer

Using wii nunchuck and Accelerometer together – Just an FYI if you disable the Wii motion plus to talk to the nunchuck via passthrough port, the wii motion plus takes about 100ms to turn back on which is SLOW. I don’t  have a wiimote/wii, so I can’t listen in on them talking with my logic analyzer. This method is good since both devices have the same I2C address…

Videos:

Sorry about the terribad quality videos!


Linear resistive divider for the ADC

Vdivider

Simulation of changing -24v to 24v into ~ 0 to 5v.

This is a topic that’s very simple, but I’ve seen individuals do it in ways that are really over complicated. My example will show how to measure from -24v to 24v using a 10bit Analog Digital Converter (ADC) with an analog reference of 5v. The micro controller for this example will be an Arduino since it’s easy to get up and running. If you are having issues with selecting resistor values for your situation, leave a comment and I’ll help you out!

Design and deriving the equation:

Vdivide eqn paper

Circuit and deriving the equations.

This is a circuit that’s basically an addition to the simple voltage divider which gives one the ability to measure high voltage ranges using an ADC with limited voltage ranges. I’m going to be using a voltage divider that starts out at half the Vdc, which is 2.5v for the Arduino’s 5V power. From there I’m going to use a higher valued resistor to pull the 2.5v up to nearly 5v at it’s peak positive voltage, and down to 0v for its minimum negative voltage. If you wanted to measure just negative voltages then get rid of Rc (use infinity in the equation).

Equations required with explanation.

For deriving the equation, I just used nodal analysis. As you can see there is no calculus or anything very math intensive, but there are some variables. This isn’t a guide on circuit analysis, but if you need some tutorials on signal analysis look around youtube or try the book – Schaum’s Outline of Basic Circuit Analysis. Just as a warning there are a similar methods of doing nodal/mesh analysis that will get different equations but yield the same final equation.

Note: Vout is the output of the resistive divider, which will be what’s connected to the Arduino’s analog input (ADC). Vout should only go from 0-5v. Vac is the input to the overall circuit which may vary from positive to negative voltages. Vout may be found by using 5*(double)analogRead(pin)/1024.

Usage notes:

This isn’t a volt meter! If you build it and you’re not measuring a voltage, you’ll notice that it reports a few volts although nothing is connected. Connect Vac to Ground and you should get close to zero volts. As you can see the example above is fairly low impedance, but you can use higher resistors.

The two resistors standing up are both 10k. Two 10k resistors in parallel are equivalent to 5k. Red wire running off of picture is Vac and black is ground.

As for problems: the only thing I can think of is if the ADC wasn’t giving off good readings. If you’re measuring something that’s time critical or behaves sinusoidally, don’t put any capacitors on Vout since this will do a phase shift on Vout. If you’re worried about voltage spikes then you could use two  zener diodes facing oppositely. Also remember that in this example the voltage spread is over 24*2 = 48 volts, so with a 10bit ADC that’s 48/1024 ~ .5 volt increments.

Example code and material:

Voltage equations from above (pdf)

Arduino example program (pdf)

I was going to use this for a 3 phase triac driver with simple pwm. I needed a zero volt detector on one phase which would allow me to calculate the other phases and trigger the triacs at the right time. Originally I was going to sample the voltage with the ADC and look for about 2.5v coming to the ADC. I ended up using a simple voltage divider and a comparator which is definitely a better route! Now you can measure negative voltages with your ADC or Arduino!

Standard Deviation and Moving Average

Recently my neighbor paid me to build a key less entry system for his dorm room. I decided to go the economical route and use a button/potentiometer that sits outside the door and an Arduino on the inside that controls a servo connected to the lock. For my room, I thought it would be interesting to use a Ping))) ultrasonic distance sensor instead of the potentiometer and lose the button.

The Ping))) sensor kept taking readings while my hand was moving. In order to fix this I decided use a Moving Average filter, then calculate the Standard Deviation of the values currently included in the M.A. filter. When my hand is still, the Standard Deviation will become very small.

Example code:

M.A._and_S.D.(pdf)- “storeValue(variable);” is how to enter data into the array, then call M.A. and S.D.

Not much of a circuit required! Arduino's regulator also powers Ping))). Servo has it's own 5v regulator... needs capacitors

pingDoorLocker(pdf) – As you can see, this program blew up a little…

Download .pde source code from RapidShare

I tried to make the M.A. and S.D. code very easy to follow. Some things could have been combined in the S.D. and Variance method, but to the beginner what I wrote above is probably easier to understand since it follows the equations. As for the pingDoorLocker – I threw that code together very quickly.

Follow up notes: That was probably the worst way to do this project… I thought of a few ways how to write the program that would chop the code WAY down, but this is an example about using M.A. and S.D.! Pretty bad use of a M.A. filter if you ask me!

His door unlocker.

Since I did put a few hours into building my neighbor’s door opener, here’s an image of it! He didn’t want numbers on the potentiometer dial, so I made the LED flash the number that is currently being entered.

Code for his door opener (pdf) – leave a comment if you want schematics/code on rapid share since pdf loses tabs.

A Beginner’s Guide to the MOSFET

IRFP260N image from warf.com. Pins are Gate, Drain, Source from left to right.

If you need to switch high current and or high voltage loads with a micro controller you’ll need to use some type of transistor. I’m going to be covering how to use a MOSFET since it’s a better option for high power loads. This guide will be just a brief introduction that will discuss how to drive a MOSFET in a simple manner with the ultimate goal of making it act like an ideal switch. I’m not going to get into any of the topics such as Triode region, Saturation, Threshold Voltage, etc…

Refer to the N or P channel basic wiring schematics and remember the three pins: Gate, Drain, and Source. When I mention something like Gate-Source potential difference, I’m talking about the difference in voltage between the two pins.

Thank you Farnell.com for supplying many of the parts that will be part of this review/guide. I wanted to also mention that all parts performed great!

N channel MOSFET

How to think of a MOSFET:

A MOSFET may be thought of as a variable resistor whose Drain-Source resistance (typically Rds) is a function of the voltage difference on the Gate-Source pins. If there is no potential difference between the Gate-Source, then the Drain-Source resistance is very high and may be thought of as an open switch — so no current may flow through the Drain-Source pins. When there is a large Gate-Source potential difference, the Drain-Source resistance is very low and may be thought of as a closed switch — current may flow through the Drain-Source pins.

P channel MOSFET

N channel – For an N channel MOSFET, the source is connected to ground. If we want to let current flow, we can easily raise the voltage on the gate allowing current to flow. If no current is to flow, the gate pin should be grounded.

P channel – Looking at the P channel MOSFET, the source is connected to the power rail V2. In order to allow current to flow the Gate needs to be pulled to ground. To stop the current flow, the gate needs to be pulled to V2. A potential problem is if V2 is a very high voltage it can be difficult raising the gate to the V2 voltage. Not only that, but the MOSFET has limitations on the Gate-Source potential difference. Also note that logic is inverted for a P type MOSFET!

Drain-Source resistance – Ideally we want Drain-Source resistance to be very high when no current is flowing, and very low when current is flowing. The main issue using MOSFETs with micro controllers is that the MOSFET may need 10-15 Gate-Source potential difference to get near its lowest Drain-Source resistance, but the microcontroller may run on 5v or 3.3v. Some sort of MOSFET driver is required.

IRFP260N gate capacitance

IRFP260N current curves.

Gate-Source Capacitance – There is also a capacitance on the Gate-Source pins which prevents the MOSFET from switching states quickly. In order to quickly change voltage on internal capacitance, the MOSFET driver needs to be high current. It needs to actively charge (source) and discharge (sink) the capacitor too (for N channel)!

MOSFET Drivers:

A  half bridge is capable of doing what was mentioned above! There are many ICs available which can do this. Here’s a list of just a few that I’ve tested. Schematics are also provided!

Fet driver is a Half Bridge

  • MIC4422YN – Max of 18v, 9Amps peak, 2 Amps continuous.
  • MCP1407 - Max of 18v, 6Amps peak, 1.3 Amps continuous.
  • UCC27424  – Can drive two MOSFETs, Max of 15v, 4Amps typical.

All of these drivers performed nearly identically (~20ns rise, ~30ns fall). Note that although these can be used for more than just MOSFET drivers, these chips do not have much heat dissipation capabilities!

MOSFETs I’ve tested:

It was originally part of the plan to get some data about these guys, but I have been very busy with school. The MOSFETs have plenty of graphs inside the datasheets!

P MOSFET body diode causing unintentional current to flow.

UCC27424

MIC4422YN and MCP1407

  • IRFP260N - 200v, 50A, N channel.
  • IRF3703PBF – 30v, 210A, N channel. Misleading ratings! Read my Datasheet Notes at end.
  • RFP30N06LE – 60v, 30A, N channel.
  • FQP27P06- 60V, 27A, P channel.

An Important Reminder – Don’t forget that typically the heat sink on the back of a mosfet is connected to the Drain! If you mount multiple MOSFETs on a heat sink, the MOSFET must be electrically isolated from the heat sink! It’s good practice to isolate regardless in case the heat sink is bolted to a grounding frame.

Body Diode – Mosfets also have an internal diode which may allow current to flow unintentionally (see example).  The body diode will also limit switching speed. This won’t be a concern if you’re operating below 1mhz.

Si component generals

Great cheat sheet, includes MOSFETS. – akafugu.jp

Side note about Gate – Source voltage: MOSFET Gates can go above or under the source voltage. So for an N channel mosfet with a source at 0v, a -10v on the gate would allow current to flow. Verify this with your MOSFET’s datasheet!

Schematic Diode – If the load is somewhat inductive, you’ll need to put a diode to discharge the inductor. If you want more detail, look at the International Rectifier pdf at the end. My “Intro to the Boost Converter” also talks about the nature of inductors when quickly switched on/off.

Gate-Source ringing – There are a few methods that I’ve heard of / seen to limit ringing on the gate. Ringing decreases efficiency, and if excessive, can damage the MOSFET. You can use a zener and resistor in series with the zener’s cathode connected to gate, anode connected to source for N channel. P channel will have the zener flipped. Add a resistor to limit current going through the zener, and watch those breakdown voltages! There is also another diode you could look into called the TVS diode.

Datasheet notes – If a part has too good to be true ratings, check the application notes carefully. For example, the IRF3703PBF claims 210 Amps continuous drain current at 25ºC. We don’t have to do any thermal calculations to know 220 Amps is a TON of current for a TO-220 package! A closer look on page 8, note 6 reveals that it can pass a maximum of 75 Amps continuously due to the package thermal limitations. For future advice: IRF is pretty good at giving accurate ratings, but you have to look for things like this. Now in the real world lots of testing reveals if your design is bad, or if you’re working with a dishonest or incompetent supplier with inaccurate/misleading data sheets.

UCC27424, MIC4422YN, MCP1407

Mosfet Example

Arduino Mosfet Example

Without the driver, the Gate takes longer to charge, and it peaks at 5v. Excessive ringing due to no gate ringing suppression.

Great Additional Reading:

International Rectifier MOSFET application note

High speed MOSFET driving guide