Electronic Basics #30: Microcontroller (Arduino) Timers

แชร์
ฝัง
  • เผยแพร่เมื่อ 15 ก.ค. 2017
  • 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)
  • วิทยาศาสตร์และเทคโนโลยี

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

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

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

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

      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 ปีที่แล้ว +6

      @@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 4 ปีที่แล้ว +3

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

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

    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 ปีที่แล้ว +2

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

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

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

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

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

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

      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 ปีที่แล้ว +2

      +1

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

      Me too!

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

      I watch this for scool haha

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

      feel it

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

    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
    @edtix 6 ปีที่แล้ว +5

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

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

    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 6 ปีที่แล้ว +8

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

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

      I also didn't know that. Thanks!

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

      Robert Miles
      I read your comment and understood that you are not nitpicking, but genuinely want to help a good TH-camr 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 TH-camrs.

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

      There better option with timer

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

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

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

    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!

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

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

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

    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.

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

    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!

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

    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!

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

    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.

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

    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!

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

    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!

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

    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!

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

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

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

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

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

    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.

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

    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!

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

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

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

    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!

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

    This is certainly the best kind of videos you make

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

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

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

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

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

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

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

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

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

    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  6 ปีที่แล้ว +17

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

  • @ix8inside891
    @ix8inside891 12 วันที่ผ่านมา

    best Explanation to that topic I've ever heard

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

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

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

    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!

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

    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.

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

    This is amazing! Thanks for doing these!

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

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

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

    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.

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

    Why 16 Mhz would equal to 1 Sec. ??

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

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

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

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

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

    Great video, very helpful keep up the good work!

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

    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 6 ปีที่แล้ว +4

      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 6 ปีที่แล้ว

      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.

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

    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.

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

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

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

    Thanks a lot dear Scott for your knowledge

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

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

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

    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

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

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

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

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

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

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

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

    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  6 ปีที่แล้ว +19

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

    • @JoaoSilva-jr9ez
      @JoaoSilva-jr9ez 6 ปีที่แล้ว +4

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

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

      Same here, just as I finished my audio amplifier project to drive some speakers from an old radio, Scott uploaded a tutorial about that.

  • @4-n0t-found-4
    @4-n0t-found-4 2 หลายเดือนก่อน

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

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

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

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

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

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

    Thank you for sharing the knowledge :)

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

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

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

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

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

    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.

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

    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.

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

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

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

    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
    @k1ckcyph3r16 6 ปีที่แล้ว

    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.

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

    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 :))

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

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

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

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

  • @your.free.electrons
    @your.free.electrons 3 ปีที่แล้ว

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

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

    What a great explanation

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

    Great videos Great Scott! You could also include in your videos not just the details on how these function but also how you got there, your thought process and the like

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

    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.

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

    Love the alarm tune!

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

    Very helpful video. Thank you!

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

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

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

    LUV U GREAT SCOTT KEEP UPLOADING

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

    Can you share the book mentioned on this video

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

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

  • @tharii314
    @tharii314 8 หลายเดือนก่อน +2

    You need to revise the captions. I saw an "Admirer Predator 8 p" microcontroller in place of an Atmel "ATMega328P" Microcontroller.

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

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

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

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

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

    Hi, any chance you could do a video on the HC-12 wireless module and the Arduino? You did the HC-05, so could you do this one too? I found out about it today and I would like to learn more about it. Thx!

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

    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

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

    thanks great scout :D you are my hero

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

    Hi great video

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

    Quality videos thanks for sharing

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

    Great explanation. Thanks!

  • @CJ-yj1qw
    @CJ-yj1qw 2 ปีที่แล้ว

    Great video! very educational!

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

    Best tutorial about timers. Tha ks

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

    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

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

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

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

    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.

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

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

  •  6 ปีที่แล้ว

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

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

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

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

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

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

    Ooookey, first GreatScott video that i dont understand completly.

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

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

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

      Thanks mate :-)

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

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

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

    Thanks for this video it helps a lot,
    But I have a question, can we increase the sampling rate of arduino using timer or any other way.bcoz I want to built a class d amplifier using an attiny85, since you said using a uC in making a circuit is better than using many ICs.Thanks in Advance

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

    Super explanation....

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

    if I'm not wrong there is an included library for timers in Arduino IDE. I used a timer in the past with ESP8266 as micro controller and I did not alter registers directly. Pretty sure you can do the same on Arduino

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

    great scot sir great video...

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

    For all those commenting that they didn't understand anything, read the datasheet. It's all there, in unintuitive locations, using awfully confusing and cryptic language. You'll have to go back and forth and reread the same stuff several times to get something to work, you can't expect to watch a 10 minutes video and have everything in your head by the time in ends.
    If you're planning to stick to this device, the best thing you could do is print a physical copy of the datasheet, you can remove unnecessary segments like electrical characteristics and such in order to reduce the printing cost. Or you can even print the datasheet of some more complex controller that you think you'll use in the future, the common modules like timers 0-2 or A/D converters are usually the same for the whole family.
    The more I learn about Arduino, the more I like pics, everything is way more clear and straightforward.

  • @Max-hf7fx
    @Max-hf7fx 7 หลายเดือนก่อน

    Great Video, but keep in mind. (Why inaccuracies can still occur?):
    Clock Source: The accuracy of the microcontroller's internal clock can vary. For precise timekeeping, consider using an external quartz clock source or another stable clock signal.
    CPU Clock Variations: Variations in the microcontroller's CPU clock frequency, not precisely at 16 MHz, can lead to deviations. External factors like temperature changes can influence this.
    Timer Resolution: Microcontroller timers have limited resolution. In your case, using a 16-bit timer means that the smallest time unit you can measure is constrained by the timer's resolution, potentially causing small discrepancies.
    Interrupt Delay: The timing of interrupt processing can introduce slight delays. Other interrupts or additional tasks within your ISR can affect the time it takes for the timer to trigger accurately.