前提・実現したいこと
2枚の写真で示されている回路は、機械系の制御を行うコンバータの回路であり、そのシミュレーションを現在私が行ております。どちらも下の回路の一番左端の部分の電圧E0と電圧E0の位相角であるfai0を計算するための回路です。
私は、E0,fai0の初期値をこの回路にまず与えた後、任意の時間ごとのE0とfai0の値を計算し、回路のE0,fai0の値を時間ごとに更新していき、その結果を波形に出したいです。下の回路のC言語ブロックでE0,fai0をもとめるためのプログラムを作成します。
下の写真はシミュレーション回路を映した図です。このシミュレーション回路は機械系の制御システムを示した回路であり、回路の左の方にあり、6個の入力と3個の出力が長方形がCブロックです。Cブロックの上の二つの入力は上の写真で計算されたE0,fai0の値をCブロックに入力します。その下の二つの入力は、シミュレーションの最初で初期値のE0,fai0の値を入力します。なお、力率PF0,PF1,PF2と書かれているメーターの上についている長方形のブロックは、力率を求めるための計算システムが入っております。また、一番右端のブロックの内部にはコンバータの回路が入っております。
次に上の図は、下の回路から電流io、電圧vo、電力p2を挿入して回路の力率、、電圧E0、E0の位相角のfai0をもとめる計算を行うシミュレーション回路です。この四角の中には計算を行うためのシステムが入っています。
発生している問題・エラーメッセージ
E0、fai0のをリアルタイムに更新するプログラムがわかりません。
エラーメッセージ
#iclude <Psim.h>
C言語/////////////////////////////////////////////////////////////////////
1// PLACE GLOBAL VARIABLES OR USER FUNCTIONS HERE... 2static float f_PI = 3.141592653, Th; //ここで、使う変数を定義しています。Thは、角度Θの意味です。// FUNCTION: SimulationStep 3// This function runs at every time step. 4//double t: (read only) time 5//double delt: (read only) time step as in Simulation control 6//double *in: (read only) zero based array of input values. in[0] is the first node, in[1] second input... 7//double *out: (write only) zero based array of output values. out[0] is the first node, out[1] second output... 8//int *pnError: (write only) assign *pnError = 1; if there is an error and set the error message in szErrorMsg 9// strcpy(szErrorMsg, "Error message here..."); 10// DO NOT CHANGE THE NAME OR PARAMETERS OF THIS FUNCTION 11void SimulationStep( 12 double t, double delt, double *in, double *out, double X, double Y, 13 int *pnError, char * szErrorMsg, 14 void ** reserved_UserData, int reserved_ThreadIndex, void * reserved_AppPtr)//ここに実行するコマンドを打ちます。 15{ 16// ENTER YOUR CODE HERE... 17 Th = Th + 2*f_PI*50.0*delt; 18 19 if (Th >= f_PI) //角度の範囲 20 { 21 Th = Th - 2.0*f_PI; 22 } 23 else if (Th <= -f_PI) 24 { 25 Th = Th + 2.0*f_PI; 26 } 27 28//////////////////////////////////////////////////////////// 29// FUNCTION: SimulationBegin 30// Initialization function. This function runs once at the beginning of simulation 31// For parameter sweep or AC sweep simulation, this function runs at the beginning of each simulation cycle. 32// Use this function to initialize static or global variables. 33//const char *szId: (read only) Name of the C-block 34//int nInputCount: (read only) Number of input nodes 35//int nOutputCount: (read only) Number of output nodes 36//int nParameterCount: (read only) Number of parameters is always zero for C-Blocks. Ignore nParameterCount and pszParameters 37//int *pnError: (write only) assign *pnError = 1; if there is an error and 38set the error message in szErrorMsg 39// strcpy(szErrorMsg, "Error message here..."); 40// DO NOT CHANGE THE NAME OR PARAMETERS OF THIS FUNCTION 41void SimulationBegin( 42 const char *szId, int nInputCount, int nOutputCount,double *in, double *out, 43 int nParameterCount, const char ** pszParameters, 44 int *pnError, char * szErrorMsg, 45 void ** reserved_UserData, int reserved_ThreadIndex, void * reserved_AppPtr) 46{ 47// ENTER INITIALIZATION CODE HERE... 48 49 50}//シミュレーションの初期値をここに言語を入力 51 52 53///////////////////////////////////////////////////////////////////// 54// FUNCTION: SimulationEnd 55// Termination function. This function runs once at the end of simulation 56// For parameter sweep or AC sweep simulation, this function runs at the end of each simulation cycle. 57// Use this function to de-allocate any allocated memory or to save the result of simulation in an alternate file. 58// Ignore all parameters for C-block 59// DO NOT CHANGE THE NAME OR PARAMETERS OF THIS FUNCTION 60void SimulationEnd(const char *szId, void ** reserved_UserData, int reserved_ThreadIndex, void * reserved_AppPtr) 61{ 62 63 64 65}//シミュレーション終了時のコマンドをうつところです。 66コード
試したこと
PSIMのCブロックを使って実際にプログラミングを行っていた人のサイトをまず探しましたが、見つかりませんでした。そこで、与えた初期値を時間ごとに更新して計算するプログラミングを調べましたが、出てきませんでした。
補足情報(FW/ツールのバージョンなど)
