Changeset 24 for trunk/firmware_v2/Core
- Timestamp:
- Aug 23, 2025, 3:27:52 PM (4 days ago)
- Location:
- trunk/firmware_v2/Core
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/firmware_v2/Core/Inc/tim.h
r23 r24 39 39 /* USER CODE BEGIN Private defines */ 40 40 41 #define STATE_NUM (3U)42 41 43 42 /* USER CODE END Private defines */ … … 50 49 /* USER CODE BEGIN Prototypes */ 51 50 52 void SetFANSpeed(unsigned speed); // Von 0 bis 100 53 unsigned GetLastSpeed(void); 51 54 52 55 53 /* USER CODE END Prototypes */ -
trunk/firmware_v2/Core/Src/stm32c0xx_it.c
r23 r24 64 64 extern TIM_HandleTypeDef htim16; 65 65 /* USER CODE BEGIN EV */ 66 66 uint32_t captureValue = 0; 67 uint32_t previousCaptureValue = 0; 68 uint32_t frequency = 0; 69 uint32_t ic_overflows = 0; 67 70 /* USER CODE END EV */ 68 71 … … 179 182 void HAL_TIM_IC_CaptureCallback(TIM_HandleTypeDef* htim) 180 183 { 181 extern uint32_t ic_overflows, freq; 182 extern uint32_t period[STATE_NUM]; 183 184 if (htim->Instance == TIM16) 185 { 186 static unsigned state; 187 188 period[state] = HAL_TIM_ReadCapturedValue(htim, TIM_CHANNEL_1) + 65536 * ic_overflows; 189 //__HAL_TIM_SetCounter(htim, 0U); 190 ic_overflows = 0U; 191 state++; 192 if (state >= STATE_NUM) 193 { 194 state = 0; 195 HAL_TIM_Base_Stop_IT(htim); 196 HAL_TIM_IC_Stop_IT(htim, TIM_CHANNEL_1); 197 uint32_t timerClock_Hz = HAL_RCC_GetPCLK1Freq(); 198 uint32_t icClock_Hz = timerClock_Hz / (htim->Instance->PSC + 1); 199 freq = (icClock_Hz * 30U) / (period[2] - period[1]); 200 } 201 } 184 if (htim->Channel == HAL_TIM_ACTIVE_CHANNEL_1) { 185 captureValue = HAL_TIM_ReadCapturedValue(htim, TIM_CHANNEL_1); 186 frequency = HAL_RCC_GetPCLK1Freq() / (htim->Instance->PSC + 1) / (captureValue); 187 //previousCaptureValue = captureValue; 188 htim->Instance->CNT=0; //Timer zurücksetzen, damit normalerweise kein Overflow auftritt. Nur bei Drehzahl 0 oder Nahe 0 wird OVL ausgelöst 189 ic_overflows=0; 190 } 202 191 } 203 192 … … 206 195 void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef* htim) 207 196 { 208 extern uint32_t ic_overflows, freq;197 209 198 210 199 if (htim->Instance == TIM16) 211 200 { 212 201 ic_overflows++; 213 if (ic_overflows > 10U) freq= 0;202 if (ic_overflows > 0) frequency = 0; 214 203 } 215 204 } -
trunk/firmware_v2/Core/Src/tim.c
r23 r24 25 25 #include <stdio.h> 26 26 27 uint32_t period[STATE_NUM]; 28 uint32_t freq; 29 uint32_t ic_overflows; 27 28 29 30 30 31 31 /* USER CODE END 0 */ … … 48 48 /* USER CODE END TIM16_Init 1 */ 49 49 htim16.Instance = TIM16; 50 htim16.Init.Prescaler = 23;50 htim16.Init.Prescaler = 119; 51 51 htim16.Init.CounterMode = TIM_COUNTERMODE_UP; 52 52 htim16.Init.Period = 65535; … … 247 247 /* USER CODE BEGIN 1 */ 248 248 249 static unsigned lastSpeed;250 251 void SetFANSpeed(unsigned speed)252 {253 const unsigned MAX_RPM = 100U; // 100.0%254 255 if (speed > MAX_RPM) speed = MAX_RPM;256 257 lastSpeed = speed;258 259 const unsigned MAX_PWM = __HAL_TIM_GET_AUTORELOAD(&htim17) + 1U;260 //printf("%u", MAX_PWM);261 const unsigned newPWM = (MAX_PWM * speed/ MAX_RPM);262 263 __HAL_TIM_SET_COMPARE(&htim17, TIM_CHANNEL_1, newPWM);264 }265 266 //-----------------------------------------------------------------------------267 268 unsigned GetLastSpeed(void)269 {270 return lastSpeed;271 }272 249 273 250 /* USER CODE END 1 */
Note: See TracChangeset
for help on using the changeset viewer.