source: ecs_cellMon/firmware/Core/Src/comp.c

Last change on this file was 3, checked in by f.jahn, 3 years ago

fw hinzugfügt-->zed

File size: 5.6 KB
Line 
1/**
2 ******************************************************************************
3 * @file comp.c
4 * @brief This file provides code for the configuration
5 * of the COMP instances.
6 ******************************************************************************
7 * @attention
8 *
9 * <h2><center>&copy; Copyright (c) 2021 STMicroelectronics.
10 * All rights reserved.</center></h2>
11 *
12 * This software component is licensed by ST under BSD 3-Clause license,
13 * the "License"; You may not use this file except in compliance with the
14 * License. You may obtain a copy of the License at:
15 * opensource.org/licenses/BSD-3-Clause
16 *
17 ******************************************************************************
18 */
19
20/* Includes ------------------------------------------------------------------*/
21#include "comp.h"
22
23/* USER CODE BEGIN 0 */
24
25/* USER CODE END 0 */
26
27COMP_HandleTypeDef hcomp1;
28COMP_HandleTypeDef hcomp2;
29
30/* COMP1 init function */
31void MX_COMP1_Init(void)
32{
33
34 /* USER CODE BEGIN COMP1_Init 0 */
35
36 /* USER CODE END COMP1_Init 0 */
37
38 /* USER CODE BEGIN COMP1_Init 1 */
39
40 /* USER CODE END COMP1_Init 1 */
41 hcomp1.Instance = COMP1;
42 hcomp1.Init.InputPlus = COMP_INPUT_PLUS_IO3;
43 hcomp1.Init.InputMinus = COMP_INPUT_MINUS_DAC1_CH1;
44 hcomp1.Init.OutputPol = COMP_OUTPUTPOL_INVERTED;
45 hcomp1.Init.WindowOutput = COMP_WINDOWOUTPUT_EACH_COMP;
46 hcomp1.Init.Hysteresis = COMP_HYSTERESIS_HIGH;
47 hcomp1.Init.BlankingSrce = COMP_BLANKINGSRC_NONE;
48 hcomp1.Init.Mode = COMP_POWERMODE_HIGHSPEED;
49 hcomp1.Init.WindowMode = COMP_WINDOWMODE_DISABLE;
50 hcomp1.Init.TriggerMode = COMP_TRIGGERMODE_NONE;
51 if (HAL_COMP_Init(&hcomp1) != HAL_OK)
52 {
53 Error_Handler();
54 }
55 /* USER CODE BEGIN COMP1_Init 2 */
56
57 /* USER CODE END COMP1_Init 2 */
58
59}
60/* COMP2 init function */
61void MX_COMP2_Init(void)
62{
63
64 /* USER CODE BEGIN COMP2_Init 0 */
65
66 /* USER CODE END COMP2_Init 0 */
67
68 /* USER CODE BEGIN COMP2_Init 1 */
69
70 /* USER CODE END COMP2_Init 1 */
71 hcomp2.Instance = COMP2;
72 hcomp2.Init.InputPlus = COMP_INPUT_PLUS_IO3;
73 hcomp2.Init.InputMinus = COMP_INPUT_MINUS_IO3;
74 hcomp2.Init.OutputPol = COMP_OUTPUTPOL_NONINVERTED;
75 hcomp2.Init.WindowOutput = COMP_WINDOWOUTPUT_EACH_COMP;
76 hcomp2.Init.Hysteresis = COMP_HYSTERESIS_HIGH;
77 hcomp2.Init.BlankingSrce = COMP_BLANKINGSRC_NONE;
78 hcomp2.Init.Mode = COMP_POWERMODE_HIGHSPEED;
79 hcomp2.Init.WindowMode = COMP_WINDOWMODE_DISABLE;
80 hcomp2.Init.TriggerMode = COMP_TRIGGERMODE_NONE;
81 if (HAL_COMP_Init(&hcomp2) != HAL_OK)
82 {
83 Error_Handler();
84 }
85 /* USER CODE BEGIN COMP2_Init 2 */
86
87 /* USER CODE END COMP2_Init 2 */
88
89}
90
91void HAL_COMP_MspInit(COMP_HandleTypeDef* compHandle)
92{
93
94 GPIO_InitTypeDef GPIO_InitStruct = {0};
95 if(compHandle->Instance==COMP1)
96 {
97 /* USER CODE BEGIN COMP1_MspInit 0 */
98
99 /* USER CODE END COMP1_MspInit 0 */
100
101 __HAL_RCC_GPIOA_CLK_ENABLE();
102 /**COMP1 GPIO Configuration
103 PA1 ------> COMP1_INP
104 PA11 [PA9] ------> COMP1_OUT
105 */
106 GPIO_InitStruct.Pin = COMP1_INP_I_SENSE_Pin;
107 GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
108 GPIO_InitStruct.Pull = GPIO_NOPULL;
109 HAL_GPIO_Init(COMP1_INP_I_SENSE_GPIO_Port, &GPIO_InitStruct);
110
111 GPIO_InitStruct.Pin = COMP1_OUT_I_PEAK_Pin;
112 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
113 GPIO_InitStruct.Pull = GPIO_NOPULL;
114 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
115 GPIO_InitStruct.Alternate = GPIO_AF7_COMP1;
116 HAL_GPIO_Init(COMP1_OUT_I_PEAK_GPIO_Port, &GPIO_InitStruct);
117
118 /* USER CODE BEGIN COMP1_MspInit 1 */
119
120 /* USER CODE END COMP1_MspInit 1 */
121 }
122 else if(compHandle->Instance==COMP2)
123 {
124 /* USER CODE BEGIN COMP2_MspInit 0 */
125 /* USER CODE END COMP2_MspInit 0 */
126
127 __HAL_RCC_GPIOA_CLK_ENABLE();
128 __HAL_RCC_GPIOB_CLK_ENABLE();
129 /**COMP2 GPIO Configuration
130 PA2 ------> COMP2_INM
131 PA3 ------> COMP2_INP
132 PB5 ------> COMP2_OUT
133 */
134 GPIO_InitStruct.Pin = COMP2_INM_U_TR_SENSE_Pin|COMP2_INP_U_TR_REF_Pin;
135 GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
136 GPIO_InitStruct.Pull = GPIO_NOPULL;
137 HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
138
139 GPIO_InitStruct.Pin = COMP2_OUT_DISCHARGE_Pin;
140 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
141 GPIO_InitStruct.Pull = GPIO_NOPULL;
142 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
143 GPIO_InitStruct.Alternate = GPIO_AF7_COMP2;
144 HAL_GPIO_Init(COMP2_OUT_DISCHARGE_GPIO_Port, &GPIO_InitStruct);
145
146 /* USER CODE BEGIN COMP2_MspInit 1 */
147
148 /* USER CODE END COMP2_MspInit 1 */
149 }
150}
151
152void HAL_COMP_MspDeInit(COMP_HandleTypeDef* compHandle)
153{
154
155 if(compHandle->Instance==COMP1)
156 {
157 /* USER CODE BEGIN COMP1_MspDeInit 0 */
158
159 /* USER CODE END COMP1_MspDeInit 0 */
160
161 /**COMP1 GPIO Configuration
162 PA1 ------> COMP1_INP
163 PA11 [PA9] ------> COMP1_OUT
164 */
165 HAL_GPIO_DeInit(GPIOA, COMP1_INP_I_SENSE_Pin|COMP1_OUT_I_PEAK_Pin);
166
167 /* USER CODE BEGIN COMP1_MspDeInit 1 */
168
169 /* USER CODE END COMP1_MspDeInit 1 */
170 }
171 else if(compHandle->Instance==COMP2)
172 {
173 /* USER CODE BEGIN COMP2_MspDeInit 0 */
174
175 /* USER CODE END COMP2_MspDeInit 0 */
176
177 /**COMP2 GPIO Configuration
178 PA2 ------> COMP2_INM
179 PA3 ------> COMP2_INP
180 PB5 ------> COMP2_OUT
181 */
182 HAL_GPIO_DeInit(GPIOA, COMP2_INM_U_TR_SENSE_Pin|COMP2_INP_U_TR_REF_Pin);
183
184 HAL_GPIO_DeInit(COMP2_OUT_DISCHARGE_GPIO_Port, COMP2_OUT_DISCHARGE_Pin);
185
186 /* USER CODE BEGIN COMP2_MspDeInit 1 */
187
188 /* USER CODE END COMP2_MspDeInit 1 */
189 }
190}
191
192/* USER CODE BEGIN 1 */
193
194/* USER CODE END 1 */
195
196/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Note: See TracBrowser for help on using the repository browser.