Path: EDN Asia >> Design Ideas >> Computing/Peripherals >> PSoC-based audio spectrum analyser using NeoPixels
Computing/Peripherals Share print

PSoC-based audio spectrum analyser using NeoPixels

16 Sep 2014  | Sree Harsha Angara

Share this page with your friends

All in all, this is a pretty neat and lightweight protocol. The data high and low values are specified by a pulse width with some pretty tight timing constraints, as the whole thing is running at either 400 or 800kHz, depending on the speed you set.

The original Arduino-based code library on Adafruit's NeoPixel Uberguide achieves this by bit-banging and optimising the code. Quite understandably, Adafruit puts up a disclaimer that this doesn't work on Arduino-compatible boards, since it used low-level, processor-specific assembly instructions.

Using UDBs on a PSoC 4, this driver can be built almost independent of the core processor by utilising available datapath and macrocells. Essentially, the component splits the protocol into two parts: a master PWM (which runs at 400/800kHz) and a 24bit shift register. At the end of each PWM cycle, it simply shifts one data bit and—depending on whether we wish to transmit a zero or a one—it loads a pre-specified duty cycle. Thanks to the datapath, this load is independent of the CPU. I'm simplifying the process a bit to exclude things like the end-of-data (also Verilog-based), but the essential idea remains.

All we need to do is load up a 24bit value and forget about it until the next LED data needs to be written. The component automatically generates a master array depending on the number of LEDs, and the UDB triggers an interrupt until you run out of data in the array. Furthermore, if you were to use a PSoC 5LP, you could employ its direct memory access (DMA) capability at this point to shift out an array of data automatically and just keep modifying the master array to make it completely independent of the core processor.

Generating the desired colour map was a little tricky. The component, by default, already has a lookup array for colours, but for my project, I wanted a brightness variation for each pixel, depending on the magnitude of the associated frequency component. Using just five LEDs for each band is a little choppy on the eyes, so giving a little bit of granularity by varying the brightness of the individual pixels made things look much better. Since each colour is just a variation of how much each LED is turned on, I simply created a simple lookup table that maps the colours green, light green, yellow, light red, and red to a 256-value array map with variations in brightness for each colour.

This ZIP file contains all of the source code available, so please feel free to reuse it and experiment. As always, I look forward to your comments and questions. In the meantime, happy blinking.

About the author
Sree Harsha Angara is with Cypress Semiconductor.

 First Page Previous Page 1 • 2

Want to more of this to be delivered to you for FREE?

Subscribe to EDN Asia alerts and receive the latest design ideas and product news in your inbox.

Got to make sure you're not a robot. Please enter the code displayed on the right.

Time to activate your subscription - it's easy!

We have sent an activate request to your registerd e-email. Simply click on the link to activate your subscription.

We're doing this to protect your privacy and ensure you successfully receive your e-mail alerts.

Add New Comment
Visitor (To avoid code verification, simply login or register with us. It is fast and free!)
*Verify code:
Tech Impact

Regional Roundup
Control this smart glass with the blink of an eye
K-Glass 2 detects users' eye movements to point the cursor to recognise computer icons or objects in the Internet, and uses winks for commands. The researchers call this interface the "i-Mouse."

GlobalFoundries extends grants to Singapore students
ARM, Tencent Games team up to improve mobile gaming

News | Products | Design Features | Regional Roundup | Tech Impact