PSoC 4 Emulation of a MSGEQ7 Audio Spectrum Analyzer

Applications engineer Sree Harsha Angara has used a programmable SoC to create an exact replica of a MSGEQ7 audio spectrum analyzer IC.

Over the last few weeks, I have been having a lot of fun implementing a simple audio spectrum analyzer using a pair of MSGEQ7 chips (designed by Mixed Signal Integration and purchased from SparkFun). For the digital processing and control portion of the system, I'm using a chipKIT MAX32 microcontroller platform featuring a 32-bit MIPS-based processor from Microchip Technology running at 80 MHz.

The columns on my project have received quite a few comments, including one from Sree Harsha Angara (a.k.a. Mithrandir), a senior applications engineer in Bangalore, India, for Cypress Semiconductor. "My interest is piqued now," he wrote. "I'll see if I can get the front-end filtering running on my PSoC 4 Pioneer kit. Weekend project, here I come :)"

Over the last few years, several of my friends have told me I should start playing with programmable SoC (PSoC) devices from Cypress. In particular, the PSoC 4 looks rather interesting, with its mixture of programmable analog fabric (opamps, 12-bit 1Msps SAR ADC, etc.), programmable digital fabric (four PLD-based logic blocks), and a 32-bit ARM Cortex-M0 processor running at up to 48 MHz. I particularly like the 1.7-5.5V operation.

Anyway, Sree and I ended up exchanging several emails. I learned that he "works mostly on power supervision designs and almost any other customer designs that come my way." He takes "a personal interest in control theory, digital filters, and power electronics." He's currently writing a series of columns on PID controllers on EEWeb. He's "always crawling around EE Times," and he reads my blogs in particular "because of the fun projects." Ooh, he knows how to get my attention (LOL).

Eventually, Sree sent me an email saying, "Hurray, I finally got my hands on an audio splitter. I also got some time to get to the filter design and I'm pretty satisfied with it. A quick peek of the characteristic curves is as shown below:"

When I asked Sree whether these curves were theoretical or empirically measured, he explained: "I create these curves the old-fashioned way using Excel. The curves I show here are theoretical, but I generally make it a habit to perform a simple Excel simulation in the digital domain once all the nasty transforms and fixed-point bit shifts are done."

A few days later, Sree sent me another email saying, "It's Alive!" It seems that he used his PSoC 4 to create "an exact replica of the MSGEQ7 chip with its seven band-pass filters and peak detectors." He also sent me a link to link to this video showing his PSoC 4 accepting an audio stream, emulating a MSGEQ7, and driving seven LEDs.

Do you recall my blog from a couple of months ago about the 32-bit PSoC 4 dev board? Since then, I've ended up with 41xx and 42xx versions of these PSoC 4 Prototyping Kits, along with a PSoC 4 Pioneer Kit, so I asked Sree if I could implement his design on these boards. He replied: "This implementation just uses one SAR ADC and the whole filter runs through a single interrupt routine. That being said, you need seven PWMs to drive the LEDs -- I basically use four fixed-function PWMs and the other three are implemented using UDBs (Universal Digital Blocks)." He also provided the following block diagrams.

Block diagram showing the analog functions used in this PSoC 4 design (click here for a larger image).

Block diagram showing the digital functions used in this PSoC 4 design (click here for a larger image).

If you want to play with this design yourself, Sree has kindly provided these main.c and adc-sar-int.c files, along with this ZIP file with all the source code and the entire PSoC Creator project.

Sree says we still have about 50-55% of the processing power free. Also, it seems that he's run across another really interesting method called the Goertzel algorithm for frequency detection. In his last message to me, he said: "I'm still chugging along with the Goertzel algorithm, but on first sight it's a lot more complicated than simple band-passes and I'm having some difficulty wrapping my head around it."

I, for one, have every faith in Sree, and I look forward to reporting on his progress with the Goertzel algorithm in a future blog. In the meantime, what do you think about the PSoC 4 devices?

I'd be interested in hearing what the power consumption is of the two designs, the dedicated hardware and the PSoC. I was intrigued by the PSoC concept years ago (PSoC 2) and tried to integrate them into products I was designing at the time. One large factor which ruled them out at the time was the massive power consumption relative to a traditional design. I would imagine that has improved and would be interested in some current (no pun intended) numbers.

I didn't take a look at the power numbers on it, but I can give it a shot in the next couple of days. Luckily the -042 Pioneer kit has a jumper in series with the 5V rail which I can remove to measure power consumption on the PSoC4 end. The numbers might be skewed due to the LED's present during running, so I'll try with/without the LED's to check.

I know the PSoC4 power consumption is pretty competetive to most other micros of the same class(I know a guy who sitting next to me who could detect a capacitive button sense with as low as 4~5uA average current draw). That being said though, this might not be the best comparision as the MSGEQ7 just gives a muxed analog output. We would still need some form of processor with an ADC at the end of it to make sense of the data. From a whole system standpoint I'd hazard the numbers would be pretty similar.

Well, that's the marketing take on it, but I am wondering about real world power consumption during operation, not standby. To me a head-head comparison of a non-PSOC implementation to a PSOC implementation is relevant, but then I have mostly worked on products where power consumption matters.

If I remember right, the apps engineer who was showing us a simple demo involving reading a pushbutton and turning on an LED said the PSOC was consuming around 20mA (with the LED off). Granted this was a generation 2 device. I imagine Gen 4 is much improved.

You're absolutely right about the marketing take, I always like to see the working numbers as well :D. Although the sleep and hibernate numbers are surprisingly useful when doing an application which sleeps most of the time, something like the touch button sense I was talking about earlier where the the processor only wakes up once a few milliseconds and runs for a few usecs.

The real numbers when running can be found on the PSoC4200 data sheet http://www.cypress.com/?docID=46322 on page 14.

From the datasheet, with the CPU running full blast at 48MHz, it'll draw around 13mA for the core. I'd expect this application will probably draw a 2~3 more mA for the ADC, buffer opamp and PWM's. Very likely this can be optimized to run at 24MHz too(probably just able to squeeze in everything on the filtering end) and we could chop the core current down to 7mA. This is all just paper calculations though, real numbers coming up tomorrow :)

Wierd, I know I've replied before but it seems to have disappeared from the comments section.

Got some bench numbers and the current consumption is around 15mA(not driving LED's, pins are open), just as expected from the datasheet(13mA for the 48Mhz core and 2 mA for the rest). Also managed to optimize the code a little to make it run at 24MHz and chopped the current down to close to 8.5mA. Pretty decent considering the ADC+8PWM's+M0 core. Far better than the 20mA PSoC you remember I'm sure :)

the typical current consumption is 0.8mA @ 5V. So percentagewise, the PSOC is still "a hog" but in absolute terms, maybe not so bad. That outrageous clock speed on the PSOC eats power, which is what I remember from before.

I can still see the devices being useful for some unique functionality where a high level of integration is rquired and no off the shelf soltuions exist. The ability to reconfigure the device on the fly is also an interesting attribute.

Alas, the outrageous clock speed is unavoidable due to the 7 digital band-pass filters :D

But, it's as you say it depends on how many things you can integrate in PSoC. At the risk of sounding 'markety', from a system level the power numbers will generally be in the ball-park range with additional savings in the BOM.

Hope you get a chance to play with PSoC again, purely from a fun perspective of the PSoC Creator IDE :)

I just used the audio output of my laptop for this one. Even at the max volume, the signal was only a 0.5V peak-peak signal on the oscilloscope. I expect most laptops(and probably cellphones) give around the same range. Worth double checking the audio output on a oscilloscope before hooking upto the kit just to make sure though.

This brings up an interesting point which I didn't mention though. If you noticed in the block diagram and the video, I didn't actually shift the incoming AC waveform to fit within the rail to rail voltage range of the ADC. The PSoC is actually getting the direct -0.25 to +0.25V signal to the internal Opamp and ADC. Due to an interesting quirk in the silicon, you can actually measure voltages(when the ADC is in differential mode) below the ground upto around -0.4V (beyond it, begins to distort the signal). Great for quick, messy projects like this one :)

Hope you have fun with it! You'll need a protoshield of some sort though to wire up the LED's.