Changeset 68 for ctrl/firmware/Main/SES/Core
- Timestamp:
- Jan 23, 2025, 9:09:36 AM (4 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
ctrl/firmware/Main/SES/Core/Src/fan_thread.cpp
r67 r68 9 9 10 10 static constexpr unsigned INPUT_BUF_SIZE = 64U; // Must be dev by 4 11 static constexpr ULONG ONE_SHOT_TIMER = 0U; 12 static constexpr ULONG TIMER_PERIOD_MS = 20U; 11 13 12 14 alignas(32) static unsigned ibuf[INPUT_BUF_SIZE] __attribute__((section(".RAM1"))); … … 16 18 17 19 //TX_EVENT_FLAGS_GROUP fanEG; 20 static TX_TIMER timer; 21 22 //------------------------------------------------------------------------------ 23 24 static VOID icTimeout(ULONG); 25 26 //------------------------------------------------------------------------------ 18 27 19 28 VOID fanThread(ULONG initial_input) … … 38 47 //ULONG actual_flags; 39 48 49 char timer_name[] = "IC overflow timer"; 50 tx_timer_create(&timer, timer_name, icTimeout, 0, TIMER_PERIOD_MS, ONE_SHOT_TIMER, TX_NO_ACTIVATE); 51 40 52 while(1) 41 53 { … … 43 55 { 44 56 HAL_TIM_IC_Start_IT(&htim8, TIM_CHANNEL_1);//, (uint32_t*)ibuf, INPUT_BUF_SIZE); 57 tx_timer_change(&timer, TIMER_PERIOD_MS, ONE_SHOT_TIMER); 58 tx_timer_activate(&timer); 45 59 //__HAL_DMA_DISABLE_IT(&hdma_tim8_ch1, DMA_IT_HT); 46 60 … … 61 75 } 62 76 63 sum /= (INPUT_BUF_SIZE / 4U); 77 sum /= (INPUT_BUF_SIZE / 4U); // T = T1 + T2 + T3 + T4 64 78 65 79 uint32_t div = htim8.Instance->PSC + 1; … … 67 81 //uint32_t arr = htim8.Instance->ARR + 1; 68 82 69 uint32_t rpm = (60U * clockHz) / sum; 83 uint32_t rpm; 84 if (sum) rpm = (60U * clockHz) / sum; 85 else rpm = 0; 70 86 printf("RPM = %u\n", rpm); 71 87 … … 108 124 //lastTime = HAL_GetTick(); 109 125 126 tx_timer_deactivate(&timer); 127 110 128 rawCnt = HAL_TIM_ReadCapturedValue(&htim8, TIM_CHANNEL_1); 111 129 //tx_event_flags_set(&fanEG, 1, TX_OR); … … 119 137 //printf("%u\n", HAL_GetTick()); 120 138 121 122 139 tx_thread_resume(&fan_thread_ptr); 123 140 } 141 142 //------------------------------------------------------------------------------ 143 144 static VOID icTimeout(ULONG) 145 { 146 extern TX_THREAD fan_thread_ptr; 147 rawCnt = 0; 148 HAL_TIM_IC_Stop_IT(&htim8, TIM_CHANNEL_1); 149 tx_thread_resume(&fan_thread_ptr); 150 }
Note: See TracChangeset
for help on using the changeset viewer.