STM32 Difference between Max interface clock and max timer clock - timer

I am using TIM1 on a H743ZI with 3 PWM channels.
I am trying to maximize the PWM resolution so I need to maximize the clock speed on TIM1.
the datasheet (screenshot below) gives 120MHz and 240MHz values for Max interface clock and Max timer clock.
What is the difference between the 2? I have the clocks setup as shown below, with 120MHz on APB2's peripheral clocks and 240MHz on APB2's Timer clocks.
I need a 24KHz frequency on the PWM channels so I set the ARR to 4999 which confirms the H743 is using the 120MHz value (and not the 240MHz one).
Is it because the I am using the timer in a hardware related manner - hence the "peripheral clock"?
of course, my follow up question, would be whether or not I could use the HRTIM instead?

Every timer consists of the counter which is fed by the timer clock and the control unit which is responsible for interfacing with the bus (core and another peripherals) which is fed by the interface clock.
More general all peripherals have a digital control part. This part is fed by the bus clock (the bus the particular peripheral is connected to). Many peripherals have more than one clock - for example ADC where the digital controller form the bus clock, and the analogue part fed from another clock source.

Related

What's the difference between APB1 peripheral clocks and APB1 Timer clocks in STM32?

Thank you for visiting my question.
I'm now trying to set up my STM32 device(NUCLEO STM32F401RE) to use timer and found that which clock the timer is working based on.
TIM2 is used so the clock signal should come from APB1.
Bus info
Below is my clock configuration.
Clock config
Here I have some questions. There are two clocks: APB1 peripheral clocks and APB1 Timer clocks.
What's the difference of these? Why are these separated, one is prescaled and the other is not?
On which clock the TIM2 works based after all?
It can be the difference between peripheral's configuration registers, that you access via APB1 with APB1 speed, and the clock timer, that ticks the counter of the clock.
Here is a clock tree section of RCC peripheral of STM32F401 reference manual RM0368, page 94:
Page 95:
And right after that is yet another interesting piece:
The last piece talks about configuration that isn't often mentioned, I've usually seen it by default, but hey, you have quite a bit a flexibility here.
In default scenario, if APB clock is not equal to system clock (i.e. APB prescaler is greater than 1), then Timer counter clocks are doubled.
So if my MCU runs at 48MHz and APB1 is also 48MHz, I access timer's registers at 48MHz, and the timer (at timer prescaler=1) ticks at 48MHz.
But if my MCU runs at 84MHz, but my APB1 runs at 42MHz, then I access timer's registers at 42MHz, but the timer (at timer prescaler=1) ticks at 84MHz.
Very often, when your MCU is at max system clock frequency, APB bus will have a prescaler greater than one, meaning the timers' counters run at double their bus speed.

stm32f446 When using dma to control PWM duty cycle, the PWM wave has abnormal waveform

MCU: f446rct6
System: freertos
Library: hal
Program logic:
Initialize the timer to output the PWM wave and initialize the DMA and connect to the Capture/Compare register
Start the timer
When data needs to be updated, start a dma transmission
Phenomenon: There is no problem with the frequency and duty cycle of the PWM wave, but a strange triangular waveform often appears in the first or second waveform of DMA transmission.
Ask everyone, do you encounter similar waveforms when using pwm? Please give me a hint to locate this problem, thank you
Potential causes include:
You're switching the pin to DAC mode (if your MCU has a DAC) and driving it with an increasing value.
The pin is disabled, and what you see is the drift of the voltage on the pin's and probe's combined capacitance.
You're inadvertently switching the PWM to a very high frequency and the scope is set to too low sample rate. Make sure you set the scope to highest possible sample rate / sample depth / sampling length, and decrease the horizontal scale (i.e. decrease the time per division by 2x or 5x).

STM32 TIM1 Internal Clock (CK_INT)

According to the datasheet snippet above, TIM1 can be clocked by the internal clock (CK_INT). What is this internal clock? I have a feeling that it's just the APB1 Timer Clocks (Mhz) in the below clock tree, but is that correct? Why is it called an internal clock in the datasheet?
From the 48MHz limit I'm assuming it's an STM32F0 series MCU.
The clock tree is documented a few chapters back, in Reset and clock control (RCC) / Clocks.
Why is it called an internal clock in the datasheet?
Because it is, well... internal. As opposed to an external clock, which is coming from an external source.

Changing clock frequency on STM32 without impacting peripherals?

I'm a bit lost with STM32L486 clock management.
I want to change the clock frequency at run-time. Typically I want to be in Low-Power Run/Sleep mode most of the time, and at full frequency the rest of the time.
I know how to set up SysClk either at 80MHz using PLL or at 1MHz using MSI for example.
However the problem is that changing Sysclk is messing up most peripherals setup. For example the USART is not working anymore if I change the clock.
Is it a common practice to do that ( changing the frequency at runtime ) ?
The peripherals I need to use are: LPTIM ( no problem since they can be clocked independantly from SysClk ), ADC, AES accelerator, USART, TIM, SPI.
On STM32L4xx it is not so hard, if you look on "Clock tree" figure in datasheet, many peripherals which are clock dependent (USART, LPTIM, I2C, ..) can be driven with other clock sources than BUS clock, there is also possible to use LSE or internal HSI.
Although internal HSI is not crystal controlled is from my experience enough accurate for UART, also in bigger range of temperatures, but you can tune frequency of this oscillator by comparing its frequency with an external and more accurate clock during runtime, or use auto-buadrate detection.

STM32 - How to trigger interrupt after a certain PWM ON time?

I'm new to ARM MCUs (STM32F411), and I have been trying to find my way around the peripherals using STM's HAL library and STM32Cube.
I've already configured my board in order to use some peripherals:
Timer 2 for running an interrupt with a certain frequency
Timer 3 for running PWMs on 3 channels of it.
ADC with 4 channels, into DMA mode, for reading some analog input.
Let us suppose, now, that the PWM's whole period is 100 ms and its duty cycle is 50% (50 ms PWM on and 50 ms PWM off).
I would like to trigger an interrupt after a certain time of the PWM on level, let us say 50% of it.
Hence, I would like to run an interrupt at 25 ms in order to use the ADC for sampling it's analog inputs.
Do you have any suggestion on how could I implement such a kind of interrupt?
Thank you in advance for your help!
Since the ADC of the STM32F411 is used in Regular mode (not Injected mode) and only three channels out of four are used to generate PWM on Timer 3, the fourth channel can be used to trigger the ADC.
Hence Timer 3 is configured as follows:
CH1 used for Output Compare mode 0 (TIM3->CCMR1.OC1M = 0)
CH2, CH3, CH4 used for PWM outputs
Therefore TIM3->CCR1 is loaded to a value that gives 25% of duty, then it will generate TIM3_CH1 events that can be used to trigger ADC start-of-conversion at 25% of your TIM3 timebase.

Resources