Skip to main content
Skada.3
Associate III
July 12, 2022
Solved

How to get fixed number of pulses with PWM mode on STM32f205xx

Using timer 1 for PWM cycle generationand getting proper PWM pulses using Standarad peripheral library.

My requirement is to get fixed number of PWM pulses on each channel of Timer 1

For this I have used one pulse mode. using HAL library able to get desired output but with standarad peripheral library not able to get pulses.

I have attached source file for code.

Please suggest what step is missing in the code.

This topic has been closed for replies.
Skada.3
Skada.3Best answer
Associate III
July 13, 2022

Hi

got an expected output with the same main.c file.

Thanks

8 replies

waclawek.jan
Super User
July 12, 2022

Read out and check/compare content of TIM1 and relevant GPIO registers.

TIM1 is Advanced Timer, so it needs to have TIM1_BDTR.MOE set.

JW

Skada.3
Skada.3Author
Associate III
July 12, 2022

Hi jan,

Thank you for your response.

In code TIM1_BDTR.MOE is already set using TIM_CtrlPWMOutputs(TIM1, ENABLE)

without enabling I will not get PWM cycle, I am facing issue to get fixed number of pulses on channel.

waclawek.jan
Super User
July 12, 2022

> I am facing issue to get fixed number of pulses on channel.

What does this mean? Do you see less or more pulses than you expect?

You are supposed to set TIMx_BDTR.MOE *before* you enable the counter.

Read out and check/post content of TIM1 registers.

JW

Skada.3
Skada.3Author
Associate III
July 12, 2022

After PWM enable then it gives continous output. but for example I required only 100 pulses on channel 1, this fixed output I am not able to get.

This is possible using RCR register and getting output using HAL library but with standarad peripheral it fails.

waclawek.jan
Super User
July 12, 2022

Read out and check/post content of TIM1 registers.

JW

Skada.3
Skada.3Author
Associate III
July 12, 2022

Hi JW,

Didn't get your suggestion.

waclawek.jan
Super User
July 12, 2022

In debugger, stop execution just before enabling the timer, and read out the TIM1 registers.

If you don't use debugger, then transmit/print/output in whatever method the content of TIM1 registers.

JW

Skada.3
Skada.3AuthorBest answer
Associate III
July 13, 2022

Hi

got an expected output with the same main.c file.

Thanks