cancel
Showing results for 
Search instead for 
Did you mean: 

Timer1 - Alternate Function - Pin state if deinitialized?

hof2
Associate II
Posted on October 16, 2015 at 14:21

Hi Guys,

I am working on a project, where I need to output a PWM for a certain period of time and then stop and deinitialize the PWM.

In my case, I use timer 1 as my PWM output. I can initialize, start, stop, and deinitialize the timer, and therefore the PWM.

Now my problem is that the signal is low active and every time the timer is not initialized, the pin is set to low.

I set the GPIO function here:

1.
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
2.
GPIO_InitStruct.Pull = GPIO_PULLUP;
3.
GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
4.
GPIO_InitStruct.Alternate = GPIO_AF1_TIM1;
5.
6.
GPIO_InitStruct.Pin = GPIO_PIN_9;
7.
HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);

In my understanding this should pull up the pin. On the other hand I seem to remember it is only pulled up, when the AF output is in reset? I am not sure if this is my mistake.

Has anybody an idea how to get the output pulled up whithout reconfiguring the GPIO pin?

Any help is highly appriciated and I thank you for your time.

eimer

#timer-gpio
2 REPLIES 2
ferrarofcf
Associate II
Posted on October 16, 2015 at 16:57

PWM pin is an output push-pull.

Set Analog mode.
Posted on October 16, 2015 at 20:06

There's no such thing as ''

deinitialize the PWM'' - you might have called a ''library'' function with this name, but you then should find out what does that function do.

Once a GPIO pin is set to AF to one of the compare-capture channels of a timer, the timer takes over the pin's control and it can basically do four things:

- it can use it as an input, if the respective channel is set to capture (TIMx_CCMRy.CCzS > 0, taking into account the ''take neighbouring pin'' function if set to 0b10). As far as output level is concerned, this is the same as the ''undriven'' variant below

- it can leave it undriven, if the respective channel is set to compare

(TIMx_CCMRy.CCzS

== 0) but not enabled (TIMx_CCER.CCzE = 0). In the advanced timers (TIM1, TIM8, TIM20) there is one more and relatively complex output control layer (see TIMx_BDTR) so in those timers there are other ways to leave the output undriven, its behaviour in this respect is described in a table in the TIMx_CCER sub-chapter.

- it can drive it actively up or low, depending on the current state of polarity setting (TIMx_CCER.CCzE) and current state of internal OCzREF signal which depends on the compare mode (TIMx_CCMRy.OCxM) and in PWM modes the mutual relationship of counter and compare register - again, the advanced timer adds that complex output layer to this. Note, that there are also two modes to set the output permanenly ''active'' or ''inactive'' level (both are driven to the pin, but their actual logic level depends on the setting of polarity, see above).

Now the GPIO, once set to AF, it still has two more things to say into the output level: it can be set to push-pull/open drain (GPIOx_OTYPER), and there are pullups/pulldowns (GPIOx_PUPDR) which can be enabled or disabled (t

his all provided you are not using an 'F1xx which has slightly different architecture of GPIO (you did not tell us which STM32 model are you using)

).

So, if the timer does not drive the pin, it can either float, or be weakly pulled down, or up (or both pullup or pulldown can be activated, but this does not make much sense).

If the timer does drive the pin and GPIO is set to push-pull, then it will output a strong 0 or strong 1, depending on the current state of timer (and, as mentioned above, it could be set to one of the levels permanently by changing the compare mode).

It the timer does drive the pin and GPIO is set to open drain, when the timer drives it to 0, it is a strong 0; and when it drives to 1, it is the same as in the undriven case (i.e. its state depends on the pullups/pulldowns).

Simple and easy, isn't it  😉

JW