Wednesday, December 3, 2014

Moved!

I got tired of using a handle that was 14 characters, and I wanted an excuse to get a personal domain :)

All content will stay up here until blogspot gets tired of me and stops hosting it, but I've copied most of it and am posting all new projects on my personal domain, www.njneer.com

Thanks for stopping by!

Wednesday, August 21, 2013

Marble Maze: The makening

A quick, hopefully simple guide on how to make a servo controlled marble maze!  Pictures for each step will hopefully be coming soon, once I get a chance to take some photos.

Materials Needed:


1x Wooden Marble Labyrinth
2x HiTec 322HD servos
1x 2.5x5.5mm barrel jack
1x 2x10 0.100" through hole male pin header
4x #8-32 x 1-1/2 inch machine screws
6x ~2.5 inch lengths of 0.100" diameter wire
6x pieces of electrically non-conducive heatshrink
Solder

Tools Needed:


Needle-nose pliers
Drill press
Power drill
Drill bits of various sizes
Phillips head screwdriver
Soldering iron
Heat gun (in a pinch, a hair dryer and a funnel)

Method:


The method for modifying the marble maze can be broken down into a series of relatively simple steps.  The control knobs will be removed from each axis, rotated around so that the flat side of the knob is facing away from the maze, the small wheel arm will be attached to the flat side of the control knob, and the servo will be attached to the box.  For the wiring, a 2x3 header is used.  On one side, the 3 pin connector from the servos will be attached.  On the other, wires will be soldered to connect power and ground to the DC power barrel jack, and power, ground, and pwm control signals to the Launchpad.  Step by step instructions for this process are as follows:
  1. Remove the control knobs from each rod:  Start with the knob on the x-axis.  Rotate the y-axis such that the edge of the maze nearest to the knob on the x-axis is tilted down as far as it can go.  Use the needle-nose pliers to stabilize the shaft and pull on the x-axis control knob.  The control knob is only secured to the shaft by friction, so it should pull off pretty easily.  The y-axis control knob is a bit harder to remove, as you can't tilt the board in such a fashion as to make an opening wide enough to get access to the shaft with the pliers.  If your pliers are small enough, you can use hole 34 or 36 to get access to the shaft.  Again, stabilize the shaft with the pliers and pull off the control knob
  2. Extend the mounting hole on the control knob:  Unfortunately, I didn't record what size drill bit was necessary for this step, but it is easy to determine.  Insert a drill bit that looks to be about the right size into the hole that rod used to occupy.  When you get to one that fits, use that drill bit on the drill press to extend the hole all the way through the control knob.
  3. Secure the small wheel arm to the control knob:  Use a 1/16" drill bit and the drill press to expand two of the holes that already exist on the small wheel arm.  Place the small wheel arm on the flat side of the control knob and use a pencil to mark the location of the expanded holes.  Use a drill press and the 1/16" drill bit to drill all the way through the control knob.  Use two of the servo mounting screws that came with the 322HD to secure the small wheel arm to the control knob.  Be careful with this step, as it is very easy to strip the heads of the servo mounting screws.
  4. Reattach the control knob to the marble maze:  Again starting with the x-axis, use the pliers to stabilize the rod and push the control knob onto the rod with the flat side (which now has the small wheel arm attached) facing outward.  Note that there is a flange on the rod that keeps the rod from extending too far outside of the marble maze housing.  Use the pliers to make sure this flange is snug against the wall of the maze.  Repeat this process for the y-axis, again using hole 34 or 36 to get access to the rod on the y-axis.
  5. Secure the servo to the marble maze:  The small karbonite gear on the HD322 should easily click into the small wheel arm that is now connected to the control knob.  Rotate the servo such that the wiring coming out of it is pointed towards the ball return of the marble maze.  Attach the 1/16" drill bit to the power drill.  Make sure the servo is level, and use one of the four mounting brackets on the servo as a guide to drill a hole into the side of the marble maze, making sure to drill all the way through the wall.  This will create a hole that is slightly smaller in width than the #8-32 machine screws.  Line the servo up with the hole, then use a hand screwdriver to screw one of the #8-32 machine screws into the hole.  It is important to use a 1-1/2" screw here, as you need to get the head of the screw flush with the mounting hole of the servo, but if the screw extends past the wall on the interior of the marble maze, it will limit the range of motion on that axis.  Now that the servo is held in place with one screw, use mounting bracket as a guide again and drill a second hole into the box, then a second #8-32 machine screw to affix the servo to the side of the box.  Repeat this process for the second servo.
  6. Wire the servo to the Launchpad and barrel jack:  Snip off a 2x3 section of the 0.100" pitch male pin header block.  Solder a wire to electrically short the two columns of the first row.  This will be used to create a four point node for connecting ground from the DC barrel jack to the launchpad and servos.  Solder a wire to electrically short the two columns of the second row.  This will be used to create a four point node for connecting 5V from the DC barrel jack to the launchpad and servos.  Solder a wire to connect ground from the barrel jack to the column one, row one of the header.  Solder a wire with a 0.100" pitch to column two, row one of the header.  Solder a wire to connect the tip of the barrel jack (5V) to column one, row two of the header.  Solder a wire with a 0.100" pitch to column two, row two of the header.  Solder a wire with a 0.100" pitch to column one, row three of the header.  Solder a wire with a 0.100" pitch to column two, row three of the header.  If possible, use an electrically non-conductive heat shrink on each solder joint to ensure that you don't accidentally short 5V to ground, the two PWM signals to each other, or the PWM signals to 5V.  Connect the wire at column two, row one of the header to either pin 1 of J2 or pin 2 of J3 on the bottom (female portion) of the launchpad XL header (GND).  Conenct the wire at column two, row two of the header to pin 1 of J3 on the bottom (female portion) of the launchpad XL header (VBUS, which is 5V).  Connect the wire at column one, row three of the header to pin 3 of J3 on the bottom of the launchpad (PD0, pwm for y-axis).  Connect the wire at column two, row three of the header to pin 4 of J3 on the bottom of the launchpad (PD1, pwm for x-axis).  Connect the three pin connector from the servo on the y-axis to column one of the header such that the black wire is on row one, the red wire is on row two, and the yellow wire is on row three.  Connect the three pin connector from the servo on the x-axis to column two of the header such that the black wire is on row one, the red wire is on row two, and the yellow wire is on row three.
  7. Calibrate the servo:  Unscrew the machine screws and detach the servo from both control knobs.  Plug in the launchpad (and program it if you have not already done so).  On startup, the launchpad will set the servo to its 90 degree position.  Manually move the control knob for each axis so that the marble maze is level.  With the launchpad still on (which will hold the servo at 90 degrees), reattach the karbonite gear of the servo to the control knob, taking care to keep the maze level while doing so.  Reattach the servo to the maze using the machine screws.  The 90 degree position of the servos should now correlate to a position in which the marble maze is level on each axis.
You now have a fully functional, launchpad and servo controlled marble maze!

Tuesday, August 6, 2013

Amazing Sensors!

A new project!

Lately, I've been working with different sensors as part of my day job at TI.  TI happens to have recently released a booster pack for the Stellaris and Tiva launchpads that contains (among other things) an accelerometer, a gyroscope, and a magnetometer.  I figured I'd use my recent experience to do something fun with sensors in my free time :)


Using only the highest quality cell phone cameras and engineering studio production values, I made a quick video describing the system and showing it in action

Project Overview


  • Accelerometer, gyroscope, and magnetometer fused via direct cosine matrix to observe roll, pitch, and yaw of hand held transmitter
  • RemoTI software stack used to pair and transmit data over Zigbee RF4CE protocol between transmitter and receiver
  • Software generated PWM signal used to control servos attached to X and Y axis of marble maze based on roll and pitch data received
  • Source code and bill of materials can be found on my github

Hardware

The key piece of hardware that made this project possible was the SensorHub Booster Pack.  The booster pack comes with an MPU 9150, which provides 3-axis data from a gyroscope, an accelerometer, and a magnetometer.  The communication between the MCU and these sensors is handled with an interrupt driven I2C interface.

An additional bonus of using the SensorHub booster pack is that it was designed to contain a set of EM headers.  For this project, I connected a CC2533 radio transceiver to those headers, which enables short range (~5 meters) radio communication between two modules.  It was a bit tricky to set up the CC2533, as there was not a plethora of sample code for using it in conjunction with a Stellaris, but fortunately I was able to find a spare development kit that made learning and debugging the radio interface much easier.

The final hardware component was the marble maze itself.  I actually was able to find this already pre-fabricated.  A TI field engineer did a project very similar to this, but using the accelerometer on an msp430 Chronos watch and an lm3s9b96 for the maze control.  Unfortunately, that demo was starting to show its age: it used the SimpliciTI stack for wireless communication, which is no longer supported, the 9b96 was from back when the Stellaris line was controlled by Luminary Micro, meaning it had no Texas Instruments branding, and the 9b96 used for the PWM control is part of the now, sadly, NRND'd m3 line.  As a result of these factors, the demo was languishing in a marketing office, and hadn't been used for a trade show in years :(

Software

Once I procured the hardware, I set about to looking for example code.  I came across a project a coworker of mine created, the wireless air mouse demo, that was a great help.

The sensor communication was the easiest part to cover (due in no small part to the fact that I've spent the past year and change working with these exact same sensors for a different project within TI).  TI has a really great sensor library that is available in the current Tivaware C series release that handles a large part of the sensor functionality.  The air mouse demo already handled taking the sensor data and feeding it into a direct cosine matrix, which generates the eigenvectors needed to determine the roll, pitch, and yaw of the device at a given time.  Once I had this data being reliably generated, I moved on to the radio transmission portion of the code.

The radio portion of the project was by far the most difficult.  I opted to use the RemoTI RF4CE software stack, because a) that's what the air mouse demo used, and b) it sounded like an interesting topic to learn more about.  The RF4CE protocol basically classifies each node on the RF network as being either a target or a controller, and sets up a very robust algorithm for pairing and sending data between two devices.  Unfortunately, the airmouse demo only covered the controller side of the code; for that demo a CC2531 USB dongle was used to handle the target side of the communication, the source code for which I was unable to find.  It took a few weeks of reading up on the RemoTI documentation and learning about how the on board MCU on the CC2533 works, but I was eventually able to get a hello world program running, which quickly gave way to transferring roll, pitch, and yaw data from the hand held controller down to the maze controlling target.

The servo communication was fairly straightforward: each is controller by a pulse width modulated signal with a base of 20 ms and an active time of between 1 and 2 ms to rotate it to either extreme.  I was hoping to use a Tiva Launchpad for this purpose, as it contains a hardware PWM module, but I was not able to find one lying around the lab, so I opted to just use a general purpose timer to create a software based PWM signal for the servos.  Once I had roll and pitch data coming over the radio interface, all I had to do was to normalize the rotation between -1 and 1, use that to generate an active time for the PWM, and generate the signal.  I ended up adding a multiplier to each axis to get the demo to make a bit more sense, as the launchad is longer along the Y axis than it is the X axis, so it takes a greater effort to change the pitch on the board than it does the roll.  As a result, without a different multiplier on each axis, the controller gave the impression that it required more effort to get the board to move in the Y axis than it did to get the same motion on the X axis.

As always, the source code for this project can be found on my github.

Future Steps

I have a few ideas for where to go from here, but nothing concrete on the horizon.  My first thought was that it would be really easy to modify this code to instead control a POV camera gimble.  Something like using the target side MCU to control a gimble that has a go-pro attached to sync the camera movement to the movement of a launchpad attached to a hat.  Then maybe finding a way to stream a low res version of that video to an RC car or quadcopter to allow for POV control of the remote vehicle without requiring line of sight.  Still thinking about what hardware would be ideal for this, maybe giving me an excuse to buy a beaglebone black.  For now, though, I'm quite happy with my little marble maze demo :)

Saturday, December 15, 2012

The Writeup 2: Electric Boogaloo


Hello everyone!  I have some new, very exciting updates to my project!

For those who aren't familiar with my previous works, my last big project was a frequency analyzer I made using a Stellaris Launchpad and an 8x8 LED panel MSP430 Launchpad booster pack that I repurposed for Stellaris.

Well, I've made a few upgrades since then :)








Project Overview

  • Timer triggered ADC for signal capture at user specified frequency (4 KHz - 80 KHz, defaults to 26 KHz)
  • Smart uDMA function determines, based on sampling frequency, whether to do signal processing on a fresh array of new data or rotate in a smaller amount of new data for each DSP loop
  • 2048 point FFT for frequency bin calculation
  • ARM CMSIS DSP library used for Hamming Window application and FFT calculation
  • Touchscreen used for variable minimum display frequency, maximum display frequency, sampling frequency, number of display elements on screen (aka number of bars), debug information, and visual effects
  • Dynamic calculations made based on current sampling frequency and max/min display frequencies to generate a logarithmic scale for frequency axis.
  • Timer controlled 18 FPS display rate (adjustable to up to 30 FPS at compile time)

Hardware

Audio Capture

The first big update to my project is on the signal capture side.  I've always been much more of a software guy, but I figured this would be an excellent opportunity to brush the rust off of my board layout skillset.

In order to get the Launchpad to be able to read line level audio, it is necessary to add a DC bias to the audio signal.  Line level audio is centered at ground and has a ~1.6 V swing, which is a problem because the ADC peripherals on the Launchpad can only take input signals between 3.3 V and ground.  To fix this, I use a simple circuit (a capacitor and two resistors) to get the signal centered at 1.65 V with a 1.6 V swing.


Instead of using a breadboard for this, though, I decided to draw up the schematic using Eagle's schematic capture tool, then do a simple board layout (again using Eagle).


Once the board layout was done, I uploaded the schematic to Batch PCB.  I was originally planning on ordering a few boards from there, but one of my coworkers found out about what I was doing and offered to pay for my board to be fabricated by Advanced Circuits instead.  As much as I like supporting batch PCB, I'm not one to turn down free fabrication :)







Overall, I was very happy with how the board ended up turning out.  For anyone interested in using/modifying/viewing my raw board design files, they can be found along with the bill of materials for my board in the hardware directory of my github.

Display

The next big change, and arguably the most impressive addition to my project, was the display.  Kentec just recently released a 3.5 inch, 320 x 240 16 bit color display, complete with resistive touchscreen overlay on a booster pack for about $50.  Needless to say, as soon as I found out about its existence, I incessantly pestered my contact on the Stellaris applications team until he let me have one to play with.  I had to make some changes to the sample driver provided for the display.  Specifically, the touch screen uses a timer to trigger ADC captures, which interfered with my audio capture functions.  With a few modifications, though, I was able to integrate the Kentec booster pack into my project pretty easily.

Software

The addition of the touch screen allowed for a much, much wider scope of functionality for my software.  I had originally designed my code such that the sampling frequency and display parameters were easy to change at compile time via a few pre-processor macros, but it took a bit of work to get those options all configurable at run time in an intuitive fashion.  That said, the software I wrote for the LMF120 is now responsible for the following functions:
  • ADC Sampling at a user defined frequency frequency
  • Digital Signal Processing on the captured audio data (2048 point FFT)
  • GPIO based communication with the Kentec display
  • Graphical User Interface for changing display and DSP parameters at runtime
I'm a software developer by day, so I did all that I could to make those steps run as efficiently as possible.  I worked primarily in Code Composer Studio, and my source code is available on github.

Audio Capture

For the ADC interaction, I ended up using three separate peripherals to give me an incredibly software efficient audio capture process.  First, I set up a timer to count down at the sampling frequency (defaulted to 26 KHz).  I set up the timer to trigger an ADC capture at the hardware level.  The ADC capture complete signal was set up to initiate a uDMA transfer, which was configured to move the data from the ADC capture FIFO to a global array of samples.  The result is very, very software efficient; One line of code starts the sampling timer, and SAMPLE_SIZE/26000 seconds later a software interrupt occurs, letting you know that the data has been captured and is ready in the sample array.  I was very proud of the efficiency of this process :-)

I did encounter some difficulty when trying to run my code at low sampling frequencies.  The flow of the above method is basically
  1. Capture Data
  2. Halt Capture
  3. Process Data
  4. Start Next Capture
  5. Display Data
The problem with this becomes obvious in the example of using 4 KHz for the sampling frequency.  The 2048 point FFT requires the use of 2048 samples, and the above method means that every time we want to do a new signal processing loop, we have to get a fresh 2048 samples.  If we're sampling at 4 KHz, that means we have at most about 2 sets of fresh samples per second to process.  That means we can only update our display at 2 frames per second.
To get around this, I have two different uDMA algorithms.  The first (fast) method is as described above.  The second (slow) method decreases the uDMA size to 256 and uses a ping pong buffer to store the data.  When the uDMA transfer for the ping buffer is complete, the uDMA engine switches to storing data in the poing buffer.  While the pong buffer is filling, the data in the sample array is shifted left by 1792 samples, then the data from the ping buffer is copied into the top 256 spots of the sample array.  The joys of flexibility :)

Digital Signal Processing

I am fortunate in that I've been playing around with audio hardware for years in the form of running soundboards and messing around with studio mixing and recording.  My last DSP class was a long, long time ago, but my interest in audio gave me a decent foundation in audio based DSP.  I am also fortunate in that ARM has a DSP library specifically designed to take advantage of the M4F's floating point instructions.  TI even has an application note detailing how to build that DSP library in Code Composer Studio.  From what I've heard, the amazingly handsome, charismatic, genius of an engineer who wrote the note did an incredible job on it, and it is wonderfully thorough and well written.  It might also be a little out of date (as ARM released a new version of CMSIS since the app note was published), but it's still quite useful.

With those tools at my disposal, the DSP portion of my code wasn't too difficult to figure out once I wrapped my head around CMSIS.  Step one is to multiply the samples by a windowing function.  I chose a hamming window, because I vaguely remember hearing that that was good for audio.  Next, I take the FFT of the input data.  I'm pretty proud of this part as well; the M4F ended up being powerful enough to take a 2048 point fft on the input data, which gives you 1024 frequency bins, each of which represents the energy found in a 12.7 Hz wide frequency band.  So once I have the fft output, I take the complex magnitude of each sample, giving me the total power found in each frequency bin.

Touch Screen/Configuration

Once I had the data captured and processed, I needed a way for the user to configure how it would be displayed.  I ended up using three screens total for my project: the main "Frequency Display" screen and two Configuration screens.  The first configuration screen is used to modify various frequency parameters and the number of display elements to use.  This is done using StellarisWare's graphics library, using slider widgets and pushbutton widgets.  Each parameter has a slider that can be used for setting the value, and a + and - button that can be used to fine tune the values.  On this screen, the user can change the maximum display frequency, the minimum display frequency, the sampling frequency, and the number of display elements (aka the number of bars) used on the display.  Once these have been entered, my code determines which bars need to correspond to which bins in order to best facilitate a logarithmic frequency display.  This normally means the lower 1/3 of the bars each represent less than 10 bins worth of FFT data, and the upper bars contain the summation of at times hundreds of bins.  If the user ever tries to get the screen to display at a greater granularity than possible (like having only 10 Hz of separation between lower and upper frequency while running at a 40 KHz sampling rate), the display will automatically be set to use as many bars as possible while still not displaying over the user's requested frequency range.

Display

The communication to the Kentec display is handled via a parallel GPIO interface.  I started out using Stellaris' Graphics Library (grlib) for everything, and was quite impressed with it.  Going into this project, I had almost no experience working with grlib.  Despite that, it ended up only taking me three hours worth of work to go from using my 8x8 LED display to having 8 bars of generic height behaving as desired on the Kentec display.  I like to think that I'm a pretty decent programmer, but I honestly feel that getting that far that fast is much more a sign of a well designed library than it is a sign of an intelligent coder.

For actually sending data to the display, I was able to use a driver that Kentec provided.  Sadly, I had to make a few modifications; the Kentec driver uses the same timer to control the same ADC sequencer that I was using for my audio capture, so I ended up changing to a different timer that performed a processor triggered ADC capture for the Kentec display.  Also, the display's draw functions all operated by drawing horizontal lines, which is nonideal if you're trying to draw lots of thin vertical lines, so I added in a function to allow for drawing images and lines by column as opposed to by row.  In hindsight, I think the display allows for changing from "portrait" to "landscape" orientation, so I probably could have just rotated my image and set the display to landscaped, but it's a bit late for that realization now.


With my modifications to the Kentec driver, I was able to get around 30-40 frames per second (depending on sampling frequency).  I found that the display looked a bit better if I cut it back to 15 frames per second though.  The instantaneous nature of the FFT meant that if I updated as fast as data was being processed, impulses in various frequency ranges would not remain on the display long enough for my eye to catch them and make sense of them.  I use a simple timer peripheral to keep the frame rate constant over time.

Credits, development time, and shaggy hair

All photographs on this post were taken by my wonderful wife, whose work can be found on her website.

In total, this project took about a month and a half to get from my last release to its current state.  I could likely have finished it in less time, but I have also been working on another big project in my free time lately; raising my first daughter :)


She was born in mid October, meaning she was about 3 weeks old when I started working on the code for this release.  She tends to fall asleep pretty easily when she's in a baby bjorn-style harness, so most of my coding was done between 9 and midnight while wearing a ten pound child on my chest :)  The unfortunate downside to this has been that between my real 8-5 job at TI (which actually has nothing to do with Launchpad), working on this project, and keeping that little lady happy, I haven't quite been able to maintain the sharp look I used to sport.  So my apologies if I look a bit shaggy in the explanation video for this one... it's been a few days since I've had a chance to have a proper shave :)

Sunday, December 9, 2012

Feature Complete!!

At 2:30 this morning, the source code for my next update officially hit feature complete.  It will take me a few days still to clean up everything for a release, but I should be able to make a public git push, a new writeup, and a few new videos by the end of the week.  This is a big one, folks :)

Sunday, September 9, 2012

The Secret Sauce

Source code is up!
https://github.com/EuphonistiHack/launchpad-freq-analyzer.git

I'm assuming that TI will follow the standard procedure for Stellaris installs for Launchpad, which is to say that when you install StellarisWare, the file structure will be such that you have a root (defaulted to C:/StellarisWare) in which driverlib will be copied.  That root will also contain a  boards directory, which in turn should contain a directory for the lm4f120.  If you do a git clone off of the above address, you'll find a similar file structure.  You should just be able to copy the led_equalizer project into the lm4f120 board directory, and copy dsplib into the stellarisWare root.

In it's current state, the only thing I've verified working is the Code Composer Studio build.  I have included project files that should at least be 95% good for all the other Stellaris supported environments: a makefile for you command line GCC enthusiasts and project files for Keil uVision, IAR Embedded Workbench, and CodeSourcery's IDE.  I'm guessing that if you tried to import and build into any of those as is, you will hit two problems.

For one, there's a config array that the uDMA engine uses that needs to be stored on a 1024 byte boundary.  I have some pragmas in place to handle that for CCS and IAR, but I haven't yet figured out the syntax for handling this in other compilers.  Shouldn't be too hard to figure out, and hopefully I'll have that done soon.

The second issue will be with the CMSIS library.  The current release contains a precompiled .lib and the headers necessary to interface with it.  This was compiled with the tms470 compiler, though, so it won't work with anything other than CCS.  If you download CMSIS for yourself, it should come with precompiled binaries for use with uVision, GCC, and CodeSourcery.  You'll want to add those to dsplib, then edit your project's library include path/list to point to the proper binary.  I am considering including these in dsplib, but I'm not really sure what ARM's policy is on redistributing their binaries, and I'd prefer not get sued out of existence :)

Enjoy!

Wednesday, September 5, 2012

The writeup

Hi, everybody!

I like playing with microcontrollers.  When I heard that TI was going to release a hobbyist centered Stellaris evaluation kit, the ek-lm4f120XL, I got excited.  When I convinced a coworker to let me have a rev0 board to work with, I got even more excited.  I decided that I would combine my love of microcontroller projects with my love of all things audio and make an LED frequency analyzer.

Many thanks to my wife, Heather Wills, for taking a decent photo of the board for me!

Hardware


The total cost of my setup is about $25 (the majority of which is from the LED display).  The Stellaris ADC requires that its input signal be a low impedance signal that is between ground and 3.3V.  This is not consistent with line level audio, so I implemented a very simple circuit on a breadboard to condition the input signal using an NTE987 opamp that I grabbed from Fry's, two 47k resistors, and a 1 uF capacitor.  The output of this circuit goes to one of the ADC input pins on the launchpad.  I found an MSP430 booster pack that is essentially an SPI controlled 8x8 LED array that I decided to use for the display.

Bill of Materials

ek-l4f120XL: $5
olimex MOD-LED8x8: $15
Opamp: $2
Resistors/Capacitors: Negligible (had them lying around in my wiring kit)

Total Cost: $22

Implementation

The signal condition circuit has to perform two functions.  First, it must bias the signal to center at ~1.65V and be limited to a 1.65V swing.  Line level audio is centered at ground and has at most around a 1.5V swing, so a simple resistor network can be used to bias this up to 1.65V.  Second, the output must be a signal with low enough impedance to power the switched capacitor array that the ADC input uses for its signal capture.  A low grade opamp can be wired up at unity gain to accomplish this.  The final result looks something like this:


For the input, I also realized that I'd need a headphone jack with exposed leads, which I picked up at Radio Shack for something like $1.50.  Were I a more patient engineer, I'm sure I could find something cheaper on digikey or mouser.  I slapped all of that together on my breadboard, which gave me the following:


The last piece of hardware work was connecting the Olimex booster pack to the Launchpad.  Unfortunately, I had to blue wire this, as the SPI RX pin on the booster pack was not aligned with the SPI TX pin on the launchpad.  Not a big deal, though, as the interface to the board is only five pins (SPI_CLK, SPI_TX, SPI_LATCH, VCC, GND).

Software


The software running on the Stellaris was responsible for the following functions:
  • ADC Sampling at a specific frequency
  • Digital Signal Processing on the captured audio data
  • SPI communication with the LED array
I'm a software developer by day, so I did all that I could to make those steps run as efficiently as possible.  The source code I'm using is up on github at https://github.com/EuphonistiHack/launchpad-freq-analyzer.git

Audio Capture

For the ADC interaction, I ended up using three separate peripherals to give me an incredibly software efficient audio capture process.  First, I set up a timer to count down at 44.6 kHz.  I set up the timer to trigger an ADC capture at the hardware level.  The ADC capture complete signal was set up to initiate a uDMA transfer, which was configured to move the data from the ADC capture FIFO to a global array of samples.  The result is very, very software efficient; One line of code starts the sampling timer, and SAMPLE_SIZE/44600 seconds later a software interrupt occurs, letting you know that the data has been captured and is ready in the sample array.  I was very proud of the efficiency of this process :-)

Digital Signal Processing

I am fortunate in that I've been playing around with audio hardware for years in the form of running soundboards and messing around with studio mixing and recording.  My last DSP class was a long, long time ago, but my interest in audio gave me a decent foundation in audio based DSP.  I am also fortunate in that ARM has a DSP library specifically designed to take advantage of the M4F's floating point instructions.  TI even has an application note detailing how to build that DSP library in Code Composer Studio.  From what I've heard, the amazingly handsome, charismatic, genius of an engineer who wrote the note did an incredible job on it, and it is wonderfully thorough and well written.  It might also be a little out of date (as ARM released a new version of CMSIS since the app note was published), but it's still good.

With those tools at my disposal, the DSP portion of my code wasn't too difficult to figure out once I wrapped my head around CMSIS.  Step one is to multiply the samples by a windowing function.  I chose a hamming window, because I vaguely remember hearing that that was good for audio.  Next, I take the FFT of the input data.  I'm pretty proud of this part as well; the M4F ended up being powerful enough to take a 2048 point fft on the input data, which gives you 1024 frequency bins, each of which represents the energy found in a 20.3 Hz wide frequency band.  So once I have the fft output, I take the complex magnitude of each sample, giving me the total power found in each frequency bin.

LED Display

To figure out how to translate 1024 frequency bins into 8 LEDs, I had to do some trial and error to figure out what looked the best.  I ended up splitting the 8 LEDs into logarithmicly spaced frequency ranges.  Each time I execute my signal processing loop, I calculate the average power found in the bins for a given frequency range (again using CMSIS for efficiency).  I divide this value by the maximum value I've seen in that frequency range.  Then, I just say if the result is greater than 1/8, turn on one LED; Greater than 2/8, turn on 2, etc.  If the result is bigger than the max, then turn on all 8 LEDs, and make that the new maximum. I also multiplied the current maximum by 0.999 to have a decay factor, which made it so my output wouldn't be decimated by a single spike in the audio.

To actually turn on the LEDs, I used a second timer for an easily configured refresh rate.  Each time the timer hits 0, I use the hardware SPI module to update the next column of the 8x8 LED display based on the value found by the above method.  The results are, if I say so myself, pretty impressive.

Future Work


I have a few ideas of where to go from here.  For one, the Olimex LED tile has an expansion header that can be used to have multiple tiles connected to the same SPI bus.  My code is theoretically written such that I can change a single macro to use a different number of frequency display elements (so I can go from 8 to 16 frequency LED columns with a simple recompile).  It'd be pretty fun to try expanding my LED tile to 16 columns wide.

A coworker of mine built what he calls his LED cube a few months ago.  Basically, it's an 8x8x8 cube of LEDs that functions very similarly to the olimex booster pack.  I have some cool ideas for how to do 3 dimensional frequency displays :)

I also found a booster pack that contains a 160x128 LCD display.  I'm pretty sure I can talk to the LCD just using Stellaris' graphics library without much work at all, and I think it'd be really visually impressive to expand my display to be contain 160 frequency bins.

Finally, it's been a long time since I've done a board layout from scratch, so I've been toying with the idea of making a custom PCB to get rid of the protoboard and blue wires that I currently have to use to make everything work.

Showing Off

For those interested in seeing how this works, I have a rather short video showing off the display!  For those who don't care much about the setup, you can fast forward to about the 2:05 mark to see the demo with music :)

I will likely add one more in the future that just shows off the finished working product with the audio overlayed directly on top of the video (as opposed to captured as it comes out of my headphones).