2025-08-27 11:39 AM - last edited on 2025-08-28 2:46 AM by Amel NASRI
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
2025-08-27 3:23 PM
> 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.
2025-08-27 3:57 PM
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.
2025-08-28 1:01 AM - edited 2025-08-28 1:01 AM
Maybe a sketch of waveforms you want to achieve (output vs. input) could bring more light.
JW
2025-08-28 6:58 AM
Input Signal:
As you can see in the attached photo, the high state lasts 146us and the low state lasts 114u, and they should be equal.
2025-08-28 7:52 AM
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
2025-08-28 1:05 PM
There was a typo, it was supposed to be 1ms. From analysis, it looks like a signal consisting of a preamble of the synchronization word 0b111000 and the rest looks like manchester.
regards
2025-08-29 3:29 AM
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
2025-08-31 10:17 PM
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
2025-08-31 11:06 PM
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