digital filter using pic micro controller

Status
This old topic is closed. If you want to reopen this topic, contact a moderator using the "Report Post" button.
hi there,
I was wondering if anybody knows how i could build a digital filter using a pic microcontroller. sombody sugested it to me and i need all the help i can get. i was requested to use the 16f877 and a frequency to voltage converter at the input of the pic.

Also can anyone tell me about the LM 311N ic. I am also working with a limited budget and time. This has to be completed by the end of April so components have to be readily available.
 
What sort of digital filter are you trying to build? With a given input, what will the output be?

More information would be useful.

You can do FFT on the PIC to save using a frequency to voltage converter on the input (do they only work on a single frequency? if so, they're not suitable for audio). There's an app note on Microchip's site.

You can find info on the LM311 on the web. Type it into Google and have a read.

(man, if I asked these questions at uni, I'd get my *** kicked - and I'm only in second year :) )
 
Hello,

If you want to do audio filtering (HIFI), just forget it.
Or you may want to use the PIC18 series (the DSPIC's)

Your I2S data, most probably, will enter your PIC with a WS of 44.1 KHz and a BCLK of 2.822 MHz.
This is serial, so you have to get in all 16 or 32 bits.
This does not leave much of processing i think when running a PIC at 20MHz.

At speach bandwidth (8khz) it is a different story.


Check www.piclist.com

grtz

Simon
 
hey guys, sorry about the post but its my first time.

The entire project is to build an audio amplifier +/- 50W RMS using MOSFETS. It must also include a digital filter using a micro-controller. I have the amplifier part of it sorted out but i am not sure how to build the filter and interface it to the amp.

the filter will have to be bandpass, the input to the filter will be 20Hz to 20kHz. the output will have to be some where around 30Hz to 17kHz. As for the DSPics, they are not yet available in my country.

The microchip specialist i spoke to told me to use the 16f877 and i should use the freq/volt. converter to interface the audio signal into the PIC. He also said that the d/a coverter on the PIC would only make it harder for me.

Is this a good idea or can i make it simpler to do.

thanks for all the help.
 
It seems that there are a number of straightforward ways of approaching this, none of which are likely to acheive any form of quality. I think your project definition is also extremely vague, at least for us forum readers. Is your project to be

line lvl analog -> black box -> line lvl analog -> amp

where the black box does the filtering in the digital domain? Why in the digital domain? Does your project plan specify flat phase response or some other quality which is difficult to achieve via active or passive filtering?

The most rational way of doing this digitally in the real world would be ADC -> TAS3001 -> DAC mediated by your uC. Probably not hi-fi, but fairly good quality. I doubt this meets the requirements of your project to show some signal processing work though.

Another option is to pick up a board like TI's c6000 series DSP eval boards. This has an on board codec (only 11kHz/16 bit-ugh) and there is free development software that could be used to create the signal processing routines. Or you could go with a SHARC but I am not familiar with these processors.

You are hoping to complete your senior design project in 2 months? I wish you the best of luck.
 
checking the requirements more carefully...

The entire project is to build an audio amplifier +/- 50W RMS using MOSFETS. It must also include a digital filter using a micro-controller. I have the amplifier part of it sorted out but i am not sure how to build the filter and interface it to the amp.

+/-50W RMS? Do you mean 50W RMS, or running from supply rails of +/-50W DC? (I'm guessing the former, in which case you shouldn't have any trouble whatsoever).

Digital filter using a microcontroller - that's pretty specific. And you need pretty beefy microcontrollers if you want to achieve any sort of quality. If I were you, I'd go out and buy or order one of everything that you can get your hands on, and figure out what you're going to do with them later.

the filter will have to be bandpass, the input to the filter will be 20Hz to 20kHz. the output will have to be some where around 30Hz to 17kHz. As for the DSPics, they are not yet available in my country.

This is pretty easy to do in analog, but a pain in digital, unless you have a lot of CPU power to throw around. Again, take a look at Microchip's website and find the application note that gives code for FFT on a PIC. There's tons more useful stuff, if you look around.

Have you ever programmed a PIC before? The architecture is somewhat different to most microcontrollers. Some people feel that they're very restrictive. (I learnt PIC assembly before any other type, so I feel that PIC is very efficient, but everything else is very flexible :) )

If you find that your PIC has enough power, your project sounds like it would be done by FFT'ing the input (using one of the PIC ADC channels - only 8-10 bit, though), zeroing out the frequency bands outside the desired range, and converting back to the time domain (I'm not sure if the same FFT algorithm will do that - I failed Signals and Systems, damnit!)

I seriously doubt that any non-DSPIC will have enough grunt for that, though. Or give you enough frequency bands to be useful, for that matter.

The microchip specialist i spoke to told me to use the 16f877 and i should use the freq/volt. converter to interface the audio signal into the PIC. He also said that the d/a coverter on the PIC would only make it harder for me.

I would say that the 16F877 is rather small for this application, unless you can do the conversion to and from time domain outside the PIC. It's 20MHz, but executes instructions once every four clock cycles, so you only get 5M instructions per second. RAM is a big problem too - only 384 bytes to play with - and I would expect that you'd want a good chunk of that for the frequency data.

A frequency to voltage converter is no good if you want, say, music signals to be legible at the output. You could move the frequency threshold continuously to achieve a really dodgy fourier transform, but the F-V converter needs a certain amount of time to do its job, and the signal will change over that period. It'll sound bad, to put it simply, if it works at all.

A single sinewave would probably be OK, though.

The ADC converter on the PIC is about as simple to use as you can possibly make it. Apply analog voltage on pin X, read digital representation on memory address Y. It's what happens after that which will be the challenge.
 
Blu_line,

Can you quantify "reasonable" in any way? I am a bit too lazy at the moment to get out Octave and find my undergraduate text on numeric stability, although I probably should. I'm interested in putting together a digital EQ at some point and this IC seems to at least have definable error bounds, unlike TAS3001 which is kind of a black box.

The Alesis 8ch/20-band eq app note lists a usable word length of 18 bits, although I think this could easily be 20 bits with less clip protection. If truncation errors could be held to 2-3 LSB this could be quite nice.

Thanks,
Tyler
 
hmmm, reasonable !?!?!?

At work we use DPS's with 24 bit coeffiecient and 24 bit data path or 12 bit coeffiecient and 24 bit data.
The ALU and multiplier in the last one can produce resp. 36 and 39 bit results.
Rounding / truncation happens after this step, but you can be sure that the ALU and multiplier hold a correct result.

As for the Alesis, 28 x 22 bit would need an alu with an result of 40bit and an multiplier which is around 44 bits.
Since the alesis has just an 28 bit result register, errors are introduced. How big the error is, i can not say.

By scaling the coefficients and data (take 16 or 20 bit data instead of 24 and use 12 bit coeffs instead of 22) the result would be reasonable (we all wish to have the maximum achievable, do we ;) ) but would still be qualified as HIFI
 
Good Luck

I think you have several issues at work here:

1) How will you get digital data into your PIC?? Well, ignore any of the nice ADCs\DACs with I2S, since you will not be able to interface to them unless you put a CPLD outside your part to convert the serial I2S to Parallel such that you can get it into and out of your PIC if you insist on using a PIC (bad idea if you ask me).

2) Ignore all those posts on FFTs, etc. That is not how you do a filter digitally in the real world. I would also forget about doing an FIR filter at audio frequencies on a PIC. It just isn't going to happen. However, a second order IIR filter should be doable. Heck, if you are really good, you may even be able to do 4th order at 44KHz.

3) If you insist on using PICs, stick to the 18C\F series at 40MHz (10 mips). This is as fast as it gets with PICs. The DSPICs will not be available for several months (these are not 18 series as one of the posts stated).

.... or you could save yourself a ton of grief and buy a DSP evaluation board from Motorola (563xx) - 24 bit for easy arithmetic, or ADI (Shark - 32 bit, real easy). These parts have I2S interfaces. In fact, their eval boards have A/D and D/A on them already. Maybe not great quality, but at this point, concentrate on that credit and getting to the PUB. Commercial quality can come later. They are less that $300 and you may even be able to find a promo for a lot less. You can usually get a freeware assembler, debugger, compiler for limited code-space that is more than enough for your requirements.

Hope this helps...
 
thanks Alvaius.

1) The information you supplied was just the sort of information, i was looking for. You say that the PICs are a bad idea, what other microprocessors do you suggest. i am familiar with the PIC and that is why i chose it. From your experience, which would be a better microcontroller for this application. forgive me for my ignorance, but what is a CPLD?

2)Iam going to stay away from FFT's 'cause i don't know much about them, however i do know something about IIR filters. Microchip has an APP. note on IIR filters. Maybe this would be a good place to start.

3)One of the technical guys at our microchip supplier said that the 16f877 should be quick enough for this application. How quick should the PIC be.

4) Hmmm..... $300, considering that i earn +/- $120 a month(student), the evaluation board would have to be out of the question for now. Iwill try to gather more information on the motorola's though.

Any idea on what the sound quality would be like?

Thanks again for all the help.
 
The 18 series of PICS have better math capability. At 44Ksps stereo, the 16F877 will have about 50 instructions max per sample. That is not much when you need to extend 8 bit math to 16 bits. The 18 series will offer you twice the MIPS. However, I would be far more inclined to drop a DSP down. 56303 or similar from Motorola, a 2185 or similar from ADI, etc. would be so much easier to work with. Given the cost, it sounds like you are not going to be able to do your own PCB, so getting a DSP eval board may not be a bad idea. Eval boards generally have a so-so 16 bit ADC\DAC combo.

I may be able to do something for you.... where are you located (city?).

Of course, you could cheat and use a Cypress PSOC microcontroller that has switch-cap building blocks. Not a digital filter, but much easier (hours to design!).
 
I'd have to agree that the PIC is not a suitable choice. 50 PIC RISC instructions per cycle is nowhere near enough, even on just 8-bit audio data - the simple reason is that the PIC micros do not have hardware multipliers. Thus, you are executing a short program to do one multiply operation. Extending the math to 16 bits only compounds the problem on these little 8-bit processors. PICs were not designed to do math, but instead just to run simple little programs for controlling things, and maybe to do some light math when there's ample time available for it to crunch away for a few thousand instructions.

Frankly, there are very few microcontrollers which will be capable of supporting decent audio filters in realtime. The Motorola 68HC16 might be a candidate to look at, since i believe the CPU16 core includes a 16-bit MAC (Multiply and Accumulate) unit, which is exactly what you need for FIR or IIR filters. A 24-bit MAC with a larger accumulator register would be even better.. but now we're talking real DSPs like the motorola or analog devices chips mentioned in prior posts.

A CPLD (Complex Programmable Logic Device) is is the same thing as an FPGA (Field Programmable Gate Array) - Xilinx calls them FPGAs, and apparently owns a trademark on that acronym, so Altera calls the same things CPLDs. Basically they are big blocks of generic logic gates you can configure through downoadable software. You write a hardware description in VHDL or Verilog and compile it, then download it to your target device and Presto! ...your blank critter suddenly becomes an ASIC (well, pretty close). Make a mistake? ...just reconfigure your chip! I'm sure your school should have some Xilinx or Altera evaluation / educational platforms somewhere that you can use for your project, along with the appropriate development tools. All you'll need to do is build the hardware to interface with the CPLD board. For your purposes, this is likely your best option, as the hardware costs should be minimal if the school owns the cpld targets and dev tools. Your second best option is indeed one of the DSP evaluation kits. You should ask if the school is willing to equip their labs with one or more of these kits... which can of course be used for subsequent student projects.

Good luck with it! :)
 
Status
This old topic is closed. If you want to reopen this topic, contact a moderator using the "Report Post" button.