Handling pointers in C using Simulink 'S-Function' block

Among my little understanding in programming I'm writing this code in C to use it in a S-Function block on Matlab/Simulink. I've been trying to follow the same logic as other S-Function codes in C timestwo.c and wrote the following code. However, although I think 'it works' in my simulation I can't understand well how does every execution line inside if-statements works. For example, at the first "if" condition I want to compare two currents going into this S-Function Block:
In case Snubber Current - *u0_Is[i] is less than Snubber Reference - *u1_Iref[i], then a gate-signal (a 1) must be delivered to an electronic device (IGBT). Now, what's the idea of writing *IGBT++ = 1 ?. I want to know if it is correct to see *IGBT as a vector or array that points to a variable stored in memory, so if I write *IGBT = 1, it will save this 1 at that location?.
Thanks in advance.
static void mdlOutputs(SimStruct *S, int_T tid)
{
int_T i;
// Snubber Current
InputRealPtrsType u0_Is = ssGetInputPortRealSignalPtrs(S, 0);
// Triangle Reference
InputRealPtrsType u1_Iref = ssGetInputPortRealSignalPtrs(S, 1);
// Voltage THY - colector/emisor
InputRealPtrsType u2_Vce = ssGetInputPortRealSignalPtrs(S, 2);
real_T *IGBT = ssGetOutputPortRealSignal(S, 0);
real_T *THY = ssGetOutputPortRealSignal(S, 1);
int_T width = ssGetOutputPortWidth(S, 0);
int_T width1 = ssGetOutputPortWidth(S, 1);
for (i=0; i<width; i++){
if (*u0_Is[i] < *u1_Iref[i]){
*IGBT++ = 1;
if (*u2_Vce[i] >= 0.8 && (*u0_Is[i] < *u1_Iref[i]) ){
*THY++ = 1;
}
else {
*THY++ = 0;
}
}
else {
*IGBT++ = 0;
*THY++ = 0;
}
}
}

Answers (0)

Categories

Find more on General Applications in Help Center and File Exchange

Products

Asked:

on 23 Mar 2018

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!