0
\$\begingroup\$

I was trying to program a PIC microcontroller with MPLabX 5.1 and PICKIT3. I'm having a weird problem. After flashing the program, with PICKIT connected, the MCU works fine but after disconnecting it from PICKIT, making it work standalone, the MCU stops working. I have no clue what's going on. I have previous experience with AVR and new to PIC world. Please help me solve this issue.

Thanks!

Update

MCLR is pulled up, debug bit is turned off in the config file in order to make PICKIT work as a programmer rather than a debugger.

Does work with PICKIT connected, Does not work standalone i.e., with external supply connected with PICKIT disconnected.

MCU is - PIC18LF45K40 (PDIP)

The circuit does not have much going on,Power supply and Pull up resistor is connected and Pin-3 is supposed to give out pulses. Configured to work with internal oscillator. MCLR pin is pulled up with 10K resistor.

\$\endgroup\$
  • 1
    \$\begingroup\$ Is it still getting its power from somewhere? Make sure the MCLR line is pulled high... I don't know, try providing more detail somehow. A schematic of what you've got would likely be helpful. \$\endgroup\$ – Richard the Spacecat Jan 17 at 13:11
  • 2
    \$\begingroup\$ All you told us was "Now it works, now it don't" There is very little for us to work with. I suggest you post the schematic and do the 1,2,3 of debugging: 1/ Check the power, 2/Check the reset, 3/ check the clock. \$\endgroup\$ – Oldfart Jan 17 at 13:11
  • \$\begingroup\$ @RichardtheSpacecat When running the MCU with PICKIT its working. After disconnecting PICKIT, MCU somehow stops executing the program until next flash. The power is provided to the MCU (3.3v), there are no external clocks connected, MCLR is pulled high, debug bit is turned off in the config. \$\endgroup\$ – Sai Prasad Jan 17 at 13:36
  • \$\begingroup\$ @Oldfart I did those and because it didn't work, I posted the issue on stackexchange. If you ever come across this kind of issue please help me out I'd really appreciate that. I'm just a beginner to the PIC world. Your words are somewhat true "Now it works" - When PICKIT is connected "now it don't" - When its disconnected from PICKIT and powered externally. Thanks! \$\endgroup\$ – Sai Prasad Jan 17 at 13:39
  • 1
    \$\begingroup\$ Be certain that the build configuration is set to "Release" . I'm not in front of a computer with MPlabX but it is somewhere in the configuration tree (left panel). \$\endgroup\$ – Dwayne Reid Jan 18 at 1:32
0
\$\begingroup\$

You really need to read the help on how to ask a better question.

For best results post a small but complete example application that show exactly how you have initialized your PIC18F45K50 with a simple demo application like a GPIO pin toggle.

A description of this is in your question the only thing missing is how you did your PIC setup.

Creating this kind of example for someone new to Microchips MPLABX tool chain this is an almost impossible task.

Developers that use the Microchip MCC (MPLAB Code Configurator) tool find that the generate code is too complex to post here as an example.

This is the kind of example you should post here:

    /*
     * file: main.c
     * target: PIC18LF45K50
     * IDE: MPLABX v5.10
     * Compiler: XC8 v1.45
     *
     *                           PIC18LF45K50
     *                    +---------:_:---------+
     * 10K pull-up RE3 -> :  1 VPP       PGD 40 : <> RB7
     *             RA0 <> :  2           PGC 39 : <> RB6
     *         LED RA1 <> :  3               38 : <> RB5
     *             RA2 <> :  4               37 : <> RB4
     *             RA3 <> :  5               36 : <> RB3
     *             RA4 <> :  6               35 : <> RB2
     *             RA5 <> :  7               34 : <> RB1
     *             RE0 <> :  8          INT0 33 : <> RB0
     *             RE1 <> :  9               32 : <- VDD 3v3
     *             RE2 <> : 10               31 : <- VSS GND
     *         3v3 VDD -> : 11               30 : <> RD7
     *         GND VSS -> : 12               29 : <> RD6
     *             RA7 <> : 13 OSC1          28 : <> RD5
     *             RA6 <> : 14 OSC2          27 : <> RD4
     *             RC0 <> : 15 SOSCO         26 : <> RC7
     *             RC1 <> : 16 SOSCI         25 : <> RC6
     *             RC2 <> : 17 CCP1          24 : <> D+
     *        3v3 VUSB -> : 18               23 : <> D-
     *             RD0 <> : 19               22 : <> RD3
     *             RD1 <> : 20               21 : <> RD2
     *                    +---------------------+
     *                            DIP-40
     *        
     * Description:
     * 
     * This applicaiton toggles the RA1 output hight for 250 millseconds then low for 250 millseconds.
     * 
     * See: https://electronics.stackexchange.com/questions/417447/pic-microcontroller-not-working-without-pickit3
     * 
     * The circuit does not have much going on,Power supply and Pull up resistor 
     * is connected and Pin-3 is supposed to give out pulses. Configured to work 
     * with internal oscillator. MCLR pin is pulled up with 10K resistor.
     */
    #include <xc.h>
    /*
     * PIC configuration words
     */
    #pragma config PLLSEL = PLL3X, CFGPLLEN = ON, CPUDIV = NOCLKDIV
    #pragma config LS48MHZ = SYS48X8, FOSC = INTOSCIO, PCLKEN = OFF
    #pragma config FCMEN = OFF, IESO = OFF, nPWRTEN = OFF, BOREN = OFF
    #pragma config BORV = 190, nLPBOR = OFF, WDTEN = SWON, WDTPS = 32768
    #pragma config CCP2MX = RC1, PBADEN = OFF, T3CMX = RC0, SDOMX = RB3
    #pragma config MCLRE = ON, STVREN = ON, LVP = OFF, ICPRT = OFF
    #pragma config XINST = OFF
    #pragma config CP0 = OFF, CP1 = OFF, CP2 = OFF, CP3 = OFF
    #pragma config CPB = OFF, CPD = OFF
    #pragma config WRT0 = OFF, WRT1 = OFF, WRT2 = OFF, WRT3 = OFF
    #pragma config WRTC = OFF, WRTB = OFF, WRTD = OFF
    #pragma config EBTR0 = OFF, EBTR1 = OFF, EBTR2 = OFF, EBTR3 = OFF
    #pragma config EBTRB = OFF

    /*
     * Constants Definition
     */
    #define _XTAL_FREQ (48000000UL)
    /*
     * Main application
     */
    void main( void )
    {
        INTCON = 0;             /* Disable all interrupt sources */
        PIE1 = 0;
        PIE2 = 0;
        INTCON3bits.INT1IE = 0;
        INTCON3bits.INT2IE = 0;

        OSCCON = 0x70;          /* set internal oscillator to 16MHz */

        /*
         * Application loop
         */
        ANSELAbits.ANSA1 = 0; /* make RA1 digital I/O    */
        TRISAbits.TRISA1 = 0; /* make RA1 digital output */
        LATAbits.LATA1   = 0; /* make RA1 output low     */
        for(;;)
        {
            LATAbits.LATA1   ^= 1; /* toggle RA1 output  */
            __delay_ms(250);
        }
    }

This is a complete application that has no dependency on any peripheral library code. The functionality described in your question is implemented. Unless there is a fault with how you have wired up your circuit this code should work with and without the PICkit3 connected.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.