2024-08-16 06:26 AM
Hi,
I am using a STM32L452RET6 (without any RTOS) and I would like to use the same timer for both:
- drive a sounder on PWM at 4KHz (but ideally also other changing frequencies above and below 1ms time period so it can make more elaborate sounds which)
- generate and also 1ms interrupt to check other tasks.
What would be the best way to configure and use the micro to implement that?
Thank you as always
Solved! Go to Solution.
2024-08-17 12:14 AM
The systick is used for system jobs, like hal-delay, and you should not touch or modify it.
But you can use the 1ms interrupt and do something there.
The timer for this system clock is part of the ARM core, so read in arm documentation about the core and it's modules, like debug unit or system timer.
You cannot use it for any pwm generation or so, it's just a timer for the system (in windows or Linux system you also have this,1ms system clock...), so use any timer of the many you have available, to do the modulated frequency generator
2024-08-16 09:46 AM
Timers have a single counter register. You can't create PWMs or callbacks at independent frequencies on the same timer.
The chips typically have plenty of timers, should be able to use two different ones here, or use the SysTick interrupt to check other tasks.
2024-08-16 10:15 AM
As writed TDK why not second timer? But for your question yes you can create 1ms on one channel interrupt and some other freq on other , but some condition here...
2024-08-16 10:30 AM
So why not just use the systick (1ms is standard) for the things to do every ms and use a / any timer to make the 2....7 kHz sounds?
2024-08-16 03:46 PM
Thank you all, rather obvious but being new to STM32 I did not think of that.
I can see the SysTick_Handler(void) has been generated by CubeMx. Could you please help/explain the following:
- I assume SysTick is the same as (i.e. the period of) the SysClk which in the diagram below (highlighted in red) is currently set to 72MHz, is that correct?
- That SysClk goes (only) to "To Power" and could not find any information as to what that is, so I don't know if changing that value changes other things in my code or generally in the micro configuration. What is that "To Power"?
- how do I set its time period (for example to 1ms) at runtime?
Thank you
2024-08-17 12:14 AM
The systick is used for system jobs, like hal-delay, and you should not touch or modify it.
But you can use the 1ms interrupt and do something there.
The timer for this system clock is part of the ARM core, so read in arm documentation about the core and it's modules, like debug unit or system timer.
You cannot use it for any pwm generation or so, it's just a timer for the system (in windows or Linux system you also have this,1ms system clock...), so use any timer of the many you have available, to do the modulated frequency generator
2024-08-17 01:54 AM
Your red mark is SYSCLK not systick. In normal HAL code set systick interrupt to every 1ms, not recommend to change is used for timeouts etc. But in handler you can place quick code you require run every 1ms.
For example toggle gpio and create some low speed PWM or blinky ...
For explain SYSTICK is somethink like hw TIM0 capable only create interrupt based on set tick count...
2024-08-17 10:08 AM
Thank you both.