Society of Robots - Robot Forum

Electronics => Electronics => Topic started by: javafiend on August 08, 2008, 10:29:45 AM

Title: PIC vs AVR
Post by: javafiend on August 08, 2008, 10:29:45 AM
It seems there are more books centered toward PIC microcontrollers and since I haven't worked with them, how difficult is it to take PIC projects and modify them for AVR microcontrollers?
Title: Re: PIC vs AVR
Post by: Admin on August 10, 2008, 07:39:54 PM
Depends on what the project is.

The code will definitely be different, the pinout will be different, but the schematics and concepts will be the same.
Title: Re: PIC vs AVR
Post by: JesseWelling on August 11, 2008, 01:01:24 AM
Much of the high level code could be the same, it all depends on if such things were abstracted well enough to be portable.
Title: Re: PIC vs AVR
Post by: javafiend on August 11, 2008, 11:39:23 AM
Financially, would it be worth it to get a PIC setup or just stick with AVR and forums?
Title: Re: PIC vs AVR
Post by: Webbot on August 11, 2008, 12:07:24 PM
I would suggest that there may be a greater knowledge bank within SoR on AVR devices.

Financially: don't PIC devices require you to make a substantial investment to buy their C compiler rather than the free AVR toolset?
Title: Re: PIC vs AVR
Post by: javafiend on August 11, 2008, 12:38:09 PM
That's what I've heard.  I don't have that kind of cash laying around.

Free is good.  AVR is good.
Title: Re: PIC vs AVR
Post by: Admin on August 11, 2008, 12:44:28 PM
I made the $50 Robot AVR based because at the time AVR's were much cheaper.

But someone mentioned recently in the forum that the newer 18 series of PICs no longer require expensive external programmers, and now come with free programming software. Basically what AVR has had for years . . .
Title: Re: PIC vs AVR
Post by: paulstreats on August 11, 2008, 01:52:10 PM
That was probably me  ;D

You can use the student version (also licensed for commercial use) of microchip C18 compiler. The only limitations are reduced code optimization (unlike previous free PIC compilers that only worked with a handful of devices and were limited in code size etc..)

 As for programming, you can buy cheap JDM programming cables like this for $11.95 ( which works in a very similar way to the atmega one in the $50 robot. If you are handy with electronics you can make your own from a schematic for under $1 (I did this in the end when my old and expensive PIC programmer got left behind and needed expensive firmware and hardware upgrades)

 To actually program with a cable like the one above you need something like IC-prog which is a freeware program.

 As well as the compiler you get to use the free MPlab IDE where you write your code. You can run software simulations of the code to make sure it works before transfering it to the pic. Also it lets you get full disassembly listings of your C code, monitors Device memory and code space usage etc...

I might do a small tutorial on using PIC18 devices soon.
Title: Re: PIC vs AVR
Post by: Iron Man on August 12, 2008, 02:11:03 PM

if you want any help with that tutorial i'm willing to help.

I've just spent the entire summer writing firmware for pic18's
Also a GREAT place for pic18/pic24/pic32 info is, they've got a great forum on there with insanely fast answer times.
another great resource is It's centered around the FIRST, but they all use pic's. And if you're looking for base code to expand from use Kevin Watson's code. It has many many things already taken to a high level of abstraction AND it's free! It's great code, you'll find all sorts of tidbits on there, from IR to Encoders to Cameras.

Kevin Watson's Website *he's a nasa dude, he's legit*

*pic24 is the 16bit controller
*pic32 is the 32bit controller
Title: Re: PIC vs AVR
Post by: GHF on August 12, 2008, 03:06:42 PM
Hi-Tech has made their extremely optimizing C compiler for PIC10/12/16 available for free last month. That compiler is really amazing compared to CCS or any of the BASIC compilers.

I got started with a PICKit 2 programmer and free samples of PIC16s from Microchip. I'm still using the PICKit, but now I'm on their pretty new PIC18 lines with built in USB transceivers. I use the free C18 compiler. The most appealing part of the PIC setup is that once you pay for the programmer, everything you do is free, because you can get free samples of chips from Microchip.

I found that the AVR compiler didn't optimize code very well, but I guess that's true for most GCC toolsets. Doesn't matter, I guess, since AVRs tend to have much larger program spaces.

As for actual hardware differences, there isn't that much. AVRs have more program memory (and, since it's modified Harvard architecture, more RAM), and fewer choices in their lineup, but still enough to fill every niche. AVRs are 12 to 20MIPS, and operate 1MHz = 1MIPS. PICs are 20MHz for 16F and 40MHz to 48MHz for 18F. However, they operate 4MHz = 1MIPS, so that's actually 5MIPS, 10MIPS and 48MIPS.

I would say AVR is definitely better, but I don't really want to pay for it, so I'll stick to my PICs. However, there are plenty of reasons to use AVR over PIC. Lots of books, documentation, and code are written for very old PICs. PICs are used more extensively in industry than are AVRs, and vice versa in hobbyist fields. Since hobbyists do cooler stuff (in general :D), that's a good reason to switch. Kind of like the reason why you should use Python over other scripting languages: because more cool stuff is going on in that camp.
Title: Re: PIC vs AVR
Post by: Iron Man on August 12, 2008, 03:53:54 PM
PICs are 20MHz for 16F and 40MHz to 48MHz for 18F. However, they operate 4MHz = 1MIPS, so that's actually 5MIPS, 10MIPS and 48MIPS.

i think you mean 12MIPS.

Why do you guys think AVR is better?
Just because more people use it? Why do you think more people use it?
Title: Re: PIC vs AVR
Post by: JesseWelling on August 12, 2008, 08:54:58 PM
AVRs ( were designed to run C code. PICs ( were most definitely not. But like it says PIC18s are a big step over the PIC17 I had (the Cerebellum back in the day, remember how many times I bricked that Admin? Gah  :P)
Title: Re: PIC vs AVR
Post by: GHF on August 13, 2008, 08:28:31 AM
Oops, you're right. 12 MIPS.

The PIC userbase is bigger, actually, but if you subscribe to PIClist, you'll find that most of these guys are pretty hardcore and they're using PICs in "applications" in their "jobs." The users of AVR are more likely to post their "projects" on their blogs.

Basically, what I'm trying to say is that you're going to find lots other hobbyists who use AVRs in robotics and homebrew electronics. The PIC community is also very knowledgeable and helpful, but sometimes they're more worried about power consumption or form factors or whatnot, because there are more professionals mixed in.

Of course, these are all generalizations. You'll find that you can do anything you like with either set of tools, and plenty of people that are doing what you're doing in either camp.
Title: Re: PIC vs AVR
Post by: TrickyNekro on August 13, 2008, 09:40:22 AM
If pic userbase is bigger you can always convert PIC projects to AVR projects...
As said before the main concept is always the same...

If I was to use PIC or AVR... Although I haven't used PIC a lot, almost non, that would be a very tough choise...

Yes AVR are free software and all... but still something I don't like... Maybe it's the compiler... cause I can not generate the frequencies
I want precisly and I'm a little bit furstrated about this... Everything else is far above the middle...

PICs.... the not free compiles was such a great repulsion so far that I would even think about them...
But some of them, have peripherals that I have dreamed of... And I'm not talking about the can bus and such...
I have never used it anyway. Some USB PIC via a bootloader can be directly recognised and programmed via USB...

That's too much for me forget the cost and anything else...
I wait for the new ATXmega to come... until then I can not talk...

Generally without being using the PICs for complicated projects and having used AVRs for almost anything, I can not
judge 'em and say: hey yo AVR rulezzzz or PIC rulezzzzz.....

Regards, Lefteris
Title: Re: PIC vs AVR
Post by: Rebelgium on August 14, 2008, 04:17:49 PM
I like them both, but I use PICS.

Mainly because PIC has a wider userbase, thus more people to ask questions to etc.
btw, I have done a few projects with PICs now, and I have paid about 1€ or so... :p

that 1€ was for the components to build my programmer. Everything else (MPLAB, C18 compiler, PICS, ...) is free.
Title: Re: PIC vs AVR
Post by: RobD on August 15, 2008, 10:59:46 AM
I generally prefer the PIC along with the assembly language.  There are limited commands available but I have yet to find a project I haven't been able to implement using assembly (sometimes like with the older 16F series, etc.. an extra math-coprocessor chip is required).  I find it to be a rewarding challenge ;)

Porting projects over from other languages, etc... is another challenge altogether.  You have to match processor speeds then figure out what steps are happening when and in what order among other minutia.  The end result is that I have been forced to try and fully grasp what is happening within my code and learn each and every aspect of the microcontroller's capabilities. 

I also like having all available memory available to my application which is typically not the case when a bootloader is involved. 

Cost-wise, the initial expense was the programmer.  Now it's just the chips - and brain cells :)

With ICSP (In Circuit Serial Programming) you can update the software while the PIC is in place using four wires.  The MPLAB suite from Microchip is free and has a debugging routine built-in.  You can also run your code in the circuit itself during debugging, although I have "yet" to try this out.  -sounds interesting though. 

Good luck! 
Title: Re: PIC vs AVR
Post by: Iron Man on August 15, 2008, 11:06:13 AM
The in-circuit debugger is nice. You should check out the Special Function Registers Watch window and the Watch window. They allow you to see what all of your registers and variables are when you stopped the debug.

No more diagnostic printf statements.