|
Which is better.. PIC or AVR ?Click here to go straight to the answer Whenever this subject comes up on discussion groups, there is invariably a heated debate. This sort of quasi-religious debate has always gone on, I'm old enough to remember people arguing about whether the 6502 was better than the Z80, and I'm sure it went on long before that. What many people fail to realise, however that in almost all fields of enginering, there is simply no such thing as "Best". The correct phrase is "Most appropriate for your application". Similarly there is no such thing as "good practice" or "bad practice". It all depends on the requirements of a particular product, manufacturing process, development method etc.. Something that would be appropriate to do on a $1000 instrument would often be completely the wrong thing in a $5 mass-market toy. Here are a few comparisons based on actual issues I've dealt with on real projects. These are mostly based on using assembler on the AT90S and current ATTiny and ATMega parts, and PIC12/PIC16 parts. Hopefully this info will help you decide what may be best for you. Feel free to contribute more differences you've come across Ways in which PICs are better than AVRsInstruction set/architecture (for Assembler users) AVR bad : highly nonorthogonal instruction set - many operations can only be done on certain registers. Relative branch range can force code to be arranged in a non-logical order. No immediate XOR instruction. Illogical mixture of skip and branch flow-control instructions (Now if only they'd made STATUS one of the registers you could do skips on....!). Clocks etc. Recent Pics (12Fxxx etc.) have more accurate calibrated RC oscillators. Watchdog wakeup from sleep continues after SLEEP instruction - on AVR it causes a reset, which can complicate things. Power consumption Interrupts Interrupt latency is constant - if you set up a regular timer interrupt on a PIC, it will occur at exactly the same interval every time. On the AVR you will get at least one cycle jitter. ADC I/O and bit-twiddly things I/O ports have much better drive capability - the output high level is easily capable of providing a few milliamps without significant voltage drop - useful for directly powering up peripheral devices (e.g. opamps) on demand for power-saving. PIC can wake up from sleep on short pulses and edges. Counters are asynchronous and can count while part is in sleep, and count faster than the CPU clock. AVR cannot wake on edges (Except the few parts that have wake on pin-change), and level-triggered interrupts must be asserted until the chip wakes up and the clock starts otherwise the part will go back to sleep. Configuring AVR reset pin as I/O disables in-circuit programming. On PICs the reset pin can be configured as an input without disabling serial programming, provided whatever is connected to it allows for the 12.5v programming voltage. Availability Microchip keep old parts available for long after they have been superceded. You can still buy PIC16C54XT's, despite now being on their fourth revision. Atmel have far fewer parts, yet have obsoleted more of them - e.g. the 90S4414 has been obsoleted twice (90S8515, now ATMega8515). Devtools, programming, production etc. AVR bad :
Ways in which AVRs are better than PICs.Instruction set/architecture AVR good : Add with carry, and compare with carry simplify multiple precision arithmetic. Good range of conditional branches. PIC bad : Unconventional mnemonic names.. Only one pointer for indirection. Inefficient lookup tables. No add/subtract with carry, small stack. Paged architecture becomes a real pain on larger projetcs, although the PIC18 architecture addresses (pun intended!) many of the issues. Clocks etc. More instructions per oscillator clock, but as most instructions take 2 cycles, and more instructions are often necessary for IO intensive tasks, this advantage is 2:1 at best. Most embedded apps are not especially throughput-dependent. Also, crystals and resonators get bigger and harder to get much below about 3MHz, so the speed advantage over a 4MHz PIC can often not be a major issue. Watchdog can be turned off by software. Power consumption UART Interrupts ADC I/O Devtools, programming, production etc.
If you've read the above, you'll have realised that the answer is Neither
of course, it all depends on what your requirements are. Coming next.... which is the best religion ;-) |
|