AnsweredAssumed Answered

Simulink model sample time vs. STM32 MCU clock configuration

Question asked by XJ Q on Nov 7, 2017
Latest reply on Nov 7, 2017 by XJ Q
Hello everyone,
In this project I just want to use the user button to toggle a LED on my board. The model is designed by using Simulink and initialization codes are generated by STM32CubeMX.
During the experiment, I was facing to a big problem: I don't know how to correctly set the sample time of Simulink model Ts and how to correctly make the clock configuration in STM32CubeMX.
simulink model sample time
Fig. 1: Simulink Model Sample Time
clock configuration
Fig. 2: Clock Configuration in STM32CubeMX
Here, I want to describe my problem in detail:
1) When the sample time of Simulink model is set to Ts = 1E-5 (fs = 0.1 MHz) and MCU HCLK is only set to HCLK = 1 MHz (all prescalers after HCLK are not modified), the LED can be toggled while pressing the user button.
2) When Ts = 1E-6 (fs = 1MHz) and HCLK = 1 MHz, the LED can't be toggled.
3) When Ts = 1E-6 (fs = 1MHz) and HCLK = 168 MHz (max. Value), the LED can be toggled.
4) When Ts = 1E-7 (fs = 10 MHz) and HCLK = 168 MHz (max. Value), the LED can't be toggled any more.
So, according to what I've done, there must be some relationship betwenn simulink model sample time Ts and MCU clock frequency HCLK. But I am not able to discover them.
Is there anyone who can tell me how to correctly set the model sample time Ts and configure the MCU clock frequency HCLK?
Thanks!

Outcomes