Blinky with PICKit 2 and Velleman Dev Board

Discussion in 'Embedded Systems and Microcontrollers' started by Dawud Beale, Dec 23, 2014.

  1. Dawud Beale

    Thread Starter Member

    Feb 10, 2012
    275
    7
    Hi everyone, I am attempting to program a PIC12C509A that has been plugged into the 8 pin IC Socket on the Velleman board. I am attempted to both program and power the PIC using a PICKit 2 since I dont have the 15V adapted or a serial port on my laptop. I am having a bit of trouble getting it going so just wondered if I could get a bit of help? Here is a picture of my equipment. I am using MPLAB X as my IDE.

    [​IMG]

    Here is my code:


    Code (Text):
    1.  
    2. ;*******************************************************************************
    3. ; Processor Inclusion
    4. ;
    5. ; TODO Step #1 Open the task list under Window > Tasks.  Include your
    6. ; device .inc file - e.g. #include <device_name>.inc.  Available
    7. ; include files are in C:\Program Files\Microchip\MPLABX\mpasmx
    8. ; assuming the default installation path for MPLAB X.  You may manually find
    9. ; the appropriate include file for your device here and include it, or
    10. ; simply copy the include generated by the configuration bits
    11. ; generator (see Step #2).
    12. ;
    13. ;*******************************************************************************
    14.  
    15. ; TODO INSERT INCLUDE CODE HERE
    16. #include "P12C509A.inc"
    17. ;*******************************************************************************
    18. ;
    19. ; TODO Step #2 - Configuration Word Setup
    20. ;
    21. ; The 'CONFIG' directive is used to embed the configuration word within the
    22. ; .asm file. MPLAB X requires users to embed their configuration words
    23. ; into source code.  See the device datasheet for additional information
    24. ; on configuration word settings.  Device configuration bits descriptions
    25. ; are in C:\Program Files\Microchip\MPLABX\mpasmx\P<device_name>.inc
    26. ; (may change depending on your MPLAB X installation directory).
    27. ;
    28. ; MPLAB X has a feature which generates configuration bits source code.  Go to
    29. ; Window > PIC Memory Views > Configuration Bits.  Configure each field as
    30. ; needed and select 'Generate Source Code to Output'.  The resulting code which
    31. ; appears in the 'Output Window' > 'Config Bits Source' tab may be copied
    32. ; below.
    33. ;
    34. ;*******************************************************************************
    35.  
    36. ; TODO INSERT CONFIG HERE
    37. __CONFIG _OSC_IntRC & _WDT_ON & _CP_OFF & _MCLRE_ON
    38. ;*******************************************************************************
    39. ;
    40. ; TODO Step #3 - Variable Definitions
    41. ;
    42. ; Refer to datasheet for available data memory (RAM) organization assuming
    43. ; relocatible code organization (which is an option in project
    44. ; properties > mpasm (Global Options)).  Absolute mode generally should
    45. ; be used sparingly.
    46. ;
    47. ; Example of using GPR Uninitialized Data
    48. ;
    49. ;   GPR_VAR        UDATA
    50. ;   MYVAR1         RES        1      ; User variable linker places
    51. ;   MYVAR2         RES        1      ; User variable linker places
    52. ;   MYVAR3         RES        1      ; User variable linker places
    53. ;
    54. ;   ; Example of using Access Uninitialized Data Section (when available)
    55. ;   ; The variables for the context saving in the device datasheet may need
    56. ;   ; memory reserved here.
    57. ;   INT_VAR        UDATA_ACS
    58. ;   W_TEMP         RES        1      ; w register for context saving (ACCESS)
    59. ;   STATUS_TEMP    RES        1      ; status used for context saving
    60. ;   BSR_TEMP       RES        1      ; bank select used for ISR context saving
    61. ;
    62. ;*******************************************************************************
    63.  
    64. ; TODO PLACE VARIABLE DEFINITIONS GO HERE
    65. _blink equ 0x020
    66.  
    67. ;*******************************************************************************
    68. ; Reset Vector
    69. ;*******************************************************************************
    70.  
    71. ;RES_VECT  CODE    0x0000            ; processor reset vector
    72. ;   GOTO    START                   ; go to beginning of program
    73.  
    74. ;*******************************************************************************
    75. ; TODO Step #4 - Interrupt Service Routines
    76. ;
    77. ; There are a few different ways to structure interrupt routines in the 8
    78. ; bit device families.  On PIC18's the high priority and low priority
    79. ; interrupts are located at 0x0008 and 0x0018, respectively.  On PIC16's and
    80. ; lower the interrupt is at 0x0004.  Between device families there is subtle
    81. ; variation in the both the hardware supporting the ISR (for restoring
    82. ; interrupt context) as well as the software used to restore the context
    83. ; (without corrupting the STATUS bits).
    84. ;
    85. ; General formats are shown below in relocatible format.
    86. ;
    87. ;------------------------------PIC16's and below--------------------------------
    88. ;
    89. ; ISR       CODE    0x0004           ; interrupt vector location
    90. ;
    91. ;     <Search the device datasheet for 'context' and copy interrupt
    92. ;     context saving code here.  Older devices need context saving code,
    93. ;     but newer devices like the 16F#### don't need context saving code.>
    94. ;
    95. ;     RETFIE
    96. ;
    97. ;----------------------------------PIC18's--------------------------------------
    98. ;
    99. ; ISRHV     CODE    0x0008
    100. ;     GOTO    HIGH_ISR
    101. ; ISRLV     CODE    0x0018
    102. ;     GOTO    LOW_ISR
    103. ;
    104. ; ISRH      CODE                     ; let linker place high ISR routine
    105. ; HIGH_ISR
    106. ;     <Insert High Priority ISR Here - no SW context saving>
    107. ;     RETFIE  FAST
    108. ;
    109. ; ISRL      CODE                     ; let linker place low ISR routine
    110. ; LOW_ISR
    111. ;       <Search the device datasheet for 'context' and copy interrupt
    112. ;       context saving code here>
    113. ;     RETFIE
    114. ;
    115. ;*******************************************************************************
    116.  
    117. ; TODO INSERT ISR HERE
    118.  
    119. ;*******************************************************************************
    120. ; MAIN PROGRAM
    121. ;*******************************************************************************
    122.  
    123. ;MAIN_PROG CODE                      ; let linker place main program
    124.  
    125. ;START
    126.  
    127.     ; TODO Step #5 - Insert Your Program Here
    128.  
    129.     MOVLW 0x55                      ; your instructions
    130.     GOTO $                          ; loop forever
    131.  
    132. END
    I am looking to get just enough basic code together so that it will actually run so I can test the hardware setup. What changes do I need to make to my code to make it run?

    Also, I have tried to program and power my PIC and Dev board and it is saying "no device detected" so what do I need to do to get this hardware working firstly for programming and secondly for actually running the PIC on the Dev board for testing?
     
  2. jpanhalt

    AAC Fanatic!

    Jan 18, 2008
    5,694
    904
    Isn't the 12C509A one-time programmable? If so, I suggest getting a 12F509A to practice on and to be sure your program works.

    Where's your code? Those are just templates.

    Edit: "Device not detected" may be the result of improperly setting your programmer. First be sure you have selected the proper chip in the configure drop-down. Then in the programmer dialog go to settings>power and select power target by programmer and set the proper voltage.

    John
     
    Last edited: Dec 23, 2014
  3. Dawud Beale

    Thread Starter Member

    Feb 10, 2012
    275
    7
    I used the template to start my code. I have some basic code within the template. Namely a link to the appropriate header file, the config word, and just a simple loop. The idea was just to make a start and then I can start building on my code and implement a blinky program, and finally move on to my intended purpose for the microcontroller.

    I hadn't realized they were OTP to be honest. I have a PIC16F84A so I will use that instead. These were just ones I had lying around and so I thought I might aswell use what I have rather than ordering in more.

    I do have about 5 of these PIC12C509A chips so its possible for me to use them I guess. I was given them. Now I know why lol.

    Still, how do I get the velleman board working for programming and also for running the microcontroller?
     
  4. jpanhalt

    AAC Fanatic!

    Jan 18, 2008
    5,694
    904
    Did you do the steps I suggested for the programmer in Configure and Programmer drop downs?

    Have you gone through any tutorial for Assembly and PIC's? There are plenty of them. Gooligum ( http://www.gooligum.com.au/tutorials.html) and Nigel Goodwin (http://winpicprog.co.uk/pic_tutorial.htm ) are two I can recommend.

    Since you appear to want to use relocatable code, at least in some of your examples, then Gooligum is the way to go. I would suggest, however, to start with absolute code. In which case, either tutorial is good. If you are really just beginning, I would recommend Nigel's until you get an LED blinking, but that bias is slight.

    John
     
    Dawud Beale likes this.
  5. tracecom

    AAC Fanatic!

    Apr 16, 2010
    3,869
    1,393
    Post deleted.
     
  6. Dawud Beale

    Thread Starter Member

    Feb 10, 2012
    275
    7
    Jpanhalt ok I will go through that to help me develop my code, but what do I need to do from a hardware perspective? Can I program the PIC using the PICKit 2 and Velleman board and can I power it up and utilise the switches and LEDs using the PICKit 2?

    Can it be done with my current hardware or should I buy something like this:

    http://www.ebay.co.uk/itm/New-PIC-U...al_Components_Supplies_ET&hash=item2eca31e3dd
     
    Last edited: Dec 23, 2014
  7. tracecom

    AAC Fanatic!

    Apr 16, 2010
    3,869
    1,393
    I have looked at the schematic for the Velleman board, and it looks like you can use it as a programming platform for the PICkit 2. All you need is a 12-15 VDC power source capable of at least 300mA for the Velleman board, and a method to connect the PICkit2 to the correct pins on the Velleman board.
     
  8. jpanhalt

    AAC Fanatic!

    Jan 18, 2008
    5,694
    904
    1) I have not looked at the Velleman board, so will take tracecom's word for how to use it.
    2) Re: eBay item. I do not believe you need that programmer. The PK2 is really a great programmer and has lots of support. You can even use it as a logic analyzer. I do not own one. I do own the PK3, which is similar but cannot be used as a logic analyzer and I/O probe. The PK3 has a fairly weak power supply, and I believe the PK2 is similar. That factor comes into play when doing In Circuit Serial Programming (ICSP, which is a registered TM of Microchip).

    General Comment:

    There are several ways to program a chip and some terms may be causing confusion. Let me try to sort it out a little for you. For simplicity, consider only the Microchip products that have been mentioned so far, e.g., 12Fxxx, 12F1xxx, 16Fxxx, and 16F1xxx chips. Consider these two choices: 1) Program the chip by itself; and 2) Program the chip while it is in a circuit by accessing specific pins. In the latter case, those pins that are used for programming need to be isolated during programming from the rest of the circuit. Such in-circuit programming is called ICSP by Microchip.

    If you look at Microchip's offerings for programmers, you will find devices such as the PicStartII Plus, which is a stand alone programmer. It has a 40-ppin ZIF socket. You attach the programmer to a PC (mine just used a standard serial, 9-pin connector), put the chip in the socket, close the lever, and program. Works great, but what do you do with a chip that doesn't have pins that fit that socket? You can make an adapter board with pins or wires to the appropriate pin locations in the socket. That is basically what the ICSP programmers do.

    As a hobbyist, the Microchip ICSP programmers to consider are the PK2, PK3, and ICD3 (more expensive). None of those programmers is designed like the PicStartII Plus with its own socket, but you can buy adapter sockets from Microchip or elsewhere, or make your own. I got mine from Joshua1Systems ( See: http://www.j1sys.com/icsp-adapters/ ). There are other vendors. I found mine on eBay. They come with ZIF sockets for various sizes of chips, Here is what the largest (40-pin) version looks like:
    upload_2014-12-24_4-33-55.png

    In operation, you must configure the jumpers for the chip you are using, then attach the ICSP programmer to the six pins on the right and program away. It is very much like using a PicStartII Plus. As I mentioned in an earlier post, you must go to programmer> settings>power and select power target by programmer and voltage (for the chips you have mentioned that is 5V). Now, "target" is the term used by Microchip for the chip. In this case, it is just the chip in an adapter board. It may be a bit of a misnomer, but it is still called ICSP.

    As an alternative, you can design your working circuit to be programmed using ICSP. That is where the Velleman board comes into play. If you are programming a chip in its operating circuit, not in just an accessory board, then you must decide whether to power the "target" by the circuit or by the programmer. The PK2 and PK3 have very small power supplies. I don't recall the exact specifications, but I believe they are limited to about 30 mA. The ICD3 can supply 100 mA. Thus, if you have a circuit that requires more power than the programmer can supply, you must provide that accessory power or provide isolation so that less power is required. As an example, assume your circuit includes a large LCD display. The backlight for that display may require 30 mA . It would be a little uncertain whether the PK2 could provide the power and program in that circuit; however, you might design your circuit with a jumper for the backlight. If you remove that jumper, then the circuit may only need a few milliamps and can be programmed just fine powered by the programmer.

    Now, you ask about powering LED's with your PK2. I don't know how many LED's you are talking about nor their current needs. But clearly, you may well exceed the supply ability of the PK2. That is where powering by the target (e.g., the Velleman board) comes into play.

    I hope this early morning (for me) drivel helps.

    John

    Addendum: On some further reading, I don't believe your PK2 can even program OTP chips, as they require voltages or currents that it cannot supply (http://www.microchip.com/forums/m510026.aspx ).
     
    Dawud Beale likes this.
  9. Dawud Beale

    Thread Starter Member

    Feb 10, 2012
    275
    7
    I agree that PICKit 2 is perfect for programming, but I need to somehow connect it to a PIC and also need to test the PIC once it's been programmed. I thought the velleman would enable me to do those two things. I don't want to construct my own for now. The Velleman board doesn't come with a power supply unfortunately.

    Is there a quick easy dev board I can insert a PIC into and the PICKit2 onto and then program the chip and test it if it has a few buttons and LEDs?

    The reason I thought I could use a Velleman board is because if you look, it has 5 pins, and the 6th pin of the PICKit 2 is just an auxillary pin. As PICs only need 5V I figured I could draw 5V from the PICKit 2 when testing. The board has multiple buttons and LEDs.I thought I could just hook my PICKit 2 onto the 5 pins on the velleman board

    As the velleman board has various IC sockets I thought I can just insert my PIC into the relevant socket to program and test it
     
  10. hexreader

    Active Member

    Apr 16, 2011
    250
    82
    You CAN program PIC16F84 with PICkit2 and the Velleman board that you have.

    PICkit2 can supply enough power, so you already have everything that you need.

    Connect PICkit2 pin 1 to SK3 pin 1 (pin 6 will just hang unconnected - that is OK)

    Fit jumpers to JP3 and JP4

    Leave the PROG switch in the run position.

    PIC16F84A goes into "18P" socket - be sure that pin1 goes to pin1

    Hex file attached that will flash all LEDs

    Enjoy!
     
    Last edited: Dec 24, 2014
    Dawud Beale likes this.
  11. tracecom

    AAC Fanatic!

    Apr 16, 2010
    3,869
    1,393
  12. hexreader

    Active Member

    Apr 16, 2011
    250
    82
    Wow - my memory really is shot! I don't even remember replying to this earlier thread. :( Take my advice - don't get old....

    Had I spotted that this was a double-post I would not have replied
     
  13. tracecom

    AAC Fanatic!

    Apr 16, 2010
    3,869
    1,393
    I tried to quit, but failed.
     
    hexreader likes this.
  14. hexreader

    Active Member

    Apr 16, 2011
    250
    82
    Not quite worthy of a ROFL response, but cheered me up just the same - thanks :)

    Robin - chronological age 56 - physical age 70 - mental age toggles between 8 and 80 :)
     
    Last edited: Dec 24, 2014
  15. Dawud Beale

    Thread Starter Member

    Feb 10, 2012
    275
    7
    The last time I had a go was when we were using PICs in university but it was very new to me at the time. We were given hand built PCBs in the end that could program and run what we had built in class. We didn't touch microchip again for years so now having another go and want to be able to go self sufficiently so once I can use my hardware and upload programs I can start experimenting.

    Since then we've used national instruments myrio which are easier to use.
     
  16. Dawud Beale

    Thread Starter Member

    Feb 10, 2012
    275
    7
    Thanks so much for your help. I'll give that a go and see how I get on. One question. What's the jumpers on jp3 and jp4 for?
     
  17. Dawud Beale

    Thread Starter Member

    Feb 10, 2012
    275
    7
    Guys I've tried uploading that hex file but it says device error, hex file not loaded

    Jpanhalt if I can't get this to work I'll prob try your eBay suggestion
     
  18. tracecom

    AAC Fanatic!

    Apr 16, 2010
    3,869
    1,393
    Here's the manual for the Velleman board. Have a look at it; you can ignore the software sections, but study the hardware sections. See the photo in Section 4 for an explanation of JP1-JP6.

    http://www.vellemanusa.com/downloads/0/modules/usermanual_vm111_uk.pdf
     
    Last edited: Dec 24, 2014
  19. jpanhalt

    AAC Fanatic!

    Jan 18, 2008
    5,694
    904
    You can do ICSP with short jumpers from the PK2 to your device on a perf board. No need to order something off ebay and wait just to trouble shoot this problem. The datasheet shows which pins to use. Ordering a set might be useful for the future, though.

    Keep the jumpers short, but practical. I did ICSP with my PicStartII and 6" jumpers. You can also erase the PIC and then do a blank check. If it doesn't read blank there is a problem early on. The programmer will report "erase" , because that is what it thinks it did with Vpp. You need to read it to be sure it is erased.

    John
     
  20. Dawud Beale

    Thread Starter Member

    Feb 10, 2012
    275
    7
    Ok so literally five wires going from pickit to a breadboard? Ok I'll give that a try
     
Loading...