声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 1027|回复: 0

[求助]一段有关硬件编程的S函数问题,为什么输出总是零呢?

[复制链接]
发表于 2006-6-3 11:33 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?我要加入

x
<P>如题,向各位高手求教了,希望不吝赐教,以下为代码,我把与硬件有关的函数都去掉了,给了个固定输出5.0,但在S函数模块输出见到的仍然是0,为什么?</P>
<P>#define     S_FUNCTION_LEVEL    2<BR>#undef      S_FUNCTION_NAME<BR>#define     S_FUNCTION_NAME     my_pcl818hd</P>
<P>#include    &lt;stddef.h&gt;<BR>#include    &lt;stdlib.h&gt;</P>
<P>#include    "simstruc.h"</P>
<P>#ifdef      MATLAB_MEX_FILE<BR>#include    "mex.h"<BR>#else<BR>#include    &lt;windows.h&gt;<BR>#include    "io_xpcimport.h"<BR>#endif</P>
<P>/* Input Arguments */</P>
<P>#define NUM_PARAMS             (3)<BR>#define BASE_ADDRESS_ARG       (ssGetSFcnParam(S,0))<BR>#define CHANNEL_ARG            (ssGetSFcnParam(S,1))<BR>#define SAMPLE_TIME_PARAM      (ssGetSFcnParam(S,2))</P>
<P><BR>/* Convert S Function Parameters to Variables of Unsigned Integer Type */</P>
<P>#define BASE                   ((uint_T) mxGetPr(BASE_ADDRESS_ARG)[0])<BR>#define NUM_CHANNEL            ((uint_T) mxGetPr(CHANNEL_ARG)[0])<BR>#define SAMPLE_TIME            ((real_T) mxGetPr(SAMPLE_TIME_PARAM)[0])<BR>#define SAMPLE_OFFSET          ((real_T) mxGetPr(SAMPLE_TIME_PARAM)[1])<BR>//#define BASE                    0x220<BR>/* Definition of Quanser Register Adresses for AD conversion */</P>

<P>static char_T msg[256];</P>
<P><BR>/*====================*<BR> * S-function methods *<BR> *====================*/</P>
<P>static void mdlCheckParameters(SimStruct *S)<BR>{<BR>}</P>
<P>static void mdlInitializeSizes(SimStruct *S)<BR>{<BR>    uint_T i;</P>
<P>#ifndef MATLAB_MEX_FILE<BR>#include "io_xpcimport.c"<BR>#endif</P>
<P><BR>    ssSetNumSFcnParams(S, NUM_PARAMS);<BR>    if (ssGetNumSFcnParams(S) == ssGetSFcnParamsCount(S)) {<BR>        mdlCheckParameters(S);<BR>        if (ssGetErrorStatus(S) != NULL) {<BR>            return;<BR>        }<BR>    } else {<BR>        return; /* Parameter mismatch will be reported by Simulink */<BR>    }</P>
<P>    ssSetNumContStates(S, 0);<BR>    ssSetNumDiscStates(S, 0);</P>

<P>    if (!ssSetNumInputPorts(S, 0)) return;</P>
<P>    if (!ssSetNumOutputPorts(S, NUM_CHANNEL)) return;</P>
<P>    for (i=0;i&lt;NUM_CHANNEL;i++) {<BR>        ssSetOutputPortWidth(S, i, 1);<BR>    }</P>
<P>    ssSetNumSampleTimes(S, 1);</P>
<P>    ssSetNumModes(S, 0);<BR>    ssSetNumNonsampledZCs(S, 0);</P>
<P>    ssSetSFcnParamNotTunable(S,0);<BR>    ssSetSFcnParamNotTunable(S,1);<BR>    ssSetSFcnParamNotTunable(S,2);</P>
<P>    ssSetOptions(S, SS_OPTION_EXCEPTION_FREE_CODE | SS_OPTION_PLACE_ASAP);</P>
<P>}</P>

<P>static void mdlInitializeSampleTimes(SimStruct *S)<BR>{<BR>    ssSetSampleTime(S, 0, SAMPLE_TIME);<BR>    ssSetOffsetTime(S, 0, SAMPLE_OFFSET);<BR>}</P>

<P><BR>static void mdlOutputs(SimStruct *S, int_T tid)<BR>{</P>
<P>#ifndef MATLAB_MEX_FILE</P>
<P>    uint_T i;<BR>  //  uint_T baseAddr = BASE;<BR>  // real_T *y,  res;<BR> real_T *y;<BR>    for (i=0;i&lt;NUM_CHANNEL;i++) {<BR>        <BR>        <BR>   y=ssGetOutputPortSignal(S,i);<BR>        </P>
<P>      //   rl32eInpB((unsigned short)(baseAddr+10));                      /* start conversion */<BR>      //   while (rl32eInpB((unsigned short)(baseAddr+8)) &amp; 0x80);     /* wait until data ready */<BR>      //   res=rl32eInpW((unsigned short)(baseAddr+4));                         /* read data */<BR>      //   rl32eInpB((unsigned short)(baseAddr+9));                    /* clear interrupt request */</P>
<P>                                      <BR>      //   y[0]=10.0*(res/32752); /* bipolar input */<BR>       y[0]=5.0;<BR>       <BR>    }</P>
<P>#endif<BR>                 <BR>}</P>
<P>static void mdlTerminate(SimStruct *S)<BR>{   <BR>}</P>
<P><BR>#ifdef MATLAB_MEX_FILE  /* Is this file being compiled as a MEX-file? */<BR>#include "simulink.c"   /* Mex glue */<BR>#else<BR>#include "cg_sfun.h"    /* Code generation glue */<BR>#endif<BR></P>
回复
分享到:

使用道具 举报

您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-9-21 19:48 , Processed in 0.052252 second(s), 18 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表