Wednesday, November 3, 2010

Enabling 32MHz Operation on the AVR XMEGA


I received an AVR XMega100 Breakout from SparkFun in the mail yesterday and I've started doing some experimenting with it. The first problem I ran across was getting into 32MHz clock mode. The XMegas have a internal oscillator but by default they are set to 2MHz operation. What's kind of neat about the XMegas though is that you can switch the speed at runtime. What tripped me up was the fact that the registers that control the oscillator and clock are both protected registers. I'm not really sure what the benefit of this is but in any case here is the code to enter 32MHz mode.

void setClockTo32MHz() {
    CCP = CCP_IOREG_gc;              // disable register security for oscillator update
    OSC.CTRL = OSC_RC32MEN_bm;       // enable 32MHz oscillator
    while(!(OSC.STATUS & OSC_RC32MRDY_bm)); // wait for oscillator to be ready
    CCP = CCP_IOREG_gc;              // disable register security for clock update
    CLK.CTRL = CLK_SCLKSEL_RC32M_gc; // switch to 32MHz clock
}

A couple things to note. Check that you set the clock speed (F_CPU) in your compile to 32000000. And since the clock can be modified at runtime, anything that relies on the F_CPU constant may be effected, this includes the build in delay functions. For what I'm doing I'm not concerned with switching back and forth but some low power applications may find that useful.

Wednesday, September 8, 2010

Populated PCB



Soldering is all done. I tested the board and everything seems to work well. I did discover a little mechanical errors with my board, the ICSP header and IMU are a little too close, and I have to remove the IMU to use the ICSP. Overall I'm quite happy how things turned out. The final board weighs in at 50g.

Saturday, September 4, 2010

PCBs Arrived



After patiently waiting 3 weeks, I finally received my PCBs from BatchPCB. These are the first PCBs I have ever sent out to be manufactured. Pricing models, gerber files, board thickness, etc. have always seemed so intimidating but, BatchPCB and a tutorial at SparkFun made the process easy. With shipping, it came out to be less than $50. I just hope it works.

If you noticed in the photo above I received two PCBs but I only ordered one. I've heard this happening with BatchPCB. I'm not really sure if it's an artifact of how they build their panels but I'm not complaining.

Now I'm off to a fun night of soldering all the parts. The board has three ATmega328 that are in TQFP32 packages and since I have never soldered anything with a pitch that small it should be interesting. After watching numerous surface mount soldering tutorials on YouTube it doesn't look to be all that hard.

Here are some more pictures of the board...

Front



Back

Wednesday, September 1, 2010

Rigol DS1052E Oscilloscope



New equipment! I received my Rigol DS1052E oscilloscope today. I choose this oscilloscope based on the glowing reviews by Dave over at the EEVblog. After I play with it for a while I'll need to post my own review.

I bought it from Amazon because I had a bunch of Amazon gift certificates, but you can find elsewhere.

Saturday, August 28, 2010

Using a Complementary Filter to Combat Vibration

This is the data I received from the IMU along the y-axis (pitch). Accelerometer data is in radians and the gyro data is in radians per second. The data points from 0 to 41 are before the motors turned on. 41-89 is the quad tilting left. 89-129 is the quad tilting right. 129- is the quad tilting to the left again.



As you can see the accelerometer data is quite noisy. I tried dampening the vibration using foam underneath the circuit board, but that didn't help much. Looking at the gyro data it is quite smooth in comparison.

So I looked into using filters that combine the accelerometer data with the gyro data. Using the code for a Complementary Filter (thanks to RoyLB). I was able to produce the following results.

Sunday, August 22, 2010

First Balance Test



I adjusted the support rig to hold the quadcopter at the left and right arms allowing it to pivot in only one axis. Above is a video after spending 3-4 hours tweaking the code and adjusting the PIDs (I'm still out one motor and I disabled the other motor for testing). It seems to start the balance quite well but begins to destabilized. After some debugging it looks like the receiver chip is receiving some bad signals. Sometime this week I'm going to debug the receiver code to figure out what's happening. I may also try to remove the receiver code for now to see if I can get a stable balance.

Puff!!! There Goes A Motor.

During a firmware upgrade one of the motors started making a very strange noise. After 3-4 seconds a puff of smoke, the motor was dead. Still not sure what happened. Unfortunately that means ordering another one from Hobby City which has the best price but takes at least a week to get here.

Sunday, August 15, 2010

First Take-Off



I managed to have a clean take-off and landing. I don't have any of the sensor data mixed in yet just the R/C receiver throttle. I have the quadcopter held down using zip ties. Next step, new rig to get higher and more control over the flight.

Circuit Physical Layout



Before I sent the PCB off to BatchPCB I wanted to make sure the physical layout would work. I printed a 1:1 version of the circuit and took a piece of foam and tried out the parts. Good thing I checked because I had an overlap between a couple of the components. My circuit also has expansion ports for GPS, general IO and other TWI components.

My ciruit on BatchPCB

Quadcopter Eats Some Propellers



My quad ate it's first propellers. During my first hover I guess things weren't secured as well as they should have been and the propellers and speed controllers had a collision.

Here is what I think happened: I had the speed controllers taped to the board and the quad took-off and ripped the tape up. Then I landed and the speed controllers went up into the props. Thankfully the speed controllers came out with only a couple of gashes.

Quadcopter Circuit



I'm using 3 ATmega328P processors for the prototype circuitry. The first is used to communicate with the R/C receiver and filter the results. The second is used to communicate and process the sensor data from the accelerometers, gyros, and compass. Those talk to the main processor over TWI which combines the receiver and sensor data to control the motors. The main processor also sends out telemetry data using an XBee serial connection as well as monitor the battery voltage.

Quadcopter Prototype



My first project is a quadcopter (prototype pictured). The frame is made from 3/4" aluminum square tube. The proto breadboard in the center has the accelerometers and gyros (IMU 6DOF Razor), the Magnetometer (HMC5843), and breakouts for the 4 speed controllers (TURNIGY Plush 30amp Speed Controller). The four motors are Turnigy 2217 16turn 1050kv 23A Outrunners with APC 12x3.8 standard and 12x3.8 pusher props. Not connected in the photo is the ZIPPY Flightmax 4000mAh 3S1P 20C battery.



Here's a closeup of the power distribution. I'm still working out options that are lighter but for now this should work for prototyping. With each motor pulling up to 20Amps times 4 for a total of 80Amps I needed some pretty beefy power distribution. The wire is Turnigy 12AWG which has very high braid count for more amperage capacity. I used a terminal block (available at Home Depot) and terminal wire connectors.

ATX Power Supply Conversion



I had a bunch of old ATX power supplies laying around, so I decided to convert one into a bench power supply until I could find one. The on/off switch on the right is hooked up to the green wire and black wire of the 20pin connector. I also brought out a hand full of grounds (black banana plugs), as well as +12V, +5V, and +3.3V. It's kind of hard to see in the photo but I also added a small LED to the left of the switch to indicate power status.

Welcome to 5Volt Blog

Welcome! I'm starting this blog to document my electronics hobby. Ever since my son Ian was born I've had to put my other hobby, woodworking, on hold. I decided to get back into electronics, a hobby of mine since I was young, which is much quieter.



One half of our unfinished basement is reserved for my woodshop. I decided to take over the other half of the basement for electronics, and repurposed some old storage furniture for a work space. Above is a picture of my electronics workbench. Since most of the projects I have planned require quite a bit of firmware I've set up a computer on the left. On the top shelf are various components. On the middle shelf I have my old Radio Shack multimeter, a converted computer power supply, an Aoyue 2900 Soldering Station, a PanaVise 350 Work Center. On the bottom I have various hookup wires and tools. Off to the right I have more storage.

If it weren't for all the unused baby stuff lying around, my basement would be my version of a perfect "man cave."