Bare-Metal MCU #8: Optimizers and Bit-Banging

Sdílet
Vložit
  • čas přidán 14. 08. 2020
  • This is the eighth video in a journey from Arduino to STM8. The goal is to begin with Arduino, which is a popular platform to serve as a starting point. I'll then break it down into a fundamental level, and then apply those fundamentals to other microcontrollers, such as the STM8.
    This video focuses on how to write code that is easier to understand for embedded programmers, and how to optimize your code to reduce the size.
    AVR Instruction Set Datasheet: ww1.microchip.com/downloads/en...
    ATMEGA328P Datasheet: ww1.microchip.com/downloads/en...
    ATMEGA328 Datasheet:
    ww1.microchip.com/downloads/en...

Komentáře • 60

  • @Optinix-gz1qg
    @Optinix-gz1qg Před 3 lety +18

    This is pure gold. Im literally learning this stuff as an engineer and the fact that u explain all this topics that easily and understandably is amazing. Can’t wait for more.
    Thanks sir

  • @n-o-i-d
    @n-o-i-d Před 3 lety +19

    The way you are explaining these topics is great, you're making them so easy to understand.

  • @gaborzsamboky3252
    @gaborzsamboky3252 Před 3 lety +3

    Absolutely brilliant! Only a handful of educators are capable of translating complex processes to this level of simplicity. Thank you, Mitch.

  • @SodAlmighty
    @SodAlmighty Před 3 lety +11

    Mitch, this video has a couple of technical inaccuracies.
    Firstly, "bit banging" is the practice of emulating a peripheral (e.g. PWM, I²C) via direct port manipulation. What you meant to say was "bit manipulation".
    Secondly, it's not an "amperstand", it's an AMPERSAND.

    • @deltakid0
      @deltakid0 Před 3 lety

      Actually, it's not "bit manipulation" as you state but instead it's "bitwise"

    • @SodAlmighty
      @SodAlmighty Před 3 lety

      @@deltakid0 No, it isn't.

    • @deltakid0
      @deltakid0 Před 3 lety

      @@SodAlmighty why not?

    • @SodAlmighty
      @SodAlmighty Před 3 lety +3

      @@deltakid0 Three reasons. First, bitwise is an adjective, not a noun. Secondly, the term I used wasn't wrong. And thirdly, while what he's doing *is* bitwise, the term 'bit manipulation' is more descriptive and specific.
      There are many "bitwise" tasks you can perform. Bit manipulation is one of them.

    • @deltakid0
      @deltakid0 Před 3 lety

      @@SodAlmighty ok, I agree 1. and 3. but 2. sounds odd since is not very descriptive.

  • @gokulramakrishnan4079
    @gokulramakrishnan4079 Před 9 měsíci +1

    This series of videos make me to see embedded system a simple one. Thanks for this.

  •  Před 2 lety +1

    These tutorials are so good! I keep coming back to these videos every time I need to implement more and more complicated things on microcontrollers

  • @hansdietrich83
    @hansdietrich83 Před 3 lety +2

    I have watched many many many low level programming tutorials, but this series is better than all of the others by a few magnitutes.

    • @hansdietrich83
      @hansdietrich83 Před 3 lety

      @@MitchDavis2 i already watched the first episode and it's perfect, that I found this series, as I'm looking for a low power uC that can be programmed over it's own USB interface and this series cleared up a lot of things

  • @rick_100
    @rick_100 Před 3 lety +3

    Very good series. I've watched them all. I liked how you showed the assembly language output of the compiler.

  • @kaxbyrita9279
    @kaxbyrita9279 Před 6 měsíci

    So goooood. I cant believe these videos dont have more views than they do.

  • @jayedr8728
    @jayedr8728 Před 9 měsíci

    bruh, your videos are literally a gold mine, you really demystified bare metal MCU for me, before i watched your videos i didn't know what happened after i write C code and upload it, it was a total Pandora box for me that i was scared to get into, but THIS! this makes it that much more exciting and easy to understand, you truly have a gift for teaching complex concepts using easy language! thanks a lot man!
    especially given the fact that i have looked to learn this information through other vids/courses, but there is always a problem of them using too specific examples and not explaining how to translate this knowledge to other processors/compilers and how to use the manuals to find all these necessary infos that you can implement for whichever processor you're using. you are amazing, thanks again Mitch

  • @emilsitka7590
    @emilsitka7590 Před 2 lety

    Most Excellent! This deserves MUCH more views.

  • @zyghom
    @zyghom Před 2 lety +2

    this part at 7:15 is simply what I was trying to understand for ages probably (not that I am not aware of boolean algebra but in practice) -as many said already: you really have this "thing" that makes you super teacher ;-)

  • @warrior7740
    @warrior7740 Před 5 měsíci

    Thank you bro👍 finally clear my all confusion about bit wais operation.

  • @paulg.3067
    @paulg.3067 Před 3 lety +1

    This video just made it to my usefull µC Bookmark list :D. Thanks for the effort you put in!

  • @testme2026
    @testme2026 Před 3 lety +1

    thank you love it! please keep them coming!

  • @SquadQuiz
    @SquadQuiz Před rokem

    Thanks for your video, that helped me a lot to understand the difference between the two methods, Cheers!

  • @superchromat
    @superchromat Před 3 lety +1

    Just discovered your channel. Great stuff!

  • @albertroswell
    @albertroswell Před rokem

    thanks for this series!

  • @markmaker2488
    @markmaker2488 Před 3 lety

    Great tutorial, I’d love to see more on bit manipulation.

  • @saikirangudla3389
    @saikirangudla3389 Před rokem

    wow! Got to learn a lot of fundamentals. Thank you!

  • @user-mr3mf8lo7y
    @user-mr3mf8lo7y Před rokem

    Great videos.

  • @Ewecnt
    @Ewecnt Před 3 měsíci

    PORTB^=(B11

  • @whatever361
    @whatever361 Před rokem

    ur seris is so cool , thank you so much!

  • @flaviocunha7576
    @flaviocunha7576 Před 2 lety

    Thank You, great video!!!

  • @joymakerRC
    @joymakerRC Před rokem

    Thanks Mitch

  • @LewisCampbellTech
    @LewisCampbellTech Před 3 lety

    I am loving these videos.
    I always thought the standard presentation of the arduinos was a bit "black box". I get it, it was targeted at makers, not high level programmers who wanted to dabble in lower level programming. but I never found it that satisfying to just download libraries and use the arduino IDE.
    I have a 7 segment display and a temperature sensor and my humble goal is to make a little thermometer without using the arduino IDE or libraries (I'll let myself use the AVR headers though)

  • @minhajsixbyte
    @minhajsixbyte Před rokem +1

    in the previous video i commented about "less" being the pager for man file. in this video i can see that you're using "more".
    this is basically the same thing. "more" being the old pager. nowadays "more" isn't used anymore. in most systems if you run "more", it actually uses "less" instead (more is symlinked to less). the original more couldn't go "up" direction in the text.

  • @choudharyom1
    @choudharyom1 Před 2 lety

    Thankyou very much

  • @MrMaxgarin
    @MrMaxgarin Před 3 lety

    Great videos! Your explanations on bitwise operators is well done. Would you mind sharing your slides? I'd love to have them for reference.

  • @dineshganesh6723
    @dineshganesh6723 Před 3 lety

    Tq bro very helpful ❤️😎

  • @aregjan
    @aregjan Před 6 měsíci

    You described two ways to turn on bit 5. One is 1

    • @davei7
      @davei7 Před 5 měsíci

      you can use 0b00100000, 32, 0x20, (1

  • @kenjiyoshida2330
    @kenjiyoshida2330 Před měsícem

    bro your content is Awesome! Having issues on programming attiny85 using arduino.The ADC analog read is not working properly I'm thinking arduino library isnt correct when it comes to the adc code parts.please help

  • @WildEngineering
    @WildEngineering Před 3 lety

    when you're doing bitwise stuff, if you use hex instead of decimal it makes it a lot easier :) nice video! i came from a reddit post in r/embedded.

  •  Před 3 lety

    Have you tried to make 32 as variable and indicate it as PROGMEM? Is there any difference then?

  • @SteveRobillard
    @SteveRobillard Před 2 lety

    Thank you, I have really enjoyed this series, though I think it would benefit from one addition a make file video (no more cheat sheet needed).

    • @MitchDavis2
      @MitchDavis2  Před 2 lety +1

      I certainly do want to revisit this series and add some above-and-beyond things. I tried to keep these videos as basic as possible to teach the fundamentals, and tried not to focus on many “quality of life” improvements yet. Sometimes, things like makefiles scare people when first introduced, but if you see what life is like without them, it makes it easier to understand why automated build scripts are an absolute necessity

    • @SteveRobillard
      @SteveRobillard Před 2 lety

      @@MitchDavis2 Thanks for the reply. I use makescripts etc. in my classes often as black boxes to avoid student's needing to remember or retype long/cryptic commands. But, I am firmly in the camp of wouldn't want to go back to the time before I discovered make files etc. especially since I have arthritis and typing can be especially painful.

  • @johnsun2416
    @johnsun2416 Před 4 měsíci

    Like "Bit-Banging"

  • @MilanKarakas
    @MilanKarakas Před 3 lety +1

    How it is possible that your "Bit-Banging" is not flagged by CZcams algorithm as an adult content as it is case with one of my video about bit and byte banging necessary for chip AD9850?

    • @MitchDavis2
      @MitchDavis2  Před 3 lety +1

      I don’t understand anything that goes on with CZcams auto-flagging. Right now I’m dealing with a copyright claim on my next video saying I used a copyrighted song. You may notice that none of my videos even have any songs.

    • @MilanKarakas
      @MilanKarakas Před 3 lety

      @@MitchDavis2 Can you please put here link to that video? I think some persons copyrighted silence, white noise and similar things.

  • @metamud8686
    @metamud8686 Před rokem

    when you compiled to assembly which you subsequently studied, you did not use -Os for size, but you typed -O1 .. at least in the video.

    • @MitchDavis2
      @MitchDavis2  Před rokem +1

      Oh wow, nice catch. I had to re-watch to see where I slipped up. It’s been so long since I made this that it’s probably just a mistake on my end

  • @AlyssaNguyen
    @AlyssaNguyen Před 2 lety

    I generally prefer to use "0b00100000" rather than "(1

    • @stocothedude
      @stocothedude Před rokem +1

      Yes, It’s all preference. In the end the compiler doesn’t care if you write in binary notation or bitwise shifts. It will optimize it if it’s instructed to do so.

  • @orenwolfe6506
    @orenwolfe6506 Před rokem

    at 5:00, might I suggest clearing bit 5 with 'PORTB &= 0b11011111' or 'PORTB &= ~0b00100000' instead? IMHO this makes the bit manipulation slightly more obvious to the future reader.

  • @ruffrecords
    @ruffrecords Před rokem

    The (1

    • @RFDarter
      @RFDarter Před 10 měsíci

      As you saw in the assembler code that is not correct

    • @ruffrecords
      @ruffrecords Před 10 měsíci

      @@RFDarter If you are referring to the actual assembler output rather than the pseudo assembler earlier in the video then the assembler clearly never shifts the one nor inverts the result.. In fact the compiler is smart enough to know that the AVR has bit set/reset instructions for ports and invokes them when it sees PORTB |= ( 1

  • @TomCarbon
    @TomCarbon Před 2 lety

    I don’t understand the point about sacrificing performance with “~(1

    • @MitchDavis2
      @MitchDavis2  Před 2 lety

      This is only calculated as a constant by the compiler if you tell the compiler to optimize things like this. By default, the compiler will often not optimize trivial things like this to reduce code. You have to add a “-O” flag to get the optimization code to kick in.
      The Arduino compiler adds the optimization flag by default, but you have to explicitly call it if you’re running avrgcc on your own

    • @TomCarbon
      @TomCarbon Před 2 lety

      @@MitchDavis2 Nope, whatever optimization level you set, such a 'direct' computation is always handled by the preprocessor way before the compiler could do anything, thus it will always end up with a constant - the final value - (either on a register or on the stack depending on the usage or the architecture) rather than instructions... It's easy to check (and I just did with gcc, clang, pcc, msvc...): you can either get the preprocessor output or just check the generated binary.
      In earlier processors, operations using the alu were often very costly in cycles... and even if shifting was way better than multiplying / dividing, its cost was for instance something like 4 + 2n cycles (where n is how much you shift). So a great effort has always been made on the preprocessor side to avoid these computations.