跨届大侠
- 积分
- 7531
- 威望
- 268
- 贡献
- 7051
- 兑换币
- 0
- 注册时间
- 2010-10-18
- 在线时间
- 106 小时
|
我这有一个PWM产生方波的程序,就是感觉幅度太大,不知道怎么调?
#include <hidef.h> /* common defines and macros */
#include "derivative.h" /* derivative-specific definitions */
void PWM_Init()
{
PWME=0; //关闭PWM
PWMPOL=0xAA; //通道1与通道3,5,7输出波形开始极性为1
// PPOL7,PPOL6,PPOL5,PPOL4,PPOL3,PPOL2,PPOL1,PPOL0
PWMCTL=0xF0; //通道01和通道23,45,67
// CON67,45,23,01,PSWAI,PFRZ,0,0
PWMCLK=0xc3; //PWM通道01时钟源为SA,23时钟源为B,45时钟源为A,67时钟源为SB
PWMPRCLK=0x22; //时钟A B,4分频,ClockA=ClockB=ClockBus/(PWMPRCLK)=40MHz/4=10MHz
PWMSCLA=0x05; //时钟SA为ClockA/(PWMSCLA*2),即10MHz/5/2=1MHz
PWMSCLB=0x05; //时钟SB为ClockB/(PWMSCLB*2),即10MHz/5/2=1MHz
PWMPER67=14000; //设定输出周期=通道时钟周期*10000=(1/1M)*10000=2ms,频率400Hz
PWMDTY67=1470; //占空比为50%
PWMPER45=5000; //设定输出周期=通道时钟周期*2000=(1/10MHZ)*5000=500us,周期500us 频率2KHz
PWMDTY45=0; //占空比为0%
PWMPER23=5000; //设定输出周期=通道时钟周期*1000=(1/10M)*5000=500us,频率2KHz
PWMDTY23=4500; //占空比为50%
PWMPER01=14000; //设定输出周期=通道时钟周期*40000=(1/1MHZ)*14000=14ms,周期14ms 频率100Hz
PWMDTY01=1517; //正脉冲宽1.52ms (1520)右极限脉宽1.70ms(1720) 左极限脉宽1.30ms(1320)
PWME=0x82; //通道01和通道45,23,67使能
}
void main(void) {
/* put your own code here */
EnableInterrupts;
for(;;) {
_FEED_COP(); /* feeds the dog */
} /* loop forever */
/* please make sure that you never leave main */
} |
|