Level Up Your Arduino Code: Timer Interrupts

แชร์
ฝัง
  • เผยแพร่เมื่อ 18 ก.พ. 2018
  • If you’re not familiar with working directly with registers or how interrupts work, we recommend viewing the previous lessons on leveling up your Arduino code.
    Registers: • Level Up Your Arduino ...
    External Interrupts: • Level Up Your Arduino ...
    On this episode of Adventures in Science, we continue diving into what makes Arduino tick. We examine the inner workings of the Microchip ATmega328P microcontroller, specifically looking at how to set up timer interrupts. We start with the always fun and ubiquitous “blinky” program and change it to flash an LED outside of the main program loop. These advanced concepts in Arduino programming can help you write more space efficient and faster embedded code.
  • วิทยาศาสตร์และเทคโนโลยี

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

  • @ceneblock
    @ceneblock 2 ปีที่แล้ว +13

    I like that you reference the datasheet. That's how people are going to move from online examples to learning and doing things on their own.
    Only thing I would change would be the math part. I was able to follow it after rewatching, but it was a little confusing at first.

  • @orignal29
    @orignal29 5 ปีที่แล้ว +126

    I was searching for this exact topic and found this video. When I saw the intro, I thought "oh great another beginner video with cheezy analogies", and almost closed its tab. Lucky me, I didn't. This turned out to be exactly the level I needed (what I consider intermediate). The language was clear and with the right amount of details for me. I liked the fact that the presenter didn't assume I already knew everything while keeping a good technical level. It's obvious a lot of thoughts have been put into the script. Well done!

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

      Very well said. I had exactly the same thoughts about the video.

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

      Exactly

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

      @Bruce Snode hello bruce, can you help me correcting my code?
      actually i need make 1000Hz frequency sampling for my EMG signal in arduino uno
      but the result cant be sharp at 1000Hz
      here my program
      const int analogInPin = A0; // Analog input pin that the potentiometer is attached to
      const int analogOutPin = 3; // Analog output pin that the LED is attached to
      int sensorValue = 0; // value read from the pot
      int outputValue = 0; // value output to the PWM (analog out)
      void setup() {
      // initialize serial communications at 9600 bps:
      pinMode(3,OUTPUT);
      Serial.begin(9600);
      noInterrupts(); // disable all interrupts
      TCCR1A = 0;
      TCCR1B = 0;
      //TCNT1 = 65484;// preload timer 65536-16MHz/256/1200Hz
      //TCNT1 = 65411;// preload timer 65536-16MHz/256/500Hz
      TCNT1 = 65473;// preload timer 65536-16MHz/256/1000Hz
      //TCNT1 = 65503;// preload timer 65536-16MHz/256/2000Hz
      //TCNT1 = 34286; // preload timer 65536-16MHz/256/2Hz
      TCCR1B |= (1

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

      you all prolly dont give a shit but does anybody know a tool to log back into an Instagram account..?
      I was dumb forgot the login password. I appreciate any tricks you can give me

    • @MohamedAshraf-vh3jo
      @MohamedAshraf-vh3jo 2 ปีที่แล้ว

      Right you said!

  • @ymemag9861
    @ymemag9861 6 ปีที่แล้ว +34

    Wow... Very well explained! I did have to watch it 6 times but... it's all there. AWESOME!

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

    The similarity is so uncanny I had to google it. Nope, not related, but definitely the Alton Brown of electronics. IMO, Good Eats is by far the best cooking show, and for the same reasons your videos are so good. Keep up the good work! Great content. Great presentation.

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

      I actually really appreciate this! Alton Brown and Bill Nye are my two biggest sources of inspiration for presenting on camera :)

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

    I had a embedded programming course on a ARM-7 platform. really taught me to embrace interrupts!

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

    These videos are gems! Very insightful for intermediate level which is hard to find in these days. Thank you very much! Keep up the great work!

  • @johnr3936
    @johnr3936 5 ปีที่แล้ว +10

    I genuinely want to buy your products for releasing this free, incredible information. Keep this trend up, I would love to keep learning about the depths of arduino.

  • @alakazellae-commerce9627
    @alakazellae-commerce9627 2 ปีที่แล้ว +1

    I like how Shawn says you can bink with this code
    //pins
    const int led_pin = 13;
    Void set()
    { pin_mode (led_pin; HIGH); [
    void loop() {
    digitalWrite(led_pin, HIGH);
    delay(500);
    digitalWrite(led_pin, LOW);
    delay(500);
    )
    or you can write this much longer code and get the same action. : P i know it for memory and more. It's just funny. SparkFun are the masters. To make a well-thought-out video. Telling how to do something with humor and technology with it not being too watered down.

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

    This is the best tutorial on programming Arduino timers! The programming journey from using "delay()" to bit banging timer registers and using ISRs was perfectly executed. The technical content and simple analogies were very well thought out and presented beautifully by Shawn. Despite this video being based on the Atmel 328P processor I was able to program the timer on an Microchip (Atmel) SAMD21. Well done SparkFun, keep making programming videos like these!

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

    Excellent video. I've learned all this years ago in school for another microcontroller, and this was a perfect video to get me up to speed with Atmel.

  • @WhoWantsToKnow81
    @WhoWantsToKnow81 5 ปีที่แล้ว +9

    Excellent tutorial.
    It gets a little more interesting when using an 8-bit timer - then you'll need to count the number of overflows ;)

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

    Thanks a bunch for this video! I really needed this info for an Arduino application in which timing between pulses is used.

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

    Very late, but this series has helped me a lot. Would Sparkfun consider making more such videos? This is such a great resource.

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

    This is exactly what I have been looking for. Great presentation and instruction

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

    Great video! I'll be back again to watch it a bunch more times :)

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

    this video have fixed up my project, I salute you

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

    Thank you so much for these great tutorials. Another thing I learned from your tutorials is to read datasheet 😂.

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

    those tutorials are gold !!! so clear and well explained. will you provide one about the ADC and how to scan several potentiometers using Analog Muxer ?

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

    Your ability to teach is outstanding 👍👍👍👍👍👍

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

    thanks sparkfun you are doing a great job. you guys are the best of the best

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

    Yeah I want to see more fun videos like these!!

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

    I hope your funding continues. You are really great.

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

    Whow, that tutorial is a very good one. Thank you very much!

  • @ColinRichardson
    @ColinRichardson 6 ปีที่แล้ว +19

    These tutorials are amazing.. Please don't stop..
    Do you have a road map of what you plan on teaching for all upcoming "Level Ups" ??

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

      Thank you! I don't have a road map, as it depends on where I'm needed. If I have time in between other projects, then I'd definitely like to continue them.

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

      One thing I would like to suggest is something I STILL struggle with, which is deep sleep..
      With the last two tutorials you have done, it has reinvigorated me with wanting to get the Arduino to sleep again and wake up and do something on a pin interrupt (button press) or a timer interrupt.. It would build on what you have been teaching us nicely

    • @ShawnHymel
      @ShawnHymel 6 ปีที่แล้ว +5

      Yes! I was thinking about that one, too. It would build on the interrupts nicely, and I could measure actual power consumption and equate that to battery life. If you're curious, Alex did a really good tutorial showing how to reduce power on the 328p: learn.sparkfun.com/tutorials/reducing-arduino-power-consumption. I don't know if it's exactly what you're looking for, but at least it's a start.

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

    Nice tutorial. Thanks!

  • @rubabvlogs1843
    @rubabvlogs1843 6 ปีที่แล้ว +7

    nice tutorial..keep it up sir..

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

    holy crap. This was amazing!

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

    Kindly make a tutorial on Wire library Your Adventure is so Informative every things perfectly cleared kindly make a tutorial on Wire library and how to access a specific Registers

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

    Love the intro!

  • @Gipsy_T.
    @Gipsy_T. 2 ปีที่แล้ว

    For those (like myself) that dont understand the

    • @Gipsy_T.
      @Gipsy_T. 2 ปีที่แล้ว

      I tried it with the = operator and still works example: TCCR5B = 0b00001010; with this method u dont have to clear the register

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

      @@Gipsy_T. i guess it overwrite it anyway

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

    video worth subscribing!!

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

    Hello Shawn Hymel,
    I can't tell you how much I enjoy your series! Fantastic to say the least. Keep up the great work. One important question. How can I get the valuable code you teach us so we may try it ourselves? It would be so much help to us so we may understand more of your important information?
    Dave

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

      Thank you, and good question! I've uploaded the final form of the code as a Gist to GitHub, so you can dissect it at your own pace: gist.github.com/ShawnHymel/d36e527928994150f5fc3cba20dd2161

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

    wholly smokes that definitely over my head, was following well, comprehending ok for first third of video, but by 12 minutes i could smell smoke, but great video, hope it is here to revisit when I get more advanced, was good to touch on the more rudimentary operation of the 328p

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

    great video. Thanks a lot.

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

    if you want all your code in an ISR so it runs at a predictable rate, what should you put in loop()? just a delay like in this example or nothing at all? great videos. thanks

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

    Excellent video.

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

    I want to know if its possible to change the value of OCR1A when the timer is working.
    What i want is to generate Pulse train in which the ON time is fixed and the OFF time changes as per the formula that i already have.
    Is it possible to do this using your explanation of timer in this video.(I think it is) but i don't exactly know which register work with.
    Thanks for the awesome explanation

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

    Thank you for your videos! I have a question, how can I implement this for counting RPM from an incremental encoder? Appreciate your help

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

    What documentation did you find Arduino timer uses'? i would like to find out what the atmega2560 timers are used for so i can utilize the correct one for my application.

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

    could you please provide a link for the datasheet?

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

    good tutorials, one zan!

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

    Great comic timing. Interesting subject.

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

    Should have reset TCCR1B as well. Didn't work here at first because of that. Still great tutorial!!!

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

    Hii
    Tutorials are priceless , Dear i want to read BCD output of 7135 ADC through timer1 in uno . how i will get the values serially coming out from ADC .
    which registers we will use .

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

    thanks, i was curious if arduino allowed for direct programming of the ATMega chip, instead of their silly API.

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

    Hi, thank you for this great video. You are writing a ISR function but where did you find this information ? from the arduino documentation ? I’m not able to find this. You are also using a variable named TIMER1_COMPA_vect , but how you find it ? Even for the sei() function. Also what’s AVR. could you make another video about it ?

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

    Wow. Exact answer to a problem I had.

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

    You saved my life

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

    Can I use both compare registers A And B at the same time to creat two interrupts at different intervals ?

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

    Thank you for the video but I have a question how make a code for the timer that you had the white box how to make a code like that one..??

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

    One couldn't explain it better.

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

    Awesome video

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

    please provide the datasheet specifically used in this lecture
    there are many available online

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

    Hello. Thank you! It will be very helpful if you make an episode for Timer interrupts for the Atmel SAM3X8E. (Arduino Due)

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

    great video

  • @idogendel
    @idogendel 6 ปีที่แล้ว +10

    And before we know it, we'll be using the Atmel Studio IDE ;-)

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

      Why use that bloatfest when you could use Great Cow BASIC?

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

      Actually I'm a fan of Pascal :-)

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

      I actually enjoyed Atmel Studio when I used it a few years ago. I'm just really sad that it's Windows-only :(

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

      It's ok to love Microsoft nowadays, because with Google and everything they're totally the underdog ;-)

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

      No, just because one guy ain't up to snuff, doesn't mean the other guy is OK - true also of politics. Maybe both are a problem.

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

    Good show, Shawn. The info at 3:51 used to take a deep dive into the arduino base code or a heck of a lot of googling to find someone else who had. It's really nice to know what interacts with what or what's already in use - engineering is all about trade-offs.
    i see you're now saying "left shift" - it seems fine to allow the beginner to ponder why C used "less than less than" to make numbers bigger...at least it's visually mnemonic. To rag on you just a little further (17:21) - you might take a sentence to say that you're using the various &= and |= (and equals, and or equals) constructs to just affect the bits you want, rather than just jamming the register (since we don't know what the other bits were and don't want to affect them).
    To a noob, that might seem like a hard to understand bunch of back and forthing...so it's good to say why it's actually a good way, and why writing whole registers might cause an issue.
    Now, if we only had the same level of cheat-sheet for the ESP8266 (or ESP32)...which would be a good platform to mention that this is all processor dependent and why we sometimes do it the slower/less efficient way in C (because #ifdefs in header files and macros make the code changes needed for us).

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

      Yes, thank you for the "left shift" tip! I did mention the single bit flip &= and |= operations in a previous episode, which is why I'm glossing over them here.
      Totally agree with the ESP series. They're fun, cheap little chips, but the documentation is lacking. Perhaps that's what I'll look into next :)

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

      You're most welcome. The observations stem in part from the fact that I've recently been asked to teach a few beginners myself - "kids ask the darndest questions" - which helps me remember what it was like to be one. I didn't catch all the episodes so I missed that.
      (Hint, I'm getting you to do some of my work for me here... ;~)
      I spent some time looking for info on the ESP-8266, or more specifically the Tensilica (now Cadence) L106 processor, but haven't gotten very far. Cadence only publishes overviews of what appears to be very customizable silicon, the specifics of this seem hard to find - which means that if you guys can find them - very valuable. This is as far as I got: ip.cadence.com/knowledgecenter/resources/know-dip-ds No datasheet like the Atmel so far. I'd hope they aren't so precious with their IP as to make it unusable by keeping the instructions secret! Maybe a deep dive into the source of their libraries? I'd done this for the Uno long ago, to find out things like which timer was already in use for millis() and so on, but wow, this is pretty daunting.

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

      I suppose we could always compile different C instructions and take a look at the machine code to decipher what the assembly instructions might be. That sounds like lot of not fun to me, though :P

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

      No, and it shouldn't be required...but what I can think of so far (other than pinging them to get them to give us a datasheet - where you guys would have more clout than I) might be to look at the defines etc in their code for things like i/o register addresses, usages, and such. After all, most of the arduino C peripheral libraries are pretty well mapped to this thing somehow. I bet it's macros and ifdef kinda stuff, I doubt they re-wrote the world. Time to work up the grep-fu, I guess. The whole world using these things stands to benefit...This isn't as hard to find on the ESP32 as it gets its own obvious directory under Arduino/hardware/... with all kinds of neato header files and info...looking for the 8266...It seems to be hiding elsewhere.
      Ah, a quick search of my linux box shows me these (as a place to begin to start, still, yuck):
      /home/doug/.arduino15/packages/esp8266/hardware/esp8266/2.4.0/cores/esp8266/Arduino.h
      /home/doug/.arduino15/packages/esp8266/hardware/esp8266/2.4.0/tests/device/libraries/BSTest/src/BSArduino.h
      /home/doug/.arduino15/packages/esp8266/hardware/esp8266/2.4.0/tests/host/common/Arduino.h
      Which of course include all manner of other .h files, but I'd bet what we want is in there...and we know it works.

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

      Nice sleuthing! I do find it interesting that the ESP32 has a datasheet, but it doesn't cover anything about the instruction set or architecture.

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

    When I write server program for wify using arduino ide in practical case I experience the serveris not active once the input current is not available for a while and then restarted .Can you please explain a good code for wify server using arduino ide using registers .

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

    In the viedo is shown CTC option when Compare is match.
    But it is done using OCR1A register.
    Is it possible to select OCR1B as TOP with CTC option???

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

    I do not know if you could do a routine where two inverted signals are treated, you know, with dead time to control inverters, thanks a lot

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

    Where can i get the manual?

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

    just curious why use &=for CS11 and CS10 while using |= on CS12? i know one is compound bitwise and while the other are compound bitwise or. but i have tried a couple of variation of the bitwise but it didnt change anything

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

    I have a ned for 3 timer interrupts. Is this possible? I am using a SAMD board.

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

    This made me feel smart hehe

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

    I have a question : is there a way to do away with the instruction "delay(500)" ? If we have a timer, do we really need to add a delay ?

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

    Very good indeed.
    Question: Portability aside, what is the benefit of writing strings of shifted-bit constructs like (15:57)
    TCCR1B |= (1

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

      I think it's just easier to read. If you take a 1 and shift it left 10 or 11 or 12 bits like they are doing here it is obvious exactly what bit in the destination register is being targeted, that is bit 10 or 11 or 12. Sure, for bit 12 they could just XOR it with 4096 decimal or 1000 hex instead, but I certainly don't remember off the top of my head that 4096 equals bit 12. Whereas if you see the CS12 you know without having to work it out that it's bit 12 that will be affected.

    • @Henry-sv3wv
      @Henry-sv3wv ปีที่แล้ว

      easier to read is:
      bitWrite(TCCR1B, CS12, 1);
      bitWrite is a macro defined in Arduino.h

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

    funny, cute, im 18 secs in and already hooked

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

    You should make more videos!!!!

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

    I have searched the Internet high and low. I am looking for information on how to use the i2c pins on this sparkfun blackboard Ad4 -sad and ad5-scl as I would use a4 and a5 on the Arduino? Can’t find any instruction sheets or Arduino code anywhere. I use i2c on real Arduino without problems.

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

    FYI: The Crystal Resonator on the UNO and MEGA is only connected to the little microcontroller, that is handling the USB communication.
    The main Microcontrollers (328 and 2560) have FAR LESS ACCURATE 16Mhz ceramic resonators as clocks!

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

    First, delay(500) does not need in loop.Just modification of tl_comp = 31250 is 0.5 sec; multiplication by 2 is 1 sec, or division to 2 is 125 millisecond.

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

    can you do tutorials on the samd21? its very different.

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

    so, if I wanna toggle led every 1s,
    change like this : const uint16_t t1_comp = 62500;
    and disable interrupt with change value OCCIEA like this: TIMSK1 = (0

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

    youre amazing...

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

    (shawn hymel sir help me) iam trying to measuring the freq and time period for square wave(iam using input capture metrhod), i connect signal to digital pin no 8 i.e ICP1. TCNT1 is automatically stored in ICR1 register while rising Edge, im setting for Falling edge TCNT1 is stored in ICP1 reg again for rising edge(means here is it taking for 1 cycle 0 to 65535 ??). how this is working am not getting please any one explain or send me any videos link iam struggling from past 2 weeks pls help me....
    rising edge means TCNT1 is incrementing upto 65535 or ??
    then what values TCNT1 is taking during falling edge.....

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

    I liked how above this was. I got lost when you were setting bits on with shift. There has to be an easier way. Like a hex number maybe or simply HIGH. My Question is Shouldn't Tload be not zero but the time it takes to execute the interrupt code?

    • @Gipsy_T.
      @Gipsy_T. 2 ปีที่แล้ว

      Yeah i got lost too, u can use the operator |= to do the same thing bit by bit.
      For example timer 5 on arduino mega:
      TCCR5B=0; // You have to clear the register first!!
      TCCR5B |= 0b00001010; /*the last 3 bits set the internal clock with a 8 preescaler, the previous bit sets the CTC mode
      0b00001(010) this bits set the preescaler
      0b0000(1)010 this bit sets the ctc mode*/

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

    Good tutorial, but it would be helpful if text was larger on sketches.

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

    Please make a video about Pointer Access Operators

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

    how does timer1 affect the servo functions? is it because of the delays being too big?

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

      I would imagine that the servo functions are affected because they rely on a specific frequency from timer1 (as configured in its default state) to control the timing of signals sent to the servos. When that timing is changed, the servo functions can't operate normally.

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

    AMAZING

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

    Hi ,
    I have a problem in a code that uses IRreciver reading to toggle in switch statement I have 3 cases the first 2 cases work great with timer interrupt because they're simple just turning on/off a led , but the third one it's not responding to the interupt because it's a hell of a long cooooode , is there any way using timer interrupts to get out from that case even if the code still running ?
    void setup()
    {
    //Setup pin modes
    pinMode(buzzerPin, OUTPUT);
    pinMode(ledPin3,OUTPUT);
    pinMode(ledPin1, OUTPUT);
    pinMode(ledPin2, OUTPUT);
    pinMode(redPin,OUTPUT);
    Serial.begin(9600);
    irrecv.enableIRIn(); // Start the receiver
    Timer1.initialize(10000);
    Timer1.attachInterrupt(Iremote);
    }
    void loop()
    {
    switch(results.value){
    case 0xFFE21D : digitalWrite(redPin,HIGH);

    break;
    case 0xFFA25D : digitalWrite(redPin,LOW);
    break ;
    case 0xFF02FD: digitalWrite(redPin,LOW);

    //Play first section
    firstSection();
    //Play second section
    secondSection();
    //Variant 1
    beep(f, 250);
    beep(gS, 500);
    beep(f, 350);
    beep(a, 125);
    beep(cH, 500);
    beep(a, 375);
    beep(cH, 125);
    beep(eH, 650);
    delay(500);
    //Repeat second section
    secondSection();
    //Variant 2
    beep(f, 250);
    beep(gS, 500);
    beep(f, 375);
    beep(cH, 125);
    beep(a, 500);
    beep(f, 375);
    beep(cH, 125);
    beep(a, 650);
    delay(1000);
    break ;
    }}
    void Iremote(){
    if (irrecv.decode(&results)) {
    Serial.println(results.value,HEX);
    irrecv.resume();
    return ;
    }
    thanks in advance .

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

      You shoud not use Serial inside of interrupts. it would be better to make your interrupt as short as possible. An example would be to set a flag with your interupt if your parameter is met. Then let your loop code check for the flag and run the code there. you should also try and get rid of the delays they can avoided with interrupts and just doing stuff that is needed to be done while just watching the clock. Here is a link that has an serial in the interrupt. arduino.stackexchange.com/questions/46595/sending-serial-data-in-an-interrupt

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

    I feel like timers would be such a useful thing but geez it's taking a while to figure out which timer to use, whether I've got anything that's dependant on it which would be affected by adjusting the prescaler etc

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

    0:22 where is the previous videos? Why Arduino videos not in you Playlist of the channel? Please make the proper playlist!

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

    Please make a video using PWM with registers

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

    still confuse about icr mode

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

    Please help me I can’t find out how to do this ..!!

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

    Isn't the AVR internal frequency 8 MHz?
    Why did you stated 16 MHz?

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

    Is the code somewhere to be found or am I overlooking something? Great explanation btw. Very, very good. 👍

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

      Sorry for the late response. It isn't listed in the description, but it can be found here: gist.github.com/ShawnHymel/d36e527928994150f5fc3cba20dd2161

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

    You can do, TCCR1B |= (1

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

    Compliant electrons rule !

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

    I don't understand, what's the point?
    What does this accomplish?

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

    It would be nice if you numbered your lessons.

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

    excuse me, anyone to help my theses ?
    i need prepare frequency sampling at my arduino uno as 1000Hz
    i use this program but cant sharp at 1000Hz
    can you help me ?
    actually i check it on osiloscop
    const int analogInPin = A0; // Analog input pin that the potentiometer is attached to
    const int analogOutPin = 3; // Analog output pin that the LED is attached to
    int sensorValue = 0; // value read from the pot
    int outputValue = 0; // value output to the PWM (analog out)
    void setup() {
    // initialize serial communications at 9600 bps:
    pinMode(3,OUTPUT);
    Serial.begin(9600);
    noInterrupts(); // disable all interrupts
    TCCR1A = 0;
    TCCR1B = 0;
    //TCNT1 = 65484;// preload timer 65536-16MHz/256/1200Hz
    //TCNT1 = 65411;// preload timer 65536-16MHz/256/500Hz
    TCNT1 = 65473;// preload timer 65536-16MHz/256/1000Hz
    //TCNT1 = 65503;// preload timer 65536-16MHz/256/2000Hz
    //TCNT1 = 34286; // preload timer 65536-16MHz/256/2Hz
    TCCR1B |= (1

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

    The code needs to be cleared please, it is too blurry and too small.

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

    Its not so beginner-friendly if you ask me. I got it all right, but I feel it could have been easier.

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

    can u plz help me generate 1khz sine wave using arduino i need it asap i will be hugely grateful

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

    This would have made more sense if you had told the viewers you were using Compound Operators or just written it out in longhand format. Still a good video though.

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

    Can you please write a code that i can upload in Arduino, I want a Small beep sound at 30mins, 1hr, 1:30hr, 2hr(all optional )

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

    All this - to save one line of programming code?
    *faint*
    :-)

  • @codeman99-dev
    @codeman99-dev 3 ปีที่แล้ว +1

    11:25 Because it is so hard to shift around a base 16 number. I mean, I love convenience, but the tutorial up to this point is anything but that.