PIC's and C Where to Start
-
- Posts: 11
- Joined: Tue Aug 05, 2008 5:27 pm
- Location: Charlotte, NC
- Contact:
PIC's and C Where to Start
In a quest to update my electronics skills I'd like to get into the Micro Controller world, and the Pic line of products looks like a good stepping off point. I've done some assembly coding (in a past life on x386 chips), but would like to try using C as the main programing language (to help speed development and lessen the learning curve). The issue I'm having is I don't know which compiler is good, and most of the one's I've looked at are not cheap. Is there a good Open source C compiler out there, with a decent library, and/or following (forums, groups, etc) ?
Also which Pic chip is a good place to start? PWM, and A to D would be nice, but compatibility would be good too.
Thanks for the help,
Bruce Maley
Also which Pic chip is a good place to start? PWM, and A to D would be nice, but compatibility would be good too.
Thanks for the help,
Bruce Maley
Re: PIC's and C Where to Start
Oh dear, nothing fills forums like a uC war...CrazyBillyBob wrote:In a quest to update my electronics skills I'd like to get into the Micro Controller world, and the Pic line of products looks like a good stepping off point.
Actually, around here its been uC versus transistors,
but I digress.
Chevy vs Ford
Apple vs PC
Democrat vs Republican
Coke vs Pepsi
Algebraic vs Reverse Polish Notation
Pick one uC that you're comfortable with and jump in.
The fact that you don't know enough to pick one
should not put you off as both the leading hobby
uC brands offer similar chip performance for
similar money. The toolschain is the issue.
BTW, Microchip (of PIC fame) recently bid to
buy Atmel (of AVR fame), the deal isn't done and
ON Semi (formerly Motorola) would like Atmel,
or at least bits of it.
If you read N and V check out Smiley's series
on learning C on an AVR. It uses the Atmel Butterfly
creatively, which is a very under priced hardware
module (about $25 IIRC).
There are some very powerful uC chips in the
ARM series for more serious hobby applications.
Running C code on a uC makes a lot more sense in
the long run than to take the safer route of playing with
PICAXE or BASIC STAMPproducts that have bootloader
BASIC.
While you're doing more research in the N and V
archives give Jon Williams column a look. He uses
the SX processor from Parallax.
Final though on this horse race, there is a low power
processor from Texas Instruments (MPS430) that
is now finding applications in the hobby.
-
- Posts: 11
- Joined: Tue Aug 05, 2008 5:27 pm
- Location: Charlotte, NC
- Contact:
I've used some of the Atena uC from Kronos Robotics (Mike, does some article for Servo, and N&V as well) Like them for easy of use but the Bootloader used up too much space and limited what kind of programs I could write.
I've been reading Smiley's articles on the Amtel butterfly, one of the big reasons I'm looking for a C compiler for Pics and not a basic compiler for Pics.
I've read all the Ford V Chevy articles here before, kind of figured I'd kick up a bee hive.
But I really want to go with the Pic family (even though some of the others have good things about them too!). I'll try and better reword one of my original Q's. In side the Pic family, what is a good Chip to start with (I don't know the difference between the 16C's , 18F, or the 16F).
I hope this clears up what I'm looking for, and keeps the bees down
Thanks for the help!
Bruce
I've been reading Smiley's articles on the Amtel butterfly, one of the big reasons I'm looking for a C compiler for Pics and not a basic compiler for Pics.
I've read all the Ford V Chevy articles here before, kind of figured I'd kick up a bee hive.
But I really want to go with the Pic family (even though some of the others have good things about them too!). I'll try and better reword one of my original Q's. In side the Pic family, what is a good Chip to start with (I don't know the difference between the 16C's , 18F, or the 16F).
I hope this clears up what I'm looking for, and keeps the bees down
Thanks for the help!
Bruce
PICs are a good choice but there really isn't a wrong one.
Within the PIC line, I'd recommend the 18F series to start with. Microchip has a free compiler. It was called C18 but, in their wisdom, they renamed it to something I can never remember. Look for student edition. It turns off some optimizations after 60 days but still works just fine - no limit on code size.
I'd also recommend getting the PICKit2 programmer/debugger from Microchip. It costs $35 and is as good or better than every other programmer outthere except the for expensive ICE units (and *maybe* the Microchip ICD2).
A nice package to get is the UBW (USB Bit Whacker). Sparkfun sells them for $25. It includes a PIC18F, breakout headers and a USB connection. It has a bootloader so you don't even need to get the programmer if you don't want (though I would, anyway)
SparkFun's UBW
UBW Homepage
Once you gain a little familiarity with the process, I'd get a solderless breadboard and plug the UBW into that to experiment with LEDs, switches, LCD displays, motor control and so on. (buy header pins and solder them into the UBW) The possibilities are just about limitless...
Within the PIC line, I'd recommend the 18F series to start with. Microchip has a free compiler. It was called C18 but, in their wisdom, they renamed it to something I can never remember. Look for student edition. It turns off some optimizations after 60 days but still works just fine - no limit on code size.
I'd also recommend getting the PICKit2 programmer/debugger from Microchip. It costs $35 and is as good or better than every other programmer outthere except the for expensive ICE units (and *maybe* the Microchip ICD2).
A nice package to get is the UBW (USB Bit Whacker). Sparkfun sells them for $25. It includes a PIC18F, breakout headers and a USB connection. It has a bootloader so you don't even need to get the programmer if you don't want (though I would, anyway)
SparkFun's UBW
UBW Homepage
Once you gain a little familiarity with the process, I'd get a solderless breadboard and plug the UBW into that to experiment with LEDs, switches, LCD displays, motor control and so on. (buy header pins and solder them into the UBW) The possibilities are just about limitless...
Since uC's are my favorite thing to work with, I thought I would chime in.
First off, all of the other comments are excellent. I use PICs, mostly because I started with them and I have a lot of tools and boards to work with for them.
That being said, if I had to do something very intensive, I think I would go the 32 bit ARM route - they have been around for a long time so they are industry proven. For example, my MP3 player uses an ARM based uC. Although Microchip has 32bit uCs now, I have not played with one. But, I, too, digress.
If you go with PICs, I, too, would suggest you start with PIC18F based parts. As philba said, the Microchip MPLAB C18 compiler is very nice and there is a free student version. Though to buy the full blown package, is expensive.
No matter what you choose, C is a great way to go. With C, it is my opinion that a uC is a uC. Each with their own quirks. For example the banking in PICs. Once you get used to those quirks, you will be all set!
Kevin
First off, all of the other comments are excellent. I use PICs, mostly because I started with them and I have a lot of tools and boards to work with for them.
That being said, if I had to do something very intensive, I think I would go the 32 bit ARM route - they have been around for a long time so they are industry proven. For example, my MP3 player uses an ARM based uC. Although Microchip has 32bit uCs now, I have not played with one. But, I, too, digress.
If you go with PICs, I, too, would suggest you start with PIC18F based parts. As philba said, the Microchip MPLAB C18 compiler is very nice and there is a free student version. Though to buy the full blown package, is expensive.
No matter what you choose, C is a great way to go. With C, it is my opinion that a uC is a uC. Each with their own quirks. For example the banking in PICs. Once you get used to those quirks, you will be all set!
Kevin
Just to add in -Hitech are now offering their 8 and 16 bit Pic C compilers in a 'lite' edition, free download, but has optimisation switched off unless you pay big bucks (U$1100 approx) for the full professional version.
Reports on the Piclist are that with no optimisation it creates horrendous assembler. However, there is a lot of code about for this compiler, it is used by many professionals (hence the price) works with MPLAB - www.hitech.com or there is also a free version of FED C - which i think is tied to just one processor - www.fored.co.uk
They (Fored) do have a free dopwnlaodable file on writing C programs. Not the best going but it is a start.
There is also a 'C' like basic from www.xcsb.com which also has a free edition, restrictions are , the libraries are pre compiled (source code for the paid version), the number of each type of variable is curtailed.
Just to keep things fair - Zilog and Renesas all so have free C compilers for their products.
There are people who ahve written some fancy code and use Studio Express 'C' to compile pic code.
Colin
Reports on the Piclist are that with no optimisation it creates horrendous assembler. However, there is a lot of code about for this compiler, it is used by many professionals (hence the price) works with MPLAB - www.hitech.com or there is also a free version of FED C - which i think is tied to just one processor - www.fored.co.uk
They (Fored) do have a free dopwnlaodable file on writing C programs. Not the best going but it is a start.
There is also a 'C' like basic from www.xcsb.com which also has a free edition, restrictions are , the libraries are pre compiled (source code for the paid version), the number of each type of variable is curtailed.
Just to keep things fair - Zilog and Renesas all so have free C compilers for their products.
There are people who ahve written some fancy code and use Studio Express 'C' to compile pic code.
Colin
On a clear disk you can seek forever.
Lol, guys take it easy. The guy just said that PICs might looks like a good point to start. He wasn't trying to start a uC war, no need to bring in Ford, Chevy, Democrats, Republicans, etc.
As for C18, yeah, it's still called C18: http://www.microchip.com/stellent/idcpl ... e=en010014 - You can download the free student version from there. It pretty awesome.
SDCC also supports PIC16/18 (still a work in progress, but maybe somewhat usable): http://sdcc.sourceforge.net/
A very, very good C compiler for PICs is MikroC by Mikroelektronika. Only downside is that you have to pay for it: http://www.mikroe.com/en/compilers/mikroc/pic/ - The one thing that makes it better than Microchip's C18 is that it has a library for doing lots of stuff (LCD - graphical/text, I2C, SPI, FAT filesystems, etc.) saving you the hassle of having to write the routines yourself.
As for C18, yeah, it's still called C18: http://www.microchip.com/stellent/idcpl ... e=en010014 - You can download the free student version from there. It pretty awesome.
SDCC also supports PIC16/18 (still a work in progress, but maybe somewhat usable): http://sdcc.sourceforge.net/
A very, very good C compiler for PICs is MikroC by Mikroelektronika. Only downside is that you have to pay for it: http://www.mikroe.com/en/compilers/mikroc/pic/ - The one thing that makes it better than Microchip's C18 is that it has a library for doing lots of stuff (LCD - graphical/text, I2C, SPI, FAT filesystems, etc.) saving you the hassle of having to write the routines yourself.
C18 has those libraries, too. But, if you are looking for a quite capable compile for a great price, MikroC is a good choice. I have used (and paid for) MikroPascal (from the makers of MikroC & also MikroBasic). I like MikroPascal. What puts their compilers up a little is that it does the 12, 14 & 16 bit cores - whereas C18 is only the 16bit core PIC18s. That 12, 14, & 16 bit core means the instruction width, for those that don't know. Not to mention you get a pretty good bang-for-the-buck. Their C compiler is $249.A very, very good C compiler for PICs is MikroC by Mikroelektronika. Only downside is that you have to pay for it: http://www.mikroe.com/en/compilers/mikroc/pic/ - The one thing that makes it better than Microchip's C18 is that it has a library for doing lots of stuff (LCD - graphical/text, I2C, SPI, FAT filesystems, etc.) saving you the hassle of having to write the routines yourself.
But they do have a 2K limited hex file version for free. And, if you want to get a bundle with one of their dev boards, the compiler is only $175... Considering some of the other compilers go for many times that, I think its a good deal. Though, like I said, the only one of their compilers I use is MikroPascal.
Two missquotes in one post...kucomp wrote:Lol, guys take it easy. The guy just said that PICs might looks(sic) like a good point to start. He wasn't trying to start a uC war, no need to bring in Ford, Chevy, Democrats, Republicans, etc.
Was tounge-in-cheek. Add some smiles for the humour-impaired.Bigglez wrote:Oh dear, nothing fills forums like a uC war...
Seems clear to me. As I know little about PICs I'll beCrazyBillyBob wrote:But I really want to go with the Pic family (even though some of the others have good things about them too!). I'll try and better reword one of my original Q's. In side the Pic family, what is a good Chip to start with (I don't know the difference between the 16C's , 18F, or the 16F).
reading along too.
What has never been clear is why there are so many
variants of the actual PIC chips?
Also, why so many options in the toolchain, that are
not quite there or run big $$$ to play?.
A PIC with an F in the name (10F, 16F, 18F) is Flash, a C is one-time-program.In side the Pic family, what is a good Chip to start with (I don't know the difference between the 16C's , 18F, or the 16F)
There are (as I mentioned in a post above), 3 different instruction lengths for the 8 bit PICs. The smallest, the 12 bit instructions, have to have less program memory than would a 16bit instruction word. Mid-range PICs are the 14bit instruction word PICs. each machine instruction is 14bits in length. The "high end" 8 bit PICs are the 16bit instruction word devices that are in the 18F category.
Also, if there is a J in the device's name, it is low voltage.
If you look at the product tree, the devices have different Flash/RAM/EEPROM configurations. Also, some have CAN, some have 2 USARTS, some only have 1. Some have USB, some have USB OTG, some have Ethernet.... Different packaging... The list goes on.What has never been clear is why there are so many
variants of the actual PIC chips?
Having said that, in the "general purpose" category, I agree that there are too many. I think they do this for the selling price point. Why would you want to pay for a device that has 3x more memory than your application would use?
I hope I explained the differences in the PIC families clearly... I am doing this all from memory but I think it is all correct
Oh. And to the OP: If you want to play around with a general purpose PIC, get yourself a 18F4620. Or, if you feel like really playing, get a 18F4550 USB device.
Odd thing is, there hasn't been a single shot fired - everyone IS taking it easy. I read nothing in Biglez's comments as being controversial. I suggest you save it up for the real wars...Lol, guys take it easy. The guy just said that PICs might looks like a good point to start. He wasn't trying to start a uC war, no need to bring in Ford, Chevy, Democrats, Republicans, etc.
The myriad of PICs is probably the result of market segment analysis and competition. "We need a version to fill ####7 gap" and "Zilog just got a big design win, we need a competitive response". I suspect that less than 10% of the versions comprise 90% of the volume (or some variant of the 80-20 rule). In the highly competitive arena, even pennies off the price of the uC can spell the difference between getting the design win and sucking wind.
Finally, optimized or not, most good assembly programmers are going to look in horror at the code a C compiler generates. And PICs with their godawfull banked architecture make the phrase "tight C code" an oxymoron. (I have to laugh at the marketing blather about the 18F series - "C optimized architecture". Complete b*llsh*t, they just un-broke some the 16F architecture.) But unless you are squeezing your code into a smaller PIC to save a few cents, it just doesn't matter. Note, I write in both C and Assembler but prefer C, even if it's vastly larger as my time is more valuable than flash memory. And as much as I think the PIC architecture is a joke, I use it more than others.
wow, x x x with out the spaces is forbidden? That's what I wrote and it got replaced with ####7. I guess it could be mistaken for p*rn sp*m. Man, some times I scratch my head at what some people think is offensive.
To actually answer your question - here's a nice, $25 board with some good features. http://www.sparkfun.com/commerce/produc ... cts_id=762
While it comes pre-programmed with the bit-whacker firmware, it is a nice general purpose PIC board. If you get a PICKit2 ($35) you can reprogram ithe UBW to your heart's content or you can use the USB bootloader and not bother with the PICKit2.
To actually answer your question - here's a nice, $25 board with some good features. http://www.sparkfun.com/commerce/produc ... cts_id=762
While it comes pre-programmed with the bit-whacker firmware, it is a nice general purpose PIC board. If you get a PICKit2 ($35) you can reprogram ithe UBW to your heart's content or you can use the USB bootloader and not bother with the PICKit2.
If you're starting anew, or bored with PICs, the ARM7 chips and boards such as LPC2103/6, are really low cost. And the Great GCC compiler and several elegant IDEs are free. The 32KB limited free version of IAR's C for ARM is more than excellent.
The ARM7 in Thumb instruction set mode is essentially a 16 bit microprocessor (not a stretched out 8 bitter). The LPC21xx and other ARMs come with a serial port bootloader pre-installed at the factory; free downloader.
I started with PICs, have used AVRs for years (because AVRs don't have the bank-switched mess that PICs have), but the many low cost ARM7s and great free tools are compelling.
Coridium (a beginner's BASIC for ARM)
Embedded Artists
many others.
And ARMs are not sole source as are AVR and PIC. Competition: Good.
The ARM7 in Thumb instruction set mode is essentially a 16 bit microprocessor (not a stretched out 8 bitter). The LPC21xx and other ARMs come with a serial port bootloader pre-installed at the factory; free downloader.
I started with PICs, have used AVRs for years (because AVRs don't have the bank-switched mess that PICs have), but the many low cost ARM7s and great free tools are compelling.
Coridium (a beginner's BASIC for ARM)
Embedded Artists
many others.
And ARMs are not sole source as are AVR and PIC. Competition: Good.
I started with PICs and have scene moved to AVRs.
some recommended reading of you choose PICs: PIC Microcontroller: An Introduction to Software & Hardware Interfacing Its expensive, but well worth it imo. Its the best book ive ever read regarding micro controllers. It uses a PIC18 µC and has examples in ASM and C for evey project/chapter in the book. This book also has great explanations of all the common µC data transfer protocols (SPI, CAN, i2c).
For AVRs: C Programming for Microcontrollers Featuring ATMEL's AVR Butterfly and the free WinAVR Compiler
My words of wisdom: No matter which you choose the first thing you should do is learn how to program your µC in system. ICSP for PICs and ISP for AVRs. I was stubborn at first and just did a lot of chip pulling, burning, and re-seating till the pins fell off. That was dumb.
I never used a demo kit to play with µC's. I just jumped right in with a bread board. If you do the same (might not have been the smartedt decision) here's my advice...
If you go PIC the PICKit2 is the way to go. Really cheap and a good all around device.
However AVR doesn't seem to have a good comparable intro programing/debugging device. The AVR Dragon is the only one that does both and its $50 and people (my self included) have had problems with it dieing a lot. Its a very sensitive device as far as ESD and things of that nature. Perhaps an Off brand device is better if you go with AVR. The JTAG ICE MKII is the best while working with AVRs but its a $300 device.
Just my general thoughts on the two flavors:
I used to be a PIC fanboy but am no longer. The idea of having to pay for a C compiler bugs me. I know the student version of PIC C is free but that still bugs me. And if you use that your stuck using PIC18 devices, which really isn't that big of a deal actually scene their probably just as cheap. GCC WinAVR is completely free for the AVR and does a great job and works for all the AVR devices.
I have never used ASM when programing AVRs before (mainly because i dont need to with a free C compiler) but I have with PICs and all i can remember is BANKSEL BANKSEL BANKSEL BANKSEL BANKSEL, which is the thing most everyone here warns about with the divided memory banks on PICs. Its not a bad thing, you just need to always keep in mind which bank you are currently in at that section of code.
There's nothing an AVR can do a PIC can't and vice versa.
some recommended reading of you choose PICs: PIC Microcontroller: An Introduction to Software & Hardware Interfacing Its expensive, but well worth it imo. Its the best book ive ever read regarding micro controllers. It uses a PIC18 µC and has examples in ASM and C for evey project/chapter in the book. This book also has great explanations of all the common µC data transfer protocols (SPI, CAN, i2c).
For AVRs: C Programming for Microcontrollers Featuring ATMEL's AVR Butterfly and the free WinAVR Compiler
My words of wisdom: No matter which you choose the first thing you should do is learn how to program your µC in system. ICSP for PICs and ISP for AVRs. I was stubborn at first and just did a lot of chip pulling, burning, and re-seating till the pins fell off. That was dumb.
I never used a demo kit to play with µC's. I just jumped right in with a bread board. If you do the same (might not have been the smartedt decision) here's my advice...
If you go PIC the PICKit2 is the way to go. Really cheap and a good all around device.
However AVR doesn't seem to have a good comparable intro programing/debugging device. The AVR Dragon is the only one that does both and its $50 and people (my self included) have had problems with it dieing a lot. Its a very sensitive device as far as ESD and things of that nature. Perhaps an Off brand device is better if you go with AVR. The JTAG ICE MKII is the best while working with AVRs but its a $300 device.
Just my general thoughts on the two flavors:
I used to be a PIC fanboy but am no longer. The idea of having to pay for a C compiler bugs me. I know the student version of PIC C is free but that still bugs me. And if you use that your stuck using PIC18 devices, which really isn't that big of a deal actually scene their probably just as cheap. GCC WinAVR is completely free for the AVR and does a great job and works for all the AVR devices.
I have never used ASM when programing AVRs before (mainly because i dont need to with a free C compiler) but I have with PICs and all i can remember is BANKSEL BANKSEL BANKSEL BANKSEL BANKSEL, which is the thing most everyone here warns about with the divided memory banks on PICs. Its not a bad thing, you just need to always keep in mind which bank you are currently in at that section of code.
There's nothing an AVR can do a PIC can't and vice versa.
Who is online
Users browsing this forum: No registered users and 1 guest