Audio samples are converted to a train of ON and OFF pulses. The average ON period of each pulse is proportional to the amplitude of the audio sample being played at that point in time. The PWM frequency, i.e. the total pulse period of ON plus OFF time, must be greater than the sampling rate of the audio being played. The output will then consist of a train of pulses where the average output voltage over the period is a function of the amplitude & frequency of the audio being played. This output signal contains unwanted noise from the PWM frequency and its harmonics. This noise can either be ignored because it is outside of the human hearing range, or it can be minimized by use of a low pass filter (integration).
History
In 1981, IBM released the IBM PC. It had a single, cheap internal speaker for audio, but to keep costs low, there was no DAC. The hardware would allow for applying power to the speaker on or off, but nothing in between.
Programmers found they could program the PC's Programmable Interval Timer (PIT) chip to drive the PC Speaker with varying pulse widths. Unfortunately, the PIT chip was only clocked at 1.2MHz. If the PWM frequency was set to 22KHz, this gave only 54 different output levels (1,193.182KHz / 22KHz = 54). If a PWM frequency of 11KHz is used, 108 possible output levels can be achieved (1,193.182KHz / 11KHz = 108), but this puts the unwanted PWM pulse frequency well into the human ear's audible frequency range, producing an undesirable 11KHz squeal on top of the audio.
Standard 8-bit audio has 256 different output levels (2 ^ 8 = 256), so playing audio on the PC Speaker had to be scaled down to the lower resolution. This made the sound quality fairly poor, but still recognizable.
More information about programming the PC's internal speaker using the PIT chip can be found here: Programming the PC Speaker.
Also during this period, some folks wired together a pile of resistors to their PC's Parallel Port to produce an 8-bit Binary Weighted DAC. This type of DAC used a specially designed resistor voltage divider network to produce the analog output. The resulting audio using this hardware could in theory be significantly better than the PWM PC Speaker method, but in practice it was difficult to get exact resistor values to make this solution work very well. Plus, not all parallel ports behaved properly either (some have internal pull-up/down resistors, etc).
High Speed Microcontrollers
Today's microcontrollers provide significantly better hardware. For example, the PIC24HJ64GP206 from Microchip provides 8 PWM pins, clocked at up to 40MHz. If a PWM frequency of 78KHz is used, each PWM output would be capable of producing 512 different output levels (40,000KHz / 78KHz = 512), or in other words, 9 bits of resolution. 10-bit resolution could be achieved, but this would limit the playback frequency to 39KHz.
What would it take to get to 16-bit resolution? Unfortunately, using the PWM technique by itself would require a clock rate of over 2.89GHz to achieve 16-bits of resolution. 2.89GHz divided by a PWM frequency of 44.1KHz allows for 16-bit resolution (2890137.6KHz / 44.1KHz = 65536). Few devices other than highly advanced microprocessors from Intel or AMD can operate at these frequencies. Obviously, using PWM alone is not going to be a feasible solution with today's equipment.作者: 90999 时间: 2010-9-27 03:07
sharpufo,STM32的DMA如何实现不间断发送?我用LPC的,切换DMA-RAM时候总有停顿(示波器看)作者: sharpufo 时间: 2010-9-27 06:53
对LPC不是很熟悉,还没用过。
我并没有使用DMA,STM32f103RB也没有IIS接口.我使用SPI接口模拟,做丛机,16位模式,IIS(其实是TDA1305的16位模式,不是严格意义上的IIS)的BCK,LRCK和MCK信号和SPI的CS信号由ATMEGA48产生(314Forever朋友介绍的方法),STM32f103在SPI的接收中断中喂数据给TDA1305(准备下次SPI传输的数据,这个中断必须拥有最高的优先权),开了4个1KB的缓冲区。
跑72M很流畅,从不断流,我测试了下,读文件速度能达到400kb多,(这个速度与SD卡也有关系).
如果有断流界面有提示,72M从不断流.当把速度降到32M时,就有可能发生断流了。作者: ifree64 时间: 2010-9-27 11:44
回复【58楼】machao
-----------------------------------------------------------------------
理论上能得到相同模拟信号。
下面2篇文章不知道是否够理论了,都用了傅里叶级数在理论上进行分析。
点击此处下载 ourdev_586093XB001G.pdf(文件大小:317K) (原文件名:Using a PWM Timer as a Digital to Analogue Converter.pdf)
点击此处下载 ourdev_586094RQ1B8X.pdf(文件大小:188K) (原文件名:pwm-dac.pdf)作者: cowboy 时间: 2010-9-27 22:49
如果不是做HIFI,12bit DA一般已满足大部分场合的要求,一般人甚至难以区分与16bit声音之间的区别,除非用高级的播放设备。当然拥有金耳朵的人除外,毕竟这是少数。
理论上能得到相同模拟信号。
下面2篇文章不知道是否够理论了,都用了傅里叶级数在理论上进行分析。
点击此处下载 ourdev_586093XB001G.pdf(文件大小:317K) (原文件名:Using a PWM Timer as a Digital to Analogue Converter.pdf)
点击此处下载 ourdev_586094RQ1B8X.pdf(文件大小:188K) (原文件名:pwm-dac.pdf)
-----------------------------------------------------------------------
谢谢提供的资料,其中秦健所写论文,我之前也搜索到看过了。
两篇文章的理论分析部分都只是分析了作为周期信号时的PWM的情况。
而对于每个PWM“周期”都需要改变占空比的信号,(已经不再是周期信号了)没有作出分析。