---
title: "Discussion on \"Generating PWM pulses on the STM32F407 for Servo Motor Control using Bare-Metal Programming\" | Hashnode"
description: "Discussion on \"Generating PWM pulses on the STM32F407 for Servo Motor Control using Bare-Metal Programming\". Introduction\nHello!!😃 Today we will discuss controlling a servo motor with PWM pulses, that are generated using the general-purpose timers available on the STM32F407 Discovery kit. As always we will be doing this with Bare-Metal programming. We will..."
url: "https://hashnode.com/posts/generating-pwm-pulses-on-the-stm32f407-for-servo-motor-control-using-bare-metal-programming/6149657b699fe76cd34857fb"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [Generating PWM pulses on the STM32F407 for Servo Motor Control using Bare-Metal Programming](https://ruturajn.hashnode.dev/generating-pwm-pulses-on-the-stm32f407-for-servo-motor-control-using-bare-metal-programming?utm_source=hashnode&utm_medium=feed)

Introduction Hello!!😃 Today we will discuss controlling a servo motor with PWM pulses, that are generated using the general-purpose timers available on the STM32F407 Discovery kit. As always we will be doing this with Bare-Metal programming. We will...

Sep 21, 2021 · 7 min read · ruturajn.hashnode.dev  
Updated Jan 22, 2022  
Read the article

-   [#embedded](https://hashnode.com/tag/embedded)

## Written by

[Ruturaj A. Nanoti](https://hashnode.com/@RuturajN)

@RuturajN

  
[View profile](https://hashnode.com/@RuturajN)

Embedded Systems Enthusiast

I am a Second year Master's student, pursuing ESE. I am interested in Embedded systems and like developing applications using various development boards like the STM32F407 Discovery, Pi Pico, and Arduino.

## Responses 3

Markdown supported · ⌘↵ to post

[Ahmed](https://hashnode.com/@Ahmed1234)

[May 2, 2024](https://hashnode.com/posts/generating-pwm-pulses-on-the-stm32f407-for-servo-motor-control-using-bare-metal-programming/6149657b699fe76cd34857fb/comment/6633ebbe7f1ae6616ce91fef)

Hi Sir! Can you help how to modify this code if I need to change intensity of motor inversely propotional to distance from some obstacle (detected by ultrasonic sensors) Thanks Sir

[me1234](https://hashnode.com/@me1234)

[Jul 27, 2022](https://hashnode.com/posts/generating-pwm-pulses-on-the-stm32f407-for-servo-motor-control-using-bare-metal-programming/6149657b699fe76cd34857fb/comment/62e1786bd15a9fb24e51457d)

Thanks for the code and the explanation, it works perfectly! Can you tell me what I need to change in order for motor to do just one iteration, I need it to go from 0 to 180 degrees and back to 0 degrees just once, not continuously. I tried a bunch of things, nothing worked so far...

[Ruturaj A. Nanoti](https://hashnode.com/@RuturajN)

[Aug 1, 2022](https://hashnode.com/posts/generating-pwm-pulses-on-the-stm32f407-for-servo-motor-control-using-bare-metal-programming/6149657b699fe76cd34857fb/comment/62e1786bd15a9fb24e51457d#reply-62e7953a053e6bd5784295ea)

Hi, I am glad you found this helpful. As for your question, add a `break` statement, after this line: [github.com/Ruturajn/Interfacing-sg90-servo-motor-…](https://github.com/Ruturajn/Interfacing-sg90-servo-motor-with-stm32f407-DISC1/blob/3e0aa99a50e7068b4328bb2417f0585d83dc0296/main.c#L49,) and that should move the motor from 0 to 180, and then back to 0, and stop.

[Muhammad Saweiz](https://hashnode.com/@Saweiz)

[Apr 30, 2022](https://hashnode.com/posts/generating-pwm-pulses-on-the-stm32f407-for-servo-motor-control-using-bare-metal-programming/6149657b699fe76cd34857fb/comment/626ce484a2d355d4df43e234)

Fabulous....

[Ruturaj A. Nanoti](https://hashnode.com/@RuturajN)

[Apr 30, 2022](https://hashnode.com/posts/generating-pwm-pulses-on-the-stm32f407-for-servo-motor-control-using-bare-metal-programming/6149657b699fe76cd34857fb/comment/626ce484a2d355d4df43e234#reply-626d19c9a2d355d4df43e975)

Thanks
