Author Topic: AVR Libraries, make it easier to program AVRs?  (Read 2196 times)

0 Members and 1 Guest are viewing this topic.

Offline corrado33Topic starter

  • Supreme Robot
  • *****
  • Posts: 611
  • Helpful? 11
AVR Libraries, make it easier to program AVRs?
« on: April 12, 2010, 08:41:54 AM »
Hello again,
       I have a quick question about AVR libraries (WebbotLib, AVRLib).  So as I'm using the AtMega8 for my first project, Webbot lib (at least the first version I think) was too big to fit on the MCU.  So I had to learn the old fashion way. 

So correct me if I'm wrong, but are AVR libraries simply a collection of commands in header files so that people don't have to mess around with bit manipulation?  Like there's a command for turning on ADC, A2DInit()?  I must say that finding the correct registers to turn on and off is a bit (no put intended) of a hassle.  I'm not downplaying the libraries in any way, WebbotLib is a very well compiled (no pun intended) set of files.  I can see how it would make programming much easier.  It even accounts for different MCUs (which is EXTREMELY cool).  But libraries themselves are generally HUGE.  Sometimes, wouldn't it be more simple to learn the how to edit the registers you need to change rather than learning the library command?  Again, I have the highest respect for the creators of the libraries (Webbot in specific).  As said in the intro of his library, he's invested enormous amounts of his own time into making it, and to that, all of us are grateful. 

I guess what I'm asking is (please webbot take no offense to this) why spend the time learning the library commands when some of them are simply making assignments for two or three registers?  Maybe it's just my mentality, but it almost seems as if you're learning another language to control the language that controls the MCU.  (Learning to use the Library to control C to control the MCU).

Also, (for me at least) learning how to control the registers has opened up a world of understanding.  I feel that if people that are new to AVR programming simply start with Libraries, they're skipping a crucial step and are just going to end up with more questions than answers. 

I know that no one says I HAVE to use AVR libraries, and I know that.  I'm not trying to put down AVR libraries in any way, I'm just trying to understand the mentality behind it.  I'm sure there are multiple huge commands that webbotlib takes care of in one little tiny bit of code, I (in my very limited experience) however, have yet to find any. 

That being said, I'll probably eventually learn how to use Webbotlib.  It definitely does make your program "look" nicer.   :D

Again, this was not meant to hurt feelings or downplay anyone's hard work, I just like to know the reasoning behind projects rather than just how they work and what they do. 
« Last Edit: April 12, 2010, 04:40:25 PM by corrado33 »

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,632
  • Helpful? 169
    • Society of Robots
Re: AVR Libraries, make it easier to program AVRs?
« Reply #1 on: April 12, 2010, 08:45:51 PM »
I'll just quickly respond to this . . .

because libraries are easier to learn, easier to remember, and you don't need to reprogram all of the registers every time you move on to a different microcontroller. Sometimes its not as simple as just a few lines of code, such as GPS or I2C, meaning everyone sharing code will save everyone time.

Everyone has a different goal for programming, but my goal is to program a cool robot, spending all my mental efforts making it perform high-level actions. If I spend all my time on low-level stuff, like registers, I'll feel like I'm being dragged down. But to each his own.

Offline richiereynolds

  • Full Member
  • ***
  • Posts: 112
  • Helpful? 3
Re: AVR Libraries, make it easier to program AVRs?
« Reply #2 on: April 13, 2010, 02:26:18 AM »
Many reasons, here's one - as you continued to program, you'd get tired of writing every detail and start replacing them with function calls. Then you'd get tied of looking at those functions cluttering up your code, you'd probably modularise them into other files hence you'd end up writing your own libraries.

But, isnt' it easier if we're all using the same libraries? If lots of people are using them, more of the bugs will get spotted quicker. If a bug is fixed, everyone will benefit. You may not be using the code with the bug now but you might in future, hence you'll benefit, without even knowing it, from someone else having noticed that bug previously.

We all benefit from using the same interface, I could use a squeezable furry dice mechanism to steer my car instead of a steering wheel, but if I did, you wouldn't be able to borrow my car! (plus I'd have terrible trouble when I wanted to sell it) There's a lot to be said for standard interfaces.

Offline corrado33Topic starter

  • Supreme Robot
  • *****
  • Posts: 611
  • Helpful? 11
Re: AVR Libraries, make it easier to program AVRs?
« Reply #3 on: April 13, 2010, 06:52:50 AM »
Many reasons, here's one - as you continued to program, you'd get tired of writing every detail and start replacing them with function calls. Then you'd get tied of looking at those functions cluttering up your code, you'd probably modularise them into other files hence you'd end up writing your own libraries.

But, isnt' it easier if we're all using the same libraries? If lots of people are using them, more of the bugs will get spotted quicker. If a bug is fixed, everyone will benefit. You may not be using the code with the bug now but you might in future, hence you'll benefit, without even knowing it, from someone else having noticed that bug previously.

We all benefit from using the same interface, I could use a squeezable furry dice mechanism to steer my car instead of a steering wheel, but if I did, you wouldn't be able to borrow my car! (plus I'd have terrible trouble when I wanted to sell it) There's a lot to be said for standard interfaces.

Makes sense.  I guess I'm just OCD about my code, and I only trust code written by me.  And you are right, I have started making everything into functions.  If I used a library I'd always blame it if my program didn't work.   ;D

Offline Cristi_Neagu

  • Robot Overlord
  • ****
  • Posts: 165
  • Helpful? 5
Re: AVR Libraries, make it easier to program AVRs?
« Reply #4 on: April 13, 2010, 07:32:37 AM »
I think that a healthy learning path for a newbie (such as myself, actually), is to first start using libraries until he/she is familiar with the language and the specific algorithms, then delve deeper into the code behind libraries all the way down to basic bit manipulations, and finally returning back to the same libraries he/she started out, because, just as richiereynolds said, if we all used the same libraries, things would be so much easier to understand.

At least that's my opinion, and that's what i'll do in the future, just as soon as my Axon gets delivered...

Offline Webbot

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 2,121
  • Helpful? 108
Re: AVR Libraries, make it easier to program AVRs?
« Reply #5 on: April 13, 2010, 10:24:00 AM »
If you want to learn how microcontrollers work - then do all the low level stuff yourself.
But if you are interested in solving a problem - then libraries help you to do that quicker by removing all the low level hassle.
I need a car to get to the shops. If I had to start off by building a car every time then I'd quickly get fed up and move to the city. So a library is just a 'tool' - just like the 'car'.

Quote
I'm sure there are multiple huge commands that webbotlib takes care of in one little tiny bit of code, I (in my very limited experience) however, have yet to find any. 
Try writing your own code for something like the Blackfin camera (amongst other things!), or controlling 18 servos.
Webbot Home: http://webbot.org.uk/
WebbotLib online docs: http://webbot.org.uk/WebbotLibDocs
If your in the neighbourhood: http://www.hovinghamspa.co.uk

Offline corrado33Topic starter

  • Supreme Robot
  • *****
  • Posts: 611
  • Helpful? 11
Re: AVR Libraries, make it easier to program AVRs?
« Reply #6 on: April 13, 2010, 10:37:41 AM »
I need a car to get to the shops. If I had to start off by building a car every time then I'd quickly get fed up and move to the city. So a library is just a 'tool' - just like the 'car'

...

Try writing your own code for something like the Blackfin camera (amongst other things!), or controlling 18 servos.

Very nice analogy!  I like it, and it makes sense.  You are correct as well, I do like to learn how microcontrollers work.  Also, (again this is my personal opinion) if I don't understand something (like the libraries) I tend to get try to get to the bottom of a problem first, then work my way up.  If I understand the MOST complicated (controlling AVRs through bits and registers), then I'll definitely understand the LESS complicated (using libraries).

And I don't plan on using a camera any time soon! (Although I can imagine programming for it would be horrendous!)

Thanks for clearing things up guys!

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,632
  • Helpful? 169
    • Society of Robots
Re: AVR Libraries, make it easier to program AVRs?
« Reply #7 on: April 13, 2010, 10:53:43 AM »
Its a question of whether you want to spend your time solving and understanding the low-level problems (bit registers and sensor communication), or the high level problems (robot navigation, vision, etc).

 


Get Your Ad Here

data_list