Skip to main content
AKh.1
Associate II
November 29, 2020
Question

Pwm mode stm32

  • November 29, 2020
  • 7 replies
  • 1951 views

How can I use PWM output pulse in my program?

Normally the PWM mode for instance for TIM1 will be generated on pin PA8, but I want to use the PWM signal internally in my code. How is it applicable?

This topic has been closed for replies.

7 replies

TDK
November 29, 2020

There are hundreds of STM32 chips. Which one?

You could use the timer period elapsed interrupt to do something within the code at a specified duration. In HAL, this can be done by implementing the HAL_TIM_PeriodElapsedCallback function.

"If you feel a post has answered your question, please click ""Accept as Solution""."
AKh.1
AKh.1Author
Associate II
December 5, 2020

Thank you so much for your reply.

Actually, I want to make a pulse with 250 ms high and 4s low. I made this pulse by using PWM but I dont know how to apply this "on and off" action on a variable and see it's effect on a specific GPIO instead of the default PWM output pin.

would be thankfuI​ if you share your ideas.

Piranha
Principal III
December 5, 2020

You cannot output timer signal on any pin, only the dedicated ones, of which there can be several options for a single channel. But if you want to use the generated times in software, then enable the update and/or compare interrupts in TIM_DIER register. And of course implement the corresponding ISR.

Vangelis Fortounas
Associate II
December 6, 2020

Hello

You can use the Update flag and Capture Compare Interrupt flag to use it internally to your code.

You can use also the interrupts for above flagσ

HAL contains the apropriate functions , macros and callbacks to do your job.

AKh.1
AKh.1Author
Associate II
December 6, 2020

Thank you vangelis.

Is it possible for you to write an example code using what you mentioned, pleases?

Thanks a million;

Piranha
Principal III
December 6, 2020

The internet is literary full of such examples.