1 /* Copyright (C) 2013, 2014 Czech Technical University in Prague
4 * - Carlos Jenkins <carlos@jenkins.co.cr>
6 * This document contains proprietary information belonging to Czech
7 * Technical University in Prague. Passing on and copying of this
8 * document, and communication of its contents is not permitted
9 * without prior written authorization.
11 * File : sfunction_aout.c
13 * C-MEX S-function block for RPP analog output.
20 * <matlabroot>/bin/mex sfunction_aout.c
32 - { name: "Analog Output", type: "uint16" }
35 - { name: "ErrFlag", type: "bool" }
38 - { name: "Pin number [1-4]", type: "uint8" }
39 - { name: "Input in millivolts", type: "bool" }
41 # Description and Help is in Markdown mark-up
44 Sets the analog value of the specified analog output pin on the RPP
47 If 'input is voltage' is set the value must be an unsigned 16 bit
48 integer between 0-12000 (millivolts to set the analog output). If
49 'input is voltage' is NOT set the value must be and unsigned 16 bit
50 integer between 0-4095 (DAC is 12 bit).
52 If an error is detected while setting the value, the ErrFlag is set
57 Sets the analog value of the specified analog output pin on the RPP board. If an error is detected
58 while setting the value, the ErrFlag is set high.
60 This block allows to write to the analog outputs on the RPP board. The UseVoltage flag allows the
61 user to configure if block inputs should be interpreted as raw DAC value or millivolts. The ErrFlag
62 should raise it `rpp_dac_update()` or `rpp_dac_set()` (or `rpp_dac_set_voltage()`
63 depending on block configuration) returns error. Because the ErrFlag should never set, once set the
64 following steps will never clear it back.
66 `rpp_dac_update()` is called on each block but the implementation provides this to be efficient.
68 There is a know bug on the RPP Library, check `rpp_dac_update()` on the RPP API for details.
69 Because of this, the outputs of the DACs are initialized on the first step of the model and not on
70 the model initialization.
74 RPP API functions used:
77 - rpp_dac_set_voltage()
87 #define S_FUNCTION_NAME sfunction_aout
91 static void mdlInitializeSizes(SimStruct *S)
94 * Configure parameters: 1
98 if (!rppSetNumParams(S, 2)) {
103 * Configure input ports: 1
106 if (!ssSetNumInputPorts(S, 1)) {
109 rppAddInputPort(S, 0, SS_UINT16);
112 * Configure output ports: 1
115 if (!ssSetNumOutputPorts(S, 1)) {
118 rppAddOutputPort(S, 0, SS_BOOLEAN);
120 /* Set standard options for this block */
121 rppSetStandardOptions(S);
125 #ifdef MATLAB_MEX_FILE
126 #define MDL_CHECK_PARAMETERS
127 static void mdlCheckParameters(SimStruct *S)
129 /* Check the parameter 1 */
130 if (!rppValidParamRange(S, 0, 1, 4)) {
134 /* Check the parameter 2 */
135 if (!rppValidParamBoolean(S, 1)) {
142 #ifdef MATLAB_MEX_FILE
143 #define MDL_SET_WORK_WIDTHS
144 static void mdlSetWorkWidths(SimStruct *S)
146 /* Set number of run-time parameters */
147 if (!ssSetNumRunTimeParams(S, 2)) {
151 /* Register the run-time parameter 1 */
152 ssRegDlgParamAsRunTimeParam(S, 0, 0, "p1", SS_UINT8);
154 /* Register the run-time parameter 2 */
155 ssRegDlgParamAsRunTimeParam(S, 1, 1, "p2", SS_BOOLEAN);
160 #define COMMON_MDLINITIALIZESAMPLETIMES_INHERIT
161 #define UNUSED_MDLOUTPUTS
162 #define UNUSED_MDLTERMINATE