How to create a "redundant" function with a C-MEX S-function ?

Hello, I have 1 input (a signal) and I want it to become 3 shifted phase (0, T/3 & 2T/3) signals. It Here is the part of my code :
static void mdlOutputs(SimStruct *S, int_T tid)
{
#ifndef MATLAB_MEX_FILE
Float64 T1, T2;
T1 = period/3;
T2 = 2*period/3;
exec_time = RTLIB_TIC_READ();
const real_T *u = (const real_T*) ssGetInputPortRealSignalPtrs(S,0);
ds1104_slave_dsp_pwm_start(tid0, SLVDSP1104_PWM_CH2_MSK);
ds1104_slave_dsp_pwm_duty_write_register(tid0, &ch1_index, 2);
ds1104_slave_dsp_pwm_duty_write(tid0, ch1_index, *u);
if (exec_time > T1)
{
ds1104_slave_dsp_pwm_start(tid1, SLVDSP1104_PWM_CH3_MSK);
ds1104_slave_dsp_pwm_duty_write_register(tid1, &ch2_index, 3);
ds1104_slave_dsp_pwm_duty_write(tid1, ch2_index, *u);
}
if (exec_time > T2)
{
ds1104_slave_dsp_pwm_start(tid2, SLVDSP1104_PWM_CH4_MSK);
ds1104_slave_dsp_pwm_duty_write_register(tid2, &ch3_index, 4);
ds1104_slave_dsp_pwm_duty_write(tid2, ch3_index, *u);
}
#endif
}
It works with the first loop, but no more. How can I do for more than 1 loop ? I know the problem come from the "if" loops but I don't know how I can replace it.
Please help me, thank you.

Respuestas (1)

Kaustubha Govind
Kaustubha Govind el 29 de Ag. de 2012
It's really hard for us to help with your code because you have library calls like RTLIB_TIC_READ() and ds1104_slave_dsp_pwm_XXX. I would recommend that you try debugging your S-function - step through your code and see if you are getting expected results from each library call. Once you have narrowed down the symptom to a Simulink-specific issue, more contributors on this forum will be able to help.

1 comentario

Do you mean the expressions: (exec_time > T1) and (exec_time > T2)? But exec_time is calculated from your custom library function RTLIB_TIC_READ(), and it's not clear what "period" is from your code snippet.

Iniciar sesión para comentar.

Categorías

Más información sobre Simulink Coder en Centro de ayuda y File Exchange.

Productos

Preguntada:

el 29 de Ag. de 2012

Community Treasure Hunt

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

Start Hunting!

Translated by