Author Topic: What to know about avr?  (Read 2816 times)

0 Members and 1 Guest are viewing this topic.

Offline rx8pilot

  • Super Contributor
  • ***
  • Posts: 3634
  • Country: us
  • If you want more money, be more valuable.
Re: What to know about avr?
« Reply #25 on: December 18, 2019, 03:49:22 pm »
But first, you need a project.  A reason for reading all that stuff.  Some application that is worthy of the effort.

Break your project down into modules (timers, PWM, port IO, etc) and tackle each component by itself.  If you don't mind creating your own header(s), you can simply rip what you need and add your own definitions.  When you are done, you actually OWN the code - not so much in the legal sense but in the sense of understanding.

 :-+ Exactly this.
Creating an actual mission is remarkably motivating and productive.
Factory400 - the worlds smallest factory. https://www.youtube.com/c/Factory400
 

Offline macboy

  • Super Contributor
  • ***
  • Posts: 2257
  • Country: ca
Re: What to know about avr?
« Reply #26 on: December 18, 2019, 04:54:20 pm »
+1 on having a project interesting to you. This is the motivator to keep on learning, experimenting, coding, and tweaking until it's right.

+1 on getting the datasheet and studying it. That is how I cut my teeth on PIC micros way back. Note however that unless you plan to write in assembly code, then ignore the entire large section about the instruction set. If you aren't sure, then the answer is resoundingly "NO". Chances are you will write in C/C++ etc.  Let the compiler worry about the instruction set!  You need mainly to know about peripherals, interrupts, and I/O. 

If you are sticking with Arduino, do yourself a favor and install a good IDE like Eclipse. You can use it just as an external editor, continuing to use Arduino IDE to build/compile and upload, or you can install an add-on and use it independently of the Arduino IDE. Either way, one main benefit this provides is a powerful editor which will index and cross-reference all the code, including the Arduino sources, libraries you are using, and your own sketch files and other source files. Without that, coding in Arduino can make you feel lost and confused. Ever wonder which code actually calls that "loop()" function over and over (and what else is it doing?), or how millis() or delay() or digitalWrite() is implemented? It's so easy to look at that code once you are inside a proper cross-referencing IDE. Then you will start to understand what is - and isn't - happening on your micro, outside of your sketch.  You also absolutely must look at the source for any library that you will use. Partly, this is because most of them are poorly documented. Mostly, it is so that you understand what hardware resources are being used by that library. You can't simultaneously use two libraries which both depend upon Timer2, for example. Some are coded so inefficiently that you might choose not to use them. For example, a very popular infra-red remote control library sets up a timer to sample the input every 50 microseconds. That 20000 interrupts per second, to look for IR signals that might be minutes or hours apart. The MCU spends a significant portion of clock cycles servicing that interrupt for no good reason. If you need high performance elsewhere, such a library might frustrate your efforts.
 

Offline rstofer

  • Super Contributor
  • ***
  • Posts: 9890
  • Country: us
Re: What to know about avr?
« Reply #27 on: December 18, 2019, 06:12:58 pm »
Windows users...

There is a plug-in Microsoft Visual Studio and it works very well.  Visual Studio is a standard environment for application development so a lot of people already have it and know how to use it.

https://www.visualmicro.com/

Microsoft Visual Studio Code Community Edition is a very sophisticated IDE which is much like the editor component of Visual Studio above.  There is a Microsoft Arduino plug-in that allows Arduino development.  It's going to take a bit of time wandering through the menus before you tumble to View->Command Pallete.  This is where you set up the board and port.  The normal Arduino IDE must be installed in order to have the compiler/linker and most of the example programs.  The only gripe I have with VS Code is that it won't print files - none of them.  I have to open them with Notepad++ and print them from there.  Despite being highly annoyed with the lack of print capability, I suspect this is the IDE I'm going to sue.

Why dump the Arduino IDE?  The STUPID choice of colors for error messages does it for me!  Yes, after wandering around Google, it is possible to figure out how to fix the colors but it's a PITA that shouldn't be unnecessary.

I have been using VS Code to write VHDL because a tutorial series I was working used it.  It's a  really nice IDE - I think I'll stay with it.  BTW, I don't know what code snippets are included for Arduino but in VHDL mode, the IDE will lay down chunks of code that are repetitive and boring to type.

I haven't mastered column editing (changing an entire column of text) nor any of the other features.  I don't need the features but it's kind of cool that they are there when I come across a need.

If you are not using the Arduino bootloader and you want to use Makefiles (and you probably do), VS Code has a plug-in for that as well.  This means you can write any code you want for the avr and use the Arduino tools (avr-gcc, avr-libc, avr-dude) to build and download the binary.  When I was fooling around with the ATmega128, the Arduino hadn't even been invented.  Everything I did was done by way of a Makefile.

Using avr-dude without the Arduino bootloader is probably an advanced topic but it is all over Google.
« Last Edit: December 18, 2019, 06:14:29 pm by rstofer »
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf