2021-07-26 07:47 AM
On F4 (and also other families) The TIM2_ETR and TIM2_CH1 are both on the same pins.
The pins are PA0, PA5 and PA15.
How can I configure the timer/gpio to get ETR on PA5 and CH1 on PA15 ?
The alternate function numbers are the same for ETR and CH1...
I need ETR and the unique features of CH1 and CH2.
An ST example uses this code to initialize the ETR GPIO PA0:
GPIO_InitStruct.Pin = GPIO_PIN_0;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
GPIO_InitStruct.Alternate = GPIO_AF1_TIM2;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
How does this code specify that this is for ETR and not CH1?
Solved! Go to Solution.
2021-07-26 01:46 PM
I've just played a bit with a 'F411 and it's as I've said above.
You can even do such a bizarre thing as to set External clock mode 2 i.e. clock the timer from ETR, set CH1 to Compare Output, and by toggling the CH1's CCMR1.OC1M between Forced Active and Forced Inactive the given pin (I've tried PA0 but it will be the same with any other pin) is toggling and clocking the same timer through ETR on the same pin.
JW
2021-07-26 12:39 PM
> How can I configure the timer/gpio to get ETR on PA5 and CH1 on PA15 ?
IMO you can't. IMO the CH1 input and ETR input to the TIM module are simply tied together.
I know it's a PITA.
Try to bring in CH1 indirectly, i.e. through a different timer's CH1->TRGO->TIM2 TRGI->TRC.
> An ST example... How does this code specify that this is for ETR and not CH1?
Which example exactly? I'd bet there's no CH1 used there.
JW
2021-07-26 01:46 PM
I've just played a bit with a 'F411 and it's as I've said above.
You can even do such a bizarre thing as to set External clock mode 2 i.e. clock the timer from ETR, set CH1 to Compare Output, and by toggling the CH1's CCMR1.OC1M between Forced Active and Forced Inactive the given pin (I've tried PA0 but it will be the same with any other pin) is toggling and clocking the same timer through ETR on the same pin.
JW
2021-07-26 02:45 PM
That's what I feared ... Thank you for your feedback.
It's a shame to have 2 functionalities, 3 pins and not being able to use them.
What a bad idea to have CH1 and ETR tied together. I would have preferred CH4 and ETR, because CH1 and CH2 have specific functionalities ...
For me this is a design mistake.
These timers are very complicated, but the basic functionalities are deficient!
In the ST example the input channel is CH2. They dodged the problem without saying why CH1 couldn't be used.
Thanks for your intermediate timer trick, I'm going to scratch my head again.
2021-07-26 03:00 PM
If you want to share details of your application/requirements, we might perhaps brainstorm this further.
> Thanks for your intermediate timer trick
This has very limited utility, as TRGO transfers only the edges.
I wonder, why do you need CH1 and CH2 AND ETR.
ETR in any its capability (External clock, or OCRef clear) together with Encoder mode does not make much sense to me. Anything other IMO can be pulled out using CH2 and any other channel.
Did I miss something in this list?
JW
2021-07-26 03:55 PM
> I need ETR and the unique features of CH1 and CH2.
Just curious, what unique features are you needing?
2021-07-26 04:13 PM
It is mainly a matter of pin and timer availibility on small packages.
I'm trying to avoid an external multiplexer by trying multiple pin/channel/timer combinations. As usual!
Your link is very informative. I was not aware of CH5 / CH6. Without GPIO, TRGO and interrupt I wonder what is their use.
This list shows the restrictions with which we have to cope... I am not familiar enough to know if they are all there (never used a motor and the features of TIM1 and TIM8). And for me it's hard to read and assimilate a thousand pages with each new MCU family.
2021-07-27 12:31 AM
CH5/CH6 started to appear on Advanced Timers in 'F3. Quoting from RM:
Channel 5 and 6 are only available inside the
microcontroller (for instance, for compound waveform generation or for ADC triggering).
The documentation does not reflect the complexity of the modules in STM32. Each and every module is much more complex than an entire 8-bit microcontroller used to be some 20-30 years ago, yet all we have is a hasty description in the RM and sometimes one or two sketchy AN. For timers, there's AN4013 and AN4776, and maybe there are some motor-oriented ones (I don't do motors/power supplies either), but I believe timers alone would deserve one or more dozens of appnotes.
But it is what it is, we have to live with it.
JW
2021-07-27 02:52 AM
The need is to measure several frequencies and pulse widths. This is from old remote sensors which generate a frequency, but which can drift. Each group of sensors therefore sends a reference frequency from which their measurements are derived (the wonders of analog of the old days).
The first idea was to use the reference frequency as a clock to measure the other frequencies with a classic structure (gated frequency meter): hence the usefulness of ETR and the other channels at the same time.
Fortunately the variations are slow and all frequencies can be measured with the internal clock of the timers, and then calculated (so DMA and all the stuff).
Using the STM32G071CB (imposed by supply restrictions) TIM2 offers 11 pins. And with the internal interconnections (TI1FP2 etc) each input allows to measure a frequency or a pulse.
No more ETR. But with this discussion I deepened my thought and I would have learned things.
Thank you.
2021-07-27 03:10 AM
> The first idea was to use the reference frequency as a clock to measure the other frequencies with a classic structure (gated frequency meter): hence the usefulness of ETR > and the other channels at the same time.
Oh, I see - so you would use ETR as clock source, and you wanted to use all other CH1/CH2 pins to multiplex several inputs to serve as gate. Smart.
And yes it's probably better to resort to some of the other models which don't impose such limitation - and which can be bought, too... :)
JW