STM32 PWM basics

แชร์
ฝัง
  • เผยแพร่เมื่อ 2 ต.ค. 2024
  • See how to create a very simple PWM output on an STM32 microcontroller. I try to keep my examples simple so that it's easy to see what's necessary and no more. After showing how to set up and control a PWM output, I go on to show how to set up interrupts on the PWM edges as well, if desired.
    Code: github.com/Ran...

ความคิดเห็น • 47

  • @martinlintzgy1361
    @martinlintzgy1361 2 ปีที่แล้ว +3

    I like the way you explain how and where to find HAL function prototypes. Much easier that the manual.

    • @randomrickUK
      @randomrickUK  2 ปีที่แล้ว +1

      Many thanks for your kind comment.

  • @evertvel
    @evertvel ปีที่แล้ว +1

    You sir are a hero an have single-handedly saved my schoolwork!!

  • @ProcrastinatingGameCat
    @ProcrastinatingGameCat ปีที่แล้ว +1

    Hey man I love this :) if you made a whole STM32 tutorial in this style. I bet more people that I would love it :) great humor also btw

    • @randomrickUK
      @randomrickUK  ปีที่แล้ว +1

      Thanks, Mr GameCat - much appreciated!

  • @milanvdzanden
    @milanvdzanden ปีที่แล้ว +6

    You absolutely saved me, I have been trying to get into STM32 and could not get it to work. Finally I found this masterpiece. Thanks a lot!

    • @randomrickUK
      @randomrickUK  ปีที่แล้ว

      Thanks for the kind comment !

    • @rishikeshtiwari5544
      @rishikeshtiwari5544 9 หลายเดือนก่อน

      hey i am from india, can u please help me regarding pwm generation and how to vary duty cycle for stm32f103c8t6 microcontroller

    • @OSAMAHABDULLAH-pd4eq
      @OSAMAHABDULLAH-pd4eq 6 หลายเดือนก่อน

      hi can i contact with you i need your help

  • @m1geo
    @m1geo ปีที่แล้ว +2

    Really useful summary! Thanks! 😁

  • @joaoafonsodossantosmestre8896
    @joaoafonsodossantosmestre8896 ปีที่แล้ว +3

    Such a clear explanation. Great video! Hope you make more videos like this.

  • @7alfatech860
    @7alfatech860 2 ปีที่แล้ว +4

    Just watched this video...what a clear explanation! Looking forward to more STM videos from you👍

    • @OSAMAHABDULLAH-pd4eq
      @OSAMAHABDULLAH-pd4eq 6 หลายเดือนก่อน

      hi can i contact with you i need your help

  • @tisserandstephane7845
    @tisserandstephane7845 2 ปีที่แล้ว +2

    Thanks for your work and good explanations .
    In other words , you speak like a teacher
    Congratulations

  • @lamle5183
    @lamle5183 2 หลายเดือนก่อน

    I'm still a beginner on this area but thank you for this valuable video! Can I have a question? Do you know how many PWM waves that I can generate from 1 STM32 MCU? And the frequency range that it can generate..? Thanks... and sorry for the beginner question..

  • @ajeshnagpal
    @ajeshnagpal ปีที่แล้ว +1

    Thank you for the video, here it very clear and easy way you have explained, thanks again, and please keep on

  • @renatavulnera7573
    @renatavulnera7573 2 ปีที่แล้ว +1

    Thank You Rick, Your video (and the code on Github) solved my PWM problem - after 4 days of debugging. Yes, the bottleneck with starting the PWM is there ... I don't like it at all.

  • @JamaAdam-wh5zw
    @JamaAdam-wh5zw 6 หลายเดือนก่อน

    Dear sir thank you for your valuable viode, can you share with me what application you had used for PWm signal display?

    • @randomrickUK
      @randomrickUK  6 หลายเดือนก่อน

      Thanks for the compliment. The application is called Ultrascope, and it comes from Rigol and works only with their oscilloscopes. If you don't already have a scope, there are much better options for viewing signals on a PC. Owon do a USB oscilloscope that's cheap and has much faster update on the computer, or if money is no problem, consider a PicoScope.

  • @rishikeshtiwari5544
    @rishikeshtiwari5544 9 หลายเดือนก่อน

    hey i am from india can u please help me regarding pwm generation and fow to vary duty cycle for stm32f103c8t6 microcontroller

    • @randomrickUK
      @randomrickUK  9 หลายเดือนก่อน

      That microcontroller also has a TIM3 timer, which means you can set it up the same way I did here. Have you tried doing this? I really need a bit more detail to help you - what did work, what didn't, etc.

  • @yasirshahzad3732
    @yasirshahzad3732 10 หลายเดือนก่อน

    AT 5.50 what does the auto-reload preload do? why it's disabled?

    • @randomrickUK
      @randomrickUK  10 หลายเดือนก่อน

      I believe this preload is used when ARR is being dynamically changed. It prevents strange events when the ARR register is updated at certain times. If you want a fixed period/frequency, then you won't be changing the ARR and therefore the pre-load register won't do much for you.

  • @Equalizer-ZA
    @Equalizer-ZA ปีที่แล้ว

    Great effort Rick .....there's not that much info on stm32. I'm busy building a set of loadcell pedals with an INA122P built amplifier on stm32. Do you perhaps have a discord .....I think I'm gonna need your help

  • @rishikeshtiwari5544
    @rishikeshtiwari5544 9 หลายเดือนก่อน

    please help me i am doing an internship if i would be not able to generate pwm with varying duty cycle i will be get layoff please help me out .... please help me i need this job

  • @Ali-jabbar
    @Ali-jabbar ปีที่แล้ว

    Thank you for sharing the useful video, can you kindly show us how to generate two PWM waveforms for half bridge inverter, as I found it hard to set the timer counting down for the second PWM.

    • @randomrickUK
      @randomrickUK  ปีที่แล้ว

      I think a half-bridge requires two PWMs - each out of phase with each other. In which case, find a timer (TIM1 is an example for the processor I used) which has both a PWM and the negative version available.
      Example would be TIM1-> PWM Generation CH1 on channel 1 and TIM1-> PWM Generation CH2N on channel 2.

  • @louisefrylinck3859
    @louisefrylinck3859 2 ปีที่แล้ว

    What software did you use to see the waveform? (The one with the yellow logo and Ds written in black)

    • @louisefrylinck3859
      @louisefrylinck3859 2 ปีที่แล้ว +1

      Nevermind, I see you already answered. Thanks!

  • @caleb7799
    @caleb7799 หลายเดือนก่อน

    Why does it feel like I can't breath listening to you speak? It's like you're talking while out of air and silent when you actually breathed. LMAO. Is this just the English way of speaking?

  • @AlcidesRamosZambrano
    @AlcidesRamosZambrano 2 ปีที่แล้ว

    Hello, excellent, what is the pc osciloscope used?

    • @randomrickUK
      @randomrickUK  2 ปีที่แล้ว +2

      Hi - the oscilloscope is a Rigol DS 1054Z, and the software is Rigol's Ultra Sigma (the driver) and UltraScope (the user interface). You can connect the scope either to your router with an ethernet cable, or to your PC via USB.

  • @raphaeltazbaz2962
    @raphaeltazbaz2962 2 ปีที่แล้ว

    You have no idea how your video helped me on project! thanks a lot.

    • @MrSlackrick
      @MrSlackrick 2 ปีที่แล้ว

      You are most welcome.

  • @mejoe444
    @mejoe444 ปีที่แล้ว

    Hi and thank you first of all. Where can I find which type of interrupts are invoked when using a timer in PWM interrupt mode? (I mean various interrupts are generated in what conditions for the PWM, where are they written). Cannot find any documentation. You say there will be interrupts at falling and rising edges for PWM. Is that all? And is there any file which shows the type interrupts generated during the PWM running?

    • @randomrickUK
      @randomrickUK  ปีที่แล้ว

      Hi - one way to find all of the interrupt types available is to look at the driver files included automatically when you've created your project in CubeIDE. In the Project Explorer, navigate to Drivers -> STM32F0xx_HAL_Driver -> Src. There you can see a file for each subsystem.
      PWM is a timer function, so the file is called stm32f0xx_hal_tim.c (not the "_ex" file). If you are using a different series of processor to me, then the directory and files will have a slightly different name. If you open that file, you can see a callback function for every type of interrupt available to you.
      In the case of the very basic STM32F030K6T6 I've used, for PWM its:
      HAL_TIM_PWM_PulseFinishedCallback
      and
      HAL_TIM_PWM_PulseFinishedHalfCpltCallback
      Hope that helps.

    • @mejoe444
      @mejoe444 ปีที่แล้ว

      @@randomrickUK Thanks that was what Im asking. But in the reference manual there is: Table 40. STM32F302xB/C/D/E vector table . This looks like a vector table. Can we also find those two interrupts you mentioned in those tables?

    • @randomrickUK
      @randomrickUK  ปีที่แล้ว

      @@mejoe444 Hi Mo. There isn't a specific interrupt vector for these functions. The Driver file (mine's called stm32f0xx_hal_tim.c) has functions that ARE directly related to the interrupt vectors, but then those functions look at the set-up registers for the timers (or DMA as well, if you are using that), and they call the correct function, depending on how that timer has been configured.
      Take a look at the HAL_TIM_IRQHandler() function (for me it's in Drivers->STM32F0xx_HAL_Driver->Src->stm32f0xx_hal_tim.c).
      HAL_TIM_IRQHandler() has 4 calls to HAL_TIM_PWM_PulseFinishedCallback(htim) - each one depends on how the timer registers have been configured, and that in turn depends on how you set that timer up in STM32CubeIDE's CubeMX configurator.

    • @OSAMAHABDULLAH-pd4eq
      @OSAMAHABDULLAH-pd4eq 6 หลายเดือนก่อน

      hi can i contact with you i need your help

  • @abdoulayebodian3583
    @abdoulayebodian3583 ปีที่แล้ว

    Hello Mr. as I can vary the duty cycle on a variable in real time without using a potentiometer ?

    • @randomrickUK
      @randomrickUK  ปีที่แล้ว +1

      Hi - yes, for sure. You can just set the register (TIM3->CCR1 in my example) to any value between 0 and TIM3->ARR. You can do this anywhere in your code that you wish - it doesn't have to be before you start the PWM output, and you can do it as often as you need to.

    • @abdoulayebodian3583
      @abdoulayebodian3583 ปีที่แล้ว

      @@randomrickUK thank you very much for your availability i did this but the problem is that the value can not be changed in real time. to change the value you have to load it and recompile the program again

    • @randomrickUK
      @randomrickUK  ปีที่แล้ว +1

      @@abdoulayebodian3583 Are you sure your code is being executed? In my video, near the end, you can see how I dynamically change the duty cycle. I put it in an interrupt callback, but you don't have to do that. It could go in the while (1) loop in main:
      while (1) {
      TIM3->CCR1++;
      if (TIM3->CCR1 == TIM3->ARR+1) TIM3->CCR1 = 0; // go back to 0% duty when 100% reached
      HAL_Delay(100);
      }
      something like that.

    • @abdoulayebodian3583
      @abdoulayebodian3583 ปีที่แล้ว +1

      @@randomrickUK tank you

  • @rishikeshtiwari5544
    @rishikeshtiwari5544 9 หลายเดือนก่อน

    hey @RANDOMRick i am seeing for your help

    • @OSAMAHABDULLAH-pd4eq
      @OSAMAHABDULLAH-pd4eq 6 หลายเดือนก่อน

      hi can i contact with you i need your help