STM32 Guide #3: PWM + Timers

Sdílet
Vložit
  • čas přidán 24. 06. 2024
  • This video covers the basics of PWM, and how to implement it with STM32.
    STM32 gives you a bit more control than Arduino, but all these extra parameters might be a bit overwhelming at first. This video describes Duty Cycle, Resolution, Frequency, and other things that will help you get started with PWM.
    Part 2 will be released eventually.
    0:00 Review
    1:14 Essential Functionality for Microcontrollers
    2:47 Analog Write (Arduino)
    3:38 PWM vs DAC
    4:23 PWM Duty Cycle
    5:25 Counters (Timers)
    6:07 PWM Resolution
    7:57 Review + Math Problem
    9:56 Blue Pill PWM implementation
    20:07 Cat

Komentáře • 255

  • @la6mp
    @la6mp Před 3 lety +89

    This is one of the best instructions I have ever had, and I’m a 65 years old EE :-) I can imagine the amounts of time you have spent making these videos. I have played with Arduino for many years, but you are the first to teach me what REALLY goes on behind the IDE. Because of you I’ll start working with STM, and you’ve already given me a flying start. But please don’t stop now ... Again, thanks a lot !

  • @nict2618
    @nict2618 Před 3 lety +107

    Such an underrated channel.

    • @AntHenson
      @AntHenson Před 2 lety +2

      It'll blow up. I can feel it in my waters.

  • @regal_7877
    @regal_7877 Před 3 lety +65

    Great video. Keep 'em coming. 20 minutes, 30 minutes, 1 hour. No problem. The explanation is what matters. Beginners coming from 8-bit AVR like me can really understand the thorough, seemingly obvious concepts that you explain. Can't wait for the next one

    • @regal_7877
      @regal_7877 Před 3 lety +4

      @@MitchDavis2 Damn. Well, it's much appreciated. And just take your time with it because it also gives us (me) time to also play around and experiment with programming the STM32. Helps me learn a lot more just in time for your next revelation. Kind of like Uni. Lol

    • @Timkaasjager
      @Timkaasjager Před 3 lety +1

      Totally agree, good explainers for stm32 systems are so precious

  • @arsebiscuitsandwine
    @arsebiscuitsandwine Před 3 lety +53

    This is fantastic Mitch, you have a real talent for explaining these concepts in a way beginners can understand.

  • @aaronjoseph3459
    @aaronjoseph3459 Před 3 lety +27

    Hello. Please continue making this series if you can. The previous ones have been super helpful. Thanks a lot for making videos :)

  • @angelosnegkas
    @angelosnegkas Před 3 lety +24

    Mitch your are an oasis in the youtube/stm world! Thank you for your time. Great explanation!

    • @MitchDavis2
      @MitchDavis2  Před 3 lety +14

      Comments like these are what make it all worth it. Thanks!

    • @botak333
      @botak333 Před 2 měsíci

      ​@@MitchDavis2 hi mate how about like this???
      Code:
      htim1.Init.Period = ((PWM_PERIOD_CYCLES) / 2);
      Code:
      sConfigOC.Pulse = (uint32_t)(((PWM_PERIOD_CYCLES) / 2) * 0.6);
      It will working?? So no need set pwmc setphasavoltage, because global pwm duty (pulse) already set max 60%??
      Or this will set all tim for 60% sir??
      Any idea?? Thank u

    • @botak333
      @botak333 Před 2 měsíci

      ​@@MitchDavis2 hi mate how about like this???
      Code:
      htim1.Init.Period = ((PWM_PERIOD_CYCLES) / 2);
      Code:
      sConfigOC.Pulse = (uint32_t)(((PWM_PERIOD_CYCLES) / 2) * 0.6);
      It will working?? So no need set pwmc setphasavoltage, because global pwm duty (pulse) already set max 60%??
      Or this will set all tim for 60% sir??
      Any idea?? Thank u

  • @pjauniau
    @pjauniau Před 3 lety +8

    your channel is just what I needed to start with stm32
    long time user of arduino here :-)
    greetings from Belgium

  • @MrHD71
    @MrHD71 Před 3 lety +14

    Yey. Finally part 3

  • @adaminsanoff
    @adaminsanoff Před 2 lety +5

    You can't imagine how good you are at teaching programming. I still watch your videos even though I already have the knowledge of what you teach.

  • @shamanthks7218
    @shamanthks7218 Před rokem +4

    "PWM series to be continued :) "
    Last upload on this series: 2 years ago :(
    We give you full support to continue to the series on STM32. Please continue with the amazing series. We will be waiting for the next videos...

  • @rrowan327
    @rrowan327 Před 3 lety +15

    LOL I saw a cat.... btw: Thank you for continuing this series.

    • @rrowan327
      @rrowan327 Před 3 lety

      @@MitchDavis2 its a shame the cat was so camera shy

  •  Před měsícem

    I know this video is already old but I have to say I am really learning a lot from this. Thank you for taking your time to make this awesome content.

  • @davebenemerito310
    @davebenemerito310 Před 3 lety +7

    never clicked subscribe button so fast

  • @tanmaygote7330
    @tanmaygote7330 Před 6 měsíci +1

    please continue this series your explaiation skills are too good.!!!

  • @ShizzleMyChizzle
    @ShizzleMyChizzle Před rokem +1

    Dude, seriously, you have insane talent explaining things. There are no gaps of knowledge left out, you answer every question I have as you go along. Videos of THIS high level of quality is rare!!!

  • @meetpatel5142
    @meetpatel5142 Před 2 lety +2

    The explanation is what matters. Beginners coming from 8-bit AVR like me can really understand the seemingly.🙌🙌💖

  • @Mr0neShotAway
    @Mr0neShotAway Před 3 lety +3

    Wow, this is amazing, this is exactly what I needed coming from Arduino. Please keep up the great job!

  • @Epiphonication
    @Epiphonication Před 2 lety +1

    Your videos are great, thank you for all the time you put into them!

  • @ductm208
    @ductm208 Před měsícem

    wow, last 2 parts were good but this one is really impressive! I think your channel deserves more subscribers!

  • @kienvo9072
    @kienvo9072 Před 2 lety +3

    This is amazing Mitch. As a beginner in stm32, i have no word to say than thank you so much. You are really talented in explaining to others

  • @abhishek2813
    @abhishek2813 Před 2 lety

    Your explanations feel like a friend is teaching me. really appreciate that!

  • @gregrogers275
    @gregrogers275 Před 3 lety +3

    Thanks again for the video Mitch!

  • @widya1836
    @widya1836 Před 2 lety +1

    i love this, OMG, spectacular content, easy to understand than others tutorials

  • @RanHam
    @RanHam Před 3 lety +1

    Thanks for posting these. They are very helpful and easy to follow

  • @xKreesherZ
    @xKreesherZ Před 3 lety

    i love your videos, some good informations, super clear explanations, no useless words, just wow

  • @LL-ue3ek
    @LL-ue3ek Před rokem +1

    This series video is a great help to those who just started using STM32, as well as those who are somewhat familiar with it without being proficient; I am the latter. All tricks learnt in operating the STM32 IDE environment are so valuable that they will save you a lot of time and energy and most importantly, frustration. These tricks and insights are bridging the gap between where I am and where I want to be. I appreciated your generous sharing of knowledge which you at one point had to put in efforts to learn yourself!

  • @jabbathehut9564
    @jabbathehut9564 Před 2 lety

    Thanks for the tutorials Mitch! You explain very well. Keep them coming!

  • @dineshganesh6723
    @dineshganesh6723 Před 3 lety +4

    Your videos are awesome.. explaining perfectly man😎.. thanks for the precious time you spent on to educate us...👍

  • @hicret2905
    @hicret2905 Před 3 lety +1

    As a newbie , I am very happy to watch your videos. Good work Mitch

  • @dukedougal16
    @dukedougal16 Před 3 lety

    This a superb first class explanations of things I’ve been trying to understand. Really really great.

  • @rflab2666
    @rflab2666 Před 2 lety

    Great video, well explained and presented. Looking forward to more videos. Thank you for your efforts to put this together

  • @rjgonzalez8108
    @rjgonzalez8108 Před 2 lety +3

    I subscribed instantly after seeing you do one simple thing most of the people making tutorials on this topic don't do . . . you took the time to zoom into the code. Both literally and figuratively speaking. Videos like yours would have saved me lots of heads and time when I was starting out.

  • @kevinanjorin8815
    @kevinanjorin8815 Před 3 lety

    Bro this is actually the best video on stm 32 I saw big thanks man keep on the good work 👌🏾👌🏾❤️❤️

  • @tareqalmustafa
    @tareqalmustafa Před 3 lety +1

    Man , usually I never leave comments on youtube , but as your channel is not yet large , I want to say this first 3 videos are best of the best . Thank you very much

  • @Vandebilt
    @Vandebilt Před 11 měsíci

    This is an absolutely excellent introduction to STM and PWM. Thank you so much for taking your time to explain to a 62 years old geek :)

  • @mudassarliaq7804
    @mudassarliaq7804 Před 2 lety

    Awesome Video Man. Keep the good work up.

  • @abutaymiyyahlectures
    @abutaymiyyahlectures Před 3 lety

    an absolute beast, best pwm video on stm32

  • @ELANCHEZHIYANRJ
    @ELANCHEZHIYANRJ Před rokem

    The best explanation for duty cycle i have ever heard bro nice one

  • @antonis476
    @antonis476 Před 5 měsíci

    amazing work Mitch

  • @onursertgil5814
    @onursertgil5814 Před 2 lety

    These videos are great and extremely helpful. Thanks for sharing such informative videos, please continue :)

  • @brendanbarbour8568
    @brendanbarbour8568 Před 3 lety +1

    Great job again Mitch...looking forward to the Nucleo implementation. That was one scared cat ..!!

  • @tayloroxelgren264
    @tayloroxelgren264 Před 3 lety +8

    This content is gold

  • @InstantInsight777
    @InstantInsight777 Před 3 měsíci

    Really nice video. I hope your channel will get more attention

  • @Pzapza
    @Pzapza Před 3 měsíci

    Really precise explanation. Didn't really leave any doubts and covered all that was needed. Hope to see more topics covered by you. Keep up the good work.

  • @naidol
    @naidol Před 3 lety

    another excellent video. perfect actually, including the cat at the end. please keep it coming.

  • @manfred4283
    @manfred4283 Před 3 lety +6

    Thanks for the video series about STM32. Your explanations are really great. There is a typo in the calculation of the PWM frequency. It is actually 281250 Hz instead of 218250 Hz. Later on the scope shows the right duty cycle but at another frequency. Might be related to the clock configuration. This is a little confusing for beginners like me. But the video still helped me to get the PWM configured.

    • @peterbraganza3258
      @peterbraganza3258 Před 3 lety +2

      Hey I had a similar confusion with the frequency at the end being about 31kHz. What I think is he used the internal HSI(High speed clock) RC oscillator which gives you a frequency of 8MHz . So when you calculate the frequency of PWM you get 8Mhz/256 = 31kHz. hope this helps! (Note: You can get 72Mhz clock speed from the external crystal oscillator but you have to configure that in the CubeMX clock configuration)

  • @southgrove
    @southgrove Před rokem

    Fantastic video. :)
    Great job! 👍

  • @ahmedhamam997
    @ahmedhamam997 Před 7 měsíci

    Great videos relly, hope you complete this series

  • @sabbrush6001
    @sabbrush6001 Před 9 měsíci

    Dude you were made a fantastic work up here.

  • @MehmetKaya01
    @MehmetKaya01 Před 2 lety

    Awesome video Mitch! Thank you so much :)

  • @labamichnetvoll5911
    @labamichnetvoll5911 Před 8 dny

    wow, very nice tutorial with so much extra informations :), well done. Looking for part 2 of the timers and all the other suff you talked about... would be nice to see more about this nice content:)

  • @wowowowdog
    @wowowowdog Před rokem

    Thank you Davis. This really saved my day!

  • @danijandiegues
    @danijandiegues Před 3 lety +1

    Thanks Mitch, and great job again!! Congrats!! Pls continue this series. PS.: Like the "post credit scene".

  • @ceydaceylanyt
    @ceydaceylanyt Před 20 dny

    this bro singlehandedly taught me 14 weeks of embedded class in 20 minutes lollllll

  • @yahyayozo8660
    @yahyayozo8660 Před 2 lety

    great explanation man I really like it
    it removed some confusion I had about PWM

  • @rishab9761
    @rishab9761 Před 3 lety +3

    Great series, you should definitely keep continuing these and cover all embedded software/firmware concepts. Love it

    • @MitchDavis2
      @MitchDavis2  Před 3 lety +2

      I’m 4 days into filming video #4 right now. I really wish they didn’t take so long to make

    • @rishab9761
      @rishab9761 Před 3 lety +1

      @@MitchDavis2 Thank You for these wonderful videos. So useful. Take your time. I have subbed to you, will be sure to check it out as soon as they are out :)

  • @tony467913
    @tony467913 Před 3 lety

    great tutorial, please keep updating.

  • @husnainabdullah5194
    @husnainabdullah5194 Před 2 měsíci +5

    Brother! where's the PWM part 2???😭

  • @progmatica1608
    @progmatica1608 Před rokem

    We need more videos like this!

  • @foodotcom
    @foodotcom Před 2 lety

    Best video on pwm&stm aaah tysm 🤌👏

  • @brandondean961
    @brandondean961 Před rokem

    Thanks you Mitch Davis! Well explained.

  • @singhman1026
    @singhman1026 Před rokem

    Best artist is the one who can simplify toughest of the concepts..... And u really are an artist

  • @sumit2k
    @sumit2k Před 3 lety

    Keep posting about STM32 Tutorials. you are doing great

  • @ManishMoorjmalani
    @ManishMoorjmalani Před 2 lety

    Great work man, keep it going.

  • @audiodiwhy2195
    @audiodiwhy2195 Před 2 lety

    Excellent video series. Thanks

  • @robo-ape72
    @robo-ape72 Před 3 dny

    You're the man Mitch Davis!

  • @zeffster2
    @zeffster2 Před rokem

    great stuff who's been a around basic Arduino. Just perfect content on a little more low level, but not too much

  • @warchiefgaming4690
    @warchiefgaming4690 Před 2 lety

    Such a amazing explanation.... Mann you deserve more view nd subs.. love you...nd thanks❤️

  • @pranavchippalkatti2850
    @pranavchippalkatti2850 Před 3 lety +3

    Loved it !! ❤ from India !!

  • @pw3111
    @pw3111 Před 2 lety

    Excellent tutorial.Thanks!

  • @offensivebias3965
    @offensivebias3965 Před 3 lety +1

    So much knowledge 🥰 thank you so much

  • @valerienihsimsion1870
    @valerienihsimsion1870 Před 3 lety

    Courage and thank for for the free education

  • @GundamTricks
    @GundamTricks Před 6 měsíci +1

    The best beginner-friendly explanation about PWM timers. For some viewers, there might be a bit of misunderstanding. At 9:25, you're using 72 MHz as example (281 kHZ fix typo), and at 19:10, you're using 8 MHz, as shown by the 31 kHz reading on the oscilloscope."

  • @edescrambler
    @edescrambler Před 2 lety

    Very good explanation.

  • @uajoku
    @uajoku Před rokem

    You're a great teacher. Thank you.

  • @fixfaxerify
    @fixfaxerify Před rokem +1

    Great stuff!

  • @davidesp11
    @davidesp11 Před 3 lety +23

    Poor cat just wanted to learn some STM32 programming

  • @startobytes
    @startobytes Před 3 lety +4

    Good explained, thanks :)

  • @225278318
    @225278318 Před rokem

    Very useful. Thank you so much!

  • @highfrequency-tx6mf
    @highfrequency-tx6mf Před 3 měsíci

    Great video bro. Thanks!

  • @TheJavaSync
    @TheJavaSync Před 2 lety

    Pretty easy to understand, since I'm not real programmer, because it's really amazing explanation!! Thank You, MitchLED 😅

  • @Samir_Zouaoui
    @Samir_Zouaoui Před 3 lety

    That cat was hilarious , Great video as always

  • @DenSvet
    @DenSvet Před 3 lety

    thank you! your video saved my time.

  • @bogusbyte
    @bogusbyte Před 2 lety

    Thank you.... finaly found i clear to the point howto.....

  • @someonesays8022
    @someonesays8022 Před 5 měsíci

    Hi man, I hope you are doing ok. You have really helped me a lot in learning to start programming the STM32 microcontrollers.

  • @nachtgoblin24
    @nachtgoblin24 Před 3 lety +1

    Your videos are serious business. Thank you so much for putting this together it helps a lot. I will forward this to all my colleagues at university XD

    • @MitchDavis2
      @MitchDavis2  Před 3 lety +2

      That would be fantastic. I do appreciate when people share this. I just don’t want to turn into that stereotypical youtubers that overwhelms you with “LIKE AND SUBSCRIBE” every 2 seconds

    • @nachtgoblin24
      @nachtgoblin24 Před 3 lety +1

      @@MitchDavis2 Your videos are of such high quality I don't even think you need to remind people to share and subscribe XD. To people starting out with STM32 your videos are just like a pot'o'gold !!!

  • @mikebarney
    @mikebarney Před 2 lety +1

    Great Video! it would be cool to see a SPI demo

  • @TheTaiton
    @TheTaiton Před 2 lety

    don't know if you will read this, but after days of frustration and try and error, I finally managed to get it running on my stm board. Only thanks to you. So Thank you very much!

    • @MitchDavis2
      @MitchDavis2  Před 2 lety

      I read every comment. Some are just easier to respond to than others. Glad you got it working!

  • @akshaykuralkar8848
    @akshaykuralkar8848 Před rokem

    it was best video on pwm
    Thank you sir

  • @andile5945
    @andile5945 Před rokem

    Hey Mitch, I cannot believe thsi is free, well i hope it isnt actually for you but this was an incredible tutorial. Thank you

  • @pratyushpatel6224
    @pratyushpatel6224 Před 3 lety

    Great video,Keep it up!!!

  • @englishguy3899
    @englishguy3899 Před rokem

    please continue on making videos your perfect

  • @AndersNielsenAA
    @AndersNielsenAA Před 3 lety

    This has been very helpful moving from Arduino to CubeIDE. I have a feeling your audience for these videos don't really need code examples for both dev boards though. I'm using both myself.
    I like your idea of showing off the difference between Arduino's HAL and ST's a lot.
    If you run out of those I would love some of the more advanced topics laid out like this - DMA for instance.

  • @tanjiro3285
    @tanjiro3285 Před 11 měsíci

    Please continue this series 🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥

  • @EngMazen
    @EngMazen Před 3 lety

    Good information comes only from good understanding

  • @aminesemlali6199
    @aminesemlali6199 Před rokem

    thank you from the heart

  • @amitvikrampujar5517
    @amitvikrampujar5517 Před 3 lety +1

    Mitch, you are doing a great job, keep it up! I have an STM32F4 Discovery Kit and was tinkering around with it. Can you make a video on what intermediate projects we can build with a STM32 board which uses the board's resources to a great extent ?

    • @MitchDavis2
      @MitchDavis2  Před 3 lety

      Glad these are helpful! I’m not sure if I’ll get to any projects any time soon. I’m planning on focusing on implementing one feature at a time, and there’s a lot to cover.
      Not to mention, using the boards resources to a great extent depends which board you’re using. For example, I was using an L031 the other day, which is a low-cost, low-power, small microcontroller. I also used the F201, which has many IO pins, is very fast, and supports a ton of peripherals. They both have very different applications, so using them to their full potential have very different meanings.

  • @patrice9480
    @patrice9480 Před 3 lety

    amazing content !!!

  • @markday3145
    @markday3145 Před 3 lety +5

    My understanding of the Auto Reload Preload is different from what you explained. By default, the timer keeps repeating. You can make it count once by enabling One Pulse Mode. The Auto Reload Preload affects when an Auto Reload Register change takes effect. If preload is enabled, it waits until the end of the current period, and the change takes effect when the counter resets. Otherwise the Auto Reload register is changed immediately, which will extend or shorten the current period.
    Consider if you're changing the ARR to a smaller value while the timer is running, and the counter is already larger than the new ARR value. With preload disabled, the counter would immediately reset (because the counter is greater than or equal to the ARR) and begin counting up to the new value. This means you'd have a glitch in the period, where it was neither the old period, nor the new period.

    • @MitchDavis2
      @MitchDavis2  Před 3 lety +3

      Thanks for pointing this out. I’ll spend a bit of time digging through the datasheet and doing a few tests, and if I made a mistake, I’ll call it out in the next video

    • @MitchDavis2
      @MitchDavis2  Před 3 lety +6

      Ok, I finally did my homework on this, and I definitely slipped up when reading the documentation. I've corrected this for video #4, and I'm giving you a shout out for pointing this out. Thanks again for the pointer before I went too deep in the mistake

  • @Bianchi77
    @Bianchi77 Před 3 lety

    Cool info, thanks :)