Low-pass filter and amp design

Dec 02, 2005 10 Replies

I'm seeking some advise on designing a low-pass filter and amp circuit. Unfortunately I've never been trained in electronics, so I'm learning things as I need to!



My application is portable, battery based. The battery is rated as



9.6v and there will be a regulated supply at +5v for the CMOS area. I'm looking to generate an audio signal from a PIC (or similar) using PWM. The digital side I'm fine with, its the analogue side I don't know. I need to clean up the PWM signal and output it to a speaker at reasonable volume.

I have the following objectives:



  • Minimise power usage where possible * Have a shut-down signal that puts the audio circuit in to standby * Keep the component count as low as possible * It has to be cheap

The audio quality doesn't have to be hifi level, a reasonable quality is fine. I've looked at loads of possible circuits, but I can't find anything concrete on how to calculate values to filter at the right frequency. Incidentally I expect the sample rate to be around 9Khz, therefore a cut-off at 4.5Khz would be best. The modulation frequency from the PWM is going to be around 36Khz. These aren't fixed figures just yet, because I need to do a bit more research on the chip capabilities. If possible I'll run it on a higher PWM frequency, but these values are good indicators for the end design.



Thanks in advance for any help given!



Michael



The corner frequency of a single-pole RC low-pass filter is 1/2/pi/R/C, but if I we're you, I'd consider a 2-pole filter. Try Googling for: active filter 2-pole low pass. The number of poles controls how steeply it rolls-off above the corner frequency: 1/f or 1/(f^2)

I haven't checked, but I'm sure there must be an audio amplifier IC in an op-amp-like configuration (inv. and non-inv. inputs) with a low-power standby mode. Alternatively, you could insert a transistor in series with the power supply to switch it off.

I presume your PWM output will be 5V logic i.e. 2.5V peak-to-peak AC

sqrt(100mW * 8 ohms * 2) = 1.26 V peak

so you won't need any voltage amplification.

I have used an LM386 low-power audio amplifier for driving small speakers with audio from microprocessors. It is an inexpensive item, in an 8 pin dip package, with a gain of 20 - 200. You could probably get away with a passive RC filter circuit between your PIC and the LM386. The nice thing about this chip, is that it can operate on a single 5V source, which you have available to you. As far as power consumption goes, it is a little greedy. I would use Andrew Holme's idea of using a transistor to supply power to the chip. This way you can turn the chip off with a signal from the PIC.

Andrew

The cheapest filter is no filter. That would probably work here; nobody can hear 36 KHz.

John

A filter cut off of 4.5kHz is not the right choice for a sampling rate of 9kHz. It may be fine for your PWM frequency, but if you try to generate audio at close to 4.5kHz you'll hear significant aliasing.

You have to ask yourself: What is the highest frequency that I'm going to play, and what's an acceptable amount of aliasing? That, plus the sampling rate, will tell you the order of the filter you'll need. I'd probably choose a 3kHz filter because it's standard telephone-quality. You can, if you're clever, get a 3-pole filter with a single amplifying element. If you're a beginner just find a cookbook 2-pole audio filter and use that; if it's not enough filtering then cascade two of them.

Tim Wescott Wescott Design Services http://www.wescottdesign.com

You've gotten several contradictory answers, none of which give any background. I'll summarize, and give some background on each:

Active filter:

This was my suggestion, and Andrew's. In this configuration you take your PWM and apply it to an active filter (probably op-amp -- be wary of switched capacitor filters because they'll alias the aliases from your PWM frequency and that could be very bad). You amplify the active filter output with any old linear audio amp (National and TI both have an impressive lineup of small audio amps for this sort of application).

L-C Filter:

Ken's suggestion. Presumably with power amplification on the PWM side. This will be more useful for knocking down the PWM than anything else, an LC filter with a cutoff of 3kHz that's capable of handling the power will be _big_, and you will have to search hard for the coils, or roll your own. Expect aliasing, which won't be too bad if you just want to make beeps.

If you amplify the PWM first, then filter, you'll get the best efficiency.

No Filter:

John's suggestion. Like LC, you could power amplify with a switcher.

36kHz aliased with 9kHz aliasing products would put lots of aliases in your passband; it may sound horrible (but it may sound fine). If you actually transmit power to the speaker at 36kHz it may not be audible by humans, but it may consume considerable power and drive local dogs totally nuts.
Tim Wescott Wescott Design Services http://www.wescottdesign.com

One final note:

If you are to do anything with a PIC other than play out a pre-recorded audio stream you may be disappointed with the speed -- don't take this as nay-saying, but please do make sure you have enough processor for the job at hand. I'm _always_ too optimistic with my processor selection at first cut; thankfully I've learned to double and triple check such things.

Tim Wescott Wescott Design Services http://www.wescottdesign.com

In article , wrote: [....]

This likely implies using an LC filter. If you have the room, it is a good way to go.

Some filtering can be done by the physics of the speaker and how it is mounted etc. You should include this in your thinking about the filter if you want to keep the costs down.

You may be able to make it such that stopping the PWM drops the power to zero.

Basically, what I suggest is like this:

------- ! Power ! From ----->! boost !----[L]----+----> To speaker PIC ! stage ! ! ------- --- --- C ! GND

Go to

formatting link
and download SwitcherCadIII. It is easy enough to use that someone with a pure digital background should have no problem learning to run it. It will be very useful from trying out suggested designs.

Before you design the L and C values, you will need to know the characteristics of the speaker in the box, near the cut off frequency. You can measure this by putting a resistor in series with the speaker and driving it from a signal generator. The voltage on the resistor gives you the current. Remember to include the phase when you work out Z=V/I.

Once you have the Z value, working out L and C isn't too hard. You then need to check that the L and C are practical. If you can't find an inductor with near inductance and current rating, you may have to give up on this idea.

On the physics side: I assume you have mechanical engineer involved. If he's any good, he will be able to help with getting the package to help you instead of hurt you.

-- kensmith@rahul.net forging knowledge

In article , John Larkin wrote: [...]

"Everytime I turn of the radio, my dog bites me."

Chances are, you need to take the sharp edges off if you want to pass the FCC or EU regs.

-- kensmith@rahul.net forging knowledge

In article , Tim Wescott wrote: [...]

Yes, depending on the power involved.

Assume Xl is about 10 Ohms:

10 = 2 * PI * 3K * L

L = 10/(2 * PI * 3K) = 530uH

Look at

formatting link

If the circuit is running from a modest voltage and can only make modest amounts of power, you could use one of these.

It may sound horrible and you don't care.

-- kensmith@rahul.net forging knowledge

Wow, thanks for all the replies! Its a lot to take in.... I'm still trying to get my head around the calculations in certain places.

I've done some testing with components that I have around the place. Unfortunately op-amps and chokes aren't really things I have around the place. Plus I really need to know what to order first!

First up I did a simple test directly driving the speaker via a transistor. This actually worked really well, all be it with relatively poor quality compared to my PC, plus it had the odd crackle or pop (most likely down to my s/w coding at this stage)... I'm guessing this isn't a good idea though. I didn't notice any difference to driving the speaker directly using the transistor compared to putting the input in to an LM386, similar volume resulted and no detectable audio quality change.

So given I've got a few basic parts around the place, I tried a 100nF capacitor and 330R resister in an RC configuraton connected in to the input of an LM386. This worked too well and trimmed all but the very low frequencies out. The formula I used was:

1/(6.283 * Capacitor * Hz)=3DResistor

This was based on a 4800Hz cut off.. I stuck with that as there will be sound effects in there, and it matched the componets I had to hand. I tried dropping the capacitor value down to 4.4nF which gave me my sound back, but i'm not sure if it actually did any useful filtering or not (I've not got a scope unfortunately), there was no audible difference.

The choke idea could be good, however I've read some stuff about that giving off a fair bit of RF.... and there is a chance I may have to implement radio within this device at a later date so I want to minimise RF where possible (sorry forgot to mention that). This of course rules out having no filtering!

The op-amp method looks good - but I've no idea which part to use and difference they have on the circuit. My ideal unit has:

- No need for funny voltages, i.e. no need for an external inverter - Lowish power consumption - If possible a shutdown signal (but can always use the transistor on the power line to the audio circuit).

Having had a quick look around Farnell for example, the KA358A looks good. Its cheap (=A30.30) and looks suitable.. but I don't know if it'd do the job... and I can't work out how I'd calculate everything... I mean I've got a good example circuit diagram here, but I don't know if the values would be different for different op-amps. The op-amp used in the diagram costs a lot more than this one and requires an inverter to supply the negative side (which costs more than the op-amp!).

As far as the physical side of it, this is to go in to an existing case design, so I have no control over the physical design or the speaker size. The currently used model is an 8 Ohm 2.5" speaker. Effectively I'm trying to design a replacement of an old design. The old design is excellent but is now about 20 years old and some components are becoming harder to source (one was dropped over 2 years ago and now is almost impossible to obtain). One of the objectives is to reduce the component count where possible but also to implement new features as well. I did look at using the ISD chips which are good, but cost too much and are difficult to alter the contents of without a programmer - this method allows me to use a normal serial flash rom which I can also alter while its in-place if needed.

On the topic of "can the PIC handle it".... well at 20Mhz it can handle driving the audio at over 8Khz sample rate using ADPCM calculations. It can do little else at the same time.... it has 15us delay between each sample that it could use. I'll most likely end up designing it with a higher maximum clock speed, but it only enters that speed when it needs to - the new PICs are good with the variable clock speed so I can minimise power usage that way.

Again - thanks for all the help!

Mike

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required