大家好,这是一个逆变器程序,从p2.0和2.1生成spwm波通过ir2101驱动四个开关管,
波形应该是正确的,但是问题是通过负载的电压和电流不稳,弄了很长时间,网上也搜不到可以问问各位我这是代码还是电路有问题
单片机源程序如下:
- #include "reg52.h"
- #define uchar signed int
- signed int code spwm [200]={40,42,43,44,45,47,48,49,50,51,53,54,55,56,57,58,60,61,62,63,64,65,66
- ,67,68,69,69,70,71,72,73,73,74,75,75,76,76,77,77,78,78,79,79,79,79,80
- ,80,80,80,80,80,80,80,80,80,79,79,79,78,78,78,77,77,76,76,75,75,74,73
- ,72,72,71,70,69,68,67,66,65,64,63,62,61,60,59,58,57,56,55,53,52,51,50
- ,48,47,46,45,43,42,41,39,38,37,35,34,33,32,30,29,28,27,25,24,23,22,21
- ,20,19,18,17,16,15,14,13,12,11,10,9,8,8,7,6,5,5,4,4,3,3,2
- ,2,2,1,1,1,0,0,0,0,0,0,0,0,0,0,1,1,1,1,2,2,3,3
- ,4,4,5,5,6,7,7,8,9,10,11,11,12,13,14,15,16,17,18,19,20,22,23
- ,24,25,26,27,29,30,31,32,33,35,36,37,38,40};
- uchar count,m,i,j ;
- uchar T;
- sbit pwm1=P2^0;
- sbit pwm2=P2^1 ;
- void main (void){
- m=0;
- TMOD=0x02 ;
- TH0=(65536-100)/256;
- TL0= (65536-100) %256;
- EA=1 ;
- ET0=1;
- TR0=1;
- count=40 ;
- T=1;
- i=0;
- while(1) ;
- }
- void time0()interrupt 1
- {
- m++;
- if (count<=spwm[i])
- {pwm2=0x00;
- for(j=5;j>0;j--);
- pwm1=0Xff ;
- }
- if (count>spwm[i])
- {pwm1=0X00;
- for(j=5;j>0;j--) ;
- pwm2=0Xff ;
- }
- if (m==2)
- {i++ ;
- if (i==200)
- {i=0;
- }
- m=0;
- }
- if (T==1)
- {
- count=count+10;
- if (count==80)
- {
- T=0;
- }
- }
- else
- {
- count=count-10;
- if (count==0)
- {
- T=1;
- }
- }
复制代码
|