Didn't realize registers were a thing. You definitely inspired some new thought today. Good work!
@BenFinio3 жыл бұрын
Thanks!
@VndNvwYvvSvv2 жыл бұрын
Is recommend some basic computer hardware classes so you can see how gate logic makes up flipflops, registers, adders, buses, etc.
@dadik74663 жыл бұрын
came from reddit, great video!
@BenFinio3 жыл бұрын
Thanks!
@shunnoysarkar69066 ай бұрын
Hey thanks a tonne Ben! Also thank you for citing Spark Fun's video on registers!
@gordmills19839 ай бұрын
Now write it in asm. For example, I wrote code that does exactly the same functions as multiple libraries, spi negotiation, i2c communication, in asm, and it compiles to just over 1.5kb…. The original code is over 24kb… there again I’m an old fart who started when memory was premium… you had to be efficient.
@esunisen386211 ай бұрын
Reminds me the good ol' time when i had to generate a 50 Hz sinewave signal with a 68705P3 and a DAC. I had to track every microsecond to have the right frequency. You kids have no idea how easier it is nowadays xD
@ezion672 жыл бұрын
AVR is one of very few processor families specifically designed to be programed in assembly. Doing so is not much harder than using a higher level language. If speed and fine control over register use is what you after, assembly might be worth looking in to. For example: You may give a routine (function) exclusive use of some of the 32 general purpose registers instead of using variables in memory, reducing the need to push and pull from stack and heap. This can give significant performance gains. Frequently called interrupts are a good target for this technique.
@gordmills19839 ай бұрын
Don’t forget if you’re not using all the ports, you can use them to hold 8bit values too…
@gordmills19839 ай бұрын
Push and pop from the stack do use several clock cycles, so minimise if you need precise timing.. also the data sheets have a nice section on the opcodes , including clock cycles to execute.
@S0K0N0MI3 жыл бұрын
I feel it shouldn't be necessary to bang on registers manually; That sort of thing should be resolved by the compiler.
@gordmills19839 ай бұрын
That is the problem, you are relying on a program to optimise a program. If the compiler is not efficient, now will the result be. No substitute for hand crafted assembly routines… smaller , faster, and if your nerdy and need to compute cycles, you can easily count the clock cycles via the cycles each op code needs to process. Great for tight timing when you want to run @8mhz and dump data to addressable leds….
@0124akash10 ай бұрын
Knowledgeable information, sir how to convert delay code into millis function?
@BrainTrance3 жыл бұрын
Two questions: 1.Is the faster/efficient code written in C? is that the reason why delay() converted into _delay_ms()? 2. Isn't it faster to bit operate the PORTB rather than reassign it a new value?
@BenFinio3 жыл бұрын
1. The code on the right is written entirely in C, but the Arduino IDE will let you mix and match, so you could write delay() instead. (disclaimer: I realize there is debate about what exactly the "Arduino language" is and I do not have a strong opinion on what to call it: hackaday.com/2015/07/28/embed-with-elliot-there-is-no-arduino-language/) 2. Yes, someone also just pointed this out on Reddit. I find that students are confused by masking and bitwise operators at first so that needs to be introduced as a separate topic. So we usually do this first, then do something like try to blink two LEDs out of sync, and realize that "whoops, we're overwriting all the pins because we're writing to the whole register" and then use that as motivation to introduce masking. It's about halfway through the list of Tinkercad tutorials linked in the description.
@edgarbonet15 ай бұрын
Do not write `0b00100000`: it is hard to read and error-prone. Write `_BV(PB5)` or `(1
@Johann752 жыл бұрын
Why not create a translator that will translate into registers? Wandering why Arduino IDE does not do that translation…
@dw652810 ай бұрын
Very nicely done!!!! Sincere thanks!
@samarmany6272 Жыл бұрын
Where is position of accumulator memory in arduino like as microcontroller AT89S51??? how to acces and save??
@BenFinio Жыл бұрын
I'm not sure, you'd have to check the microcontroller's datasheet.
@brucemangy3 жыл бұрын
I strongly believe that the compiler should do that for us :( i'm disappointed.
@fauxpasiii3 жыл бұрын
Came here to post basically this. Especially for a platform that will be a lot of people's introduction to this type of programming, training them to try to outsmart their compiler is going to cause problems further down the line. Not taking away anything from this very useful and informative video though! I found it illuminating.
@BenFinio3 жыл бұрын
@@fauxpasiii @brucemangy there is a lot of good discussion in the reddit thread that you may be interested in: www.reddit.com/r/arduino/comments/mnfxwl/optimize_your_arduino_code_with_registers/
@omkarkhade46023 жыл бұрын
Great tutorial, Thanks.
@IamSJ2 жыл бұрын
they should make macros using the constexpr that would be clean
@TericT3 жыл бұрын
Any tips on finding the documentation for such registers? I always find that to be incredibly difficult.
@BenFinio3 жыл бұрын
The ATMega328P datasheet has the full documentation. It's hundreds of pages long and a bit overwhelming at first. My Tinkercad Circuits tutorial series introduces things one step at a time, you may find that useful: kzbin.info/aero/PLKL6KBeCnI3X7cb1sznYuyScUesOxS-kL
@pocopoco3468 Жыл бұрын
Chat gpt said that we can store out libraries and parts of the program(Sketch) in SD card, I didn't find any video tutorial on this, how its done?
@BenFinio Жыл бұрын
ChatGPT makes things up sometimes! kzbin.info/www/bejne/aYnLapSEm7SanKc
@vodkaboi4974 Жыл бұрын
you can store data inside an sd card but you'd need to learn how to make files and write in them in c++, thanfully it's not complicated and there are some good tutorial on youtube. Edit : this is limited to variables, i doubt you can store programme as it's not the same type of memory.
@esunisen386211 ай бұрын
@@vodkaboi4974 Well, technically if you can read/write directly the sectors without any filesystem, this is considered as virtual memory, sort of. The thing is it's MUCH slower. You could execute some code if it was first copied in RAM, that's how MBR worked in DOS.
@jeevanshrestha88882 жыл бұрын
wow nice tutorial...
@joshuavincent78843 жыл бұрын
Great video
@nobodyeverybody84375 ай бұрын
how to learn about the registers and keywords?
@sagnost4 ай бұрын
Read datasheets or search avr tutorials
@imamnegeri88253 жыл бұрын
Wow,its very helpful with complex project algorithm on arduino. Could you please share your documents about this? Thanks
@BenFinio3 жыл бұрын
Hi - not sure what documents you're referring to?
@nonaak2 жыл бұрын
and how to do IF THEN ELSE in register code. great fid you make. thanks
@BenFinio2 жыл бұрын
Hi - the syntax for if/then statements is the same in both C and the Arduino language, you can't replace it with registers (as far as I know).
@nonaak2 жыл бұрын
@@BenFinio ok. Thanks for you anser 👍
@TheFauriGames Жыл бұрын
Most of the time, registers on embedded systems are used for peripheral configurations (pins, timers, UART, ...), thats the things surrounding the CPU and both peripherals and CPU makes the µC. So depending on the bits stored on that register, the behavior of the peripheral will vary. On the other hand, instructions like if/then/else are directly involved in the ALU of the CPU. And most of the time standart libraries in C should handle the job.
@vodkaboi4974 Жыл бұрын
@@nonaak you can use logic gates but if else is already kinda a logic gate
@osamarabee39276 ай бұрын
some codes dosnot work with this methos i transfered a oled and dht sensor to this methos and it was impossible to work ???????????
@yasirrakhurrafat114220 күн бұрын
How so? Maybe you have a library that doesn't recognise the low level code. You'd have to manually edit some of the code from the sketch.
@tubical715 ай бұрын
Hihi... And nowadays people do this using something like rust or py.... 😉