// Simulation of a single-phase fully-controlled bridge // rectifier circuit. // This program produces the transient response, the periodic // response. Commuation overlap angle is also computed. // Calculations normalized. The average voltage that would // occur for diode-bridge rectifier with a resistive load is // taken to be unity. The average current through the load // resistor with a pure resistive load on the diode bridge // rectifier is taken as the unity current. The parameters to // be fed are just three: the ratio of load inductive reactance // to the load resistance, wL1/R , the ratio of source reactance // to the load resistance to load resistance wL2/R and the firing // angle in degrees. #include #include #include #include #include void kreateRespFile(void); void tranResponse(void); void OneCycle(void); void computeOneStep(void); void produceEntries(void); const double pi=3.1415926; const double deg_rad=pi/180.0; const double step=pi/720.0; double L1,L2,alpha,fang,elapseAng,cycleAng,tote_knt; double cur_load,cur_line,outVolt,vSource,vInput,capVolt; double OverLapangle,Cap,capCur,dcLinkCur,Res; int commute,toggle,yes_Entry,modeSw; FILE *fnew; char *tstr,*p; int main(void) { float ka1,kb2,kc3,kd4,ke5; printf(" \n"); printf(" Load Time Constant in radians = "); scanf("%f",&ka1); L1=(double)ka1; if (L1<0.05) L1=0.05; printf(" \n"); printf(" Line Reactance Time Constant in radians = "); scanf("%f",&kb2); L2=(double)kb2; printf(" \n"); printf(" Cap. Filter Time Constant in radians = "); scanf("%f",&kc3); Cap=(double)kc3; if (Cap<0.1) Cap=0.1; if (Cap>10.0) Cap=10.0; printf(" \n"); printf(" Load Resistance in p.u. = "); scanf("%f",&ke5); Res=(double)ke5; if (Res<0.1) Res=0.1; if (Res>10.0) Res=10.0; printf(" \n"); printf(" Firing angle in degrees = "); scanf("%f",&kd4); alpha=(double)kd4; fang=alpha*deg_rad; alpha=0.0; printf(" \n"); // Initialise though not necessary for global variables elapseAng=0.0 ; cycleAng=0.0; capCur=0.0; capVolt=0.0; cur_load=0.0; cur_line=0.0; outVolt=0.0; tote_knt=0.0; OverLapangle=0.0; commute=0; yes_Entry=0; dcLinkCur=0.0; cur_load=0.0; // Create a file for entering transient response fnew=fopen("tran_v3.csv","w+r"); tranResponse(); fclose(fnew); return 0; } void kreateRespFile(void) { int n1,n2; tstr="Angle,InputV,VoutBr,dcLinkCur,LineCur,IndVolt,LoadVolt,capCur"; p=strtok(tstr,","); fprintf(fnew,p); fprintf(fnew,","); n2=8; for (n1=0;n1<(n2-1);n1++) { p=strtok(NULL,","); if (n1!=(n2-2)) { fprintf(fnew,p); fprintf(fnew,","); } else { fprintf(fnew,p); fprintf(fnew,"\n"); } } } void tranResponse(void) { double d1; int NumCycles,count; d1=(6.0*(L1+L2+Cap))/(2.0*pi)+0.5; NumCycles=(int)d1 + 1; kreateRespFile(); modeSw=1; for (count=0;count<=NumCycles;count++) OneCycle(); } void OneCycle(void) { int knt; double dknt; dknt=0.0; for (knt=0;knt<1440;knt++) { cycleAng=dknt*step; vInput=pi/2.0*sin(cycleAng); if ((cycleAng(fang+pi))) { if (cycleAngdcLinkCur) commute=0; } if (toggle==0) { if ((cur_line+dcLinkCur)<0.0) commute=0; } if (dcLinkCur<0.00001) outVolt=capVolt; else outVolt=0.0; cur_load=capVolt/Res; capCur=dcLinkCur-cur_load; break; } tote_knt+=1.0; elapseAng=tote_knt*step; alpha=tote_knt/4.0; yes_Entry+=1; if (yes_Entry==4) produceEntries(); if (yes_Entry==4) yes_Entry=0; } void produceEntries(void) { double negate; gcvt(alpha,5,p); fprintf(fnew,p); fprintf(fnew,","); gcvt(vInput,5,p); fprintf(fnew,p); fprintf(fnew,","); gcvt(outVolt,5,p); fprintf(fnew,p); fprintf(fnew,","); gcvt(dcLinkCur,5,p); fprintf(fnew,p); fprintf(fnew,","); gcvt(cur_line,5,p); fprintf(fnew,p); fprintf(fnew,","); if (toggle==0) negate = 1.0; else negate=-1.0; gcvt(vInput-negate*outVolt,5,p); fprintf(fnew,p); fprintf(fnew,","); gcvt(capVolt,5,p); fprintf(fnew,p); fprintf(fnew,","); gcvt(capCur,5,p); fprintf(fnew,p); fprintf(fnew,"\n"); }