Improve your Arduino programming skills - The qualifier volatile explained.

Sdílet
Vložit
  • čas přidán 27. 08. 2024
  • In this video I like to focus on the keyword volatile. Volatile is a qualifier that can be applied to a variable when it is declared. When you search this keyword you will probably find that a variable always needs to be declared volatile when it’s changed in an interrupt routine.
    But why, and what is it exactly that this volatile qualifier does? Let’s find out with the help of some examples.
    Other “Improve your Arduino programming skills” videos:
    • Improve your Arduino p...
    Hexadecimal information can be found here:
    en.wikipedia.o...

Komentáře • 58

  • @Lkabouter
    @Lkabouter Před 5 lety +4

    A very nice explanation of the volatile keyword ! Great !
    It is mainly used when programming interrupt routines and perhaps it is usefull also emphasizing another important thing when using this volatile keyword when programming interrupts:
    If the volatile variable consists of more than one byte ( a 16 bit int or a 32 bit long variable), the microcontroller can not read it in one cycle, because we are (often) dealing with 8 bit microcontrollers. This means that sometimes while the main code is reading the first byte of the volatile variable, an sudden interrupt can allready change the next byte of it ! This is often forgotten and can produce hard to find "now and then" errors in the value of this volatile variable !
    A solution is to disable the interrupts while reading the volatile variable in the main code, so the individual bytes of this volatile variable will be "kept together".

  • @coldwolf6735
    @coldwolf6735 Před 6 lety +8

    This is one of the most enlightening series I have ever watched. Thank you for sharing your knowledge, you are doing a very great job explaining engineering at it's finest. If possible please upload more on this series, it is like treat for budding engineers like me. Bless you.

  • @ELECTRONOOBS
    @ELECTRONOOBS Před 7 lety +35

    In name of all electro'noobs I say thankyou!

    • @mpls_link
      @mpls_link Před 7 lety

      electronoob am your follower on instagram, check out my IG @hello_inventions

    • @barunbasnet
      @barunbasnet Před 3 lety

      Wow

  • @KrisTemmermanNP
    @KrisTemmermanNP Před 7 lety +2

    Thanks for your great tutorials Joop!
    It really inspires me to up my game when it comes to Arduino programming :)

  • @cloudlee1027
    @cloudlee1027 Před 2 lety

    Nice tutorial, especial the last example.

  • @Jlousauvage
    @Jlousauvage Před 4 lety

    So good pedagogic content

  • @pirateman1966
    @pirateman1966 Před 6 lety +1

    damn dude... you should do more videos. you're so good at it.

  • @josef.prosek
    @josef.prosek Před 7 lety +2

    Absolutely fantastic :) Thank you.

  • @AxelWerner
    @AxelWerner Před 7 lety

    EXTREME VALUABLE VIDEO !!! Thanks mate!!!

  • @edilsonfernandes4703
    @edilsonfernandes4703 Před 7 lety

    Awersome explanation! Thanks a lot and tumbs up again of course!

  • @PoulBundgaard
    @PoulBundgaard Před 6 lety

    This is a very good explanation. Please keep up the good work :)

  • @MC-Cali
    @MC-Cali Před 7 lety

    I really like your Bigbird and Elmo images in the diagram

  • @ChrisFredriksson
    @ChrisFredriksson Před 7 lety

    I've learned a lot! I knew maybe about 5% of what you said, so the rest is new knowledge =D Really nice, for my brain, that you used the cartoons, made it a little bit easier to follow!
    I haven't used volatile a whole lot, but when I have its because I "had" to.. well, I tried without and found that it didn't work, tried volatile and then it did work =D Now I know a little more, so I will hopefully be able to use it more responsibly and more accurately =) Thanks!

  • @tameroran5551
    @tameroran5551 Před 5 lety

    Thanks for the clear and valuable explaining

  • @VDDThomas
    @VDDThomas Před 7 lety

    Very nice video series, and well explained; thanks!

  • @Avionics1958
    @Avionics1958 Před 7 lety

    what a fantastic tutorial. thouroughly enjoyed it.

  • @tiagovla
    @tiagovla Před 7 lety

    Your videos are great! Show us more about the atmel studio.

  • @FisVii77
    @FisVii77 Před 7 lety

    Awesome Job brother, keep up the good vids :)

  • @andreashotzel172
    @andreashotzel172 Před 7 lety

    Hi Joop, this is another nice video. I like it, good job. :-D

  • @wargaming67
    @wargaming67 Před 7 lety

    Fantastic and very useful videos. Thank you for your work :)

  • @phinok.m.628
    @phinok.m.628 Před 4 lety

    How does your program at 8:25 not freeze at the delay(10) if timer 0 is disabled?

  • @nmgreg11
    @nmgreg11 Před 6 lety

    Outstanding video. Thank You!

  • @incxxxx
    @incxxxx Před 4 lety

    How you switched to hexdecimal view??? I couldnt find this way.

  • @Dekan88
    @Dekan88 Před rokem

    Hi, where can we buy the Atmel debugging tool and the software? for Arduino?

  • @VentoRacing1
    @VentoRacing1 Před 7 lety

    Great job presenting this.

  • @jeanpierredaviau7478
    @jeanpierredaviau7478 Před 4 lety

    Do we need Atmel Ice to be able to see the stack, the mrmories, etc.?

  • @mpls_link
    @mpls_link Před 7 lety +1

    very nice video, well explained, thanks

  • @rahulr9301
    @rahulr9301 Před 4 lety

    great video....what you mean is in first example the bigbird variables value is copied from flash and in second example the bigbird variable is copying from sRAM , please correct me if iam wrong.

  • @ilyakos8178
    @ilyakos8178 Před 5 lety

    impressive work, thank you!

  • @IGBeTix-Electronique
    @IGBeTix-Electronique Před 7 lety

    The volatile is used to make temporary timers.

  • @JesseBaker121
    @JesseBaker121 Před 7 lety

    Great video dude!

  • @Ringer1982
    @Ringer1982 Před 6 lety

    Hi. I tried to debug Arduino with Atmel ICE and it showed me the message that the fuses should be modefied, I click OK button, it showed the message that I must toggle the power, I did. After that I see errors and the ATMEGA chip is no longer recognizable by Atmel Studio... What can I do now? I saw some mentioning that a pull up capacitor on Arduino board is interfering with the debugger but I don't know if that's true and where that capacitor on the Arduino board...

  • @H1ghtower3
    @H1ghtower3 Před 7 lety

    great explanation!

  • @sh8zen
    @sh8zen Před 4 lety

    Joop, great video!
    So is it only Atmel Studio that defaults to Optimizing some data this way?
    I've had unexpected results with AVR chips when working in AS7 that I don't have in PlatformIO on VScode. I wonder if some of my data was optimized away.

  • @patrickvangulik4680
    @patrickvangulik4680 Před 7 lety

    Very nice video. Thanks!!!!

  • @knki_95
    @knki_95 Před 6 lety

    Can you kindly make a similar video on static qualifier?

  • @SumitKumar-fc4bq
    @SumitKumar-fc4bq Před 7 lety +2

    when new videos coming ??? :)

  • @noijze
    @noijze Před 7 lety

    Hi Joop, quick question; how did you manage to use the DebugWire on the arduino board. I'm able to read out the fuses and other data via the SPI interface with the ICE, but when try the debugwire i get some errors saying that it doesnt support the interface. thanks for the great series so far ! groetjes

    • @Joop_Brokking
      @Joop_Brokking  Před 7 lety +1

      Next to the 16MHz crystal you see two blobs of solder with a small line between them (RESET EN). You need to cut this wire to activate the debug wire.
      To get it to work again with the Arduino IDE you need to disable the debug wire fuse, solder a bridge between the pads and burn the bootloader.

  • @nldestinyx1440
    @nldestinyx1440 Před 7 lety +2

    Are there any new videos coming out? 😁😁

    • @Joop_Brokking
      @Joop_Brokking  Před 7 lety

      Sorry, I have very little time to make videos. I'm currently working on a new project but it takes a lot of time to make the videos.

  • @SumitKumar-fc4bq
    @SumitKumar-fc4bq Před 7 lety

    how to add GPS in YMFC V2 ?

  • @robertparenton7470
    @robertparenton7470 Před 6 lety

    Thank You!

  • @daskasspatzle2396
    @daskasspatzle2396 Před 7 lety +2

    Very well explained, thank you ;-)

  • @caioqwerty1
    @caioqwerty1 Před 7 lety

    Thanks for the video!! I would appreciate a LOT if you could teach how to use the Arduino Nano as a programmer for Atmel studio, because I have no money to buy an Atmel programmer!

    • @Joop_Brokking
      @Joop_Brokking  Před 7 lety +1

      This video should give you some ideas: czcams.com/video/zEbSQaQJvHI/video.html

  • @RSP13
    @RSP13 Před 4 lety

    AMAZING!

  • @MDFRESCUER
    @MDFRESCUER Před 7 lety

    Good video.

  • @TheKetsa
    @TheKetsa Před 7 lety

    Thanks !

  • @subarnaadhikari677
    @subarnaadhikari677 Před 7 lety

    can you put link of programming of drone through adruino uno

  • @sidharthtalia
    @sidharthtalia Před 6 lety

    Couldn't you just put the value of the volatile variable into a non volatile variable and get the best of both worlds? like the value can be changed at any instant for the volatile variable and the non-volatile variable is say updated just once every cycle with the value of the non volatile variable. The reason why i would want to use a volatile variable is that I have had some bad experience with arduinos and interrupts when i didn't declare the variable as volatile. Hence i declare the ISR variables as volatile just to be on the safe side.

  • @mukund22kar
    @mukund22kar Před 7 lety

    Nice video is it possible to hack the code from the flash memory.

    • @Joop_Brokking
      @Joop_Brokking  Před 7 lety +2

      With the debugger it's possible to change the data in the flash memory.

  • @rusticza1355
    @rusticza1355 Před 7 lety

    Great channel Joop, sub'd