# MATLAB: Problem with Update Methode in S-Function Builder (R2006B)

rtws-function builderunit delay

Hey,
I've modeled a really simple function in Simulink (Version 6.5) which contains a "Unit Delay" block. After that I used Real Time Workshop (Version 6.5) to build C-Code from my model. All I want to do now, is to include my C-Code back with a S-Function builder.
My Problem is, that I don't know where to put the update-methode. If I include the update methode in the Outputs-pane of the S-Function Builder, I get a segmentation fault. If I manually insert the code contained in the Update Function (Funktion_DWork.UnitDelay1_DSTATE = Funktion_B.Add1;), everything is fine.
So my basic question is, where to put the update-methode, to update my Unit-Delay blocks?
The generated Update Funktion looks like this:
 /* Model update function */static void Funktion_update(int_T tid){  /* Update for UnitDelay: '<Root>/Unit Delay1' */  Funktion_DWork.UnitDelay1_DSTATE = Funktion_B.Add1;/* Update absolute time for base rate */if (!(++Funktion_M->Timing.clockTick0))  ++Funktion_M->Timing.clockTickH0;Funktion_M->Timing.t[0] = Funktion_M->Timing.clockTick0 *  Funktion_M->Timing.stepSize0 + Funktion_M->Timing.clockTickH0 *  Funktion_M->Timing.stepSize0 * 4294967296.0;UNUSED_PARAMETER(tid);}
Edit: I just found out, that the lower part after "/* Update absolute time for base rate */" causes the segmentation fault.

#### Best Answer

• Meh found the solution! :) I had to call another initialze function first. I somehow missed that.