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

  Рет қаралды 83,960

Julian Ilett

Julian Ilett

Күн бұрын

Пікірлер: 100
@deangreenhough3479
@deangreenhough3479 10 жыл бұрын
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 5 ай бұрын
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!
@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.
@carltone
@carltone 9 жыл бұрын
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 жыл бұрын
Of course! - I've done that now.
@deltapparo4451
@deltapparo4451 8 жыл бұрын
Ever so grateful for this one Julian! Love all your content. Keep it up please!
@asfnobambu
@asfnobambu 6 жыл бұрын
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.
@clems6989
@clems6989 2 жыл бұрын
Thank you i was just working with pwm. I was curious about changing freq. Thanks.
@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!!!
@gleiverperez1953
@gleiverperez1953 5 жыл бұрын
To. The. Point. You're the dude, bravo!
@TurboStreetCar
@TurboStreetCar 8 жыл бұрын
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?
@SSCchannel
@SSCchannel 3 жыл бұрын
hello sir, why is this program not working on ATtiny85 ic?
@deangreenhough3479
@deangreenhough3479 10 жыл бұрын
I was wondering if you could an introduction into the basic use of an oscilloscope
@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
@saturn5tony
@saturn5tony 9 жыл бұрын
yup.... brilliant! Thanks for sharing Julian!
@kiangkianggta
@kiangkianggta 4 жыл бұрын
You just literally saved my life thank you!
@alphonsesynrem28
@alphonsesynrem28 5 жыл бұрын
Thank you for detailed instructions. Very helpful.
@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.
@BeepBopFlopKaplop
@BeepBopFlopKaplop 8 жыл бұрын
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.
@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..
@Al-bd8hm
@Al-bd8hm 6 жыл бұрын
Excellent video. Please, Could you tell me what was the arduino version you ran the sketch? Thanks.
@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
@icepickkk
@icepickkk 8 жыл бұрын
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
@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!
@mortaldrumming
@mortaldrumming 7 жыл бұрын
do you think I can use this library on an attiny13 or attiny85 using the internal oscillator at 3.3V?
@BeepBopFlopKaplop
@BeepBopFlopKaplop 8 жыл бұрын
Hi Julian, thanks for the video! Is the library interrupt-based so that the processor is not deadlocked by delays?
@androidgalaxy7184
@androidgalaxy7184 7 жыл бұрын
when we change the pwm frequency, it is will effect the speed of the load ? for example like an ac motor.
@Tjousk
@Tjousk 11 жыл бұрын
That certainly makes things easier, nice find.
@caleblisu
@caleblisu 5 жыл бұрын
hello, i want to get a variable voltage output using PWM without using POT . What should i do.
@endremurti
@endremurti 5 ай бұрын
can it producing complementary output?
@Dilworthy
@Dilworthy 8 жыл бұрын
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 жыл бұрын
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 жыл бұрын
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
@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
@ksharsha7779
@ksharsha7779 9 жыл бұрын
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
@chbonnici
@chbonnici 6 жыл бұрын
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.
@sean123456789
@sean123456789 4 жыл бұрын
Has anyone found a way to make this library work on the ATtiny? Or found a similar library that does work?
@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!
@a3rv803
@a3rv803 10 жыл бұрын
Excellent videos!!!! congratulation!!! keep uploading videos like these!!!! =D
@lf2k2495
@lf2k2495 5 жыл бұрын
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?
@tilotamakodam1810
@tilotamakodam1810 3 жыл бұрын
Can we have a frequency of 225khz using this library
@pranavnarayan728
@pranavnarayan728 11 жыл бұрын
Is there anyway of making it work on Arduino Duemalinove? If so please help me!!
@Ram2006-e9x
@Ram2006-e9x 3 жыл бұрын
Great informative content!
@wasimpysadee984
@wasimpysadee984 5 жыл бұрын
Have you published your codes?
@greatvbn
@greatvbn 8 жыл бұрын
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 8 жыл бұрын
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.
@jasonLFS
@jasonLFS 7 жыл бұрын
How to make it 50% duty cycle with variable frequency?
@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
@Jandaxy
@Jandaxy 11 жыл бұрын
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 жыл бұрын
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.
@adamubaid3608
@adamubaid3608 6 жыл бұрын
please,help me,,how i use two pins pwm inverted for inverter.plz
@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 жыл бұрын
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".
@ztitan69
@ztitan69 10 жыл бұрын
THANK YOU SO MUCH!!!! :D
@AnteoSerani
@AnteoSerani 8 жыл бұрын
does this work on the arduino due?
@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.
@reshmam4646
@reshmam4646 6 жыл бұрын
sir,i want 2 complementry pwm's with 50hz and time period 20msec can u send the code pls
@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.
@janbroz4681
@janbroz4681 4 жыл бұрын
Can it handle 25khz?
@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 8 жыл бұрын
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
@ArcanePath360
@ArcanePath360 8 жыл бұрын
Brilliant! Thanks
@reshmam4646
@reshmam4646 6 жыл бұрын
can u send the full code,reply soon pls
@stevec5000
@stevec5000 7 жыл бұрын
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.
@piudancepad2394
@piudancepad2394 6 жыл бұрын
Dear friend, pls make video your various pwm freq onto your buck/boost converter ;)
@bijenmali648
@bijenmali648 7 жыл бұрын
AMAZING
@dinoauci1252
@dinoauci1252 8 жыл бұрын
je l'ai poussé jusqu'a 2MGz ca fonctionne
@ceech123
@ceech123 11 жыл бұрын
Thank you.
@il51diablo
@il51diablo 11 жыл бұрын
Nice. Thank you :)
@saerhoga7643
@saerhoga7643 10 жыл бұрын
super!!
@ivanaldas1157
@ivanaldas1157 10 жыл бұрын
THANK YOU SO MUCH
@to1n_powere675
@to1n_powere675 8 жыл бұрын
thank
@zakikho2928
@zakikho2928 8 жыл бұрын
hi , iam asking if i can use arduino uno instead arduino mega?
@Luis001155
@Luis001155 6 жыл бұрын
THANK YOU SO MUCH!!!! :D
Arduino Basics Change your PWM Frequency
7:35
learnelectronics
Рет қаралды 89 М.
Arduino PWM without analogWrite() - Muppet 2 Project
13:08
Julian Ilett
Рет қаралды 28 М.
IL'HAN - Qalqam | Official Music Video
03:17
Ilhan Ihsanov
Рет қаралды 700 М.
The evil clown plays a prank on the angel
00:39
超人夫妇
Рет қаралды 53 МЛН
Try this prank with your friends 😂 @karina-kola
00:18
Andrey Grechka
Рет қаралды 9 МЛН
Turn your Pico into a 400MHz 24 Channel Logic Analyser
25:26
Happy Little Diodes
Рет қаралды 67 М.
SPWM sine INVERTER with Arduino
11:10
Electronoobs
Рет қаралды 120 М.
#72 Arduino controlled Dual PWM controller & Timer thoughts
34:31
Ralph S Bacon
Рет қаралды 20 М.
Converting an Arduino PWM Output to a DAC Output
18:48
ForceTronics
Рет қаралды 112 М.
What is worth salvaging from an old smartphone?
8:35
GreatScott!
Рет қаралды 1,2 МЛН
Retro MS-DOS Coding - Recreating the Iconic Award BIOS Screen
18:16
NCOT Technology
Рет қаралды 54 М.
Getting Started With the Hailo AI Kit For Raspberry Pi 5
14:53
Expat Professor
Рет қаралды 13 М.
Control Large Gearmotors with PWM & Arduino
34:34
DroneBot Workshop
Рет қаралды 264 М.
IL'HAN - Qalqam | Official Music Video
03:17
Ilhan Ihsanov
Рет қаралды 700 М.