cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F103 GPIO config for alternate function input capture TIM1

FFont.9
Associate

Hi all,

I'm a newbie to STM32 and have been struggling with input capture for advanced timer TIM1 on the STM32F103.

Documentation shows that GPIO A8 can be used as an input for the timer input capture. This is one of the alternate functions for this pin.

I've followed the instructions given in the reference manual for the configuration of the timer for input capture. However, it did not work as the value of the capture/compare register was always 0.

After a lot of trial-and-error and searching I found that the problem was not so much with the configuration of the timer, but rather with the configuration of the GPIO pin. I had assumed that as I was using A8 as an input it had to be configured as an input (floating). Now the thing is that alternate functions are only selectable for outputs. When I configured A8 as an alternate function output (I chose open drain to play as safe as possible), the input capture started working and I got sensible values from the capture register.

It feels akward and confusing to configure a pin as alternate function output, while I'm actually using it as an input. I'm also a bit worried for hardware conflicts​ while driving this pin from an external peripheral.

So I have a few questions on this​ issue:

Is this really the way to configure this IO pin for input capture on the timer?

Is the output driver stage in this configuration disconnected from the pin​?

Is this way of configuring an alternate function as output to get it to work as input only associated with the timer? I've used UART_RX before as an alternate function input and there the GPIO configuration was input mode (floating), worked fine​....

I hope someone can shed some light on this subject as it confuses me quit a bit!

Thanks,

Filip​

2 REPLIES 2

TIM1 is odd in that you need to "Enable PWM Outputs" for the Input to work. TIM1 and TIM8 are Advanced Timers.

The F1 part is a decade old, I've moved on to new parts with better pin level muxing options, so not sure I want to dwell on the functionality too much.

I would have expected configuring in "Input Floating" would have worked as the TIM should be taking signal from the output of the Input Schmitt Trigger

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
FFont.9
Associate

Hi Clive,

Thanks for your response.

At a fresh start on moday morning I noticed a few errors in my code for setting up the timer and the capture register. Did some more testing and now the input capture PWM set-up works with GPIO A8 configred as a floating input. Not sure what specific error in my code caused the problem.