Simple DSP Crossover implemented using PIC32MX450 - diyAudio
Go Back   Home > Forums > Blogs > googlyone

Please consider donating to help us continue to serve you.

Ads on/off / Custom Title / More PMs / More album space / Advanced printing & mass image saving
Rate this Entry

Simple DSP Crossover implemented using PIC32MX450

Posted 17th March 2014 at 10:49 AM by googlyone
Updated 17th March 2014 at 10:58 AM by googlyone (incomplete)

It must be close to 12 months ago that I saw the PIC32MX450. I was convinced that a chip that included two I2S audio interfaces, and ran at 100MHz implementing 32bit arithmetic in pretty snappy time would surely be able to do some fun audio stuff.

I started with getting a board designed, and porting the code that I use to control my Analog Devices audio DSP. Then I generated the code to implement a direct digital synthesiser. These worked fine.

Over the last couple of weeks I have completed the "core code" for a digital crossover all implemented in the PIC32 itself.

The basic implementation is:
- An analogue to digital converter
- The PIC
- A digital to analogue converter
(Oh and an interface PCB done on veroboard to route the MCLK and power to the A/D and D/As. I am kind of tempted to re-spin the PIC32 board to do this for me...)

The PIC drives the I2S interface as master, generating MCLK, L/RCLC and SCLK. This drives both the A/D and D/A.

The A/D and D/A are pinched from my previous DSP crossover - they could be anything though as the interface is totally generic.

As with the direct digital synthesiser, I have set the clock dividers in the PIC to ensure that there is no intentional jitter on the MCLK signal. The PIC works by using an integer plus "fractional" clock divider for the system clock to generate the MCLK signal. so if you want 48Ks/s sample rate exactly you wind up with imposed jitter on the timing. The average is right, but at the MCLK rate things get a bit funky.

If you choose 46,875 samples per second, you wind up with EXACTLY 4 as the divider and no intentional jitter.

So what can you shoe-horn in there?

Well kind of more than you might think - and not that much. Both at the same time. How so?
- I have implemented the math as signed 7.24 fixed point for data, and signed 64 point data for the accumulator / result. This is way more precision than is necessary - but I did not want to try shoehorning the results into 32 bits (it wouldn't work).
- Until I optimised the code a bit, and used the PIC32 MADD (Multiple and Add to accumulator) command, the code was way too slow. This is the PIC32MX's closest thing to a DSP instruction. It does help through.

What did I get in there?
- Eight stereo Biquad filters
- Delay for time alignment
- Channel inversion
- Volume control

That allows
- One input, two outputs
- Low band has Low frequency cut (6, BW 12 and LR24 dB/octave)
- Low band has high frequency roll-off, again providing 6, BW 12 and LR24 dB/octave filters
- high band has low frequency filter, again per above to 4th order
- Two general filters, primarily aimed at parametric EQ, but you can program these for a lowpass for the second filter - making this unit do two bandpass filters.
- Some simple code to ensure sensible behaviour in clipping etc.

I have the code running well enough to have tested the timing and stability - it looks fine. I now need to recode all the human machine interface from another project - which is about half done. (The DSP algorithm was fun - now for some hack work to turn it into something halfway useful).

The DSP code runs as the core of an interrupt service routine - and from my experience on the DDS project will be rock stable on timing as long as I don't overdo the instructions in the DSP section.

The user interface needs to fit itself in "the rest of the time". The DDS worked just fine. I do wonder whether I will need to do anything fancy to avoid clicks and pops when the user changes DSP settings. (I fully intend that I can tune filters using a know in real time - with a nice display showing me what is going on.)

Is it worth it? I don't know yet. It does amaze me that a five buck chip (or whatever I paid for them) can do this much. As an intellectual exercise this has been great fun so far. As a practical exercise, the "rub" is:
- A/D converter CS5381 - $25 or so
- Micro PIC32MX450 - $5
- D/A converter CS4398 -$14 or so

Something seems to be wrong there... but it is fun

And you can code ANYTHING you damn well please into the chip.

The code optimisation is currently at a "super basic" level. By that I mean that I have structured the 32 bit multiply and add code such that the compiler can use the MADD instruction - and I have been a bit cautious about selection of variables etc. But I suspect there is a fair bit of extra optimisation to be had in there.

Anyway - even as is I think a full stereo DSP crossover with 4th order filters, time alignment and two parametrics is not a bad start.

No picture of the crossover - it uses exactly the same hardware as the other PIC32 stuff in the blog. Oh, and the same desk, computer and cat...
Posted in Uncategorized
Views 499 Comments 3 Email Blog Entry
Total Comments 3


  1. Old Comment
    Nice! A little short on available biquads, but a great project.

    How do you implement volume control?
    Posted 19th March 2014 at 04:39 PM by CharlieLaub CharlieLaub is offline
  2. Old Comment
    Originally Posted by CharlieLaub View Comment
    Nice! A little short on available biquads, but a great project.

    How do you implement volume control?
    Yhea - compared to the full on DSPs like the adau 1442 I use in my other stuff, the PIC is "not right up there". but then again, it is a general purpose micro.... when I was at uni this would have been a pipe dream. Now it is cheap as chips!!!

    Volume control in the simplest implementation will be direct scaling (multiplication in the DSP).

    The DACS that I have also include a PGA3210 (or whatever the part number is - I am not at my desk now). The code can write to these instead if I use those DACS.
    Posted 21st March 2014 at 11:45 AM by googlyone googlyone is offline
  3. Old Comment
    Is there a way instead of driving a DAC, use a PWM signal output? Reason I ask it would be neat to drive a Class-D output stage directly from the DSP. Technically since the DSP is doing all the audio processing anyway, instead of taking final processed output and sending it I2S, use a timer to generate a PWM from the same data? Also unless I am missing something, I dont see a link for the code.
    Posted 23rd August 2014 at 01:40 AM by mbates14 mbates14 is offline
Hide this!Advertise here!

New To Site? Need Help?

All times are GMT. The time now is 05:53 AM.

vBulletin Optimisation provided by vB Optimise (Pro) - vBulletin Mods & Addons Copyright © 2014 DragonByte Technologies Ltd.
Copyright 1999-2014 diyAudio

Content Relevant URLs by vBSEO 3.3.2