#include <reg52.h> //Keil header file name #include "use.h" #include "Ver.h" //extern void LedOut(unsigned char *pLed); #define Pmax 55000 //55000 //42666(18.4320) #define Ki 2.2 //i=2 //---------------------------- sbit PwinPin=P3^5; //---------------------------- typedef union { unsigned int Pwm; //pwm的数据 unsigned char PwmUse[2]; //[0]=H;[1]=L }PWM; //---------------------------- PWM PwmData; unsigned int PwmBak; //---------------------------- unsigned char PwmF=0; //输出的1,0的标志 /***************************************** PWM计算,输出 t0=T50ms(b0/[fs-fo]+Sgn(U)*20%+a1 ;T50ms=Pwm50+Ah ;B0<fo=>0V;Must Bo In(Fo-Fs) *******************************************/ void PwmOut(void) { float Pwm,i,k,j; k=Pmax+(Mp1.AH+OminH)*Ki; i=(PminL+Mp1.AL)*Ki; //---------------------------- //LedOut(LedBuf); //LED显示输出 //---------------------------- j=(LedMenu.B-Mp1.Fo)/(Mp1.Fs-Mp1.Fo); if(j<0) j=0; if(j>1) j=1; Pwm=j*k; //Bo/(Fs-Fo)*Pk j=Pwm*0.8+k*0.2+i; //先计算 if(Mp1.U==1) {Pwm=j;} else Pwm=Pwm+i; TR0=0; PwmBak=(unsigned int)Pwm; //更新数据 TR0=1; } //------------------------------- void Init_Pwm(void) { PwmData.Pwm=0; PwmPin=0; //输出0 (地点平) // PwmOut(); } //定时器0 中断处理 pwmout() void T0_Do(void) interrupt 1{ TR0=0; if(PwmF==0) //输出高电平 { PwmData.Pwm=-PwmBak; TH0=PwmData.PwmUse[0]; TL0=PwmData.PwmUse[1]; PwmPin=1; //0 输出 PwmF=1; }else{ PwmData.Pwm=-PwmData.Pwm; TH0=PwmData.PwmUse[0]; TL0=PwmData.PwmUse[1]; PwmPin=0; //1 输出 PwmF=0; } TR0=1; }
|