Тёмный

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

Mitch Davis
Подписаться 40 тыс.
Просмотров 23 тыс.
50% 1

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.c...
ATMEGA328P Datasheet: ww1.microchip.c...
ATMEGA328 Datasheet:
ww1.microchip.c...

Опубликовано:

 

1 окт 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 61   
@Optinix-gz1qg
@Optinix-gz1qg 3 года назад
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 3 года назад
The way you are explaining these topics is great, you're making them so easy to understand.
@SodAlmighty
@SodAlmighty 3 года назад
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 3 года назад
Actually, it's not "bit manipulation" as you state but instead it's "bitwise"
@SodAlmighty
@SodAlmighty 3 года назад
@@deltakid0 No, it isn't.
@deltakid0
@deltakid0 3 года назад
@@SodAlmighty why not?
@SodAlmighty
@SodAlmighty 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 3 года назад
@@SodAlmighty ok, I agree 1. and 3. but 2. sounds odd since is not very descriptive.
@minhajsixbyte
@minhajsixbyte Год назад
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.
@rick_100
@rick_100 4 года назад
Very good series. I've watched them all. I liked how you showed the assembly language output of the compiler.
@gaborzsamboky3252
@gaborzsamboky3252 3 года назад
Absolutely brilliant! Only a handful of educators are capable of translating complex processes to this level of simplicity. Thank you, Mitch.
@zyghom
@zyghom 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 ;-)
@johnsun2416
@johnsun2416 7 месяцев назад
Like "Bit-Banging"
@hansdietrich83
@hansdietrich83 3 года назад
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 3 года назад
@@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
@orenwolfe6506
@orenwolfe6506 Год назад
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.
@kenjiyoshida2330
@kenjiyoshida2330 4 месяца назад
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
@Ewecnt
@Ewecnt 6 месяцев назад
PORTB^=(B11
@gokulramakrishnan4079
@gokulramakrishnan4079 Год назад
This series of videos make me to see embedded system a simple one. Thanks for this.
@paulg.3067
@paulg.3067 3 года назад
This video just made it to my usefull µC Bookmark list :D. Thanks for the effort you put in!
@warrior7740
@warrior7740 8 месяцев назад
Thank you bro👍 finally clear my all confusion about bit wais operation.
@superchromat
@superchromat 4 года назад
Just discovered your channel. Great stuff!
@aregjan
@aregjan 9 месяцев назад
You described two ways to turn on bit 5. One is 1
@davei7
@davei7 8 месяцев назад
you can use 0b00100000, 32, 0x20, (1
2 года назад
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
@MilanKarakas
@MilanKarakas 3 года назад
How it is possible that your "Bit-Banging" is not flagged by RU-vid 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 3 года назад
I don’t understand anything that goes on with RU-vid 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 3 года назад
@@MitchDavis2 Can you please put here link to that video? I think some persons copyrighted silence, white noise and similar things.
@metamud8686
@metamud8686 Год назад
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 Год назад
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
3 года назад
Have you tried to make 32 as variable and indicate it as PROGMEM? Is there any difference then?
@LewisCampbellTech
@LewisCampbellTech 3 года назад
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)
@whatever361
@whatever361 Год назад
ur seris is so cool , thank you so much!
@testme2026
@testme2026 3 года назад
thank you love it! please keep them coming!
@choudharyom1
@choudharyom1 2 года назад
Thankyou very much
@ruffrecords
@ruffrecords Год назад
The (1
@RFDarter
@RFDarter Год назад
As you saw in the assembler code that is not correct
@ruffrecords
@ruffrecords Год назад
@@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
@jayedr8728
@jayedr8728 Год назад
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
@James_Hello
@James_Hello Месяц назад
Fantastic ❤
@user-mr3mf8lo7y
@user-mr3mf8lo7y 2 года назад
Great videos.
@MrMaxgarin
@MrMaxgarin 4 года назад
Great videos! Your explanations on bitwise operators is well done. Would you mind sharing your slides? I'd love to have them for reference.
@joymakerRC
@joymakerRC 2 года назад
Thanks Mitch
@SquadQuiz
@SquadQuiz 2 года назад
Thanks for your video, that helped me a lot to understand the difference between the two methods, Cheers!
@kaxbyrita9279
@kaxbyrita9279 9 месяцев назад
So goooood. I cant believe these videos dont have more views than they do.
@emilsitka7590
@emilsitka7590 2 года назад
Most Excellent! This deserves MUCH more views.
@saikirangudla3389
@saikirangudla3389 Год назад
wow! Got to learn a lot of fundamentals. Thank you!
@AlyssaNguyen
@AlyssaNguyen 2 года назад
I generally prefer to use "0b00100000" rather than "(1
@stocothedude
@stocothedude 2 года назад
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.
@flaviocunha7576
@flaviocunha7576 3 года назад
Thank You, great video!!!
@markmaker2488
@markmaker2488 3 года назад
Great tutorial, I’d love to see more on bit manipulation.
@dineshganesh6723
@dineshganesh6723 3 года назад
Tq bro very helpful ❤️😎
@albertroswell
@albertroswell Год назад
thanks for this series!
@TomCarbon
@TomCarbon 3 года назад
I don’t understand the point about sacrificing performance with “~(1
@MitchDavis2
@MitchDavis2 3 года назад
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 3 года назад
@@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.
@SteveRobillard
@SteveRobillard 3 года назад
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 3 года назад
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 3 года назад
@@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.
@WildEngineering
@WildEngineering 4 года назад
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.
Далее
Bare-Metal MCU #9 - Review; ATTiny85 from scratch
14:25
Bare-Metal MCU #4 - Bootloaders and Programmers
18:24
Optimizing Arduino Code: no setup(), no loop() ⛔
9:27
Bare-Metal MCU #7: Libraries (Preprocessor & Linker)
19:58
PlatformIO: All you need to know in 10 Minutes!
10:56
Просмотров 315 тыс.
Bare-Metal MCU #1 - Intro to registers
13:10
Просмотров 74 тыс.
SPI (Bit Banging)- IO from Scratch - Part 4
30:04
Просмотров 10 тыс.
Bare Metal Bit Banging: WS2812B Driver
1:21:03
Просмотров 9 тыс.
Bare metal GPIO driver for ESP32 | Toggling an LED
12:43
How to get source code onto a PIC microcontroller
11:21