Go Back   Home > Forums > Blogs > googlyone

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 1791 Comments 4
Total Comments 4

Comments

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

    How do you implement volume control?
    permalink
    Posted 19th March 2014 at 04:39 PM by CharlieLaub CharlieLaub is offline
  2. Old Comment
    Quote:
    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.
    permalink
    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.
    permalink
    Posted 23rd August 2014 at 01:40 AM by mbates14 mbates14 is offline
  4. Old Comment
    Quote:
    Originally Posted by mbates14 View 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.
    An interesting thought - I have not thought much about this...

    The PICs are floating in timers and PWM generators. Without thinking too hard about it, I have no doubt that the PIC32 would make a "fair go" at driving a class D output stage.

    The rub will be "How good a job will it do?".

    The software knows would be able to update the hardware PWM / Timer system at the sample rate quite easily. I wonder if anybody has looked at this.
    permalink
    Posted 6th September 2014 at 01:44 PM by googlyone googlyone is offline
 

New To Site? Need Help?
Copyright ©1999-2017 diyAudio