Skip to main content
Ala1980
Associate III
November 17, 2019
Question

PWM TIM3

Hi,

I am using STM32 F303 VCT6 and want to output PWM signal on TIM3, TIM2.

I followed the instructions in some video to build the code using STM32CubeMX.

I set the Clock Source for both timers to 'Internal Clock'.

I set all four channels for bother timers to 'PWM Generation Chx'

I set the Parameter Settings as follows:

Prescaler: 16

Counter Period (AutoReload Register): 100

Pulse: different values to each channel from 25 to 100

I created the project and then started the timers:

HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_1); // for each channel and for both timers.

The question is, what is still missing? I dont get any output on the timers????

This topic has been closed for replies.

6 replies

Ala1980
Ala1980Author
Associate III
November 17, 2019

The complete code is attached in the file

waclawek.jan
Super User
November 17, 2019

You may perhaps also need to set the respective pins in GPIO: in MODER, set respective bits to AF for given pins, and in AFR[] set the respective AF.

If in doubts, read out the respective timers and GPIO registers' content and check.

I don't Cube.

JW

PS. Please change your username to a normal nick.

Ala1980
Ala1980Author
Associate III
November 17, 2019

Thanks for the reply.

As I am beginner here, can you please write more details?

waclawek.jan
Super User
November 17, 2019

All pins are controlled by the GPIO module. In that, you have to set the pin's mode, and if the mode is not a plain input or output or analog, you set it as "Alternate Function", and then you have to chose which particular alternate function for that pin you want to use (see the pin assignment table in the datasheet for your STM32).

Read the GPIO chapter in the Reference Manual (RM) for your STM32.

JW

Ala1980
Ala1980Author
Associate III
November 17, 2019

I see in the datasheet that the PIN2 PE2 has three alternate functions:

TRACECK, TIM3_CH1, G7_IO1.

Does this mean that I should explicitly set the alternate function TIM3_CH1 as active?

According to the RM, the registers GPIOx_AFRL , GPIOx_AFRH are responsible for changing alternate functions, but how can write in those registers? Which function should I call for this purpose? (Knowing that I am using HAL).

Sorry for my primitive questions

Regards