]> rtime.felk.cvut.cz Git - jenkicar/rpp-simulink.git/blob - rpp/blocks/sfunction_hbr.c
e154ededa3d32ff21b711f1b87d47d6151806938
[jenkicar/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:
55   Tested:
56     - Compilation and general use.
57   Untested:
58     - Faulty situation for the ErrFlag to set.
59   Not working:
60
61 RPP API functions used:
62     - rpp_hbr_enable()
63     - rpp_hbr_control()
64
65 Relevant demos:
66    - hbridge_analog_control
67    - hbridge_digital_control
68    - hbridge_sinewave_control
69 ...
70 */
71
72 #define S_FUNCTION_NAME sfunction_hbr
73 #include "header.c"
74
75
76 static void mdlInitializeSizes(SimStruct *S)
77 {
78     /*
79      * Configure parameters: 0
80      */
81     if (!rppSetNumParams(S, 0)) {
82         return;
83     }
84
85     /*
86      * Configure input ports: 1
87      *  - Enable
88      *  - Control power.
89      */
90     if (!ssSetNumInputPorts(S, 2)) {
91         return;
92     }
93     rppAddInputPort(S, 0, SS_BOOLEAN);
94     rppAddInputPort(S, 1, SS_DOUBLE);
95
96     /*
97      * Configure output ports: 1
98      *  - Error flag.
99      */
100     if (!ssSetNumOutputPorts(S, 1)) {
101         return;
102     }
103     rppAddOutputPort(S, 0, SS_BOOLEAN);
104
105     /* Set standard options for this block */
106     rppSetStandardOptions(S);
107 }
108
109
110 #define COMMON_MDLINITIALIZESAMPLETIMES_INHERIT
111 #define UNUSED_MDLCHECKPARAMETERS
112 #define UNUSED_MDLOUTPUTS
113 #define UNUSED_MDLTERMINATE
114 #include "trailer.c"