Arduino PWM Tutorial #2 - How to Set PWM Frequency Accurately

แชร์
ฝัง
  • เผยแพร่เมื่อ 18 พ.ย. 2024

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

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

    Julian, I knew I followed you for a reason. Im making a physical spectrum analyser, this is pretty much my first real project. Im using a Sparkfun Spectrum shield using the MSGEQ7, which splits the stereo into 7 left and 7 right outputs are varying frequencies I have fitted 14 x 40mm fans into the bottom of a small cabinet, I have made, fitted a grill over the top and placed 4mm polystyrene balls inside.. so instead of the standard stereo lights just going up and down, you have this physical movement.
    Had a few issues using 2 pin 12v fans, controlled with 8 way relay board, got a lot of buzzing (drove me made) and have picked up a high quality fan 4 wire with PWM. Ahh I thought this is like a relay board, 12v positive & negative, I thought, ahh i can run the PWM @ 5V, minimal load on the Arduino job done. Spent a longtime last night and could not get it to work.
    After much research, I realised the input signal needs to be at 25-28kHz, I was lost, code and registeres GGRRRR,then realised the Arduino is 16kHz, penny dropped, all the solutions on the Arduino site just left me more perplexed.. As you have been the inspiration for me getting into this and I have most of the same kit, the voice of reason told me to check in with you.
    Ive spent 14 solid hours trying to work this out, your clear and concise explanation has to say the least, filled me with joy, had a little skip around the house @ 415am and just about to follow your tutorial, download the code and to test my theory out.
    Bless you Julian, I tip my cap with respect and for saving my mental well being.. Just how long have you been doing this for? I have no formula, I just read , get lost, pull my hair out. Your page has been such a help, beyond words.. Keep up the great work, sorry for the length. If you have any input, it would of course be more than welcome
    Kindest regards
    Dean

  • @tb303wpf1
    @tb303wpf1 4 หลายเดือนก่อน +1

    Thank you so much for this mate! I've been considering creating a library for controlling PWM frequency of timer 2 on the 328p chips. That way it's safe for millis()/delay() etc.
    This is a superb repository to start me off. I love the Arduino community. I've been working with embedded systems for years. The Arduino community is by far the most helpful and extensive of any I've experienced. Filled with top guys/gals who are always putting in the legwork to make life easier for others. Cheers for this bro!

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

    Excellent video Julian, you shortened the learning curve substantially for an AC Motor control project. I need a 15khz PWM freq that is now not an issue. 👍👍

  • @JulianIlett
    @JulianIlett  11 ปีที่แล้ว

    Indeed. Now I'm sure the Arduino can be tweaked in a lot more ways. One thing that will come up later is power consumption - I'm hoping I can switch to the internal RC oscillator and slow the clock down. There'll need to be a low power night mode, otherwise all the extra energy collected by MPPT during the day will be used up overnight.

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

    hello sir, why is this program not working on ATtiny85 ic?

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

    Thank you i was just working with pwm. I was curious about changing freq. Thanks.

  • @deltapparo4451
    @deltapparo4451 8 ปีที่แล้ว

    Ever so grateful for this one Julian! Love all your content. Keep it up please!

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

    The library: github.com/terryjmyers/PWM
    And THANK YOU !! This was the first place i found showing that the frequency can be changed continually... All the other places just offers five or six specific values of it.

  • @scolem2681
    @scolem2681 11 ปีที่แล้ว

    Awesome video. Im just starting and have had trouble locating variable frequency control. If there was a way to use potentiometer to set the frequency value linked to the library. I would be set. Thanks much.

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

    Of course! - I've done that now.

  • @deangreenhough3479
    @deangreenhough3479 10 ปีที่แล้ว

    I was wondering if you could an introduction into the basic use of an oscilloscope

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

    There is a problem with this library, I had an inverter project where I needed to switch between mosfets at 10 milliseconds to get 50 hz acv output. The millis function works fine until 20 hz, no matter how hard I tried I couldn't switch between mosfets faster than 20 hz. So any timing above 20 milliseconds with the millis function works but not faster.

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

    eines der wichtigstens lib, wenn man mit dem arduino steuern und regeln möchte. Ohne ist keine Drehzahlregelung von DC.Motoren möglich. Einen passenden nFET, die Lastspannung und gut ist.
    Thanks for this important tutorial!!!

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

    Hey! I'm having trouble downloading the PWM library to my arduino IDE. I know this video was made a while ago so I'm wondering if this library still works? I'm able to download the library to my computer but when I try the add .zip library it says "archive is not valid: multiple file found in zip file top level" also do you knwo if this library works for the ATtiny85? thanks

  • @Al-bd8hm
    @Al-bd8hm 6 ปีที่แล้ว

    Excellent video. Please, Could you tell me what was the arduino version you ran the sketch?
    Thanks.

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

    When using this, does it set the frequency in the backround from that point on? For instance, if using this code once, then uploading a completely new sketch that contains none of these functions or library, when calling analogWrite, will it still use the previously set frequency? Or revert back to the default frequency?

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

    To. The. Point. You're the dude, bravo!

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

    You just literally saved my life thank you!

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

    Can we have a frequency of 225khz using this library

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

    can it
    producing complementary output?

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

    I follow this video carefully and I copied your modified program but when I tried to compile it keep getting the message "Error compiling for board Arduino Nano" I tried to go tools menu and set Board "Arduino Nano" and Port " Com 3" but still no joy. Maybe I did a mistake in the program but cannot locate. Please see program underneath.
    #include
    int32_t frequency = 33000; //frequency (in Hz)
    void setup()
    {

    InitTimersSafe();
    bool success = SetPinFrequencySafe(9, frequency);
    if(success) {
    pinMode(13, OUTPUT);
    digitalWrite(13, HIGH);
    }
    }
    void loop()
    {
    int sensorValue = analogRead(A0);
    pwmWrite(9, sensorValue / 4);
    delay(30);
    }
    Please I would appreciate if you can help meas would like to drive an fet for a Tesla violet wand for health purposes. Thank you beforehand.

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

    Hi julian..
    how to set the frequency on the igbt via the arduino mega command and how to get 120 degree phase on the motor induktion 3 phase..

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

    hello, i want to get a variable voltage output using PWM without using POT . What should i do.

  • @BeepBopFlopKaplop
    @BeepBopFlopKaplop 8 ปีที่แล้ว

    Hi Julian, thanks for the video! Is the library interrupt-based so that the processor is not deadlocked by delays?

  • @saturn5tony
    @saturn5tony 8 ปีที่แล้ว

    yup.... brilliant! Thanks for sharing Julian!

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

    Hi Julian, how did you include this PWM.h file? I see your #include, but I'm wondering where you put the header file. Does it go in your project directory? When I do this I get a compiler error. Thanks for your time.

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

    Thank you for detailed instructions. Very helpful.

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

    hey thanks for sharing this. i need to control my PWM frequency to trigger the triac. my question is is there any limit of PWM frequency ? because i need to set my PWM frequency to 60Hz thanks

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

    Hi, I'm not sure if I'm doing something stupid but I can't seem to find a way to download this library into Arduino software, this library seems to be just what I need to build my project, which is the reasonI bought arduino. could you please explain how to download this pwm frequency library?

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

      If you find out tell me.

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

      will do mate :)

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

      and tell me too

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

      I had to unzip the files and navigate to the top folder PWM and select that, not the two other example files. inside this folder was the Pwm.h file and the arduino added that too its library. I had to use the sketch > Include library > add .zip library

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

      I had to unzip the files and navigate to the top folder PWM and select that, not the two other example files. inside this folder was the Pwm.h file and the arduino added that too its library. I had to use the sketch > Include library > add .zip library

  • @syamilmustaffa2152
    @syamilmustaffa2152 9 ปีที่แล้ว

    I just want to ask whether if we can set several types of frequency (as an example 4 types of different frequency) that can switch after a few seconds interval and loops forever

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

    when we change the pwm frequency, it is will effect the speed of the load ? for example like an ac motor.

  • @luisfrances
    @luisfrances 9 ปีที่แล้ว

    Hi Julien! How do you think i can use pin 5-6 instead of 9 on my Uno? I have 9 used by a shield.. Do you think i can get a 150Khz pwm signal? Thank you very much!

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

    Has anyone found a way to make this library work on the ATtiny? Or found a similar library that does work?

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

    do you think I can use this library on an attiny13 or attiny85 using the internal oscillator at 3.3V?

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

    Hello Julian, I am an old guy new to Arduino. I used your code for this generator. I need to output 369,000Hz. I can get 363k or 380k but not 369k. I wonder if I were to add a line of code to scan between 363k and 380k would it hit 369k. Can you help?

  • @ksharsha7779
    @ksharsha7779 8 ปีที่แล้ว

    can u tell me the code how to produce pwm for -ve cycle or store this pwm for +ve cycle and send it during -ve cycle

  • @pranavnarayan728
    @pranavnarayan728 10 ปีที่แล้ว

    Is there anyway of making it work on Arduino Duemalinove? If so please help me!!

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

    Really nice Video, that was exactly, what I was looking for! I connected a fan to it, which needed 25kHz. What I am wondering about is, if it is possible to change the frequenzy for each pin individually, because my high power led, don't need to run at 25kHz. Did you find out, if that is possible?

    • @JulianIlett
      @JulianIlett  11 ปีที่แล้ว

      Thanks Jan. It's the chip's internal timers that are modified, so I believe this would affect pairs of pins.

    • @himarkabane
      @himarkabane 8 ปีที่แล้ว

      +Julian Ilett Thank you so much for the video.I would like to ask you if you know how to set Arduino PWM frequency using matlab support block(S-function)?

    • @claudiaftprivacy6478
      @claudiaftprivacy6478 8 ปีที่แล้ว

      +Jan Reiners Did you solved it? And if so, how?

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

      Nope, I did not. Sry for that!

    • @claudiaftprivacy6478
      @claudiaftprivacy6478 8 ปีที่แล้ว

      +Jan Reiners No problem, thank you for answering. I just managed with this script to set the freq. from pin 9 and 10 at 30kHz, but pin 11 stay's at 400Hz for some reason.

  • @Tjousk
    @Tjousk 11 ปีที่แล้ว

    That certainly makes things easier, nice find.

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

    Hi,
    I'm having some trouble using a potentiometer to change the duty cicle with this example. I need a variable duty with 30kHz. Could you help me or send me your code? Thanks!

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

    Hi Julian,
    I have arduino Micro board
    and I need to generate 32ms pulse with 4msec ON duty and 28msec OFF duty.Please help on this.

    • @EdAlvar
      @EdAlvar 8 ปีที่แล้ว

      i´m interested in doing something like that, can someone please help us?? :D

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

      What about digitalWrite(1, HIGH);
      delay(4);
      digitalWrite(1, LOW);
      delay(28);
      Or "delayMicroseconds" for µS

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

      Set the frequency to 31.25 Hz and voltage to 0.625v. The formula for a Period of 32ms is 1sec/31.25Hz.

  • @sanglam4035
    @sanglam4035 8 ปีที่แล้ว

    i want calibrate the brightness LEDs by pulse frequency about 100Khz. Changing duty cycles to calibrate the brightness, 5,10,...,95% duty cycles, use port PWM

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

    Can it handle 25khz?

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

    How to make it 50% duty cycle with variable frequency?

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

    Have you published your codes?

  • @sprezzaturarrd
    @sprezzaturarrd 8 ปีที่แล้ว

    Great video until the part about "I installed the library..." When trying to install as a ZIP, how did you get around Arduino IDE errors of:
    "The library "Arduino PWM Frequency Library v_05" cannot be used. Library names must contain only basic letters and numbers. (ASCII only and no spaces, and it cannot start with a number) Specified folder/zip file does not contain a valid librarywhen you install it as a ZIP to the library?"

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

      ok, figure it out. I had to unzip the "PWM" into the Arduino's library directory as PWM, then unzip the examples as subdirectories of "PWM".

  • @Ram2006-e9x
    @Ram2006-e9x 3 ปีที่แล้ว

    Great informative content!

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

    please,help me,,how i use two pins pwm inverted for inverter.plz

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

    Nice Day! How can I do if for example I got to have three diferents frequencies in the same program. can I set the frequencies in a switch case?, how can I do?

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

      i want two different frequencies too. have you done it or not? if so i would appreciate your help

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

    sir,i want 2 complementry pwm's with 50hz and time period 20msec can u send the code pls

  • @AnteoSerani
    @AnteoSerani 8 ปีที่แล้ว

    does this work on the arduino due?

  • @a3rv803
    @a3rv803 10 ปีที่แล้ว

    Excellent videos!!!! congratulation!!! keep uploading videos like these!!!! =D

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

    thanks for your tutorial i need to generate 100khz frequency for giving gate pulse to my mosfet is it possible ?

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

      driving a mosfet at that freq can only mean one thing.... tesla coil? :D

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

      i want to drive my mosfet with arduino too (80kHz). did you do it with this library?

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

      Reyhaneh Eskandari I’ll try it tomorrow, I’ll tell you if it possible

  • @claudiaftprivacy6478
    @claudiaftprivacy6478 8 ปีที่แล้ว

    It just works with pin 9 and 10. With other pin's it does not work for some reason.

  • @BillyHoyle15
    @BillyHoyle15 10 ปีที่แล้ว

    Hey Julian. Is it possible to get 100kHz from Arduino or 62.5kHz is the border?

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

      have you tried to generate 100khz?

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

      i have tried this and got 100kHz but i am new to this and may be incorrect somewhere. I did push it to 210kHz but after that the reading on the scope went back to reading 50hz, don't know why? hope this help. using audrino uno.

  • @NaeemAwan36
    @NaeemAwan36 8 ปีที่แล้ว

    hello Sir actually library you tell us in video i cant add to arduino software, arduino software say that its un valid library please help me how to add that library in arduino Thanks

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

      Rename the unzipped library as "PWM" and put it in the "libraries" folder in the "Arduino" project folder.

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

      You have to unzip the zip file and then copy only the folder with the .h file (It's called PWM, leave the other 2 folders) to the "libraries" folder in the Arduino folder

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

    can u send the full code,reply soon pls

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

    THANK YOU SO MUCH!!!! :D

  • @ArcanePath360
    @ArcanePath360 8 ปีที่แล้ว

    Brilliant! Thanks

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

    I'd like to know where to find Julian's sketch so I can copy what he did? It would be great if that was included somewhere otherwise the whole thing is entirely pointless! I copied down the whole thing from the screen and tried it but it won't compile anyway, it's total rubbish! InitTimersSafe and pwmWrite commands don't work so he must have faked this video to make it look like it works!

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

      You obviously didn't pay attention, bud. This is a good lesson.

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

      No, still rubbish. I've since got it to work by watching several other videos and putting it all together but you also need a library that isn't mentioned here.

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

    AMAZING

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

    Dear friend, pls make video your various pwm freq onto your buck/boost converter ;)

  • @ceech123
    @ceech123 11 ปีที่แล้ว

    Thank you.

  • @dinoauci1252
    @dinoauci1252 8 ปีที่แล้ว

    je l'ai poussé jusqu'a 2MGz ca fonctionne

  • @saerhoga7643
    @saerhoga7643 9 ปีที่แล้ว

    super!!

  • @il51diablo
    @il51diablo 11 ปีที่แล้ว

    Nice. Thank you :)

  • @to1n_powere675
    @to1n_powere675 8 ปีที่แล้ว

    thank

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


    THANK YOU SO MUCH

  • @zakikho2928
    @zakikho2928 8 ปีที่แล้ว

    hi , iam asking if i can use arduino uno instead arduino mega?

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

    THANK YOU SO MUCH!!!! :D