New to pic programming, help needed please.

Discussion in 'Programmer's Corner' started by bainsk8, May 31, 2011.

  1. bainsk8

    Thread Starter New Member

    May 31, 2011
    25
    0
    A big hello to all here, I am new on the forum and also to PIC programming. I would like to learn PIC programming as a hobby, I don't have much experience with electrics either and am currently reading Teach yourself Electricity and Electrics by Stan Gibilisco as a starter.

    I am aware that there is a huge resource of tutorials and projects online , but what I would like to know is where to start?

    I have read that the PICkit 2 Starter Kit would be a great place to start, is this the general feeling amongst forum members here?

    Would there be any other recommendations for reading material or projects that would be of great use for someone like me? I realise that programming PIC's is done in C, again this is a language I know nothing about so maybe a good foundation book on this would be of great help.

    I look forward to spending some time here and learning from you guys and hope that one day I can return the help.

    Darren :)
     
  2. DerStrom8

    Well-Known Member

    Feb 20, 2011
    2,428
    1,328
    Welcome to AAC, Darren! :)

    I personally use the PICkit2, and it seems to work very well. I also downloaded MPLAB from the microchip website, as well as the C18 compiler. I bought two PIC18F1330 chips, and so far, they serve my purposes very well.
    As for getting started with C, there are a few tutorials out there on the internet, though I have not found any really extensive ones yet. Here are a few links to get you started, though:

    http://www.swarthmore.edu/NatSci/echeeve1/Ref/C for PIC/C_Intro.html
    http://seniord.ece.iastate.edu/dec0604/index_files/tutorialDec0604.pdf
    http://www.rocklore.com/3v0/tutorials/JunebugTut1C3.pdf
    http://www.gooligum.com.au/tut_baseline_C.html

    It is important to understand that this all depends on the type of chip and compiler you choose. I would recommend deciding what you are going to get, and then posting here again to let us know. We will be able to help more when we have that information.
    I hope his helps, and good luck! :)
    Der Strom
     
    bainsk8 likes this.
  3. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    bainsk8 likes this.
  4. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    Oh screw the budget, get the board too! When you are just starting you don't want to wonder why your LED isn't blinking because the code is bad, or the board is bad. Or both are bad. If you want it to take days or weeks to get the very first simple thing to work go ahead and build your own board.

    On the other hand, if you are using a PIC with an internal oscillator then it gets a lot easier and you just may worry your way thru it all. I just could not recommend it for a beginner.

    On the third hand, the pre-built board comes with demo programs that work on that board, and just getting those to work is worth the effort.
     
    bainsk8 likes this.
  5. bainsk8

    Thread Starter New Member

    May 31, 2011
    25
    0
    Thank you guys for your replies and the food for thought.

    @ Der Strom, those links are great, I especaly like the 3rd link as it explains with good diagrams the workings of a uC. The last link is the list of tutorials I thought would be a good starting point, but was looking at starting with the Baseline PIC Architecture and Assembly Language Tutorials and then working to the Baseline PIC C Programming Tutorials.

    @ t06afre I think I will get the PICkit2 as the tutorials refer to that board and I don't really know what the differences are between this board and the PICkit 3 Debug Express. Obviously there are benefits of using the PICkit 3 bundle but for someone with no knowledge like me, I can't see the positives or understand how to use them.

    What is debug? Would I be right in thinking it is a software sequence that runs through the board/uC program looking for faults? I am sorry for my lack of knowledge.

    It would be great to build something that I could use as a tool to further my education but I do find myself agreeing with ErnieM to some extent, more so at this stage but maybe after completing some tuts. I may have the confidence to build this board.

    Der Strom you wrote:
    It is important to understand that this all depends on the type of chip and compiler you choose.

    If I am to start with the Baseline PIC Architecture and Assembly Language Tutorials then I would need to work with the 12F509 chip. Is this what you meant? I am also aware that this is not C language but Assembly, what the difference is i don't know which is why I thought I better start here to work out and have an understanding of what the difference is. Is this a wise thing to do or necessary for that matter?

    thanks again guys for your time, input and valuable help. ;)
     
  6. bainsk8

    Thread Starter New Member

    May 31, 2011
    25
    0
    OK so I have done a fair bit of reading on the Pickit 3 and am confused as to if the demo board that comes with it will except other family of chips, the PIC18F45K20 that is on the board looks to be soldered?

    If I wanted to work with say a PIC16F690 with the Pickit 3 what additional board would I need or would I need a Socket Module?

    Am I right in thinking the Pickit 2 low count board that comes with the Pickit 2 will except more than just the one chip it comes with? If so how do I get this flexibility with the Pickit 3?

    I hope my questions makes sense.
     
  7. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    Both PICKIT 2 and 3 are general programmer debugger units. So you are not locked to use a demo board only. The debug express bundle use a board with a SMD MCU soldered in place. So you can not change chip.
    If you want to use a pic16f690. You can mount it on a solderless bread board. And hook it up to your PICKIT
    [​IMG]
     
    bainsk8 likes this.
  8. DerStrom8

    Well-Known Member

    Feb 20, 2011
    2,428
    1,328
    If you download MPLAB from the microchip website, it comes with the PIC ASM compiler. Here is another tutorial for assembly that helped me back when I was still using it. It is for the PIC16F84, which is probably a bit easier to start with than the 12F509. It has more I/O pins and has more functions associated with it. I think this might be worth getting instead of the 509.
    Der Strom
     
    bainsk8 likes this.
  9. Barnaby Walters

    Member

    Mar 2, 2011
    103
    4
    Hi there,

    I started out not with PICs not long ago, and I think I can answer some of your questions…

    First of all: Debugging. I cannot do it myself as my programming setup is on a Mac, and you need MPLAB to use debugging. What debugging allows you to do is have the circuit connected to the computer, and at any point you can pause the program and see what values are in the PICs memory. You can also step through instruction by instruction. An invaluable resource! It would have saved me lots of time.

    Yes, if you get the debugging board you will only be able to use it as a standalone unit. If you get either the PICKIT 2 or 3 starter kit, you can use the boards not only as training boards but also to program PICs to then use in your own circuits.

    There is a HUGE difference between assembly 'language' and C. Assembly is very close to the hardware — it's more complicated and slightly harder to understand, but the PICKIT 2 lessons take you through it from the very beginning and explain everything well. If you use assembly, you will be meddling at a very base level with bits, bytes and configuration.
    C, however, is a 'high'(er) level language. It allows you to do things like delays and multiplication very easily — but bear in mind that whatever you write in C is converted into ASM for the chip.

    In short — C *might* be easier, ASM *will* be more complex, but will give you a greater understanding of what's going on in the MCU.

    I use assembly at the moment. I plan to give C a serious try once I've fully got my head round assembly.

    Another thing to bear in mind! The PICKIT 2 starter kit includes lessons about ASM, whereas the PICKIT 3 includes C lessons. Both are available for free off the microchip website, if you want to get a taste of what the languages 'feel' like.

    MCUs are great fun and extremely interesting — good luck!

    Thanks,
    Barnaby
     
    bainsk8 likes this.
  10. bainsk8

    Thread Starter New Member

    May 31, 2011
    25
    0
    That is great info guy's and answers all my questions.

    I think I will get a PK2 and work through the lessons and upgrade later to PK3 at a later date.

    Thanks again for all your input and help.
     
  11. bertus

    Administrator

    Apr 5, 2008
    15,645
    2,344
    Hello,

    If you want to program the pics without a demo board, this page will give you the information how to connect the pic to the pickit:
    http://www.sprut.de/electronic/pic/icsp/icsp.htm

    The page is in german, but the pictures are clear.

    Bertus
     
    bainsk8 likes this.
  12. Barnaby Walters

    Member

    Mar 2, 2011
    103
    4
    Sounds to me like a Good Plan ;)

    Thanks,
    Barnaby
     
  13. bainsk8

    Thread Starter New Member

    May 31, 2011
    25
    0
    Hi Bertus this is great so I could in fact use the PK3 and make a ICSP board to connect a PIC16F84 to do Der Strom earlier link Assembly language tutorials? I think now I am understanding how connectivity to the programmer works.

    I also found this that shows how to connect the PK3 ICSP when using a breadboard, this shows the very thing that I was having trouble with and that is how to work with a chosen PIC and PK3.

    http://blog.makezine.com/archive/2010/10/make-it-last-build-series-hello-wor.html

    So I think that's it then, I am going to get the PK 3, a breadboard, necessary components and start the tuts. using the PIC16F84.

    It has also dawned on me that I can use other PIC's to complete the tuts providing there is enough pins and the PIC meets the requirements. That is right, isn't it?

    Thanks again all. :D
     
  14. bainsk8

    Thread Starter New Member

    May 31, 2011
    25
    0
    Another thing I learnt while searching for information that a newbie like me would of never considered and is definetly worth a mention for anyone also reading this in my position is to add 0.1uF "supply bypass" caps across the power pins. More info here: http://forum.allaboutcircuits.com/showthread.php?t=45583
     
  15. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    Don't keep changing PICs till you get VERY comfortable with them. Each has subtle diferences, and they can drive you batty. Additionally, you don't need any complications when starting off. If your tutorial is for PICXXX123 then you should absolutely get a PICXXX123 and nothing else.

    Another reason to get the full debug kit with a PICKIT and board (said from the guy who build 3 graphic based PIC system breadboards as needs changes and the PIC needed an "upgrade", then tossed em all aside when he found a graphic developer board for $150).

    (No, you don't want that board.)

    (Yet...)
     
  16. bainsk8

    Thread Starter New Member

    May 31, 2011
    25
    0
    That sounds like good advise to me and it will be exercised, thank you. I was just reading that I will need to include a 4Mhz Crystal, I have never worked with a crystal before so thought I better have an understanding of them first... good old Wikipedia. ;)

    Its odd but I feel as if this is all coming together now after 4 days of head scratching. :D

    LOL I bet you had fun making them on breadboards and learnt quite a bit along the way. Again I will take your advise on the Graphic dev. board. :D

    It's strange because I have had the burning desire to get into electrics and PIC programming for about 4 years and now I have finally decided to pursue it, I find myself asking the question why, for what means am I doing it. I guess the ideas of things to make for myself, friends, family or home will come later once I fully understand the potential and how to do it. A custom built alarm system for the house would be good I guess. Oh and maybe a automatic irrigation system for the green house, that way I could spend less time tending to the plants and more time learning to program PIC's. ;)

    Thanks for your help ErnieM and all, its mostly appreciated.
     
  17. DerStrom8

    Well-Known Member

    Feb 20, 2011
    2,428
    1,328
    I don't see why not to start with a PICkit2. It also has ICSP and has enough features for any beginner. It is quite user-friendly and easy to learn with. I personally don't see any any advantages a PICkit3 has over a PICkit2, especially if you're just starting out.
    Der Strom
     
  18. bainsk8

    Thread Starter New Member

    May 31, 2011
    25
    0
    I have two reasons from what I kept finding from other peoples comments, they are not really advantages as such.

    1) Being the switch from PK2 to PK3 is not a smooth transition as 2 appears to be a super piece of kit and 3 seems to of lost some of the ease of use that 2 has. I thought by using 3 at the out start I would not be faced with such problems later on.

    2) PK3 is at its early stages and I have read that there will be more features that will become available and the fact that there is a driver update with each PIC means that PIC's that are still in development will be supported once released, so should I decide to move to another PIC later I thought it would give me the most flexibility.

    Please note I am a newbie so I could be shooting myself in the back with a gun I loaded... I am just basing my decisions on what I have read.

    I have already hit a small problem in deciding what PIC to use as I didn't realise that there are so many different variations of PIC16F84. I have been looking at this one, (PIC16F84A-04/P) to use for this tutorial that you posted earlier on. What are your thoughts Der Strom? Do you think this would be fine? I didn't realise how many variations of the same PIC there was, I'm absolutely amazed :)
     
  19. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    The PIC16F84A is a very old device. It has no analog converters, no PWM, one crappy timer, and it has no internal oscillator so you are stuck with an external one.

    I myself own 3 Pickit 2's, and have heard some not nice things about the Pickit 3 version, but bottom line is it works for the importaint things, programming and debugging. The PICkit 3 Debug Express is a great place to start, I got one when it came with the Pickit 2.


    • PICkit 3 Debugger/Programmer
    • PICkit 3 Users Guide
    • A series of 12 lessons on assembly programming that cover I/O, A/D converters, timers, interrupts, and data tables (All source code files are provided)
    • A Debugging Tutorial on using the PICkit 3 as a debugger with the MPLAB IDE
    • Microchips FREE MPLAB IDE software and C Compiler for a complete code development environment
    What more could you want for 70 bucks?

    They also have a Low Pin Count USB Development Kit w/ Pickit 2 but that isn't a good place to start. If you're stuck on the Pickit 2 then it would be best to buy the kit and a board separately.

    As odd as it may seem Radio Shack sells (or sold till recently) a very good dev tool. It is a Basic Stamp board with a prototyping area. A Stamp is a PIC programmed with a Basic language interpreter, you write code on your computer and upload it over an RS-232.
     
    bainsk8 likes this.
  20. Barnaby Walters

    Member

    Mar 2, 2011
    103
    4
    Hi there,

    Not having actually used the PICKIT 3, I feel unqualified to say this, but… both of these reasons seem to point to the PK2 being an easier, more stable device. And, check out it's supported device list — that'd keep me happy for years! 8 bit, 16 bit, 32 bit, DSPics — the PK2 is not particularly lacking!

    However, as Ernie says, either will give you a solid foundation. I personally have had no problems with a PK2 clone that cost half as much and came with a free universal ZIF socket…

    There are a scary number of PICs — when I have more experience with a wider range of them, I plan to put together a 'shortlist' of some particularly useful ones, with sensible descriptions of their features and what applications they're suited to. Until then, use the ones provided, or ones featured in tutorials. Microchip do a very good samples program — I've never bought a PIC, I just order whatever I need, leaving a month or so in between orders.

    You will come across problems if you switch between PICs a lot — some use different C compilers and different instruction sets, and have different features mapped to different memory locations — very confusing! Be prepared to do some serious datasheet reading when trying out a new PIC with lots of features…

    Thanks,
    Barnaby
     
    bainsk8 likes this.
Loading...