PICKit 3 programming problems!

Discussion in 'Embedded Systems and Microcontrollers' started by ruuhkis, Jan 19, 2012.

  1. ruuhkis

    Thread Starter New Member

    Jan 19, 2012
    8
    0
    Hello guys!
    I've finally got my PICKit to succesfully program code on my PIC but it doesn't seem to work properly. MPLab identifies my PIC and it programs and verifies the program correctly but the code doesn't seem to run! I've also tried to use any led blink code that I found online, it builds correctly and programs but doesn't seem to run at all. I've tried to measure the power levels from the pins with mutlimeter also did hook up led there but it didn't lit. I've also changed the code so it will only turn the pin on etc. but still nothing happens. I used diagram from PICKit 3 user guide link at the page DS51795B-page 2 with title " PROPER CONNECTIONS FOR PROGRAMMIN" I ended up with this kind of setup. link to HUGE image
    I read somewhere that I'd need some components such as diode and capacitor added somewhere to filter noise. Also is it okay that I use 10k ohm resistor instead of 4.7k resistors as I don't have one around? I am using PIC PIC16F628A. Any help / suggestions are great! :)

    Also! Heres the code:

    Code ( (Unknown Language)):
    1. include <p16f628a.inc>
    2.  
    3. LED equ 02h;
    4. TRISA equ 85h;
    5. PORTA equ 05h;
    6.  
    7.  
    8. org 0
    9.    
    10.     BSF STATUS, RP0; GO TO BANK 1
    11.     MOVLW 00h ;SET W REGISTER TO 0
    12.     MOVWF TRISA; MOVE W REGISTER TO TRISA REGISTER SETTING PINS TO OUTPUT
    13.     BCF STATUS, RP0; GO TO BANK 0
    14.    
    15.     MOVLW LED; SET W REGISTER TO 2
    16.     MOVWF PORTA; MOVE W TO PORTA SETTING PINS HIGH
    17.  
    18.    
    19.  
    20. end    
    21.  
     
  2. peter_morley

    Member

    Mar 12, 2011
    179
    0
    Is it possible that your program runs for less than micro seconds and so the led turns on and off at a frequency your eye can not detect?

    I have never tried this but will the port pins stay in the same state they were in during the program, even after the program is done executing.
     
  3. ruuhkis

    Thread Starter New Member

    Jan 19, 2012
    8
    0
    You woke plenty of questions in my mind.. Gonna run some tests now! :D
    Will comment back when I am done!! (I thought the program wud loop and loop forever.. :D)
    Why don't this work out :( I made it go on infinite loop etc. and it still doesn't output any voltage!
    None of what I tried did work :(
     
    Last edited: Jan 19, 2012
  4. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    Try this. Also do you power the 16f628 from the PICKIT or a power supply. You can power the PIC from the PICKIT. But by default this option is turned off
    Code ( (Unknown Language)):
    1.  
    2. ;not tested in mplab so it may be errors
    3. include <p16f628a.inc>
    4.  
    5. LED equ 02h;
    6. ;TRISA equ 85h;
    7. ;PORTA equ 05h;
    8. ;The latter is defined in the p16f628a.inc file not needed
    9.  
    10. org    0
    11.  
    12. [LEFT]CLRF PORTA ;Initialize PORTA by
    13. ;setting
    14. ;output data latches
    15. MOVLW 0x07 ;Turn comparators off and
    16. MOVWF CMCON ;enable pins for I/O
    17. ;functions
    18. BCF STATUS, RP1
    19. BSF STATUS, RP0 ;Select Bank1
    20. MOVLW 0x00 ;Value used to initialize
    21. ;data direction
    22. MOVWF TRISA ;Set port A  as inputs
    23. ;TRISA<5> always
    24. ;read as ‘1’.
    25. ;TRISA<7:6>
    26. ;depend on oscillator[/LEFT]
    27. ;mode
    28. loop:
    29. MOVLW LED; SET W REGISTER TO 2
    30.     MOVWF PORTA; MOVE W TO PORTA SETTING PINS HIGH
    31. goto loop
    32.  
     
  5. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    Put this line after the include line in T06AFRE's code:
    Code ( (Unknown Language)):
    1.     __CONFIG _CP_OFF & _WDT_OFF & _BODEN_ON & _PWRTE_ON & _INTRC_OSC_NOCLKOUT & _MCLRE_ON & _LVP_OFF
    With these settings the MCLR pin should be connected to +ve of the supply with a 10K resistor.
    Also I think it should be #include, but include may work.
     
    ruuhkis likes this.
  6. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    Without a loop, the PIC continues executing through the whole program memory, which I think on a blank PIC is full of NOPs and will then start again at the first instruction. It's a bad idea, but for this simple program there would be no observable difference.
     
  7. ruuhkis

    Thread Starter New Member

    Jan 19, 2012
    8
    0
    Hey and thanks for quick response!
    You only forget to come back to first bank, other that that the code was perfect. Only this is that it still didn't give even a signal of working on my PIC after programming it.
    Is it normal that the programming takes under second with this size of code or is something going wrong? And is it possible that there's something that could improve the circuit or just anything? Or can the chip be damaged as I might have been input something on wrong ports testing how can i get it to work... :D Or would it give me error report not being able to program or something? I think the code is perfect, it must be the circuit or the chip?


    Thanks dude, giving it a shot ASAP and reporting back! :)
     
  8. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    Programming time of under a second is normal, have you tried adding the __config line?
     
  9. ruuhkis

    Thread Starter New Member

    Jan 19, 2012
    8
    0
    Thanks for the info.
    I did add it but I am trying to make sure that VE+ means the positive energy source(it is, right?).
    Also, I still keep pickits MCLR connected to chips MCLR, right?
     
  10. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    I think the main culprit may be the missing __config setting. DoH! why did I not see that. I have not used the 16f628. But it is a common mistake to forget turning off analog functions then using the port pins as common digital IO. By default after power up. Pins with analog functions will have this function not digital I/O functions. And this may cause all kinds of strange behavior. This is true for 16F and 18F devices. And probably the rest of Microchip controllers also
     
    ruuhkis likes this.
  11. ruuhkis

    Thread Starter New Member

    Jan 19, 2012
    8
    0
    Amazing got it working, didn't have to connect anything additional to original, or should i do that anyway?
    Now I've just to get this blink.. :D

    PS. super big thanks for you t06afre and Markd77!! :)
     
  12. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    This should blink port A0
    Code ( (Unknown Language)):
    1.  
    2. ;not tested in mplab so it may be errors
    3. include <p16f628a.inc>
    4.     __CONFIG _CP_OFF & _WDT_OFF & _BODEN_ON & _PWRTE_ON & _INTRC_OSC_NOCLKOUT & _MCLRE_ON & _LVP_OFF
    5.  cblock 0x20
    6.  Delay1                   ; Define two file registers for the
    7.  Delay2                   ; delay loop
    8.      endc
    9.      
    10.      org 0
    11. Start:
    12.  banksel PORTA      
    13.  CLRF PORTA ;Initialize PORTA by
    14.  ;setting
    15.  ;output data latches
    16. banksel CMCON
    17.  MOVLW 0x07 ;Turn comparators off and
    18.  MOVWF CMCON ;enable pins for I/O
    19.  ;functions
    20.  banksel TRISA ;Select Bank1
    21.  MOVLW 0x00 ;Value used to initialize
    22.  ;data direction
    23.  MOVWF TRISA ;Set port A  as inputs
    24.  ;TRISA<5> always
    25.  ;read as ‘1’.
    26.  ;TRISA<7:6>
    27.  ;depend on oscillator
    28.  ;mode
    29.   banksel PORTA    
    30. MainLoop:
    31.      bsf       PORTA,0             ; turn on LED on A0
    32. OndelayLoop:
    33.      decfsz    Delay1,f            ; Waste time.  
    34.      goto      OndelayLoop         ; The Inner loop takes 3 instructions per loop * 256 loopss = 768 instructions
    35.      decfsz    Delay2,f            ; The outer loop takes and additional 3 instructions per lap * 256 loops
    36.      goto      OndelayLoop         ; (768+3) * 256 = 197376 instructions / 1M instructions per second = 0.197 sec.
    37.                                    ; call it a two-tenths of a second.
    38.      
    39.      bcf       PORTA,0             ; Turn off LED A0
    40. OffDelayLoop:
    41.      decfsz    Delay1,f            ; same delay as above
    42.      goto      OffDelayLoop
    43.      decfsz    Delay2,f
    44.      goto      OffDelayLoop
    45.      goto      MainLoop            ; Do it again...
    46.      end
    47.      
     
    ruuhkis likes this.
  13. ruuhkis

    Thread Starter New Member

    Jan 19, 2012
    8
    0
    You guys are way too nice for me! :) Thanks again, you've been such a great help! Its glad that I joined in such community. Gonna give this a try very soon! :) And I have now whole weekend to learn! :) Can you answer me one more question? Is the connection from MCLR pin to V+ of the supply with a 10K resistor required? And what is it for? It wasn't on the docs so just wondering :)
     
  14. CraigHB

    Member

    Aug 12, 2011
    127
    15
    I've never actually tried to run a PIC without a loop either intentionally or unintentionally. Wouldn't the program counter just keep going until it rolls over at which time it starts counting again from zero?
     
Loading...