The Siemens Community Catalyst program was co-created with our community to acknowledge technology leaders who consistently contribute to the Siemens Community. Nominations are accepted on a rolling basis.
I am trying to use a custom C code to generate an activation signal. Are there specific examples to show how a simple activation signal can be generated from a C Block? I am able to use the C Block for generating outputs, but not event signals.
I don't know the exact solution, but you start with definition of numer of output event ports:
If you generate the skeleton of the c function code you get:
#include 'vss_block4.h' VSS_EXPORT void CBlockFunction(vss_block *block,int flag) { SCSREAL_COP *in=(SCSREAL_COP *)GetInPortPtrs(block,1); int min=GetInPortRows(block,1); int nin=GetInPortCols(block,1); SCSREAL_COP *out=(SCSREAL_COP *)GetOutPortPtrs(block,1); int mout=GetOutPortRows(block,1); int nout=GetOutPortCols(block,1); int nevprt=GetEventCode(block); SCSREAL_COP *evout=GetNevOutPtrs(block); switch (flag){ case VssFlag_Initialize: break; case VssFlag_Reinitialize: break; case VssFlag_Terminate: break; case VssFlag_OutputUpdate: break; case VssFlag_EventScheduling: break; } }
Now *evout is the variable to be used for the event, e. g. *evout = 1;. It has to be set with flag == VssFlag_EventScheduling.
I try to set up a small example, where I set the output event depending on an input value (x > const), but the event occurs sometime, but not at the expected point of time. Here I need the help of someone else.
Hello Roket,
Thanks for your reply. I tried it and am able to get the activation signal form a C block. But as you said, there is a problem with the timing as well.
Here is the code i used for the C Block.
#include 'vss_block4.h' VSS_EXPORT void CBlockFunction(vss_block *block,int flag) { SCSREAL_COP *u1=(SCSREAL_COP *)GetInPortPtrs(block,1); int mu1=GetInPortRows(block,1); int nu1=GetInPortCols(block,1); SCSREAL_COP *u2=(SCSREAL_COP *)GetInPortPtrs(block,2); int mu2=GetInPortRows(block,2); int nu2=GetInPortCols(block,2); SCSREAL_COP *u3=(SCSREAL_COP *)GetInPortPtrs(block,3); int mu3=GetInPortRows(block,3); int nu3=GetInPortCols(block,3); SCSREAL_COP *BrkDir=(SCSREAL_COP *)GetOutPortPtrs(block,1); int mBrkDir=GetOutPortRows(block,1); int nBrkDir=GetOutPortCols(block,1); int nevprt=GetEventCode(block); SCSREAL_COP *evout=GetNevOutPtrs(block); switch (flag){ case VssFlag_Initialize: break; case VssFlag_Reinitialize: break; case VssFlag_Terminate: break; case VssFlag_OutputUpdate: break; case VssFlag_EventScheduling: double PosDif = 0.1; double VelDif = 0.1; if (*u3 !=1) { if ((*u1 >= 0) && (*u1 <=PosDif) && (*u2 >=0) && (*u2 <=VelDif) ) { *evout = 1; *BrkDir = -1; } else if ( (*u1 <= 0) && (*u1 >= (-1)*PosDif) && (*u2 <=0) && (*u2 >= (-1)*VelDif) ) { *evout = 1; *BrkDir = 1; } } break; } }
#include 'vss_block4.h' VSS_EXPORT void CBlockFunction(vss_block *block,int flag) { SCSREAL_COP *u1=(SCSREAL_COP *)GetInPortPtrs(block,1); int mu1=GetInPortRows(block,1); int nu1=GetInPortCols(block,1); SCSREAL_COP *u2=(SCSREAL_COP *)GetInPortPtrs(block,2); int mu2=GetInPortRows(block,2); int nu2=GetInPortCols(block,2); SCSREAL_COP *u3=(SCSREAL_COP *)GetInPortPtrs(block,3); int mu3=GetInPortRows(block,3); int nu3=GetInPortCols(block,3); SCSREAL_COP *BrkDir=(SCSREAL_COP *)GetOutPortPtrs(block,1); int mBrkDir=GetOutPortRows(block,1); int nBrkDir=GetOutPortCols(block,1); int nevprt=GetEventCode(block); SCSREAL_COP *evout=GetNevOutPtrs(block);
switch (flag){ case VssFlag_Initialize:
break; case VssFlag_Reinitialize:
break; case VssFlag_Terminate:
break; case VssFlag_OutputUpdate: break; case VssFlag_EventScheduling: double PosDif = 0.1; double VelDif = 0.1; if (*u3 !=1) { if ((*u1 >= 0) && (*u1 <=PosDif) && (*u2 >=0) && (*u2 <=VelDif) ) { *evout = 1; *BrkDir = -1;
} else if ( (*u1 <= 0) && (*u1 >= (-1)*PosDif) && (*u2 <=0) && (*u2 >= (-1)*VelDif) ) { *evout = 1; *BrkDir = 1;
} } break; } }
Although the evout and the BrkDir are generated at the same point, the timing is way off. This is what the graphs of the event and the BrkDir look like.
Can anyone from the Altair technical team help ?
BR
Saurya
<?xml version="1.0" encoding="UTF-8"?>
Hi Saurya,
I misunderstood the function of evout. It is the relative time between current activation and output of activation (and not the signal itself as I supposed).
Best regards, Ronald
Join us for a community conversation on how High-Performance Computing (HPC) and Simcenter PSIM work together to meet the increasing demands of modern power electronics simulation. During this one-hour technical session, you'll discover how leveraging HPC can speed up simulations, improve scalability, and empower engineers…
Join us for a community conversation on accelerating your motor simulation workflow with Simcenter Simlab. In this beginner-friendly session, we'll introduce the platform's automated model-building capabilities and show how easy it is to set up your first electric motor analysis. You'll see the basic steps of geometry…
Join us for a Community Conversation where we'll discuss practical approaches to analyzing complex electromagnetic models using hybrid solver techniques. This session will provide a general overview of how different computational methods can be combined within a single simulation to address models containing varied…