cancel
Showing results for 
Search instead for 
Did you mean: 

PWM TIM3

Ala1980
Associate II

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????

6 REPLIES 6
Ala1980
Associate II

The complete code is attached in the file

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.

Thanks for the reply.

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

Am I really using GPIO? I am using only the timer, and I can identify the pins for each timer/channel on the board, and I am connecting my external LEDs to those pins.

Is this not enough?

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

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