Arduino Basics Change your PWM Frequency

แชร์
ฝัง
  • เผยแพร่เมื่อ 29 มิ.ย. 2024
  • Arduino Basics: PWM Frequency
    The PWM frequencies in Arduino a pretty much set. You can't really change them from the IDE. For example, pin 9 PWM frequency is set at 490Hz. Other pins have different frequencies, which are controlled by the Atmega 328P timers.
    You can change the pre-scaler for these timers and effectively change the frequency, but it can be a bit of a bother to look up the code.
    But, the good news is that there is a library, called PWM that let's you change the frequency of the PWM pins in the IDE with the SetPinFrequencySafe() function.
    You can download this library here: code.google.com/archive/p/ard...
    The frequency counter I used in this video is from BangGood.com. It's a kit, and it's available here: Geekcreit® DIY Frequency Tester 1Hz-50MHz Crystal Counter -- goo.gl/DCy9Pz
    ~-~~-~~~-~~-~
    Please watch: "Diodes: The basic building block of all digital circuits"
    • Diodes: The basic buil...
    ~-~~-~~~-~~-~
  • บันเทิง

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

  • @user-te3wf5fs1k
    @user-te3wf5fs1k ปีที่แล้ว

    In the middle of studying headache of definiition of the counter, clock, I finally found the easiest way of using pwm frequency change by its library. Thank you so much. It is really helpful!

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

    Worked great for my Nano 14 inch radiator fans controller! Quiet at any pulse width. Thanks.

  • @S-Tach
    @S-Tach 5 ปีที่แล้ว

    I gouache your video...after watching 100s of video to find this kind of right tutorial. ...nice explain. ..thank you so much. ...I've been stuck. .but now my project going to finish. ...thanks again. ..

  • @pedro-neves
    @pedro-neves 5 หลายเดือนก่อน

    Thanks! Finally, I was able to change my PWM frequency.

  • @josip1881
    @josip1881 4 ปีที่แล้ว

    Thanks! Very well explained in short time.

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

    Very handy, thanks! Using this to fix the broken immobilizer in my Honda

  • @ismaillashari7597
    @ismaillashari7597 5 ปีที่แล้ว +4

    thank you so much ................... because of this short value I understood about my project. even I have studied hundreds of research papers and couples of thesis ... thank you so much today I got clear concept about my project

  • @koomber777
    @koomber777 14 ชั่วโมงที่ผ่านมา

    Perfect. Been making an led controller and had issues the whole way through, finally got it working but when hooked to the LED strip they squealed. Changed the pwm to 1khz and the noise is gone!

  • @georgechambers3197
    @georgechambers3197 7 ปีที่แล้ว

    A project! I can't wait. Thanks for making the code and library available! I know this didn't need it but a simple schematic would also be very helpful for us duffers.

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

    That is amazing! Thank you! You are awesome!!

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

    Nice, I was hoping that this was possible, I needed a PWM refresh rate of 1200MHz. I've also just bought one of those frequency counter kits too. Thanks for the video. Thumbs up from me :D

    • @hazim6801
      @hazim6801 4 ปีที่แล้ว

      Can we change the frequency of arduino pin up to 8khz?

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

    Thank you! This is veryquick and easy way to set the frequency. On the higher frequency range it works better with some number than others. For example setting frequency to 666,666 Hz, gives me 666,675 on the freq. meter, which is quite OK.However a setpoint of 666,667 Hz outputs 727,282 Hz. The higest I was able to get is 2 MHz.

  • @michaelpadovani9566
    @michaelpadovani9566 7 ปีที่แล้ว

    Hey thx for sharing this seems like a super simple library

    • @learnelectronics
      @learnelectronics  7 ปีที่แล้ว

      Michael Padovani just about as simple as they come

  • @MrTrollBeast
    @MrTrollBeast 6 ปีที่แล้ว

    Awesome stuff man

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

    Thanks for substituting the metal screwdriver to point at electrical signals and scratchable screens, into a wooden stick.

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

    Thank you! You helped a lot.

  • @Potatogambit
    @Potatogambit 6 ปีที่แล้ว

    Awesome thanks for sharing this. Question? Does this mess up the delay function?

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

    thank you man, yous aved my ass...I was messing with delays and that crap, but found that useless, need a 25 kHz frequency to drive the motor for my trike so thanks once again

  • @tcratius1748
    @tcratius1748 3 ปีที่แล้ว

    Awesome, keen to see where this is going especially since PWM seems to pop up a lot in 3d, CNC, and robotic. Just a quick not, as a python programmer, certain segments such as the if statement should be commented.

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

    Thanks, great video.

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

    İt is saving my life babe. Thx for everything

  • @mackrin9366
    @mackrin9366 3 ปีที่แล้ว

    Thank you for help!!

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

    Awesome tutorial. Do you have a sketch for changing the pulse width with the potentiometer? Thanks

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

    Hello
    Thank you for the great information you provide
    I wish you to live with pleasure
    can I ask a question
    the question is
    Can I get the 15 Hz frequency directly from the Arduino?

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

    GREAT thanks man 😌

  • @Nebilson
    @Nebilson 4 ปีที่แล้ว

    Thank you so much.

  • @ameralahmad3563
    @ameralahmad3563 3 ปีที่แล้ว

    thank you , it was very useful, because I want kHz pwm for my dc motor driver, thank you very much

  • @cyberwasp461
    @cyberwasp461 4 ปีที่แล้ว +4

    Sir. I'm new to scopes and the Arduino. I would like to try the example you showed above but can't find the same in the library.

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

    ID like to know what the distinction is between setting a pulse width modulation and configuring a timer todo basically watch seems to be the same thing

  • @Dennis000236
    @Dennis000236 4 ปีที่แล้ว

    Great Video! Is this also can change the noise out of my dc fan?

  • @CrazyHHO19
    @CrazyHHO19 6 ปีที่แล้ว

    hello i was wondering if you would be able to help me.i have digital puls generator .how can i program it to run 10% duty cycle at 0.64 v input and gradually increacing voltage to 3.86v with duty cycle 90%.its for my project where voltage coming from throttle position valve potenciometer control my pulse/duty cycle generator which then directly control fuel injector.any advice most appreciated cheers jo

  • @wa8eem
    @wa8eem 4 ปีที่แล้ว

    It simply works

  • @alexstone691
    @alexstone691 3 ปีที่แล้ว

    Note that the analogWrite can run only once in setup, cause its a hardware timer

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

    Sir what is the max frquency of arduino uno?

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

    The relationship between High Time and the Period is called "Duty Cycle". The duty cycle is the ratio of highTime/Period. (edited to correct my error)

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

      You don't say

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

      Not quite. PWM is the ratio of highTime to the period. According to your logic a 50% duty cycle would have a duty cycle of 100% because highTime and lowTime would be equal.

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

      @@drumbum7999 You're absolutely right. Apologies for my error, and thanks for correcting me. 👍

  • @TheScambreaker
    @TheScambreaker 5 ปีที่แล้ว

    Thanks for good job. But this method does not compatible with DigiSpark. Could you please, fix that for DigiSpark?

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

    Thank you for the tutorial. But actually, I am looking for the frequency of 16 to 20KHz to avoid the noise in my DC motor. can you please give me any idea without using library.
    Thank you in advance

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

    Can you do it with two to 4 pins putting different freq and PWM . Maybe one pin 20Khz at 5% and pin 2 at 90% at 20khz

  • @JDI4DAVID
    @JDI4DAVID 6 ปีที่แล้ว

    Have you tried varying the frequency within the loop program? Can it be done? Thanks for the very interesting video. I want to make some noise with the Arduino.

    • @learnelectronics
      @learnelectronics  6 ปีที่แล้ว

      +David Tucker I tried changing it with a pot, I didn't have any luck. But to be fair, I only tried for about 5 minutes.

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

    Hi!! I have downloaded the PWM Library but not able to add it on Arduino. It does not show up on sketch. What could be the problem?

  • @UpcycleElectronics
    @UpcycleElectronics 7 ปีที่แล้ว

    Have you ever thought about making a DC converter out of an Arduino?
    I have an old portable heater I was given for parts. It used 2 PIC12F675's as switching controllers in a boost topology for the heating element and an 'ozone ionizing grid.' I thought it might be interesting to make an Arduino version of a DC Converter controller. I'm a slow handicap gimp with a bad back. I'm not sure how long a project like that would take for me to complete.

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

      Upcycle Electronics any Arduinos would be more than capable, but it seems to me to be a bit of an overkill. A 555 timer will do the job nicely. did you see my "make your own boost converter" video? If not, here's a link...th-cam.com/video/IxzoqzbAYfE/w-d-xo.html

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

      learnelectronics
      Sure it can be done with a 555. I've seen people try to use an Arduino just for the display interface of a bench power supply. I would find it interesting to try to build the display, interface, and controller on a single platform. I don't even know if it's possible for the Arduino to handle both the interface and controller, but a PWM constant current controller with adjustable current and voltage would probably be popular for those ready to start exploring more relevant technology than ancient linear supplies.

  • @elmirrsetiawan7557
    @elmirrsetiawan7557 5 ปีที่แล้ว

    if 3 phases can or not?
    And how to make a 120 degree phase ?

  • @JuanCarlos-ff6vp
    @JuanCarlos-ff6vp 2 ปีที่แล้ว

    Can you set different frequencies in different pins at the same time (in the same program)?. Greetings.

  • @mohammedelqadmiry2999
    @mohammedelqadmiry2999 4 ปีที่แล้ว

    this library works on the arduino nano also ?

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

    i got real question why is pin 5 the pwm frequency cannot be set i was blocked here with the motor going full speed for no reason when signal was high enough(should be dimmable)
    and the i try adding a second set of code for trying and set to pin 9 it work >_>
    fu my life i broke 2 arduino chip set and the main ebike arduino for such a crap thing

  • @PG-qm5nk
    @PG-qm5nk 6 ปีที่แล้ว

    Can you incorporate a 2nd pot to vary the frequency value as set by the instruction... " int32_t frequency = xxxx "... so that you can do it on the fly without a code change? just as your doing with the duty cycle.?

    • @learnelectronics
      @learnelectronics  6 ปีที่แล้ว

      paul gray I tried that with no luck, but I may have done something wrong.

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

    Hey! I'm not able to install the library.

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

    I can't install the library. help please!

  • @santoshm7354
    @santoshm7354 4 ปีที่แล้ว

    a doubt ..sir, bu=y using this function can we give that pwm to a mosfet.. or it will only work for led??
    please reply... thank you for video .. really helpful

    • @dee5556
      @dee5556 3 ปีที่แล้ว

      If you want to drive a MOSFET with a gate over 5V you need to go through a optocoupler

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

    How can I get the frequency counter that you are using? The link that you provided is not good anymore.

  • @evanperrygiblin
    @evanperrygiblin 3 ปีที่แล้ว

    so there are no prescalars?

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

    It worked for me with pins 9 and 10 of the Arduino Uno. But the other PWM pins didn't work. Can I change anything to make it work? Thanks for the video.

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

    Could this work with the at tiny 85?

    • @learnelectronics
      @learnelectronics  6 ปีที่แล้ว

      ("RNA0ROGER") I've never used the AT Tiny, so I don't know. Can't hurt to try though.

  • @user-mz1xc2tj3y
    @user-mz1xc2tj3y ปีที่แล้ว

    hey please rply, i am not able to add library. please can you tell me steps to add library.

  • @davemooreracing
    @davemooreracing 6 ปีที่แล้ว

    Paul did you ever test how low you could go the frequency?

  • @KyrosNox
    @KyrosNox 4 ปีที่แล้ว

    I can't install the library. "Library.properties not found."

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

    hello, you dont modify the frequency, only the duration of the power.

  • @user-ll7ky2pf4n
    @user-ll7ky2pf4n 4 ปีที่แล้ว

    Links to the library are inactive. Please update.

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

    Three pins worked ok: digital D3 (PD3), D9 (PB1) and PD10 (PB2). Other PWM - pins did not work. Those that worked ok, worked well.

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

      thanks i was using D5 couldn't figure out why it wouldn't work

  • @electronicsenthusiast4957
    @electronicsenthusiast4957 3 ปีที่แล้ว

    Can you send me a code with 2 pots 1 for changing frequency and other for changing duty cycle

  • @eddymeshack
    @eddymeshack 6 ปีที่แล้ว

    is it even possible to change the frequency on the arduino using matlab gui

    • @learnelectronics
      @learnelectronics  6 ปีที่แล้ว

      +Eddy Meshack I am not familiar with Matlab

  • @filigenzilab9613
    @filigenzilab9613 4 ปีที่แล้ว

    What’s the maximum frequency an arduino can generate with this code?

    • @Boborski06
      @Boborski06 4 ปีที่แล้ว

      In the comments of the lib, it's written 2MHz

    • @filigenzilab9613
      @filigenzilab9613 4 ปีที่แล้ว

      Boborski06 thanks

  • @xgrapher
    @xgrapher 4 ปีที่แล้ว

    that on to off ratio is called DUTY CYCLE sir

    • @learnelectronics
      @learnelectronics  4 ปีที่แล้ว

      yeah. I know. sometimes I cant remember terms.

  • @JCchan99
    @JCchan99 5 ปีที่แล้ว

    When I try to install it as a zip library it says Specified folder/zip file does not contain a valid library! v5

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

      solved changed the name to something without dashes or spaces and took out all the unessential files

    • @ezgieftekin4495
      @ezgieftekin4495 4 ปีที่แล้ว

      @@JCchan99 I see the same error. Which are the unnecessary files? How can i know?

  • @danieldominguez8135
    @danieldominguez8135 5 ปีที่แล้ว

    does it work also with the arduino mega?

  • @ericthered9655
    @ericthered9655 3 ปีที่แล้ว

    I can't see the code

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

    hmm code.google? i thought they discontinued that. i would advise looking for a library that is on github :P

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

      GitHub bleh

    • @fredlllll
      @fredlllll 7 ปีที่แล้ว

      you dont have to use it :P just download the zip

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

    Now just feed that signal in a mosfet and you got a powerful speed controller!

  • @JCchan99
    @JCchan99 5 ปีที่แล้ว

    Sadly I can't have 1 second on one second off with this library because I need a frequency of 0.5 Hz and freq. is controlled by an int32 and I would need a float

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

      You could code that with delays or Millis, it's a very low frequency

  • @hilmydzulfaqar8087
    @hilmydzulfaqar8087 7 ปีที่แล้ว

    can i change to 50hz?