// Three phase sine voltage source with voltage and frequency control inputs. // The four outputs are labeled pha, phb, phc and phn (can be connected // to gnd or considered as a floating point). Phase pha is the // reference phase. Phases phb & phc lead and lag by 120 deg, respectively. module vsrc_3ph(amp,fre,gnd,pha,phb,phc,phn); input amp,fre,gnd; output pha,phb,phc,phn; voltage amp,fre,gnd; voltage pha,phb,phc,phn; parameter real ka=1.0, // coefficient on the magnitude kf=1.0, // coefficient on the frequency phi=0; // phase difference real phia,phib,phic,vamp,wfre; analog begin if (analysis("static")) begin @(initial_step) begin phia = phi; // phase difference on phase a phib = phi + `M_TWO_PI/3.0; // phase difference on phase b phic = phi - `M_TWO_PI/3.0; // phase difference on phase c end end wfre = kf*`M_TWO_PI*V(fre,gnd); vamp = ka*V(amp,gnd); V(pha,phn) <+ vamp*sin(wfre*$realtime + phia); V(phb,phn) <+ vamp*sin(wfre*$realtime + phib); V(phc,phn) <+ vamp*sin(wfre*$realtime + phic); bound_step(0.05/wfre); V(pha,phn) <+ ac_stim("ac",vamp,phia); V(phb,phn) <+ ac_stim("ac",vamp,phib); V(phc,phn) <+ ac_stim("ac",vamp,phic); end endmodule