Ignore:
Timestamp:
Jan 23, 2025, 9:09:36 AM (4 months ago)
Author:
Zed
Message:

Fixing project before Ethernet implementation.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • ctrl/firmware/Main/SES/Core/Src/fan_thread.cpp

    r67 r68  
    99
    1010static constexpr unsigned INPUT_BUF_SIZE = 64U;  // Must be dev by 4
     11static constexpr ULONG ONE_SHOT_TIMER = 0U;
     12static constexpr ULONG TIMER_PERIOD_MS = 20U;
    1113
    1214alignas(32) static unsigned ibuf[INPUT_BUF_SIZE]                                                                __attribute__((section(".RAM1")));
     
    1618
    1719//TX_EVENT_FLAGS_GROUP fanEG;
     20static TX_TIMER timer;
     21
     22//------------------------------------------------------------------------------
     23
     24static VOID icTimeout(ULONG);
     25
     26//------------------------------------------------------------------------------
    1827
    1928VOID fanThread(ULONG initial_input)
     
    3847        //ULONG actual_flags;
    3948
     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
    4052        while(1)
    4153        {
     
    4355                {
    4456                        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);
    4559                        //__HAL_DMA_DISABLE_IT(&hdma_tim8_ch1, DMA_IT_HT);
    4660
     
    6175                }
    6276
    63                 sum /= (INPUT_BUF_SIZE / 4U);
     77                sum /= (INPUT_BUF_SIZE / 4U); // T = T1 + T2 + T3 + T4
    6478
    6579                uint32_t div = htim8.Instance->PSC + 1;
     
    6781                //uint32_t arr = htim8.Instance->ARR + 1;
    6882
    69                 uint32_t rpm = (60U * clockHz) / sum;
     83                uint32_t rpm;
     84                if (sum) rpm  = (60U * clockHz) / sum;
     85                else rpm = 0;
    7086                printf("RPM = %u\n", rpm);
    7187
     
    108124        //lastTime = HAL_GetTick();
    109125
     126        tx_timer_deactivate(&timer);
     127
    110128        rawCnt = HAL_TIM_ReadCapturedValue(&htim8, TIM_CHANNEL_1);
    111129        //tx_event_flags_set(&fanEG, 1, TX_OR);
     
    119137        //printf("%u\n", HAL_GetTick());
    120138
    121 
    122139        tx_thread_resume(&fan_thread_ptr);
    123140}
     141
     142//------------------------------------------------------------------------------
     143
     144static 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.