#include#include typedef unsigned char BYTE; typedef unsigned int WORD; sbit P13=P1^3; sbit P14=P1^4; sbit sd =P1^5; // /* BYTE code Pwm[]= { 5, 14, 23, 32, 41, 51, 60, 68, 77, 86, 94,103,111,119,127,135,142,149,156,163, 169,175,181,187,192,197,202,206,210,214, 217,220,222,225,226,228,229,230,232,232, 230,229,228,227,225,223,220,217,214,210, 206,202,197,192,187,181,175,169,163,156, 149,142,135,127,119,111,103,94,86,77,68, 60, 51, 41, 32, 23, 14,5 }; //77点 7.812k 12分频 */ ///* BYTE code Pwm[]= { 1, 7, 12, 16, 21, 26, 30, 35, 39, 44, 48, 53, 57, 62, 66, 71, 75, 79, 84, 88, 92, 97,101,105,109,113,117,121,125,129, 133,136,140,144,147,151,154,158,161,164, 168,171,174,177,180,183,185,188,191,193, 196,198,200,203,205,207,209,211,213,214, 216,218,219,221,222,223,224,225,226,227, 228,228,229,229,230,230,230,230,231,230, 230,230,229,229,228,227,226,225,224,223, 222,221,219,218,216,215,213,211,209,207, 205,203,201,199,196,194,191,189,186,183, 180,178,175,171,168,165,162,159,155,152, 148,145,141,137,134,130,126,122,118,114, 110,106,102, 98, 93, 89, 85, 81, 76, 72, 67, 63, 58, 54, 49, 45, 40, 36, 31, 26, 21, 17, 12, 8, 1 }; //155点 15.625k 6分频 //*/ WORD Flag=0,ZF=0,i=0; //----函数声明---- void init(); void delay(); //-----主函数----- void main() { sd =1; P13=0; P14=0; init(); delay(); sd =0; while(1); } void init() { AUXR = 0x80; TMOD = 0x02; // TL0 = 244; //7.812K 12分频 // TH0 = 244; //7.812K 12分频 TL0 = 250; //15.625K 6分频 TH0 = 250; //15.625K 6分频 TR0 = 1; ET0 = 0; //----PCA初始化---- CCON = 0; CL = 0; CH = 0; CMOD = 0X04; CCAP0H = 5; CCAP0L = 5; CCAPM0 = 0X53; /* CCAP1H = 128; CCAP1L = 128; CCAPM1 = 0x00; */ CR = 1; EA = 1; } void PCAPWM0() interrupt 7 using 1 { CCF0=0; CCF1=0; i++; // if(i==7812) //7.812K if(i==15625) //15.625K { P0=~P0; i=0; } // if(Flag>=77) //7.812K if(Flag>=155)//15.625K { // CR=0; Flag=0; ZF=!ZF; switch(ZF) { case(1): { sd = 1; _nop_(); P13 = 0; CCAPM0 = 0x00; CCAPM1 = 0x53; sd = 0; }break; case(0): { sd = 1; _nop_(); P14 = 0; CCAPM0 = 0x53; CCAPM1 = 0x00; sd = 0; }break; } // CR=1; } switch(ZF) { case(0): { CCAP0H=CCAP0L=(256-Pwm[Flag]); }break; case(1): { CCAP1H=CCAP1L=(256-Pwm[Flag]); }break; } Flag++; } void delay(void) //100ms延时 { unsigned char a,b,c; for(c=65;c>0;c--) for(b=104;b>0;b--)
for(a=176;a>0;a--); _nop_(); //if Keil,require use intrins.h _nop_(); //if Keil,require use intrins.h }
这是我用几天时间憋出来的程序,放在桥上能正常运行,输出加大电阻也有矩形波输出,现在就差滤波部分。
手上电容电感种类很少,大致算了一下 就用了个10mh电感和六个0.47uf电容并联滤波,看大致波形。。求可靠的计算算法,然后重新买元器件。。
直流输入:30v 载波频率:15.625k 调制比0.9 输出电压有效值大约24v
下面是相关图片