cancel
Showing results for 
Search instead for 
Did you mean: 

STM32G474 – TIM_ETR to tim_trgo

EThom.3
Senior II

Hello,

I may have made a *** of myself on a prototype, and need a bit of help with a work-around. I have an external clock signal on TIM20_ETR (PG5) for some pulse counting stuff. This works.

However, I intended to use the same clock signal to trigger TIM2 one-pulse (and later TIM5 one-pulse as well), and thought that I could use tim_trgo from TIM20 to clock them. My problem is that, now I have the prototype PCBs in hand, I cannot figure out how to pass the TIM20_ETR clock signal on to tim_trgo – or if it is even possible.

My best guess is that I can set TIM20_CR2 MMS to 0010 (Update), and set PSC and ARR to 0. I have already set TIM20_SMCR to use TIM20_ETR as the trigger source. If I understand the timer functionality correctly, this should give me an update event for each clock pulse.

This work-around will make me lose the TIM20 counter feature, but if I can just get the external trigger signal out on tim_trgo, then I can use that to clock TIM1 or TIM8, which can then be used for the actual counting.

I have also wondered if I can instead make the PG5 input generate an event, and use that for something. However, I have no experience with GPIO-generated events, and it doesn't look like TIM2 and TIM5 can be triggered by such events anyway.

Using interrupts to start the TIM2 one-pulse is out of the question, as this will certainly create unwanted jitter.

What do you think of my work-around? Doable or rubbish?

Are there better solutions that I just haven't thought of? Any help will be greatly appreciated.

1 REPLY 1

Your method, which will take away your TIM20, should work (with ARR=1). Alternatively, you can use a similar procedure, where you set TIM20 to one-pulse mode with ARR=1, triggered from the ETR pin, and set TRGO to "Enable" (trigger) event. It should work equivalently to what you suggested (using the "update" event).

But be careful, ARR must not be 0, in my opinion. So this solution will reduce the maximum frequency you can bring to ETR. But that shouldn't be such a problem.

I can't think of any other method to internally route PG5 to other timers.