1 /*********************************************************************************************************//**
2  * @file    ht32f66xxx_pid.h
3  * @version $Rev:: 8260         $
4  * @date    $Date:: 2024-11-05 #$
5  * @brief   The header file of the PID library.
6  *************************************************************************************************************
7  * @attention
8  *
9  * Firmware Disclaimer Information
10  *
11  * 1. The customer hereby acknowledges and agrees that the program technical documentation, including the
12  *    code, which is supplied by Holtek Semiconductor Inc., (hereinafter referred to as "HOLTEK") is the
13  *    proprietary and confidential intellectual property of HOLTEK, and is protected by copyright law and
14  *    other intellectual property laws.
15  *
16  * 2. The customer hereby acknowledges and agrees that the program technical documentation, including the
17  *    code, is confidential information belonging to HOLTEK, and must not be disclosed to any third parties
18  *    other than HOLTEK and the customer.
19  *
20  * 3. The program technical documentation, including the code, is provided "as is" and for customer reference
21  *    only. After delivery by HOLTEK, the customer shall use the program technical documentation, including
22  *    the code, at their own risk. HOLTEK disclaims any expressed, implied or statutory warranties, including
23  *    the warranties of merchantability, satisfactory quality and fitness for a particular purpose.
24  *
25  * <h2><center>Copyright (C) Holtek Semiconductor Inc. All rights reserved</center></h2>
26  ************************************************************************************************************/
27 
28 /* Define to prevent recursive inclusion -------------------------------------------------------------------*/
29 #ifndef __HT32F66XXX_PID_H
30 #define __HT32F66XXX_PID_H
31 
32 #ifdef __cplusplus
33  extern "C" {
34 #endif
35 
36 /* Includes ------------------------------------------------------------------------------------------------*/
37 #include "ht32.h"
38 
39 /** @addtogroup HT32F5xxxx_Peripheral_Driver HT32F5xxxx Peripheral Driver
40   * @{
41   */
42 
43 /** @addtogroup PID
44   * @{
45   */
46 
47 /* Exported types ------------------------------------------------------------------------------------------*/
48 /** @defgroup PID_Exported_Types PID exported types
49   * @{
50   */
51 
52 /**
53  * @brief PID PID_Mode
54  */
55 typedef enum
56 {
57   PID_SPD_MODE   = 0,
58   PID_IQ_MODE,
59   PID_ID_MODE,
60   PID_FWNK_MODE,
61   PID_PLL_MODE,
62   PID_USR_MODE,
63 } PID_Mode_Enum;
64 
65 #define IS_PID_MODE(PID_MODE)    (((PID_MODE) == PID_SPD_MODE)   || \
66                                   ((PID_MODE) == PID_IQ_MODE)    || \
67                                   ((PID_MODE) == PID_ID_MODE)    || \
68                                   ((PID_MODE) == PID_FWNK_MODE)  || \
69                                   ((PID_MODE) == PID_PLL_MODE)   || \
70                                   ((PID_MODE) == PID_USR_MODE))
71 
72 /**
73  * @brief PID paramater init structure
74  */
75 typedef struct
76 {
77   s32 ERRn_1;
78   s32 UIn_1;
79   s32 KP;
80   s32 KI;
81   s32 KD;
82   s32 UI_MAX;
83   s32 UI_MIN;
84   s16 OUT_MAX;
85   s16 OUT_MIN;
86 } PID_InitTypeDef;
87 /**
88   * @}
89   */
90 
91 /* Exported constants --------------------------------------------------------------------------------------*/
92 /** @defgroup PID_Exported_Constants PID exported constants
93   * @{
94   */
95 #define IS_PID(x)                IS_PID0(x)
96 #define IS_PID0(x)               (x == HT_PID0)
97 
98 /**
99  * @brief PID CR Bit Field Definitions
100  */
101 #define PID_CR_MODSEL_Pos        24
102 #define PID_CR_MODSEL_Msk        (0xFul << PID_CR_MODSEL_Pos)
103 
104 #define PID_CR_UIF               (0x00000008)
105 #define PID_CR_PIDEN             (0x00000001)
106 
107 #define PID_FLAG_OVF             (0x00020000)
108 #define PID_FLAG_CMP             (0x00000200)
109 
110 #define IS_PID_FLAG(FLAG)        ((FLAG == PID_FLAG_OVF) || \
111                                   (FLAG == PID_FLAG_CMP))
112 
113 #define PID_INT_OVF              (0x00010000)
114 #define PID_INT_CMP              (0x00000100)
115 
116 #define IS_PID_INT(INT)          ((INT == PID_INT_OVF) || \
117                                   (INT == PID_INT_CMP))
118 
119 #define PID_INT_Status_Pos       2
120 #define PID_INT_Clear_Pos        3
121 
122 /**
123   * @}
124   */
125 
126 /* Exported functions --------------------------------------------------------------------------------------*/
127 /** @defgroup PID_Exported_Functions PID exported functions
128   * @{
129   */
130 void PID_DeInit(HT_PID_TypeDef* HT_PIDn);
131 void PID_Init(HT_PID_TypeDef* HT_PIDn, PID_Mode_Enum PID_Mode, PID_InitTypeDef* PID_Para);
132 void PID_IntConfig(HT_PID_TypeDef* HT_PIDn, u32 PID_INT_x, ControlStatus NewState);
133 FlagStatus PID_GetIntStatus(HT_PID_TypeDef* HT_PIDn, u32 PID_INT_x);
134 void PID_ClearIntPendingBit(HT_PID_TypeDef* HT_PIDn, u32 PID_INT_x);
135 void PID_SetComPara_ERRn(HT_PID_TypeDef* HT_PIDn, s32 ERRn);
136 void PID_SetComPara_UI_Input(HT_PID_TypeDef* HT_PIDn, s32 UI_Input);
137 void PID_Compute(HT_PID_TypeDef* HT_PIDn, PID_Mode_Enum PID_Mode);
138 s16  PID_GetOutResult(HT_PID_TypeDef* HT_PIDn);
139 FlagStatus PID_GetFlagStatus(HT_PID_TypeDef* HT_PIDn, u32 PID_FLAG_x);
140 void PID_UI_InputCmd(HT_PID_TypeDef* HT_PIDn, ControlStatus NewState);
141 s32  PID_GetERRn_1(HT_PID_TypeDef* HT_PIDn, PID_Mode_Enum PID_Mode);
142 s32  PID_GetUIn_1(HT_PID_TypeDef* HT_PIDn, PID_Mode_Enum PID_Mode);
143 /**
144   * @}
145   */
146 
147 /**
148   * @}
149   */
150 
151 /**
152   * @}
153   */
154 
155 #ifdef __cplusplus
156 }
157 #endif
158 
159 #endif
160