ConOpSys V2970  P004.07
ANVILEX control operating system
P015_09_V1_0_Encoder.h
Go to the documentation of this file.
1 //------------------------------------------------------------------------------
2 //! @file P015_09_V1_0_Encoder.h
3 //! @brief Control board P015.09 CB incremental encoder hardware driver header file.
4 //! @attention No special attention requered.
5 //! @copyright (C) 2015-2020 ANVILEX LLC
6 //! $HeadURL: https://192.168.3.4:8443/svn/P004_07/ConOpSys/Hardware/P015_09_V1_0/P015_09_V1_0_Encoder.h $
7 //! $Revision: 2546 $
8 //! $Date: 2021-03-25 14:04:50 +0500 (Do, 25 Mrz 2021) $
9 //! $Author: minch $
10 //------------------------------------------------------------------------------
11 //
12 // Redistribution and use in source and binary forms, with or without
13 // modification, are permitted provided that the following conditions are met:
14 //
15 // 1. Redistributions of source code must retain the above copyright notice,
16 // this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright notice,
19 // this list of conditions and the following disclaimer in the documentation
20 // and/or other materials provided with the distribution.
21 //
22 // 3. Neither the name of ANVILEX nor the names of its contributors may be
23 // used to endorse or promote products derived from this software without
24 // specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
27 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
30 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 // POSSIBILITY OF SUCH DAMAGE.
37 //
38 //------------------------------------------------------------------------------
39 
40 //------------------------------------------------------------------------------
41 // Protecting header files from mutual, recursive inclusion.
42 //------------------------------------------------------------------------------
43 
44 #pragma once
45 
46 //------------------------------------------------------------------------------
47 // Include standard libraries header files
48 //------------------------------------------------------------------------------
49 
50 //------------------------------------------------------------------------------
51 // Include thrid party header files
52 //------------------------------------------------------------------------------
53 
54 //------------------------------------------------------------------------------
55 // Include ConOpSys header files
56 //------------------------------------------------------------------------------
57 
58 #include "Function_Block_Base.h"
59 
60 //------------------------------------------------------------------------------
61 // Include ConOpSys application header files
62 //------------------------------------------------------------------------------
63 
64 //------------------------------------------------------------------------------
65 //! @brief Encoder board P015.09 V1.0 class
66 //------------------------------------------------------------------------------
67 
69 {
70 
71  //----------------------------------------------------------------------------
72  // Public methods and variables
73  //----------------------------------------------------------------------------
74 
75  public:
76 
77  // Register structure for generic access
78  typedef struct
79  {
80 
81  // Analog value registers
82  U16 u16_Status; //!< Status register
83  U16 u16_Counter; //!< Counter register
84  U16 u16_Counter_Latch; //!< Counter latch register
85  U16 u16_Period; //!< Period in FPGA clocks
86  U16 u16_Unused_0x04; //!< Reserved register
87  U16 u16_Unused_0x05; //!< Reserved register
88  U16 u16_Unused_0x06; //!< Reserved register
89  U16 u16_Unused_0x07; //!< Reserved register
90 
92 
93  //--------------------------------------------------------------------------
94  // Public methods
95  //--------------------------------------------------------------------------
96 
97  // Constructor and destructor
98  TP015_09_V1_0_Encoder(); //!< Constructor method
99  virtual ~TP015_09_V1_0_Encoder(); //!< Destructor method
100 
101  VOID Map( TP015_09_V1_0_Encoder_Registers *struct_Registers_Base_Address );
102  virtual VOID Init(); //!< Initialisation method
103  virtual VOID Execute(); //!< Execute method
104  virtual VOID Send_Information( TProtocol_Base *object_Protocol ); //!< Send information about functional block
105 
106  //--------------------------------------------------------------------------
107  // Block inputs
108  //--------------------------------------------------------------------------
109 
110  TBlock_Input_Connector object_u32_Pulse; //!< [-] Encoder pulse per revolution
112 // TBlock_Input_Connector object_f32_Theta_Offset;
113  TBlock_Input_Connector object_f32_Max_Omega_Change_Rate; //!< [rad/s] Maximal omega change rate
114 
115  //--------------------------------------------------------------------------
116  // Block outputs
117  //--------------------------------------------------------------------------
118 
120 
122  TBlock_Output_Connector object_f32_Omega; //!< [rad/s] Rotor speed
124 
125  //----------------------------------------------------------------------------
126  // Protected methods and variables
127  //----------------------------------------------------------------------------
128 
129  protected:
130 
131  //----------------------------------------------------------------------------
132  // Private methods and variables
133  //----------------------------------------------------------------------------
134 
135  private:
136 
137  volatile TP015_09_V1_0_Encoder_Registers *struct_Registers; //!< Hardware mapped registers
138 
139  U32 u32_Error_Counter; //!< Error counter
140 
141  F32 f32_Theta_Gain; //!< Internal variable
142  F32 f32_Omega_Gain; //!< Internal variable
143  F32 f32_Omega_Magnitude_Storage; //!< Omega magnitude storage
144  F32 f32_Max_Omega_Change_Rate; //!< Maximal omega change rate
145 
146  BOOL bool_First_Iteration; //!< First iteration flag
147 
148  #ifdef FUNCTIONAL_BLOCK_CREATE_DIAGNOSE_OUTPUTS
149  U16 u16_Status; //!< Quadrature encoder status
150  U16 u16_Counter; //!< Quadrature counter
151  U16 u16_Period; //!< Rotation period in FPGA clocks
152  #endif
153 
154 };
155 
156 //------------------------------------------------------------------------------
157 
158 //! @brief KG3 digital I/O board (P020.29 / KG3 ENC T1) type 1 class
160 {
161 
162  //----------------------------------------------------------------------------
163  // Public defines, methods and variables
164  //----------------------------------------------------------------------------
165 
166  public:
167 
168  //--------------------------------------------------------------------------
169  // Public defines
170  //--------------------------------------------------------------------------
171 
172  //! @brief Register structure for digital I/O access
173  typedef struct
174  {
175 
176  //! @brief 0x00 : Module identification low register
178 
179  //! @brief 0x01 : Module identification high register
181 
182  //! @brief 0x02 : Status registers
184 
186 
187  //--------------------------------------------------------------------------
188  // Public methods
189  //--------------------------------------------------------------------------
190 
191  //!-------------------------------------------------------------------------
192  //! @brief Function block class constructor method.
193  //! @note None
194  //! \par Override
195  //! Not allowed
196  //! @attention Don't call this method directly.
197  //--------------------------------------------------------------------------
198 
200 
201  //!-------------------------------------------------------------------------
202  //! @brief Function block class destructor method.
203  //! @note None
204  //! \par Override
205  //! Not allowed
206  //! @attention Don't call this method directly.
207  //--------------------------------------------------------------------------
208 
209  virtual ~TP015_09_V1_0_Encoder_T2();
210 
211  //!-------------------------------------------------------------------------
212  //! @brief Hardware mapping method.
213  //! @note None
214  //! @param [in] *struct_Registers_Base_Address - Base adress to register structure mapping
215  //! \par Override
216  //! Not allowed
217  //! @attention None
218  //--------------------------------------------------------------------------
219 
220  VOID Map( TP015_09_V1_0_Encoder_Registers *struct_Registers_Base_Address );
221 
222  //!-------------------------------------------------------------------------
223  //! @brief Function block initialisation method.
224  //! @note None
225  //! \par Override
226  //! Not allowed
227  //! @attention None
228  //--------------------------------------------------------------------------
229 
230  virtual VOID Init();
231 
232  //!-------------------------------------------------------------------------
233  //! @brief Function block execution method.
234  //! @note None
235  //! \par Override
236  //! Not allowed
237  //! @attention None
238  //--------------------------------------------------------------------------
239 
240  virtual VOID Execute();
241 
242  //--------------------------------------------------------------------------
243  // ??? ==> ANVILEX KM: Move to the hardware class
244  //--------------------------------------------------------------------------
245 
246  U32 Get_Module_ID();
247 
248  //!-------------------------------------------------------------------------
249  //! @brief Send information about digital I/O baortd driver over communication link protocol
250  //! @note This method sends information about digital I/O driver over specified communication link protocol.
251  //! @param [in] *object_Protocol - Pointer to the communication link protocol
252  //! @return None
253  //! \par Override
254  //! Not allowed
255  //! @attention None
256  //--------------------------------------------------------------------------
257 
258  virtual VOID Send_Information( TProtocol_Base *object_Protocol );
259 
260  //--------------------------------------------------------------------------
261  // Public variables
262  //--------------------------------------------------------------------------
263 
264  //--------------------------------------------------------------------------
265  // Parameters
266  //--------------------------------------------------------------------------
267 
268  //--------------------------------------------------------------------------
269  // Input signal connectors
270  //--------------------------------------------------------------------------
271 
272  //--------------------------------------------------------------------------
273  // Output signal connectorss
274  //--------------------------------------------------------------------------
275 
276  //! @brief Digital input for channel A
278 
279  //! @brief Digital input for channel B
281 
282  //! @brief Digital input for channel Z
284 
285  //----------------------------------------------------------------------------
286  // Protected defines, mathods and variables
287  //----------------------------------------------------------------------------
288 
289  protected:
290 
291  //----------------------------------------------------------------------------
292  // Private defines, mathods and variables
293  //----------------------------------------------------------------------------
294 
295  private:
296 
297  //--------------------------------------------------------------------------
298  // Private defines
299  //--------------------------------------------------------------------------
300 
301  //! @brief Structure for bit parsing
302  typedef union
303  {
304 
305  //! @brief Raw data
307 
308  //! @brief Structure of the bits
309  struct
310  {
311 
312  //! @brief Bit 0 : Channel A input data
314 
315  //! @brief Bits 1...3 : Reserved bits
316  U16 :3;
317 
318  //! @brief Bit 4, Channel B input data
320 
321  //! @brief Bits 5...7 : Reserved bits
322  U16 :3;
323 
324  //! @brief Bit 8, Channel Z input data
326 
327  //! @brief Bits 9..15 : Reserved bits
328  U16 :7;
329 
330  };
331 
332  } TStatus_Register;
333 
334  //--------------------------------------------------------------------------
335  // Private variables
336  //--------------------------------------------------------------------------
337 
338  //! @brief Pointer to the memory area in FPGA address space
340 
341 };
342 
343 //------------------------------------------------------------------------------
344 // End of file
345 //------------------------------------------------------------------------------
int BOOL
Boolean datatype definition.
Definition: Defines.h:124
void VOID
Datatypesess datatype definition.
Definition: Defines.h:105
unsigned long U32
Binary 32-Bit unsigned integer datatype defenition.
Definition: Defines.h:203
float F32
IEEE-754 32-Bit single presession floating point numbers datatype defenition.
Definition: Defines.h:324
unsigned short U16
Binary 16-Bit unsigned integer datatype defenition.
Definition: Defines.h:193
Function block base class header file.
Function block input connector class.
Definition: Block_Input_Connector.h:83
Function block output connector class.
Definition: Block_Output_Connector.h:59
Function block base class for device.
Definition: Function_Block_Base.h:96
KG3 digital I/O board (P020.29 / KG3 ENC T1) type 1 class.
Definition: P015_09_V1_0_Encoder.h:160
volatile TP015_09_V1_0_Encoder_Registers * struct_Registers
Pointer to the memory area in FPGA address space.
Definition: P015_09_V1_0_Encoder.h:339
TBlock_Output_Connector object_bool_Channel_Z_Data
Digital input for channel Z.
Definition: P015_09_V1_0_Encoder.h:283
TP015_09_V1_0_Encoder_T2()
Function block class constructor method.
Definition: P015_09_V1_0_Encoder.cpp:418
VOID Map(TP015_09_V1_0_Encoder_Registers *struct_Registers_Base_Address)
Hardware mapping method.
Definition: P015_09_V1_0_Encoder.cpp:451
U32 Get_Module_ID()
Definition: P015_09_V1_0_Encoder.cpp:507
virtual ~TP015_09_V1_0_Encoder_T2()
Function block class destructor method.
Definition: P015_09_V1_0_Encoder.cpp:443
virtual VOID Init()
Function block initialisation method.
Definition: P015_09_V1_0_Encoder.cpp:466
TBlock_Output_Connector object_bool_Channel_A_Data
Digital input for channel A.
Definition: P015_09_V1_0_Encoder.h:277
virtual VOID Send_Information(TProtocol_Base *object_Protocol)
Send information about digital I/O baortd driver over communication link protocol.
Definition: P015_09_V1_0_Encoder.cpp:522
virtual VOID Execute()
Function block execution method.
Definition: P015_09_V1_0_Encoder.cpp:487
TBlock_Output_Connector object_bool_Channel_B_Data
Digital input for channel B.
Definition: P015_09_V1_0_Encoder.h:280
Encoder board P015.09 V1.0 class.
Definition: P015_09_V1_0_Encoder.h:69
virtual VOID Init()
Initialisation method.
Definition: P015_09_V1_0_Encoder.cpp:147
TBlock_Input_Connector object_f32_Counter_Clock_Frequency
[Hz] Counter clock frequency
Definition: P015_09_V1_0_Encoder.h:111
F32 f32_Omega_Magnitude_Storage
Omega magnitude storage.
Definition: P015_09_V1_0_Encoder.h:143
virtual VOID Send_Information(TProtocol_Base *object_Protocol)
Send information about functional block.
Definition: P015_09_V1_0_Encoder.cpp:332
VOID Map(TP015_09_V1_0_Encoder_Registers *struct_Registers_Base_Address)
Encoder board P015.09 V1.0 memory map.
Definition: P015_09_V1_0_Encoder.cpp:133
TBlock_Output_Connector object_bool_Error
Error flag.
Definition: P015_09_V1_0_Encoder.h:123
TBlock_Output_Connector object_f32_Theta
[rad] Rotor theta
Definition: P015_09_V1_0_Encoder.h:121
F32 f32_Theta_Gain
Internal variable.
Definition: P015_09_V1_0_Encoder.h:141
virtual ~TP015_09_V1_0_Encoder()
Destructor method.
Definition: P015_09_V1_0_Encoder.cpp:122
F32 f32_Max_Omega_Change_Rate
Maximal omega change rate.
Definition: P015_09_V1_0_Encoder.h:144
F32 f32_Omega_Gain
Internal variable.
Definition: P015_09_V1_0_Encoder.h:142
U32 u32_Error_Counter
Error counter.
Definition: P015_09_V1_0_Encoder.h:139
TBlock_Output_Connector object_f32_Omega
[rad/s] Rotor speed
Definition: P015_09_V1_0_Encoder.h:122
TBlock_Output_Connector object_f32_Counter
Encoder counter.
Definition: P015_09_V1_0_Encoder.h:119
BOOL bool_First_Iteration
First iteration flag.
Definition: P015_09_V1_0_Encoder.h:146
volatile TP015_09_V1_0_Encoder_Registers * struct_Registers
Hardware mapped registers.
Definition: P015_09_V1_0_Encoder.h:137
TBlock_Input_Connector object_u32_Pulse
[-] Encoder pulse per revolution
Definition: P015_09_V1_0_Encoder.h:110
virtual VOID Execute()
Execute method.
Definition: P015_09_V1_0_Encoder.cpp:188
TP015_09_V1_0_Encoder()
Constructor method.
Definition: P015_09_V1_0_Encoder.cpp:73
TBlock_Input_Connector object_f32_Max_Omega_Change_Rate
[rad/s] Maximal omega change rate
Definition: P015_09_V1_0_Encoder.h:113
Definition: Protocol_Base.h:57
Definition: P015_09_V1_0_Encoder.h:79
U16 u16_Status
Status register.
Definition: P015_09_V1_0_Encoder.h:82
U16 u16_Counter_Latch
Counter latch register.
Definition: P015_09_V1_0_Encoder.h:84
U16 u16_Unused_0x05
Reserved register.
Definition: P015_09_V1_0_Encoder.h:87
U16 u16_Unused_0x07
Reserved register.
Definition: P015_09_V1_0_Encoder.h:89
U16 u16_Unused_0x06
Reserved register.
Definition: P015_09_V1_0_Encoder.h:88
U16 u16_Period
Period in FPGA clocks.
Definition: P015_09_V1_0_Encoder.h:85
U16 u16_Counter
Counter register.
Definition: P015_09_V1_0_Encoder.h:83
U16 u16_Unused_0x04
Reserved register.
Definition: P015_09_V1_0_Encoder.h:86
Register structure for digital I/O access.
Definition: P015_09_V1_0_Encoder.h:174
U16 u16_Unit_ID_L
0x00 : Module identification low register
Definition: P015_09_V1_0_Encoder.h:177
U16 u16_Unit_ID_H
0x01 : Module identification high register
Definition: P015_09_V1_0_Encoder.h:180
U16 u16_Status_Register
0x02 : Status registers
Definition: P015_09_V1_0_Encoder.h:183
U16 b1_Channel_B_Input
Bit 4, Channel B input data.
Definition: P015_09_V1_0_Encoder.h:319
U16 u16_Raw_Data
Raw data.
Definition: P015_09_V1_0_Encoder.h:306
U16 b1_Channel_Z_Input
Bit 8, Channel Z input data.
Definition: P015_09_V1_0_Encoder.h:325
U16 b1_Channel_A_Input
Bit 0 : Channel A input data.
Definition: P015_09_V1_0_Encoder.h:313