Electronic Basics #30: Microcontroller (Arduino) Timers

Ғылым және технология

Support me for more videos: / greatscott
Previous video: • HACKED!: ATX Power Sup...
Facebook: / greatscottlab
Twitter: / greatscottlab
In this episode of Electronic Basics I will show you how to use the timer of a microcontroller (Arduino Uno -- ATmega328P) to not only create precisely timed events but also generate a PWM signal with variable duty cycle and frequency up to 8MHz.
Music:
2011 Lookalike by Bartlebeats
Killing Time, Kevin MacLeod (incompetech.com)

Пікірлер: 533

  • @Geradovitch
    @Geradovitch7 жыл бұрын

    So different of electronics I earned in the late sixties. Have tried to keep up to date on my own. Learned how to fix digital tv's and am now interested in microprocessors .I have ordered a full arduino kit with sensors and learning Python and Linux. Plus I have been following you on You Tube for the great projects you explain. Keep up the great work, You are a good teacher.

  • @vaibhavpatil9956

    @vaibhavpatil9956

    4 жыл бұрын

    I am interested in old electronics can please share what type of electronic were in 60s

  • @executorarktanis2323

    @executorarktanis2323

    Жыл бұрын

    That's great seeing you still learning sir please reach out to me if you require any help also btw they are called microcontroller 😊

  • @pesterenan
    @pesterenan7 жыл бұрын

    This is the basics? wow! And here I was thinking that I was smart by using a previousmillis(); function xD

  • @nishadnadkarni7874

    @nishadnadkarni7874

    7 жыл бұрын

    Pesterenan the stuff he's doing is basically what you do when you use the atmega on its own without the arduino ide and its libraries (but with atmel's libraries), its mostly just writing data to registers and reading from them. In the video he goes kinda fast so you will find it overwhelming, but take the time to look at other videos and tutorials about the 328p's timers, its not that hard. The datasheet gives you what bits you need to set in which registers to configure the timers how you want. Obviously you need to look at tutorials and read up on them to understand them well. But once you have an idea of how to configure timers and what registers to use and a few basic modes, figuring out other modes isn't that hard and you can refer to the datasheet. You will need to look up stuff online but its not that hard. I don't know everything about the atmega 328's timers but from what I know its pretty easy. I've moved on from the atmega though.

  • @SuperNesmaster

    @SuperNesmaster

    5 жыл бұрын

    @@nishadnadkarni7874 what other boards have you moved on to? Just curious. I'm just getting started with the arduino platform but do not know if i should start with the arduino IDE or using atmel studio.

  • @shivashankar28

    @shivashankar28

    5 жыл бұрын

    @@SuperNesmaster Start with arduino IDE then move on to atmel studio

  • @JaySilva88
    @JaySilva887 жыл бұрын

    I didn't understand a thing, but great video! ahah

  • @kuyanatnatdkrx7

    @kuyanatnatdkrx7

    7 жыл бұрын

    Embedded Micro controller Technical Jargon didn't make sense to me at first time I heard it. interrupts, timers etc are just a bunch of built in useful peripherals that does a particular function for a programmable logic device.This stuff is around the second layer of electronic and computer systems you'd have to study the basics of electrical and digital electronics.

  • @mohamed_fawzy

    @mohamed_fawzy

    5 жыл бұрын

    +1

  • @nametag1723

    @nametag1723

    4 жыл бұрын

    Me too!

  • @baumdings1782

    @baumdings1782

    4 жыл бұрын

    I watch this for scool haha

  • @chuck_norris

    @chuck_norris

    4 жыл бұрын

    feel it

  • @frank4one
    @frank4one3 жыл бұрын

    I have been struggling to understand timer interupts. THIS IS THE BEST EVER! I can now control my steppers using either overflows or compare timers. THANK YOU!

  • @MikeGecawicz
    @MikeGecawicz5 жыл бұрын

    I have been working on a project using LCDs and Stepper Motors for the past two weeks and this is the exact video I have been looking for; of course it comes from one of my favorite youtubers. Keep it up!

  • @RobertMilesAI
    @RobertMilesAI7 жыл бұрын

    I feel like you would want to know this: "Mandatory" is usually only used for things that come from human rules, and usually a better word to use is "necessary". Consider "using a precise timer here is mandatory under EEC regulations for electronic products", vs "using a precise timer here is necessary if you want your alarm clock not to drift a lot over time". Like, wearing a motorcycle helmet is always necessary if you want to be safe, but in some parts of the world it is not mandatory. I normally wouldn't point that kind of thing out but your English is already pretty excellent so I thought you'd want to perfect it.

  • @DatNerddSwaqq

    @DatNerddSwaqq

    7 жыл бұрын

    Robert Miles Wasn't expecting to see you here! Love your videos on Computerphile and big fan of your channel!

  • @ganzsichertobi

    @ganzsichertobi

    7 жыл бұрын

    I also didn't know that. Thanks!

  • @borisdorofeev5602

    @borisdorofeev5602

    6 жыл бұрын

    Robert Miles I read your comment and understood that you are not nitpicking, but genuinely want to help a good KZreadr improve his English. So, I checked out your channel, noticed that you produce some excellent content, and I subscribed to you. The comment sections to videos like this are a goldmine of extraordinary KZreadrs.

  • @joelsantiagovalentin2231

    @joelsantiagovalentin2231

    6 жыл бұрын

    There better option with timer

  • @MikeysLab
    @MikeysLab7 жыл бұрын

    Having worked with electronics a lot in my life, I always found timers and interrupts to be kind of a dark art, especially before Arduino and when dealing solely with AVR or PIC. Thanks for addressing this :)

  • @edtix
    @edtix7 жыл бұрын

    Finally! I miss in-depth videos like that. Keep going :)

  • @hybridskeeter
    @hybridskeeter7 жыл бұрын

    This is a great video. Thanks for putting these timers into context with good examples, they make much more sense to me now!

  • @WarrenGarabrandt
    @WarrenGarabrandt7 жыл бұрын

    I'm about to build a 500 Watt 30V - 42V motor controller for a project I'm working on. I had not yet looked into how to generate stable PWM signals in code without spinning the Arduino in busy waits that eat battery. You've given me some great ideas in this video, so thanks for your time and effort making this.

  • @raybright5805
    @raybright58057 жыл бұрын

    Excellent companion to your previous "Arduino Basics 102: Control Structures, Variables, Interrupts" - Love Your Work...

  • @makermonkey6591
    @makermonkey65917 жыл бұрын

    I'm writing an arduino sketch to control a stepper while monitoring some sensors. The accelstepper library did not really cut it, for my application. Using this new timer knowledge I was able to make the hardware act exactly as I intended. HUGE THANKS for this tip. Awesome GreatScott.

  • @Bartong666
    @Bartong6667 жыл бұрын

    Great video! These more advanced videos are great since the amount of videos on how to blink leds is so high and no one really goes that much into advanced arduino / ucontroller functions. Keep at it!

  • @klausnielsen1537
    @klausnielsen15377 жыл бұрын

    Thank you for doing these videos. I keep coming back and watching and now I even bought a ton of arduino stuff to have a go at some simple stuff. Totally subscribed!

  • @mrjohhhnnnyyy5797
    @mrjohhhnnnyyy57977 жыл бұрын

    Well done, this video has cleared a lot of the confusion I had thinking about timers. Now I know how CTC mode works, thanks for informative video!

  • @TheMegaloloful
    @TheMegaloloful7 жыл бұрын

    Thank you for this video! I made a arduino alarm clock a while ago, but because I didn't use a timer, the clock "lost" about 10 minutes every week. With this information I can finally fix the clock! Thank you!

  • @ChrisMuncy
    @ChrisMuncy7 жыл бұрын

    Scott. Fantastic video. I would not have even known about this without either reading the docs or watching your video. Keep 'em coming.

  • @ryanelliott4092
    @ryanelliott40927 жыл бұрын

    This is perfect! I have an exam on this today! Thanks for the review Great Scott!

  • @andrewwatts1997

    @andrewwatts1997

    2 жыл бұрын

    How did the exam go ?

  • @insightfool
    @insightfool7 жыл бұрын

    SUCH a good explanation of how to use Arduino style interrupts. You're officially AWESOME.

  • @emrekeremozyurt296
    @emrekeremozyurt2964 жыл бұрын

    u can feel the illumunation after watching this 50 time. It is more brighter than the edison's and I'm understanding them now. I loved it!

  • @zetaconvex1987
    @zetaconvex19873 жыл бұрын

    Thanks for that, very informative. I was looking to create a variable duty cycle at a fixed frequency, and figured I wanted fast PWM mode. Your tutorial helped me put a few things in place.

  • @kai7474
    @kai74747 жыл бұрын

    This cleared up a lot of how to understand the timers & documentation about them for me. I was just getting to the point in some projects where I need them too!

  • @RinksRides
    @RinksRides7 жыл бұрын

    It is a great video. AVR timers even after explanation are still mysterious and confusing because of how they can interconnect. Respect on a next level! PWM to 8MHz?! Awesome!

  • @binaryme335
    @binaryme3357 жыл бұрын

    Great video. Some was little over my head, but if I watch things I already know, I'm not gaining​ anything. Thanks again for another excellent video.

  • @NorbertHarrer
    @NorbertHarrer7 жыл бұрын

    Great tutorial. I have used timers on the Arduino before. But only through libraries. That was a great overview on how that works under the hood.

  • @nihaludeenkaisome2796
    @nihaludeenkaisome27966 жыл бұрын

    Superb explanation about the uses of timer great scott ! Thank you for this video, it helps me lot.

  • @prestonmatheny9756
    @prestonmatheny97567 жыл бұрын

    Great video! I really like how you get straight to the point, and pack in as much info as possible. Lengthy videos aren't as entertaining, and even if I have to watch this one a couple times to really get it, I would much rather prefer a shorter video than a longer video. Keep up the good work!

  • @greatscottlab

    @greatscottlab

    7 жыл бұрын

    I think the same way :-) Thanks for the feedback.

  • @riassenpai1590
    @riassenpai15907 жыл бұрын

    Hello Scott! Remember the clap circuit project? I build it from the first time and put it under my desk and plugged in my pc I enjoy it so much when i come home with one clap I turn on my pc!Greetings from my electronics teacher I showed some your projects to him and he sad:You can learn so much from him.

  • @Tarbard
    @Tarbard7 жыл бұрын

    Great explanation as always, I like the way you present.

  • @Jay0neDE
    @Jay0neDE7 жыл бұрын

    I can't tell you how helpful this video is. thanks!

  • @moustafa19997
    @moustafa199976 жыл бұрын

    This is certainly the best kind of videos you make

  • @TheJay6621
    @TheJay66217 жыл бұрын

    A step inside the arduino functions. Lot of thanks for such detailed explanation. No body cares to explain these basic stuffs only you are the saviour for beginners as well as advance users. as always Love from India. thank you for your time and efforts. keep up the good work.

  • @greatscottlab

    @greatscottlab

    7 жыл бұрын

    Thanks mate :-)

  • @stevenlittle2384
    @stevenlittle23842 жыл бұрын

    Thank you so much, for helping me tackle this daunting topic.

  • @soxxks
    @soxxks2 жыл бұрын

    Amazing video. This video with Arduino documentation go perfect together. Thank you!

  • @brianhackit7900
    @brianhackit79007 жыл бұрын

    hey dude. just wanted to say thanks for all the vids. when i started my degree 2 years ago i found your channel. its been a great resource and ur perfect as far a host. you get all the info across well and you provide schematics and downloads and everything. so i just wanted to say tx. would've msgd you but couldve find that on this channel. thanks for providing such an incredible FREE resource for education man.

  • @greatscottlab

    @greatscottlab

    7 жыл бұрын

    No problem :-)

  • @SuperFlyCH
    @SuperFlyCH3 жыл бұрын

    I have so much still to learn, sigh... This is one of those videos where I need to do some research and then come back to to watch the video again to get a much better understanding. Thanks for challenging me with your great videos.

  • @simoncroatia
    @simoncroatia7 жыл бұрын

    You are a very smart man and although I don't understand everything I still enjoy your videos. Thank you.

  • @erfanelmtalab3426
    @erfanelmtalab34263 жыл бұрын

    I had problems learning the timer counter , but this video helped me enough ... Thank you sir

  • @user-vs1du9tl2p
    @user-vs1du9tl2p7 жыл бұрын

    GreatScott is really great, Keep up the good work. Thumbs up!

  • @clivemayo4049
    @clivemayo40496 жыл бұрын

    Great video, you've made it so easy to understand, Thank you.

  • @HannesMrg
    @HannesMrg7 жыл бұрын

    You have the perfect timing, always if I finish a project you explain exactly that in a video and it's really easy to understand the little things I didn't know already :) Also keep up the great work, I'm always really happy when the "New Video" notification pops up.

  • @greatscottlab

    @greatscottlab

    7 жыл бұрын

    Thanks for the feedback :-) I will try to keep it up.

  • @JoaoSilva-jr9ez

    @JoaoSilva-jr9ez

    7 жыл бұрын

    does it happen to you too? thought it was only me ;D

  • @luizz1997
    @luizz19977 жыл бұрын

    Holy cow... that is another one of your videos i'm gonna need repeat a lot of times to understand

  • @yusy4501
    @yusy45014 жыл бұрын

    An advanced topic but u make it so easy to understand. Thank u.

  • @drkastenbrot
    @drkastenbrot7 жыл бұрын

    Im prettty sure theres many libraries available for this threading/timing approach. Very informative, I didnt know much about this. Thanks.

  • @ix8inside891
    @ix8inside8912 ай бұрын

    best Explanation to that topic I've ever heard

  • @5minutetimer
    @5minutetimer Жыл бұрын

    This is amazing! Thanks for doing these!

  • @brzydka_i_bestia
    @brzydka_i_bestia7 жыл бұрын

    Great video, very helpful keep up the good work!

  • @Delali
    @Delali3 жыл бұрын

    This is just what i need. Thank you Mr. Scott

  • @4-n0t-found-4
    @4-n0t-found-45 ай бұрын

    Thank you for this video, it's exactly what I needed to get it 👍

  • @shedactivist
    @shedactivist3 жыл бұрын

    Great video as always. I didn't realise just how capable the Arduino was, but please forgive me when I just buy a RTC module for my next project.

  • @k1ckcyph3r16
    @k1ckcyph3r167 жыл бұрын

    Oh I see what you did there...this is just a guide, but I find it very usefull because you managed to put all the information in 9 minutes so we can see the video search for the information to complement it ans continue watching. I guess that's not the format everybody likes, but I find it very interesting because it "forces" me to do more research and learn more than if you just give me the recipe, but that's just my opinion. Thanks for the video, nice job.

  • @MinecraftM0b
    @MinecraftM0b7 жыл бұрын

    Hey, the drift off of the millis() function is caused by the Serial.println which takes some clock cycles (depends on baud rate ofc) - the timer is precise in this situation

  • @MD-vs9ff

    @MD-vs9ff

    7 жыл бұрын

    delta I think that's the point he was making. Delay causes drift because the other code takes some time to execute, so your loop time is delay time + code time.

  • @jort93z

    @jort93z

    7 жыл бұрын

    i use an RTC for my clock project i did with the arduino(binary and lcd clock). its the DS3231(M) and its very precise and really cheap(the whole board is literally $1 on ebay). it makes a whole lot of things a whole lot easier. and it has a battery backup. And the arduino itself drifts off a lot faster than an RTC.

  • @ArthurIslamRU
    @ArthurIslamRU4 жыл бұрын

    Thanks a lot dear Scott for your knowledge

  • @markusjuntunen6631
    @markusjuntunen66317 жыл бұрын

    You are my idol, keep ON with gr8 videos, these are diamond.

  • @remowo_
    @remowo_7 жыл бұрын

    thank you for the analysis...This topic has always been fuzzy for me even when reading the datasheet...

  • @Frisky0563
    @Frisky05632 жыл бұрын

    Boy that was quick I had to replay many times lol great video I appreciate it

  • @Remy561
    @Remy5617 жыл бұрын

    Great video, was easy to follow! (as an embedded systems student)

  • @ankitgupta9008
    @ankitgupta90086 жыл бұрын

    I was finding this video for months very important thanks subscribe to your channel

  • @IndieSamurai101
    @IndieSamurai1017 жыл бұрын

    Man you are so good at electronics! Wish you were my physics teacher!

  • @Axelios
    @Axelios7 жыл бұрын

    excellent video. i learned a lot about how to use an arduino beyond the included libraries

  • @greatscottlab

    @greatscottlab

    7 жыл бұрын

    Awesome!

  • @wiko211
    @wiko2114 жыл бұрын

    Great video, found it really helpfull while programming the arduino uno in pure C

  • @shubhamadtp
    @shubhamadtp5 жыл бұрын

    So much information packed in one video. Error data limits exided

  • @germas369
    @germas3694 жыл бұрын

    thanks so much for this. i understand how timers work on microcontrollers and how pwm is generated, this is awesome. I just made a pwm on AT89C2051 chip :))

  • @PCBMakerBD
    @PCBMakerBD7 жыл бұрын

    I am from Bangladesh, Your working is great for new learner.

  • @your.free.electrons
    @your.free.electrons3 жыл бұрын

    I loved this explanation...I'm presently working on a project with atmega 8a :')

  • @BillySugger1965
    @BillySugger19657 жыл бұрын

    Great video Scott! I use the atXMEGA series of processors, and always run a 1ms interrupt which does just two things: it sets a sync flag, so I can synchronise main loop processes to the timer without having interrupts disabled for a long time in the ISR; and increments a signed long value called time, which I use to keep track of timeout conditions for processing. Very powerful, takes very little processor resource and ties up the processor in ISRs (which block other interrupts) the least.

  • @HersonBagay

    @HersonBagay

    4 жыл бұрын

    The xmegas support multilevel interrupts so you can always interrupt an ongoing ISR. Perfect for ultra time critical task

  • @kingvarus
    @kingvarus7 жыл бұрын

    digger ich hab keinen plan wovon du redest, aber ich schau jedes video! weiter so

  • @hubercats
    @hubercats3 жыл бұрын

    Very helpful video. Thank you!

  • @curiegupta7585
    @curiegupta75854 жыл бұрын

    Thank you for sharing the knowledge :)

  • @williefleete
    @williefleete3 жыл бұрын

    been driving a large matrix of LEDs from an LED sign I reverse engineered. Using the timer helps to keep the display showing something and still execute other code without having to call the routine regularly, had to use a different prescale value and pre-load the counter to tweak the refresh rate but works great now

  • @jacobpaniagua8785
    @jacobpaniagua87857 жыл бұрын

    Love the alarm tune!

  • @jayanthabandara9871
    @jayanthabandara9871 Жыл бұрын

    What a great explanation

  • @CJ-yj1qw
    @CJ-yj1qw2 жыл бұрын

    Great video! very educational!

  • @BreakingYTown
    @BreakingYTown7 жыл бұрын

    you are a mind reader...I was just thinking that there has to be a better way for my IOT home automation devices to poll the server without clogging the loop function...this is pretty awesome!!! thanks for the help

  • @ratchet1freak
    @ratchet1freak7 жыл бұрын

    I really enjoy this kind of arduino stuff. It's really hard to find someone willing to poke the control registers directly and go around the arduino's standard library.

  • @apurvsharma1261
    @apurvsharma12617 жыл бұрын

    LUV U GREAT SCOTT KEEP UPLOADING

  • @programer0713
    @programer07137 жыл бұрын

    Ooookey, first GreatScott video that i dont understand completly.

  • @CIOWhitepapers
    @CIOWhitepapers4 жыл бұрын

    Great explanation. Thanks!

  • @_ninjax8
    @_ninjax87 жыл бұрын

    mind blowing video!!

  • @sunny90908
    @sunny909087 жыл бұрын

    Nice video!!! Has been a fan for long time!!

  • @greatscottlab

    @greatscottlab

    7 жыл бұрын

    Thanks mate :-)

  • @sunny90908

    @sunny90908

    7 жыл бұрын

    GreatScott! Have you read Microprocessor in your Undergraduation!!??

  • @wisnuindrawan6496
    @wisnuindrawan64965 жыл бұрын

    thanks great scout :D you are my hero

  • @kalifack
    @kalifack7 жыл бұрын

    like always Dope videos ! :D

  • @anandhakrishnant6788
    @anandhakrishnant67887 жыл бұрын

    Great!! love ur videos .

  • @KanalMcLP
    @KanalMcLP7 жыл бұрын

    Finally! I had to do his very complex and unnescessary before ... Would be nice if you said whats the slowest possible timer (where you dont have to count the ticks).

  • @cemf4330
    @cemf43304 жыл бұрын

    I thougt i knew everything about arduino, then i saw this. Wonderful my friend youre a hacker

  • @rahim9568
    @rahim95682 жыл бұрын

    Thank you so much, even if i didn't understand some points.

  • @rahulvc7791
    @rahulvc77917 жыл бұрын

    Hi great video

  • @MrMANOJVELMURUGAN
    @MrMANOJVELMURUGAN5 жыл бұрын

    Its an awesome video. Thank you

  • @ferreirasilva101
    @ferreirasilva1017 жыл бұрын

    hey great scott say hello from Brazil!!

  • @themonkeyminds7252
    @themonkeyminds72527 жыл бұрын

    great scot sir great video...

  • @sonypiplode8750
    @sonypiplode87507 жыл бұрын

    Quality videos thanks for sharing

  • 7 жыл бұрын

    A very hart topic explained very simple! Good work!!!!

  • @greatscottlab

    @greatscottlab

    7 жыл бұрын

    Thank you

  • @ferr4226
    @ferr42264 ай бұрын

    holy, finally found my mistake after hours. thank you, good sir.

  • @capdsl19
    @capdsl197 жыл бұрын

    great video, I remember a project that I made, a clock With an Arduino, it was hard and doesn't work perfectly

  • @MCsCreations
    @MCsCreations7 жыл бұрын

    Really, really nice!

  • @IBasilisvirus
    @IBasilisvirus6 жыл бұрын

    Best tutorial about timers. Tha ks

  • @azzu9098
    @azzu90987 жыл бұрын

    Cool video! thnx bro!

  • @DwiNoviantoUntidar
    @DwiNoviantoUntidar Жыл бұрын

    Super explanation....

  • @robinsonargumero992
    @robinsonargumero9927 жыл бұрын

    Hello. Good video, greetings from Colombia

  • @greatscottlab

    @greatscottlab

    7 жыл бұрын

    Thanks mate :-)

Келесі