2017-11-07 03:53 AM
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.
Fig. 1: Simulink Model Sample Time
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!
#stm32-mat/target-matlab #cubemx #simulink2017-11-07 04:50 AM
Hello,
I recommend you to follow the instructions in the attached document
'STM32 MAT-TARGET HandsOn'it may help you on your clock configuration.
Best Regards
Imen
________________ Attachments : STM32_MAT-TARGET_HandsOn_v1_0.pdf : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006HyJE&d=%2Fa%2F0X0000000b68%2F5lPQPgBcPFvQcKguX2kJeCAZ0GoLWquukNOxu7DUDI0&asPdf=false2017-11-07 06:26 AM
Hi Imen,
thank you for your reply!
I went through this instruction. Although in the section 'Application Code Generation' of the HandsOn the clock configuration is introduced, there are still no information about how to set the sample time in Simulink model with regard to the clock configuration of MCU.
In that section, we don't know to which value the sample time of the introduced simulink model is set to be. So I would recommend that it would be better if you could upload that simulink demo project file.
As for my project, actually, it needs a relativly high sampling frequency for my motor control algorithm. So I think it's necessery to identify, how high the sampling frequency of the simulink model can I set if the MCU clock HCLK is set to its maximal value?
However, in this test model, the LED doesn't work when fs = 10 MHz.
Best Regards
XJ Q