Changeset 24 for trunk/firmware_v2/Core


Ignore:
Timestamp:
Aug 23, 2025, 3:27:52 PM (4 days ago)
Author:
f.jahn
Message:
LVP, OVP, LVP
OVP modes implementiert
  • Lüftersteuerung in eigenes Modul verlagert
Location:
trunk/firmware_v2/Core
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/firmware_v2/Core/Inc/tim.h

    r23 r24  
    3939/* USER CODE BEGIN Private defines */
    4040
    41 #define STATE_NUM       (3U)
    4241
    4342/* USER CODE END Private defines */
     
    5049/* USER CODE BEGIN Prototypes */
    5150
    52 void SetFANSpeed(unsigned speed);                 // Von 0 bis 100
    53 unsigned GetLastSpeed(void);
     51
    5452
    5553/* USER CODE END Prototypes */
  • trunk/firmware_v2/Core/Src/stm32c0xx_it.c

    r23 r24  
    6464extern TIM_HandleTypeDef htim16;
    6565/* 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;
    6770/* USER CODE END EV */
    6871
     
    179182void HAL_TIM_IC_CaptureCallback(TIM_HandleTypeDef* htim)
    180183{
    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    }
    202191}
    203192
     
    206195void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef* htim)
    207196{
    208         extern uint32_t ic_overflows, freq;
     197       
    209198
    210199        if (htim->Instance == TIM16)
    211200        {
    212201                ic_overflows++;
    213                 if (ic_overflows > 10U) freq = 0;
     202                if (ic_overflows > 0) frequency = 0;
    214203        }
    215204}
  • trunk/firmware_v2/Core/Src/tim.c

    r23 r24  
    2525#include <stdio.h>
    2626
    27 uint32_t period[STATE_NUM];
    28 uint32_t freq;
    29 uint32_t ic_overflows;
     27
     28
     29
    3030
    3131/* USER CODE END 0 */
     
    4848  /* USER CODE END TIM16_Init 1 */
    4949  htim16.Instance = TIM16;
    50   htim16.Init.Prescaler = 23;
     50  htim16.Init.Prescaler = 119;
    5151  htim16.Init.CounterMode = TIM_COUNTERMODE_UP;
    5252  htim16.Init.Period = 65535;
     
    247247/* USER CODE BEGIN 1 */
    248248
    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 }
    272249
    273250/* USER CODE END 1 */
Note: See TracChangeset for help on using the changeset viewer.