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

1 次查看(过去 30 天)
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.

回答(1 个)

Kaustubha Govind
Kaustubha Govind 2012-8-29
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 个评论
Kaustubha Govind
Kaustubha Govind 2012-8-29
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Simulink Coder 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by