Skip to main content
Explorer II
December 13, 2024
Solved

increment doesn't work in a systick function

  • December 13, 2024
  • 2 replies
  • 1596 views

Hello,

Now I'm testing a systick work on STM32L0538-DISCO.

The aim in my project is to make 100Hz, 10Hz, 6Hz, 5Hz, 2Hz and 1Hz systick functions.

In the project, 100Hz, 10Hz, 6Hz and 5Hz systick functions worked, but 2Hz and 1Hz systick functions didn't work.

In my main.c code, 10Hz systick driver ( deci_sec_systick_Driver()) could drive 5Hz systick driver (vigesimal_sec_systick_Driver()) but couldn't drive 2Hz systick driver (demi_sec_systick_Driver()).

I found by debugging that a local static variable (demi_sec_systick_count) reached to 4 but it was reset before reaching 5.

Of course there are nowhere the local static variable is cleared but didn't reach to 5 it's really incredible phenomenon.

Are there someone who experienced like this?

If you know the cause and how to fix it tell me about it.

as reference I'll attach the project.

Thanks,

 

// 10 Hz systick driver

static void deci_sec_systick_Driver()

{

static uint32_t vigesimal_systick_count = 0;

static uint32_t demi_sec_systick_count = 0;

// 5 Hz systick driver

vigesimal_systick_count += 1;

if(vigesimal_systick_count >= 2)

{

vigesimal_sec_systick_Driver();

vigesimal_systick_count = 0;

}

// 2 Hz systick driver

demi_sec_systick_count += 1;

if(demi_sec_systick_count >= 5)

{

demi_sec_systick_Driver();

demi_sec_systick_count = 0;

}

}

 

 

    This topic has been closed for replies.
    Best answer by Karl Yamashita

    @curiae wrote:

    After your suggestion, I changed hiwdg.Init.Prescaler up to MAX and surely 1sec systick works.

    But even at MAX Prescaler, reset itself seemed to occur.

    Firstly I thought IWDG generates reset if loop takes time than time-up value by IWDG but real I felt.behavior seems to be different.

    I guess reset by IWDG inevitably occurs is it right?

    And show me how to avoid IWDG reset when IWDG is used.

    Thanks,.


    You need to reset the IWDG in your main while loop

    while(1)
    {
    	// Reset WDT
    	HAL_IWDG_Refresh(&hiwdg);
    
    // other code
    }

    And you have to make sure your other code doesn't take up more time before it can loop back to reset the IWDG

     

    2 replies

    curiaeAuthor
    Explorer II
    December 13, 2024

    Hello,

    Let me add more information.

    After the unforeseen phenomenon, I predicted MCU reset is done within 500msec.

    I added an increment counter in the msec systick driver and as I expected the counter never reached to 500.

    So I'm convinced that Systick occurs MCU reset within 500 msec.

    If the systick generate MCU reset, how should I stop it?

    Please show me how to solve it.

    Thanks,

     

    Graduate
    December 13, 2024

    The SysTick surely does not generate reset. Some other stuff does. Isolate the problem by deactivating the  peripherals. The problem probably lies in some runaway ISR. Deactivate the watchdog if activated.

    Explorer
    December 13, 2024

    > Deactivate the watchdog if activated.

    Yes. Besides of power supply issues, only watchdogs reset the core.

    Technical Moderator
    December 13, 2024

    Hello @curiae ,

    Please in next time kindly use </> button to paste your code. Please refer to How to insert source code.

    I'm editing your post.

    Thank you for your understanding.