Monday, April 23, 2012

Why the AVR is better than the PIC

It has only been a few short weeks since I took the plunge back into microcontroller programming and already I have regrets.  Back in earlier posts, I listed a few reasons that I am sticking with the PIC.  Since then, I have solidified my position even more by purchasing a PICkit2, and installed the CCS and Microchip C compilers.  Sadly, my frustration continues and it has absolutely NOTHING to do with the chips and everything to do with the development environment.

20 years ago, the devices were so small (RAM/ROM/Flash) and there were so few variants that developing in assembly was not too bad.  With the variations of chips today, it would be foolish to write almost anything for these microcontrollers in assembly.  If you are old enough, or hard core enough, you know that writing reusable and modular (library) code in assembly is akin to stabbing a pencil in your own eye (it hurts).  A simple example would be to imagine upgrading code on a PIC that had a single W register to a PIC with 4 W registers.  Sure you could just migrate the code, but all that optimization that could be leveraged is lost!  Hence, we have C.

I will be the first to admit from a hardware size, what I have at hand is pretty nice.  I have a handful of powerful and flexible PICs at my disposal.  However, the compilers are really starting to wear me down.
  • The free compiler (from Hi-Tech) is almost worthless when the optimization expires
  • The available C compilers are between $150 and $500
  • Don't forget about maintenance
  • Due to copy write restraints, I cannot share with my readers how I customized the code to fit a particular situation
  • If the reader does not have the compiler, my source code is all but worthless
  • You help $timulate the economy by buying a new compiler for each chip family (16 vs 18 vs 24).
So, in short, here I sit trying to squeeze coding into a tiny device and all I can do is produce bloated code files.  And let me assure you, there is a difference.  My once simple temperature with RS232 will no longer fit onto the device.  Previously, it was only filling up 70% of the code space.

Of course hindsight is 20/20.  Right now, as I look over my shoulder I wish I would have dropped $50 on the AVR Dragon instead of the PICkit2 (mind you, the PICkit2 really is a fantastic setup).  So, I implore you to not follow my path and shift (or start) with the AVR as soon as possible.  And, I hate to say it.  I don't think you (or I) will look back and think we made the wrong decision.  Look at some of the benefits:
  • tried, true and free compiler with GCC
  • -O 3 (gcc's optimization flag)
  • The $ that would be spent on the compiler can go towards a logic analyzer, Oscope or a bench power supply
  • Ability to switch among device types w/o buying a new compiler for each
  • Ever growing list of user created libraries that you can freely copy, change, enhance, and share
    • 1-wire
    • I2C
    • USB
    • Manchester encoding
    • RS232
    • Wireless modules
    • List is long and keeps growing
  • AVRfreaks as a resource (yes, they are a wee bit hostile towards PIC people)
  • Hobbyist and Magazine support is bar none
  • Let's not forget the quick and simple Arduino
  • I consider all the other items (price, features, pin count, availability) to be the same
Am I switching?  Not right now.  But be assured when I run out of my supply of PIC's, the inventory and tools will be refreshed with AVR's.
Am I wrong or am I missing something obvious?  Post below and let me know.

No comments:

Post a Comment