PWM -> Audio

Recently there were some comments in another thread about microcontroller audio output techniques. (I can't find them now - having to use Google Groups sucks - my otherwise reliable ISP discontinued supporting a dedicated news server), and it leads me to ponder a bit on what the best way to do this is.

On a prototype, using 8-bit audio (voice) data sampled at 8 kHz to drive a PWM output, I just brute-forced the audio output path: A multistage active LP filter (4 kHz corner freq) and a simple PA to drive the earphones/speaker. I'd like to do something smarter/better/ cheaper on the next iteration.

Some options:

1) Multiply the PWM rate by N, reusing the data N times (or perhaps interpolating), cut down on the active filtering required. However, significantly upping the rate chews up processor cycles and increases power. Enough to matter? I dunno yet.

2) Make a charge pump out of a tristateable output and internal counters, drive it using differential data, and feed an external integrator. The sampling frequency component at the output would be significantly less compared to the PWM output and thus could result in savings in the filtering circuitry.

3) Implement the "traditional" class-D LC filter output.

4) Just try to get the PWM frequency as high as the rest of the system will allow and then drive the earphones/speaker directly, using the speaker/headphones as part of the filter. Certainly cheap, but what about emissions, especially out of probably non-shielded headphone cords?

I haven't thought this all out, but am asking the group for input because I'm sure some of you have already done this thinking for me :-) So, what have you done / would you do?

(P.S. The National LM48511 looks interesting. Have any of you used it?)

-- Silvar Beitel

Reply to
Silvar Beitel
Loading thread data ...

Yes you can get a reasonable quality speech output from a PWM on a microcontroller.

This improves quality a lot. Run the PWM at 32kHz sample rate. Upsample the speech to 32kHz by the simplest linear interpolation. This doesn't take much computation. Use the double edge PWM rather then single edge.

This will attenuate the carrier however the sidebands will be the same. The carrier at 32KHz is inaudible anyway, so I wouldn't care much about it unless there are some other concerns.

This is a 2nd order filter no better or worse then any other filter of the 2nd order.

The reasonable PWM sample rate for the audio purpose is x10...x20 of the maximum audio frequency of interest. There is little point to go higher then that. Emissions are the huge problem with the PWM amps.

It depends. What exactly are you trying to accomplish?

Vladimir Vassilevsky DSP and Mixed Signal Design Consultant

formatting link

Reply to
Vladimir Vassilevsky

5) Use a controller with real DAC

6) Use 2 PWM outputs. Use one for most significant 4 bits, other for least significant bits, and combine outputs at 1:16 ratio. This increases the frequency of the PWM noise.

Reply to
Arlet Ottens

A small increase in the PWM rate can make quite a large improvement in the quality of the voice data. If you assume an upper limit on the bandwidth of the audio of 4KHz, you want to sample at more than twice the 4KHz.

The Nyquist frequency is the first frequency you can't fully reepresent and not the last one you can. You want to suppress Nyquist and above. When Nyquist equals the top of the band, this is imposible.

You can stop short of that. The PWM data can have its frequency responce adjusted to correct for the shape of the filter. This allows a much simpler filter because the power in the signal decreases greatly above 1KHz. Your filter could have its 3dB point at 1.5KHz and the data could be boosted above 1.5KHz.

If you do this never test it to see if it passes FCC.

Reply to
MooseFET

Yes, this seems like the first thing to do.

I presume it would make it so that the carrier and sidebands would be suppressed in the output with simpler (read: cheaper) filtering.

But possibly cheaper, with lower component count, than an active filter?

Well, that's part of what I'm asking about. Class D appeals for its cheapness and efficiency, but emissions are tough, as you say. Note that the LM48511 part I mentioned dithers the carrier frequency specifically to spread the noise around so the Feds won't find it on a spectrum analyzer :-)

Cheap, efficient, acceptable emissions, low power consumption voice output from a cheap uC w/o a D/A from 4-kHz-bandlimited voice data sampled at 8 kHz. It would be nice if the National part a) was cheap and b) had digital input so I could just dump the voice data into it directly without converting it to an analog signal.

Thanks for your input.

-- Silvar Beitel

Reply to
Silvar Beitel

I would if I could find one that had all the other junk I wanted on it.

Hmm. I'll have to think about that. I suppose I could just go the whole hog and stick an R-2R resistor pack on it and roll my own DAC that way, but I may not have enough pins/outputs available for that.

Thanks for your input.

-- Silvar Beitel

Reply to
Silvar Beitel

Yes. This is voice audio < 4 kHz sampled at 8 kHz.

Interesting thought, but computationally not something I want to do in the microcontroller! For voice data sourced from a server or burned into ROM, sounds like a good idea.

I can buy stickers cheap :-)

Thanks for your input.

-- Silvar Beitel

Reply to
Silvar Beitel

We often use delta-sigma instead of pwm to make 1-bit dac outputs. But that's usually in an fpga, where computation is cheap. D-S doesn't have the constant-frequency pwm carrier frequency issue.

It would take a periodic process, doing roughly a dozen lines of assembly code - depending on the machine - to bit-bang a port pin in delta-sigma mode.

John

Reply to
John Larkin

...

I suppose if you had a spare 8-bit output port, you wouldn't be asking, but if you do, an R-2R ladder comes to mind...

Good Luck! Rich

Reply to
Rich Grise

PWM is the nonlinear operation, and this makes the things complicated. Although the Nyquist condition applies for the PWM, the nonlinear processing of the original signal is required to restore it acurately. That is not very simple; the brute force way to deal with that is to boost the PWM rate to somewhat x10...x20 of the maximum audio frequency of interest.

Furthermore, it is good to apply the preemphasis to the original voice data and design the output PWM filter slope so it would do the deemphasis. This improves the quality quite significantly.

Vladimir Vassilevsky DSP and Mixed Signal Design Consultant

formatting link

Reply to
Vladimir Vassilevsky

But how much less than 4KHz? For voice 3KHz is usually considered the highest frequency. 3KHz is too close to 4KHz for a really cheap filter.

Wimp!

Temp = PrevSample; PrevSample = NewSample; NewSample = NewSample - Temp/2;

This gives a 3X boost at Nyquist. The divide is a simple shift to the right.

The latter was my case.

Reply to
MooseFET

How do you conclude it must be non-linear? I can think of ways it can be but it seems that it needn't be. Even if it is non-linear, since it is before the filter, you can correct the data to make it produce the linear result.

In the extreme case, you can apply preemphasis and then do a one bit output to a comparitor and still understand what is being said.

Reply to
MooseFET

PCM(x) + PCM(y) == PCM(x+y) PWM(x) + PWM(y) != PWM(x+y)

Imagine a DC + small sinewave on the top of it. At the PWM output, the phase shift of the sinewave will be dependent on the DC level. With two sinewaves you will get all sorts of harmonics and intermods.

It doesn't matter before or after filter. This is a dynamic nonlinearity problem; it is fairly difficult to correct.

Vladimir Vassilevsky DSP and Mixed Signal Design Consultant

formatting link

Reply to
Vladimir Vassilevsky

That is not enough to make it non-linear from our point of view. You need some of the differences to be within the band of interest.

This depends on how the PWM is done. If only one edge of the PWM is modulated, it is true but if both edges of the PWM are modulated, it need not be.

With modulation of both edges in PWM, the phase will be constant as the DC level is changed.

This is voice not music, so it matters a lot less.

Reply to
MooseFET

This is enough. The order of the difference is infinite.

Yes, the double sided PWM has lower distortion, then the single sided PWM. However the double sided PWM is not free from distortion either.

The PWM artifacts should be of the same order of magnitude as all other artifacts (quantization, nonlinearity and such). This requires the PWM rate to be at least at x10 of the max. frequency of interest, unless the nonlinear correction is employed.

...but so much for the boring PWM stuff. Once you mentioned that you made an invertor using the switching rectifier on the secondary side. How did you control the cross conduction? For the proper operation, the current should be switched from one side to another precisely. The actual switching time depends on temperature, voltage and current. Did you just use snubbers or did you have to adjust the dead time dynamically?

Vladimir Vassilevsky DSP and Mixed Signal Design Consultant

formatting link

Reply to
Vladimir Vassilevsky

I disagree. Merely saying that there is a difference doesn't mean that there is distortion within the band of interest. Consider the example of:

F(X) = X + sin(1E9 * t);

F(A+B) != F(A) + F(B)

Since all of the sin(1E9 * t) is well above the audio range, it couldn't be considered as distortion in the OP's product. There is likely to be some proof about the distortion subject and if I found it more interesting than the subject below, I would continue with this subject.

I did, sort of, neither. First I will fill any who may be reading along in on what the heck we are talking about.

I built a 12V DC in to 120V AC at 60Hz out DC to AC converter that made a good sine wave on its output.

The basic design has a push pull drive to a tranformer and an array of MOSFETs on the secondary side. After the MOSFETs was a LC filter to smoothen out the sine wave.

ASCII ART: L2 GND--[SW]-- ---[SW]----+----)))))----+---- ) !! ( ! ! L1 ) !! ( ! --- ---))))------+ !! +--GND ! --- ) !! ( ! ! ) !! ( ! GND GND--[SW]-- ---[SW]----

The secondary side used pairs of MOSFETs connected source to source so that the body diodes would not conduct when the switch was supposed to be off.

The gates of the secondary MOSFETs were driven by a transformer so their switching was not quite as fast as the primary ones. As a result, the switching situation on the two sides were slightly different.

The primary side MOSFETs swithed very quickly. The capacitance in the tranformer would normally have made a current spike during the switching. L1 blocks this spike and absorbs energy. L1 was connected to a "snubbing circuit" sort of like this:

L1 ----+----(((((----+------ ! ! ! --- ! --- ! ! L3 ----!

Reply to
MooseFET

Silvar Beitel snipped-for-privacy@net1plus.com posted to sci.electronics.design:

Hmmm. Perhaps a high speed serial interface to a real DAC.

Reply to
JosephKK

MooseFET snipped-for-privacy@rahul.net posted to sci.electronics.design:

Alternatively you can transcode it and use a telephone type CVSD.

Reply to
JosephKK

John Larkin snipped-for-privacy@highNOTlandTHIStechnologyPART.com posted to sci.electronics.design:

You have me curious here, are you feeding a traditional CVSD chip with that or are you somehow using it directly (just shoved into a filter)? In either case what is the bit bang rate, and the effective audio bandwidth.

Reply to
JosephKK

On Dec 9, 4:06 am, JosephKK wrote: [... audio via PWM ...]

Depending on the micro, a parallel port to a DAC may be better, but a real DAC sounds like a good idea. A voltage output DAC feeding a very simple low pass filter would give good performance with a low number of parts.

Reply to
MooseFET

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.