]> rtime.felk.cvut.cz Git - pes-rpp/rpp-simulink.git/blob - rpp/blocks/sfunction_hbr.c
doc: Update documentation of external mode and related stuff
[pes-rpp/rpp-simulink.git] / rpp / blocks / sfunction_hbr.c
1 /* Copyright (C) 2013, 2014 Czech Technical University in Prague
2  *
3  * Authors:
4  *     - Carlos Jenkins <carlos@jenkins.co.cr>
5  *
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.
10  *
11  * File : sfunction_hbr.c
12  * Abstract:
13  *     C-MEX S-function block for RPP H-Bridge output.
14  *
15  * References:
16  *     header.c
17  *     trailer.c
18  *
19  * Compile with:
20  *     <matlabroot>/bin/mex sfunction_hbr.c
21  */
22
23 /*
24 %YAML 1.2
25 ---
26 Name: H-Bridge Control
27 Category: Power output blocks
28 Header: rpp/hbr.h
29 Mnemonic: HBR
30
31 Inputs:
32   - { name: "Enable",  type: "bool"   }
33   - { name: "Control", type: "double" }
34
35 Outputs:
36   - { name: "ErrFlag", type: "bool" }
37
38 Parameters:
39
40 # Description and Help is in Markdown mark-up
41 Description: |
42
43   Control H-Bridge (10A, PWM) at default frequency.
44
45   This block expects input in range [-1.0, 1.0].
46
47 Help: |
48
49   This block allows to control the H-Bridge on the RPP board. The ErrFlag should raise only if
50   `rpp_hbr_control()` returns error. The H-Bridge is initialized with the default frequency 
51   (~18kHz). A future improvement could include a parameter to set the frequency. Because the ErrFlag 
52   should never set, once set the following steps will never clear it back.
53
54 Status: Stable
55
56 RPP API functions used:
57     - rpp_hbr_enable()
58     - rpp_hbr_control()
59
60 Relevant demos:
61    - hbridge_analog_control
62    - hbridge_digital_control
63    - hbridge_sinewave_control
64 ...
65 */
66
67 #define S_FUNCTION_NAME sfunction_hbr
68 #include "header.c"
69
70
71 static void mdlInitializeSizes(SimStruct *S)
72 {
73     /*
74      * Configure parameters: 0
75      */
76     if (!rppSetNumParams(S, 0)) {
77         return;
78     }
79
80     /*
81      * Configure input ports: 1
82      *  - Enable
83      *  - Control power.
84      */
85     if (!ssSetNumInputPorts(S, 2)) {
86         return;
87     }
88     rppAddInputPort(S, 0, SS_BOOLEAN);
89     rppAddInputPort(S, 1, SS_DOUBLE);
90
91     /*
92      * Configure output ports: 1
93      *  - Error flag.
94      */
95     if (!ssSetNumOutputPorts(S, 1)) {
96         return;
97     }
98     rppAddOutputPort(S, 0, SS_BOOLEAN);
99
100     /* Set standard options for this block */
101     rppSetStandardOptions(S);
102 }
103
104
105 #define COMMON_MDLINITIALIZESAMPLETIMES_INHERIT
106 #define UNUSED_MDLCHECKPARAMETERS
107 #define UNUSED_MDLOUTPUTS
108 #define UNUSED_MDLTERMINATE
109 #include "trailer.c"