Skip to main content
Associate III
August 27, 2025
Question

STM32F303 TIM1 to TIM15 repeater

  • August 27, 2025
  • 4 replies
  • 591 views

Hi,

On the STM32F303, the TIM1 timer is running in input capture, slave mode – reset, with the trigger source set to TI1FP1 (CH1 direct rising, CH2 indirect falling) to record the incoming stream. It operates with DMA in circular mode using two buffers (separately storing the duration of the high and low states).

I want to further develop the project, and I have two use cases:

1) I want to forward this signal unchanged with minimal (or no) delay using TIM15.

2) In the DMA interrupts TIM_DMACaptureHalfCplt and TIM_DMACaptureCplt, I want to modify the original waveform and then output it through TIM15.

In general, I want the processor to act like a “repeater.”
Any hints would be greatly appreciated — maybe the solution is trivial, but advanced timers are still a bit of a mystery to me ;)

 

regards

 

4 replies

TDK
Super User
August 27, 2025

> 1) I want to forward this signal unchanged with minimal (or no) delay using TIM15.

To my knowledge, there's no way to output the same channel that is being input without CPU intervention. Some chips have op-amps built in which could to this on certain pins. (op-amp follower). You could use an EXTI interrupt to do this with relatively low delay (order of microseconds).

If it's a PWM signal, you can measure it and then output the same PWM signal. Will have some delay.

> 2) In the DMA interrupts TIM_DMACaptureHalfCplt and TIM_DMACaptureCplt, I want to modify the original waveform and then output it through TIM15.

Might be possible depending on what modifications in particular you are making and the allowable waveform types coming in. For example, a steady PWM signal could be modified, but an arbitrary waveform not as much. You could do ADC -> buffer -> modify -> DAC.

"If you feel a post has answered your question, please click ""Accept as Solution""."
PKurz.1Author
Associate III
August 27, 2025

The processed signal has a data rate of about 8 kbps, and the delay can be around 10 µs.
The need for modification comes from the fact that the ratio of the high state to the low state is 60:40 instead of 50:50.

waclawek.jan
Super User
August 28, 2025

Maybe a sketch of waveforms you want to achieve (output vs. input) could bring more light.

JW

PKurz.1Author
Associate III
August 28, 2025

Input Signal:
PKurz1_0-1756389281224.png

As you can see in the attached photo, the high state lasts 146us and the low state lasts 114u, and they should be equal.

waclawek.jan
Super User
August 28, 2025

Okay, and what about the other pulses? There are at least two other pulse lengths there. How much variability is to be expected there?

Also, according to your description above, you want that event to be replayed with both the high and low lasting half of the original duration of both. For that, you have to wait until the end of the low state, to be able to determine the sum and half of it, and only after that the replay may happen. That's a delay of some 250us, rather than what you'd stipulated above, 10us.

So, try to develop an algorithm first, which would fulfill your requirements, theoretically (and perhaps simulating at a PC); and only after that try to implement that on the microcontroller.

JW

waclawek.jan
Super User
August 29, 2025

So then, you can proceed as you've planned: "receive" the edges into a buffer, process in the DMA HT/TC interrupts, and "transmit" using a second DMA.

JW

PKurz.1Author
Associate III
September 1, 2025

Receiving and processing the signal was a textbook problem, but in which mode is it best to use the timer for transmitting it further?

 

PK

waclawek.jan
Super User
September 1, 2025

I would leave the counter free running up to its maximum i.e. roll over at 0xFFFF, set one of its channel to output compare and Toggle mode, calculate ahead the points of toggling and feed them using DMA triggered by that very channel. Note, that in this case you want to avoid that channel's TIMx_CCRx to be preloaded.

JW