Microcontroller newbie needs some advice re. PICs and AVRs. - Page 1
Forum section: electronics / general

author: elcomtel
author_rank: Regular Contributor
timestamp: October 06, 2013, 01:27:30 pm
content: As far as computers are concerned I am old school. I cut my teeth on PDP-11s and other mini-computers and mainframes. I walk and talk CISC (microcode) architecture and I'm not too bad with RISC. I can talk about memory management systems or how cache memory works till the cows come home. I know a thing or two about asynchronous and synchronous data busses. I can tell you what a multiplexed bus is and talk about the finer points of IEEE 802.Yet would you believe I have never touched a 'single chip' micro such as a PIC or an AVR.oh...the shame of it.I've decided to change this and I have ordered (see list below) various PIC and AVR development systems on eBay and Aliexpress from China as a learning platform. An original Atmel STK500 development kit is quite pricey so I decided on the Chinese development systems for its inherent value.ATtiny13 Development Boardhttp://www.aliexpress.com/item/ATtiny13-Development-Board-AVR-Mini-System-Learning-Board-With-USB-Cable/770171557.htmlArduino Nano 3.0http://www.aliexpress.com/item/Free-Ship-Wholesale-IC-Parts-Integrated-Circuits-Atmel-ATmega328-Board-with-Mini-USB-Cable-Full-Compatible/704043993.htmlPIC16F877A Development Boardhttp://www.aliexpress.com/item/Free-shipping-PIC-development-board-PIC-learning-board-PIC16F877A-BK200/559785859.htmlATMEGA128 Development Boardhttp://www.aliexpress.com/item/Free-shipping-AVR-development-board-ATMEGA128-BK-AVR128-learning-board-test-board/565300380.htmlPICKit 3 Programmer ICEhttp://www.aliexpress.com/item/FREE-SHIPPING-PIC-PICKit-3-PICKit3-programer-PIC-Kit3-PIC-Simulator/900898384.htmlAVR JTAG ICEhttp://www.aliexpress.com/item/Free-shipping-AVR-USB-Emulator-debugger-programmer-JTAG-ICE-for-Atmel-ATMEGA16-JTAG-simulation-head/623898152.htmlNow given that I have a very strong assembly language background and to a lesser degree experience with C (I'm ok with C, but I kick arse with assembler....yes I'm an old fart).I was hoping that you worldly ladies and gentlemen would point me in the direction of what development environments I should consider. I have never seen a MPLAB, Atmel Studio or a HiTech application running (I simply know that these tools exist).I want to learn both AVRs and PICs (so far I have been silent about my ARM ambitions).Most of my life I have been dealing with 'big systems' (A $10M mainframe is a big system) that I never had the opportunity to get involved with microcontrollers. I now have some ideas I want to put together and microcontrollers seem to be the best way forward.Based on what I have written would you please be so kind and suggest what IDEs (I like a challenge so I will avoid Arduino....I bought the Nano 3 simply for the micro and not to run Arduino....The first thing I will do is erase the boot loader....real men use JTAG) and other software (compilers, debuggers, simulators, etc) I might find useful.I was also interested in buying this book as a reference.Programming PIC microcontrollershttp://www.altronics.com.au/index.asp?area=item&id=B2451Does anybody know if this book is any good? Are there any other good 'Bibles' that cover PICs, AVRs and ARM (I've been very hush hush about my ARM fantasies......strewth, I didn't intend to make that statement sound so inappropriate) for someone with a strong digital and assembly language background?Many thanks in advance.

author: AlfBaz
author_rank: Super Contributor
timestamp: October 06, 2013, 02:05:01 pm
content: Quote from: elcomtel on October 06, 2013, 01:27:30 pmI don't know if it's been updated but I bought that book before any pic's had flash and I remember hating his writing style... "I do this and I like that and I I I I me me me" very annoying

author: dannyf
author_rank: Super Contributor
timestamp: October 06, 2013, 03:12:23 pm
content: My 2 cents:1. PIC vs. AVR: With pic, you get lots of sample code. However, the IDE (mplab and mplab x) are difficult to use; With the avrs, you get a reasonably good ide (avr studio / VS), lots of plugin's and a good compiler. You also have the option to use Code::Blocks. Plus, the AVRs allow vectored interrupt, something you find very useful on modern chips.2. Getting started: All you need is the daatsheet, compiler manual, header files + lots of practice. No books are needed in my view. That particular book is ancient and not terribly useful today.3. programmer: you will need to have some way to get your code programmed onto the nano. Some sort of programmers is needed, particularly if you intend to wipe out the arduino bootloader.

author: amyk
author_rank: Super Contributor
timestamp: October 06, 2013, 03:22:53 pm
content: Quote from: elcomtel on October 06, 2013, 01:27:30 pmIf you really want a challenge, how about manually programming with DIP switches and pushbuttons?Quote from: elcomtel on October 06, 2013, 01:27:30 pmSome people have a fetish for feet...

author: Rufus
author_rank: Super Contributor
timestamp: October 06, 2013, 03:55:18 pm
content: You should get by without buying books.Try IDEs, if you don't get productive quickly they are no good.I'm an old fart and learned long ago writing in assembler is just tedious, error prone, almost non-portable.Being able to read assembler and understanding of the instruction set is good and sometimes essential, but, ffs write in C like everyone else - most of the example code you find will be in C.The biggest part of what you will have to learn is probably how to configure and use the processor core functions and peripherals. Working examples can be a great help and you probably want to come up with a real project(s) to implement.

author: Kremmen
author_rank: Super Contributor
timestamp: October 06, 2013, 04:09:30 pm
content: For AVRs, the IDE of choice is a no-brainer: the Atmel Studio. Freely downloadable from Atmel website, supports practically all Atmel chips (even ARMs).You mentioned AVR JTAG ICE. For Atmel Studio, get the JTAGICE 3 and that's all you need for debugging and programming the chips (transferring the binary on board, that is). The STK500 and STK600 also program chips but they do not debug, like JTAGICE does.If you want to debug Atmel ARMs later, get the Segger J-Link Edu. Horsepower for negligible price. You just cannot use it for commercial purposes.And don't for a moment think you don't need no f-ing debugger. When you get beyond blink-the-led, you are guaranteed to need it so you should have one from the get-go.All the AVR books for embedded development i have encountered are a waste of money. Scan the inet instead - you will find all the same info for free that way. And then there is this place and AVR Freaks forum for Atmel stuff. Other mfgs must have similar sites but i let others write about those.

author: WarSim
author_rank: Frequent Contributor
timestamp: October 06, 2013, 04:55:36 pm
content: I also transition from mini to micro to pico systems. In reality for a strong programer the chip you pick is irrelevant. Once you get past the bias opinions for either side PIC and AVR are essentially equal. Both PIC and AVR have adopted features of the other. For example a previous post stated that PICs do not have interrupt vectors, this was true along time ago, now it is not true.There are fan clubs on both sides. People made their choice for valid reasons at the time and want to validate their reasons by convincing others. Even if their past reason in no longer valid.Given your selected choices you will most likely make you selection for reasons other than hardware. For example the programming tools, vender support, 3rd party tools or even package options. It is like selecting Intel or AMD back when they where equal competitors, it really didn't matter. Same-thing when selecting a CPLD and FPGA venders.Both uC venders provide free programming tools and IDEs. Download them ant try them out. Depending on your previous tools one will likely be more intuitive.Both uC venders publish their package catalog as free downloads. You may have a preference.Both uC vender sites link to their 3rd party partners.I suggest you pick one and try it out, if you use free samples your only investment is the programer and they are cheep. Then try out the other one. You seem to have a varied resume so I suspect you won't fall into fandom right away and be able to make the choice based on your experiences/preferences. Truly if in the future you want to switch venders later it is not a big deal for a strong programer.I currently have 8 uC programers on my shelf, each used for different reasons and different uC. Right now I use only two of them PIC Kit 3 and IDC-3 and this is only because I found some PICs I want to use. To a lesser extent I wanted to try Microchips OSX MPLAB X IDE. If I want to switch again no big deal. I have programmed on systems I am confident people here have never heard of because I had to.If this is an open choice for you, find out your preferences and pick. Asking here will only give you opinion and most of the opinion will be biased. An opinion which gets even more biased because they focus on their choice and are likely not current on the other.

author: Skimask
author_rank: Super Contributor
timestamp: October 06, 2013, 06:54:25 pm
content: Quote from: AlfBaz on October 06, 2013, 02:05:01 pmMe too, long time ago. While the info was ok, I got the same vibe from the writing...

author: elcomtel
author_rank: Regular Contributor
timestamp: October 06, 2013, 09:15:55 pm
content: Quote from: amyk on October 06, 2013, 03:22:53 pmOk sonny....I might not have programmed with 'DIP Switches' but I spent hours entering code using toggle switches. Does that qualify? I've included images of what an 'IDE' looked like in the late 70s to early 80s. You get so good at machine code that you assemble all the code in your head and the binary comes out automatically. To this day I can still assemble IBM 360 code off the top of my head.Did you know that the CPU architecture between a DEC PDP-11 and a Motorola 68K is nearly identical? Except for subtle differences where the 68K is hex based (PDP-11 is octal) and has a different memory setup. The instruction set is nearly identical. The first minute I laid eyes on 68K assembly code it felt as if I had known 68K all my life.......ah the good ol days

author: dannyf
author_rank: Super Contributor
timestamp: October 06, 2013, 10:05:27 pm
content: Quote2nd that.

author: Hamster
author_rank: Regular Contributor
timestamp: October 06, 2013, 11:39:42 pm
content: I have also used the Arduino Suite to program AVR processors that were not used in the arduino line, and you could use a UNO with avr studio.I am biased for AVR, as i have been using avr studio since v2 ? , also own the STK500, STK600, AVRISP/JTAG/ICE toys... and lots of router cards for the STK600.. however, i find myself using a uno for small little projects.

author: IanB
author_rank: Super Contributor
timestamp: October 07, 2013, 12:51:06 am
content: Quote from: elcomtel on October 06, 2013, 09:15:55 pmAh, a PDP-11/40. I've booted one of those by entering the boot loader program from the toggle switches.If your program got stuck in a loop you could halt the machine from the front panel and single step it, reading the register status displays to figure out what it was doing.

author: drake
author_rank: Newbie
timestamp: October 07, 2013, 02:40:14 am
content: I went from java and c# to programing avrs and pics in c and had a hard time. It's a completely different world. I found arduinos the easiest to learn then slowly edged over to pics using the microchip ide because of work requirements. For hobbiest use, I would recommend the mikroc ide for pics as its pretty easy to pick up and has some nice tutorials on YouTube. But to be honest I'm still a sucker for high level languages, I'm currently working on a project using a raspberry pi with python. If I need to make a programming change, I can ssh in and change it on the fly.

author: walshms
author_rank: Regular Contributor
timestamp: October 07, 2013, 02:48:34 am
content: I remember the PDP-11... had one in my high school. That brings back some memories... ours even had an optical tape reader, so that once you got the boot code in on the switches you could get the rest read in at "high speed" via the tape.<sigh> Now I really feel old...

author: elcomtel
author_rank: Regular Contributor
timestamp: October 07, 2013, 05:34:33 am
content: Quote from: walshms on October 07, 2013, 02:48:34 amFinally I don't feel so lonely. Digital Equipment Corporation also ran an identical architecture called the LSI-11. The LSI-11/23 that I was familiar with had a RS232 console ( a VT-100) with a low level interface known as ODT (Seehttp://en.wikipedia.org/wiki/On-line_Debugging_Tool). This was a great advance because you didn't have to stand in front of the system bashing toggle switches all day.Back in those days a field service engineer was equal to a software developer and really had to know their stuff. These days a hardware engineer (not everyone) is someone who repairs Xbox or Playstation 3 by simply reflowing the solder under the BGA chip without the help of an oscilloscope or a logic analyser. If a reflow doesn't fix it then the game console is deemed as B.E.R. (Beyond Economical Repair).Anyway back to the subject....PICs and AVRs. So far I have found all your tips very useful. I've found a swag of tutorials and lots of good information with Google.I suspect that as I am also interested in ARM microcontrollers that ATMEL Studio 6 probably is the IDE I should focus most of my energy on.

author: poorchava
author_rank: Super Contributor
timestamp: October 07, 2013, 05:46:23 am
content: But really: both PIC and AVR have pros and cons. AVR has better architecture, is faster and has more friendlyu assembler should you need to use it. It also usually has waaay less silicon bugs than MicrochipPICs on the other hand are available in much larger variety, so you're more likely to find what you need. Microchip is also known for supporting their products for a very long time, so they are an obvious pick for industrial production.They also have one thing in common: they both totally and utterly suck when compared to cheapest Cortex M3 from NXP, ST, TI or Freescale

author: WarSim
author_rank: Frequent Contributor
timestamp: October 07, 2013, 05:51:48 am
content: Quote from: poorchava on October 07, 2013, 05:46:23 amI was waiting for that comment.

author: westfw
author_rank: Super Contributor
timestamp: October 07, 2013, 08:27:48 am
content: It's pretty much a no-brainer. You use Atmel Studio (6.1) for the AVRs, and MPLABX for the PICs.Some people will tell you that the older versions are better, but they're dead going forward, and you ought to form your opinions about the vendors' tool sets by using what they're providing now. If you really like the Microchip IDE, it's based on NetBeans, which is an open source IDE that can probably be coerced into supporting AVR as well. Atmel Studio is based on Microsoft Visual Studio, and I think you'd have to pay for a version that MIGHT be customizable for PICs.Both IDEs are built on top of command-line tools, so you can use your favorite editor and cli-based assembler/compiler/make/etc if you want to. I think this is a little more obvious with Atmel. OTOH, the Microchip tools will run on MacOSX and Linux as well as windows. They're both huge downloads; I hope you have a good internet connection.QuoteYes. Lovely architectures. You should find the AVR looks familiar as well, though you'll be annoyed by the orthogonality and elegance that got left out in order for them to support 32 registers in the same instruction size. You'd also like the TI MSP430 (which you haven't bought!)The 8bit PICs will be more of a shock. It's good for you, though.QuoteOnly one of the AVR CPUs you bought supports JTAG, I think. Hopefully your chinglish-documented programmer/jtag interfaces supports the other protocols for debugging as well.QuoteWow!

author: Kremmen
author_rank: Super Contributor
timestamp: October 07, 2013, 08:46:43 am
content: Again, speaking only of the AVRs (): most hobbyists wouldn't know what to do with a "true" JTAG interface because that has more to do with product quality assurance in manufacturing than what a hobbyist is doing. For many if not a majority of applications it is a good thing that you don't need a cumbersome 20 pin JTAG connector on a possibly tiny board. In that respect Atmel's interfaces are OK, with just 6 or in some cases less, signals. The downside is that there is a lot of variation between what each chip family and generation supports. Studio can handle that but not necessarily the hardware available to a low end hobbyist.As to PIC and AVR sucking compared to some specific ARMS; your suction may vary considerably. Shoehorning a Cortex in place of say a low end ATtiny could be considered misdesign. If one is just creating blink-a-led apps for the fun of it then who cares but any "serious" design has other criteria. I am not one to squeeze out the last unnecessary feature but the solution should match the task at least by orders of magnitude. In that respect the low end 8 bit wonders that easily and simply(!) do what is expected of them do not suck at all. You get no points for overkill, but you might get some from standardization. So there is a soft line to be drawn somewhere.Having said all that i fully agree that a nice ARM chip is a regular workhorse and much more bang for the buck. But why does it have to be so messy to set up a nice (free) dev toolchain for almost all of them? I use ST and Atmel ARMs and the Studio is a joy to set up and use compared to anything for the ST. With the possible exception of CoIDE.

author: AlfBaz
author_rank: Super Contributor
timestamp: October 07, 2013, 09:36:45 am
content: Another thing to consider is how you would like to progress your knowledge. Given your sound understanding of assembly and the mechanisms they operate on, it may be prudent to download some family reference manuals from different vendors to get a feel for the architectures. Especially the difference between Harvard and (probably in your case) the more common von Neumann architectures.Again with your background you are most likely more at home with absolute code, so it may pay to get your head around relocatable assembly first, just to see what the linker can bring to the table. From there its a short skip and jump to C/C++ with a good grounding on what happens behind the scenesIf however, you are happy with pressing the make button, and not overly interested in the underlying processes that take place then by all means jump in

author: filip_cro
author_rank: Regular Contributor
timestamp: October 07, 2013, 10:58:24 am
content: Thing that get me started on AVRs was cost. I bought USBASP (3$), breadboard and Atmega168. Problem is that with third party programmers you can't use Atmel Studio alone, but AVRdude can be used.

author: dannyf
author_rank: Super Contributor
timestamp: October 07, 2013, 11:07:01 am
content: QuoteVS is quite good but bloated. However, the plug-ins are plenty and personally I use VS to use Visual Assist X,With ARM, you get a lot of other IDE choices, from CodeBlocks (emBlocks / emIDE) to Eclipse (CCS, CoIDE for example) and commercial tools (Keil / IAR). Among the free tools, CoIDE is excellent.

author: dannyf
author_rank: Super Contributor
timestamp: October 07, 2013, 11:09:35 am
content: QuoteYou can always code in Arduino and burn it withou the bootloader. So the Arduino-generated hex files can run on plain old AVR - one way to get started very quickly withou tthe Arduino bloatware.QuoteCavemen use JTAG: most of the chips now use one-wire debug interfaces.

author: dannyf
author_rank: Super Contributor
timestamp: October 07, 2013, 11:14:09 am
content: QuoteIf I had to pick an 8-bit mcu now, I would pick STM8L - very versatile and inexpensive. Unfortunately, it has limited tool support.

author: elcomtel
author_rank: Regular Contributor
timestamp: October 07, 2013, 12:29:18 pm
content: Quote from: dannyf on October 07, 2013, 11:09:35 amDidn't hear about boundary scan testing using one-wire interfaces?Though I imagine that you could write diagnostics for a PIC/AVR/ARM that would test the surrounding hardware and once satisfied all was good the microcontroller would be reloaded with the intended application. Plenty ways to skin a cat and JTAG is not the bees knees that it is made out to be.One-wire interfaces are the way to go with low pin count micros. Pretty silly if you ask me to connect a 4 signal JTAG interface to a 6 pin device. JTAG can make development, manufacturing and service a lot easier.Regarding microcontroller (single chip devices) emulation....without doing any research on the subject there are basically two ways that this could be achived.One...To simulate a microcontroller (PIC, AVR, ARM) on a host (a PC) and have a small monitor program reside on the microcontroller that communicates with the host. The host telling the microcontroller what pins to drive and to query levels on pins.The other implementation of emulation (I suspect this is the case with JTAG enabled microcontrollers) is to have the microcontroller 'twiddling its thumbs' doing nothing while the host takes full control of all the pins via JTAG under the control of a microcontroller simulator running on the host. This way you can make the 'physical' microcontroller appear to be running the show, where in fact the signal stimulus is done by JTAG.I've had quite a lot to do with microprocessor emulators (Z80, 6502,etc) of various incarnations. I became very fond of the good old Fluke 9010A. The 'old school' emulators were often real time while I don't expect this to be the case with regard to PIC or AVR in circuit emulation.

author: WarSim
author_rank: Frequent Contributor
timestamp: October 07, 2013, 04:30:51 pm
content: Stating things as if they are unique to AVR when they are not is a bit silly. So I am going to assume you are saying you like the way AVR implements these common features.AVR has I/O pins that allow electrical energy flow in and out of the chip!AVR has power pins!AVR has full software simulation!AVR has hardware snoop!AVR has a debug interaction mode!Both chips and IDEs are very feature similar. There are differences in the naming conventions, two name for the same thing.

author: nctnico
author_rank: Super Contributor
timestamp: October 07, 2013, 05:01:15 pm
content: @elcomtel:You better investigate for yourself whether ARM controllers are really more difficult than PIC / AVR or that its just people parrotting other people.

author: dannyf
author_rank: Super Contributor
timestamp: October 07, 2013, 06:45:06 pm
content: QuoteAgreed. The newer chips are just more powerful and with more advanced peripherals. Other than that, not much difference.

author: Rellum
author_rank: Newbie
timestamp: October 07, 2013, 07:28:32 pm
content: My 2 centsDon't underestimate Arduino , it has good points, don't care about the critics, you can learn a lot with it. I learned (and quickly than PIC/AVR alone) ! And remember you can always build your own version, it's open source.Try Both AVR and PIC solutions, pick whatever you find most suitable for you or use both. MPLAB X is good as AVR Studio is. Both are not "the best" but they are "the best free available" and for start to play around that's quite enough.Start small and scale after. As you are quite proficiency you won't take too much time to learn the basics. As you are also from old school, a book is always welcomed. I liked a lot Designing Embedded Systems With Pic Microcontroller. It uses a 16F84 which maybe not the best choice by now but which will guide very well.Regarding ARM, my opinion is forget it by now. Start simple, build your projects, and then go ARM. Don't go straight to ARM, nobody deserves this !

author: westfw
author_rank: Super Contributor
timestamp: October 08, 2013, 01:00:17 am
content: In the microcontroller "software development" world, "JTAG support" most often seems to refer to "using JTAG protocols to access internal registers that control the debug capabilities of the chip", rather than the more traditional "provide ability to set pin states to arbitrary values for system-level debugging." (huh. I don't even know whether JTAG on AVR offer pin-setting. Atmel doesn't seem to document much of their debug capability.)QuoteThat seems EXTREMELY unlikey. The whole point of having on-chip debugging aids is to permit the code to run at full-speed, except when debug functions are explicitly invoked. There are tools like AVRICE that specifically connect the Atmel tools to 3rd party debuggers that do NOT (AFAIK) include any simulation.

author: WarSim
author_rank: Frequent Contributor
timestamp: October 08, 2013, 06:20:36 am
content: Quote from: westfw on October 08, 2013, 01:00:17 amThis feature is for debugging the board not the chip. JTAG pin driving is for simulating chip.