|
发表于 2008-4-25 15:47:21
|
显示全部楼层
我所讲的,都是方式三.方式二本身不适合做PWM的应用(手册上没有讲作为PWM应用!),方式四为慢速的PWM应用,对你的要求也不合适.
输出的PWM频率:F(pwm)=F(cpu)/(256*N)
Fast PWM Mode
The fast Pulse Width Modulation or fast PWM mode (WGM02:0 = 3 or 7) provides a high frequency PWM waveform generation option. The fast PWM differs from the other PWM option by its single-slope operation. The counter counts from BOTTOM to TOP then restarts from BOTTOM. TOP is defined as 0xFF when WGM2:0 = 3, and OCR0A when WGM2:0 = 7. In non-inverting Compare Output mode, the Output Compare (OC0x) is cleared on the Compare Match between TCNT0 and OCR0x, and set at BOTTOM. In inverting Compare Output mode, the output is set on Compare Match and cleared at BOTTOM. Due to the single-slope operation, the operating frequency of the fast PWM mode can be twice as high as the phase correct PWM mode that use dual-slope operation.
This high frequency makes the fast PWM mode well suited for power regulation, rectification, and DAC applications. High frequency allows physically small sized external components (coils, capacitors), and therefore reduces total system cost.
In fast PWM mode, the counter is incremented until the counter value matches the TOP value. The counter is then cleared at the following timer clock cycle. The timing diagram for the fast PWM mode is shown in Figure 31. The TCNT0 value is in the timing diagram shown as a histogram for illustrating the single-slope operation. The diagram includes non-inverted and inverted PWM outputs. The small horizontal line marks on the TCNT0 slopes represent Compare Matches between OCR0x and TCNT0.
1.使用内部RC(9.6M),9.6M/90K = 107.OCR0A = 107(TOP),OCR0B = 50, 可以得到89.719KHz,占空比为46.729%的PWM.
2.外部输入20M脉冲(浪费一个I/O)作为系统时钟,20M/90K = 222.OCR0A = 222(TOP),OCR0B = 111, 可以得到90.090KHz,占空比为50%的PWM.
上面2个使用OCR0A作为TOP(WGM2:0 = 7),N =1,所以输出的PWM频率:F(pwm)=9.6M/107 或 20M/222
===========================================================================================
同时产生2个90K的PWM,外部要使用22.95M的脉冲(可以尝试).如果按20M(手册上限)计算,可以产生78.431K的2个PWM.占空比分别由OCR0A和OCR0B控制,精度255.
使用TCNT0的MAX作为TOP(WGM2:0 = 3),N =1,所以输出的PWM频率:F(pwm)=22.95M/255 或 20M/255.
=============================================================================================
我都冒汗了!你还"新接项目"!? 唬你的老板吧. |
|