• AVR Freaks

Hot!PIC32MX Works only in debug mode with pickit3

Author
luis_e7
New Member
  • Total Posts : 16
  • Reward points : 0
  • Joined: 2008/10/10 13:57:50
  • Location: 0
  • Status: offline
2019/08/15 21:37:23 (permalink)
0

PIC32MX Works only in debug mode with pickit3

Hello everyone,
I am programming a PIC32MX795F512L, making a simple program to turn a LED on and off.
It turns out that if I run the program in debug mode with the pickit3 it works perfect, but when I load the program into a release configuration, it doesn't work.
I have read several posts, and I have done everything about it but I still don't have the solution.
I have a 10k pull-up resistor on the MCLR pin with a 50ohm series resistor, and 50ohm series reistors in PGD1 PGC1 pins
MPLABX IDE 5.20, XC32 2.05 Compiler
External Crystal 8MHZ
This is my code:

#include <xc.h>
#include <p32xxxx.h>

#pragma config FPLLMUL = MUL_20, FPLLIDIV = DIV_2, FPLLODIV = DIV_1
#pragma config POSCMOD = HS, FNOSC = PRIPLL, FPBDIV = DIV_2
#pragma FWDTEN = OFF, FSOSCEN = OFF, DEBUG = OFF, PWP = OFF, BWP = OFF, CP = OFF
#pragma config ICESEL = ICS_PGx1, FMIIEN = OFF, FETHIO = OFF, FCANIO = OFF, FUSBIDIO = OFF, FVBUSONIO = OFF, UPLLEN = OFF
 
 
 
#define SYS_FREQ (80000000L)
#define PLIB_FREQ (40000000L)

int main(void)
{
    SYSTEMConfig(SYS_FREQ, SYS_CFG_WAIT_STATES | SYS_CFG_PCACHE);
    DDPCONbits.JTAGEN = 0;
    AD1PCFG = 0xFFFF; // All Ports as Digital
    TRISEbits.TRISE8 = 0;
TRISEbits.TRISE9 = 0;
TRISDbits.TRISD2 = 0;
TRISDbits.TRISD12 = 0;
TRISDbits.TRISD4 = 0;
 
TRISDbits.TRISD6 = 0;
TRISDbits.TRISD3 = 0;
TRISDbits.TRISD15 = 0;
TRISDbits.TRISD14 = 0;
TRISDbits.TRISD13 = 0;
TRISDbits.TRISD7 = 0;
TRISDbits.TRISD5 = 0;
TRISFbits.TRISF8 = 0;
TRISFbits.TRISF2 = 0;
TRISFbits.TRISF4 = 1;
TRISFbits.TRISF5 = 1;
TRISGbits.TRISG2 = 1;
TRISGbits.TRISG3 = 1;
TRISAbits.TRISA2 = 1;
TRISAbits.TRISA3 = 1;
TRISAbits.TRISA15 = 1;
TRISAbits.TRISA14 = 1;
 
    unsigned long i=0;
    while(1)
    {
        Nop();
        PORTEbits.RE8 = 0;
        while(i<40000000){
           i++;
        }
        i=0;
        PORTEbits.RE8 = 1;
        Nop();
    } // main loop
}


Perform the following test, just turn on the RE8 pin after finishing the while loop with the variable ( i ) and then an infinite while loop, just to keep RE8 on.
The RE8 pin only turns on when ( i ) is less than 500.
    unsigned long i=0;
    while(1)
    {
        Nop();
        PORTEbits.RE8 = 0;
        while(i<300){
           i++;
        }
        i=0;
        PORTEbits.RE8 = 1;
        Nop();
        while(1);
    } // main loop

 
I've been trying to find the problem for a week, I can't think of anything else.
Thanks for any help
post edited by luis_e7 - 2019/08/15 21:49:23
#1

9 Replies Related Threads

    davekw7x
    Entropy++
    • Total Posts : 1804
    • Reward points : 0
    • Joined: 2012/01/16 12:01:07
    • Location: Second star on the right, straight on till morning
    • Status: offline
    Re: PIC32MX Works only in debug mode with pickit3 2019/08/15 23:46:11 (permalink)
    0
    luis_e7
    ...
    I've been trying to find the problem for a week, I can't think of anything else.
    ...



     
    Been there; done that.
     
    So, maybe it's time to try another method of debugging.
     
    First of all, I determined (heuristically) that your delay routine gives about five seconds delay.  I got tired of waiting for it every stinkin' time I ran the project, so I decided to shorten it to give about half a second delay:

            while (i < 4000000) { // 4 million instead of 40 million
                i++;
            }

     
    (Of course you wouldn't have known this, and using your delay routine would still work if your code were correct; it's just that you would have to wait longer between LED toggles.)
     
    Anyhow...
    Now, you know that your device is up and running since you can, under certain circumstances, turn On the LED.  I verified (by other means) that the clock frequency is, indeed 80 MHz (assuming your crystal is really 8 MHz, as it is on my PIC32 USB StarterKit II).  So, your setup is OK for testing.

    So, instead of reaching for the debugger, how about looking (yes, really looking at your code.  The most effective debugger on the planet, I claim, is your eyes coupled to your brain, but it takes practice.  The very first time is tough.  After all, no one was born knowing this stuff!

    Here's what I see in your first example (assuming that the LED is Off when its 32MX pin is low and is On when the pin is high):

    Initialize stuff

    Repeat this loop forever:
    •     Turn Off the LED
    •     Wait a while (About five seconds for your delay loop, 0.5 seconds for mine)
    •     Turn On the LED
    •     Wait for the several instructions cycles it takes to go back
          the beginning of the loop, where the LED turns Off again.
          This "just happens" to be about 280 ns for XC16 version 2.10
          with optimization level 0, so you can't see the LED turn on
          without a 'scope.

    Bottom line: It "works" exactly the way you programmed it!  At least it does for me.
     
    If you don't have a 'scope, you won't be able to quantify things as I did, but by looking at your code, you can, at least, know why it doesn't work the way you expect.
     

    Regards,

    Dave
     
    Footnote:
    As a matter of style using less code, my loop would (probably) go like this:
    Repeat this loop forever:
    •     Toggle the LED
    •     Wait a little while (approximately 0.5 seconds)
    post edited by davekw7x - 2019/08/16 00:10:55

    Sometimes I just can't help myself...
    #2
    MisterHemi
    Senior Member
    • Total Posts : 143
    • Reward points : 0
    • Joined: 2017/11/02 12:24:21
    • Location: Commerce, CA USA
    • Status: offline
    Re: PIC32MX Works only in debug mode with pickit3 2019/08/16 00:10:57 (permalink)
    0
    davekw7x
    luis_e7
    ...
    I've been trying to find the problem for a week, I can't think of anything else.
    ...



     
    Been there; done that.
     
    So, maybe it's time to try another method of debugging.
     
    First of all, I determined (heuristically) that your delay routine gives about five seconds delay.  I got tired of waiting for it every stinkin' time I ran the project, so I decided to shorten it to give about half a second delay:

            while (i < 4000000) { // 4 million instead of 40 million
                i++;
            }

     
    (Of course you wouldn't have known this, and using your delay routine would still work if your code were correct; it's just that you would have to wait longer between LED toggles.)
     
    Anyhow...
    Now, you know that your device is up and running since you can, under certain circumstances, turn On the LED.  I verified that the clock frequency is, indeed 80 MHz (assuming your crystal is really 8 MHz, as it is on my PIC32 USB StarterKit II).

    So, instead of reaching for the debugger, how about looking (yes, really looking at your code.  The most effective debugger on the planet, I claim, is your eyes coupled to your brain, but it takes practice.  The very first time is tough.  After all, no one was born knowing this stuff!

    Here's what I see in your first example (assuming that the LED is Off when its 32MX pin is low and is On when the pin is high):

    Initialize stuff

    Repeat this loop forever:
    •     Turn Off the LED
    •     Wait a while (About five seconds for your delay loop, 0.5 seconds for mine)
    •     Turn On the LED
    •     Wait for the couple of instructions cycles it takes to go back
         the beginning of the loop, where it the LED turns Off again.
         This "just happens" to be about 280 ns for XC16 version 2.10
         with optimization level 0, so you can't see the LED turn on
         without a 'scope.

    Bottom line: It "works" exactly the way you programmed it!  At least it does for me.
     
    If you don't have a 'scope, you won't be able to quantify things as I did, but by looking at your code, you can, at least, know why it doesn't work the way you expect.
     

    Regards,

    Dave
     
    Footnote:
    As a matter of style using less code, my loop would (probably) go like this:
    Repeat this loop forever:
    •     Toggle the LED
    •     Wait a little while (approximately 0.5 seconds)




    Good help!
     
    luis_e7 FYI there are 2 ways you could toggle the LED...
     
    I usually do something like this:

    // An alias for the LED:
    #define LED PORTEbits.RE8
     
    // To toggle the LED with each pass of the loop:
    LED = ~LED;

     
    You could also just do this:

    // To toggle the LED on/off with each pass of the loop:
    PORTEbits.RE8 = ~PORTEbits.RE8;


    My configuration:
    MacBook Pro (Retina, 15-inch, Mid 2015) with MacOS High Sierra (10.14.5) and MPLAB X IDE v5.20
     
    Curiosity PIC32MZ EF, PIC24F Curiosity, XPRESS EVAL BOARD (PIC16F18855), SAMA5D3 Xplained and various custom boards.
    #3
    ric
    Super Member
    • Total Posts : 23525
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: PIC32MX Works only in debug mode with pickit3 2019/08/16 00:11:42 (permalink)
    0
    Dave, I think you missed the "while(1);" at the end of his main loop, rendering the whole loop useless.
    i.e. it should stop dead after setting RE8 high.
     
    This whole thing smells of Watchdog Timer, which just happens to be disabled when you are in Debug mode.
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #4
    davekw7x
    Entropy++
    • Total Posts : 1804
    • Reward points : 0
    • Joined: 2012/01/16 12:01:07
    • Location: Second star on the right, straight on till morning
    • Status: offline
    Re: PIC32MX Works only in debug mode with pickit3 2019/08/16 00:39:34 (permalink)
    0
    ric
    Dave, I think you missed the "while(1);" at the end of his main loop, rendering the whole loop useless.
    i.e. it should stop dead after setting RE8 high.

    Maybe it got lost in the verbiage (sorry 'bout that) but my quasi-code was based on his first example.
     
    ric
    This whole thing smells of Watchdog Timer, which just happens to be disabled when you are in Debug mode.

    Which is why I rarely use debugger for my own code.  I like to test with real code on a real device running at real-time speed.  Brain+Eyes is better than PicKitIII
     
    And, by the way he has
    #pragma FWDTEN = OFF

     
    I used his setup and code as the basis of the program on my PIC32MX795 board, which (with a "simple" fix that I hope could be inferred from my description) has been blinking happily for the several minutes that I spent composing my response.  I rarely post about things that I haven't tested.
     
    Regards,

    Dave
     
    post edited by davekw7x - 2019/08/16 00:42:16

    Sometimes I just can't help myself...
    #5
    dan1138
    Super Member
    • Total Posts : 3187
    • Reward points : 0
    • Joined: 2007/02/21 23:04:16
    • Location: 0
    • Status: offline
    Re: PIC32MX Works only in debug mode with pickit3 2019/08/16 00:41:05 (permalink)
    0
    @luis_e7,
     
    The code you posed looks like it may have issues.
     
    This is the code I used to do the LED blinky for a PIC32MX795F512L:
    /*
     * File:   main.c
     * Target: PIC32MX795F512L
     * Compiler: C32 v2.02, XC32 v1.44
     *
     * Description:
     *  Blink LEDs on PORTF bits RF2, RF4, RF8
     *
     * Notes:
     *  Define symbol USE_XTAL to use an external 8.0MHz crystal.
     *  Define symbol USE_PLL to enable the PLL and set clock to 80MHz.
     *  Does not use the PLIB library so should build with any Microchip compiler for PIC32.
     *  When building with XC32 v1.44 MPLAB v8.92 asserts an error dialog box.
     */

    /*
     * Configuration words
     */
    #pragma config FSRSSEL = PRIORITY_7     /* SRS Select (SRS Priority 7) */
    #pragma config FMIIEN = OFF             /* Ethernet RMII/MII Enable (RMII Enabled) */
    #pragma config FETHIO = OFF             /* Ethernet I/O Pin Select (Alternate Ethernet I/O) */
    #pragma config FCANIO = OFF             /* CAN I/O Pin Select (Alternate CAN I/O) */
    #pragma config FUSBIDIO = OFF           /* USB USID Selection (Controlled by Port Function) */
    #pragma config FVBUSONIO = OFF          /* USB VBUS ON Selection (Controlled by Port Function) */
    #pragma config FPLLIDIV = DIV_2         /* PLL Input Divider (2x Divider) */
    #pragma config FPLLMUL = MUL_20         /* PLL Multiplier (20x Multiplier) */
    #pragma config UPLLIDIV = DIV_2         /* USB PLL Input Divider (2x Divider) */
    #pragma config UPLLEN = OFF             /* USB PLL Enable (Disabled and Bypassed) */
    #pragma config FPLLODIV = DIV_1         /* System PLL Output Clock Divider (PLL Divide by 1) */
    #pragma config FSOSCEN = OFF            /* Secondary Oscillator Enable (Disabled) */
    #pragma config IESO = OFF               /* Internal/External Switch Over (Disabled) */
    #pragma config OSCIOFNC = OFF           /* CLKO Output Signal Active on the OSCO Pin (Disabled) */
    #pragma config FPBDIV = DIV_1           /* Peripheral Clock Divisor (Pb_Clk is Sys_Clk/1) */
    #pragma config WDTPS = PS1              /* Watchdog Timer Postscaler (1:1) */
    #pragma config FWDTEN = OFF             /* Watchdog Timer Enable (WDT Disabled (SWDTEN Bit Controls)) */
    #pragma config ICESEL = ICS_PGx2        /* ICE/ICD Comm Channel Select (ICE EMUC2/EMUD2 pins shared with PGC2/PGD2) */
    #pragma config PWP = OFF                /* Program Flash Write Protect (Disable) */
    #pragma config BWP = OFF                /* Boot Flash Write Protect bit (Protection Disabled) */
    #pragma config CP = OFF                 /* Code Protect (Protection Disabled) */
    #pragma config FNOSC = FRC              /* Oscillator Selection Bits (Fast RC Osc) */
    #pragma config FCKSM = CSECMD           /* Clock Switching and Monitor Selection (Clock Switch Enable, FSCM Disabled) */

    #if defined(USE_XTAL)

    #pragma config POSCMOD = XT             /* Primary Oscillator Configuration (XT osc mode) */
    #define OSC_FREQUENCY       (8000000ul) /* External crystal frequency */
    #define PLL_INPUT_DIVIDER   (2ul)
    #define PLL_MULTIPLIER      (20ul)

    #if defined(USE_PLL)
    #define OSC_SELECTOR        (0b011)     /* Use Primary Oscillator + PLL*/
    #else
    #define OSC_SELECTOR        (0b010)     /* Use Primary Oscillator */
    #endif

    #else

    #pragma config POSCMOD = OFF            /* Primary Oscillator Configuration (Primary osc disabled) */
    #define OSC_FREQUENCY       (8000000ul) /* Internal Fast RC oscillator frequency */
    #define PLL_INPUT_DIVIDER   (2ul)
    #define PLL_MULTIPLIER      (20ul)

    #if defined(USE_PLL)
    #define OSC_SELECTOR        (0b001)     /* Use FRC + PLL */
    #else
    #define OSC_SELECTOR        (0b000)     /* Use FRC */
    #endif

    #endif

    #if defined(__XC32)
    #include <xc.h>
    #elif defined(__C32__)
    #include <p32xxxx.h>
    #else
    #error "Unknown PIC32 compiler"
    #endif



    #if defined(USE_PLL)
    #define GetSystemClock()        ((OSC_FREQUENCY/PLL_INPUT_DIVIDER)*PLL_MULTIPLIER)
    #define PB_CLOCK_DIVIDER        (1ul)
    #else
    #define GetSystemClock()        (OSC_FREQUENCY)
    #define PB_CLOCK_DIVIDER        (1ul)
    #endif
    #define GetPeripheralClock()    (GetSystemClock()/PB_CLOCK_DIVIDER)
    #define GetInstructionClock()   (GetSystemClock())


    #define FLASH_SPEED_HZ          30000000ul //Max Flash speed
    #define PB_BUS_MAX_FREQ_HZ      80000000ul //Max Peripheral bus speed

    /***************************************************************
     * <combinewith CHE_CONF_PF_ALL, CHE_CONF_PF_C, CHE_CONF_PF_NC>
     *
     * Flash Prefetch option - Values are mutually exclusive
     **************************************************************
     */
    #define CHE_CONF_PF_DISABLE  (0 << _CHECON_PREFEN_POSITION)
    #define CHE_CONF_PF_C        (1 << _CHECON_PREFEN_POSITION )
    #define CHE_CONF_PF_NC       (2 << _CHECON_PREFEN_POSITION)
    #define CHE_CONF_PF_ALL      (3 << _CHECON_PREFEN_POSITION)

    /* Initialize this PIC */
    void __attribute__ ((nomips16)) PIC_Init(void)
    {
        // Configure the device for maximum performance,
        // This function will change the program Flash wait states,
        // RAM wait state and enable prefetch cache
        // The PBDIV value must be already set via the pragma FPBDIV option in configuration words.

        unsigned int sys_clock;
        unsigned int pb_clock;
        unsigned int int_status;
        unsigned int wait_states;
        register unsigned long cache_tmp;
        register unsigned long clock_switch_timeout;

        sys_clock = GetSystemClock();

        /* Save current interrupt enable state and disable interrupts */
        asm volatile("di    %0" : "=r"(int_status));

        /* Check that we can change the system clock frequency */
        if(!OSCCONbits.CLKLOCK)
        {
            /* swich system clock to FRC, no PLL */
            SYSKEY = 0, SYSKEY = 0xAA996655, SYSKEY = 0x556699AA;
            OSCCONbits.NOSC = 0b000; /* select FRC as system oscillator */
            OSCCONbits.OSWEN = 1;    /* start a clock switch */
            SYSKEY = 0x33333333;
            for(clock_switch_timeout=80000; clock_switch_timeout; clock_switch_timeout--)
            {
                if(!OSCCONbits.OSWEN) break;
            }
        }
        /* Disable the JTAG interface */
        DDPCONbits.JTAGEN = 0;

        /* Disable the JTAG TDO output */
        DDPCONbits.TDOEN = 0;

        /* Disable the TRACE interface */
        DDPCONbits.TROEN = 0;

        /* Set RAM to use MAX wait states */
        BMXCONCLR = _BMXCON_BMXWSDRM_MASK;

        /* Set FLASH wait states for desired system clock */
        wait_states = 0;
        while(sys_clock > (FLASH_SPEED_HZ * (wait_states + 1)))
        {
            wait_states++;
        }

        /* turn on cache and set FLASH wate states */
        CHECON = CHE_CONF_PF_ALL | wait_states;

        /* Select Kseg0 coherency algorithm as 3, cacheable. */
        asm("mfc0 %0,$16,0" :  "=r"(cache_tmp));
        cache_tmp = (cache_tmp & ~7) | 3;
        asm("mtc0 %0,$16,0" :: "r" (cache_tmp));

        /* compute peripherial bus clock frequency from sys_clock */
        pb_clock = (sys_clock >> OSCCONbits.PBDIV);

        if(!OSCCONbits.CLKLOCK)
        {
            /* swich system clock to Primary oscillation amplifier with PLL */
            SYSKEY = 0, SYSKEY = 0xAA996655, SYSKEY = 0x556699AA;
    #if   (PLL_INPUT_DIVIDER == 1)
            OSCCONbits.FRCDIV =0b000;
    #elif (PLL_INPUT_DIVIDER == 2)
            OSCCONbits.FRCDIV =0b001;
    #elif (PLL_INPUT_DIVIDER == 4)
            OSCCONbits.FRCDIV =0b010;
    #elif (PLL_INPUT_DIVIDER == 8)
            OSCCONbits.FRCDIV =0b011;
    #elif (PLL_INPUT_DIVIDER == 16)
            OSCCONbits.FRCDIV =0b100;
    #elif (PLL_INPUT_DIVIDER == 32)
            OSCCONbits.FRCDIV =0b101;
    #elif (PLL_INPUT_DIVIDER == 64)
            OSCCONbits.FRCDIV =0b110;
    #elif (PLL_INPUT_DIVIDER == 256)
            OSCCONbits.FRCDIV =0b111;
    #else
    #error PLL input divider has bad value
    #endif

    #if   (PLL_MULTIPLIER == 15)
            OSCCONbits.PLLMULT =0b000;
    #elif (PLL_MULTIPLIER == 16)
            OSCCONbits.PLLMULT =0b001;
    #elif (PLL_MULTIPLIER == 17)
            OSCCONbits.PLLMULT =0b010;
    #elif (PLL_MULTIPLIER == 18)
            OSCCONbits.PLLMULT =0b011;
    #elif (PLL_MULTIPLIER == 19)
            OSCCONbits.PLLMULT =0b100;
    #elif (PLL_MULTIPLIER == 20)
            OSCCONbits.PLLMULT =0b101;
    #elif (PLL_MULTIPLIER == 21)
            OSCCONbits.PLLMULT =0b110;
    #elif (PLL_MULTIPLIER == 24)
            OSCCONbits.PLLMULT =0b111;
    #else
    #error PLL multiplier has bad value
    #endif
            OSCCONbits.PLLODIV = 0b000; /* set PLL output divider to 1:1 */
            OSCCONbits.NOSC = OSC_SELECTOR;
            OSCCONbits.OSWEN = 1;       /* start a clock switch */
            SYSKEY = 0x33333333;
            for(clock_switch_timeout=80000; clock_switch_timeout; clock_switch_timeout--)
            {
                if(!OSCCONbits.OSWEN) break;
            }
        }

        /* set GPIO pins for digital I/O */
        AD1PCFG = 0xFFFFUL;

        /* Restore interrupt state */
        if(int_status & 0x00000001)
        {
           asm volatile("ei    %0" : "=r"(int_status));
        }
        /*
         * At this point the values for sys_clock and pb_clock
         * should be assigned.
         */
    }
    /*
     *
     */
    void DelayMS( unsigned long Delay )
    {
    #define TICKS_IN_ONE_MILLISECOND (GetSystemClock() / 2000ul)
        unsigned long Time0, Time1;

        Time0 = _CP0_GET_COUNT(); /* 2 system clocks per count */

        if (Delay < (unsigned long)(0xFFFFFFFF) / TICKS_IN_ONE_MILLISECOND)
            Delay = Delay * TICKS_IN_ONE_MILLISECOND;
        else
            Delay = (unsigned long)(0xFFFFFFFF);

        for(;;)
        {
            Time1 = _CP0_GET_COUNT();
            Time1 = Time1 - Time0;      /* Get cycle from start of spin */
            if (Time1 >= Delay)
                break;
        }
    }
    /*
     * Main application
     */
    #define LED_D1          LATFbits.LATF2
    #define LED_D2          LATFbits.LATF8
    #define LED_D3          LATFbits.LATF4

    #define LED_D1_DIR      TRISFbits.TRISF2
    #define LED_D2_DIR      TRISFbits.TRISF8
    #define LED_D3_DIR      TRISFbits.TRISF4

    void main(void)
    {
        int i ;

        PIC_Init();

        DelayMS(1000);

        LED_D1_DIR = 0;
        LED_D2_DIR = 0;
        LED_D3_DIR = 0;

        DelayMS(1000);

        while(1)
        {
            LED_D1   = 0;
            LED_D2   = 1;
            LED_D3   = 0;
            DelayMS(1000);

            LED_D1   = 1;
            LED_D2   = 0;
            LED_D3   = 1;
            DelayMS(1000);
        }
    }

    The is as stripped down as I could make it. No PLIBs, no Harmony just bare metal.
    #6
    luis_e7
    New Member
    • Total Posts : 16
    • Reward points : 0
    • Joined: 2008/10/10 13:57:50
    • Location: 0
    • Status: offline
    Re: PIC32MX Works only in debug mode with pickit3 2019/08/16 10:49:08 (permalink)
    0
    Hi All, thank you very much for the help.
    Already make your recommendations, I corrected the program, as @davekw7x suggested, since I was clearing the RD5 PIN immediately. but still not working.
     while(1){
      Nop();
      while(i<1000000){
       i++;
      }
      i=0;
      PORTDbits.RD5 = !PORTDbits.RD5;
      Nop();
    } // main loop

     
    dan1138 I tried your program but it does not run, in debug mode check and always stop in this line:
     _reset:
    jal _startup
    nop

    and that happens after executing this line:
     OSCCONbits.OSWEN = 1;       /* start a clock switch */

     
    After dealing with my program, it sometimes works when I physically reset the pic with MCLR pin. But not many ocations.
    But it works for a long time when I restart with the MCLR pin after trying many times.
    I think I need some configuration so that when I turn on the PIC it starts correctly.
    post edited by luis_e7 - 2019/08/16 20:25:19
    #7
    luis_e7
    New Member
    • Total Posts : 16
    • Reward points : 0
    • Joined: 2008/10/10 13:57:50
    • Location: 0
    • Status: offline
    Re: PIC32MX Works only in debug mode with pickit3 2019/08/16 19:28:34 (permalink)
    0
    Hi,
    Continuing with the troubleshooting and trying to understand the code of @dan1138, in the initialization part, I deleted this line:
     SYSTEMConfig(SYS_FREQ, SYS_CFG_WAIT_STATES | SYS_CFG_PCACHE); 

    The PIC starts correctly after programming with pickit3 and also when turn on and off the power supply, but with the differences that the delay time does not correspond to the clock frequency.
     
    I need to better understand how to replace this line, what could be wrong in the compiler, or if this line needs some additional parameters.
     
    #8
    dan1138
    Super Member
    • Total Posts : 3187
    • Reward points : 0
    • Joined: 2007/02/21 23:04:16
    • Location: 0
    • Status: offline
    Re: PIC32MX Works only in debug mode with pickit3 2019/08/16 22:21:37 (permalink)
    0
    luis_e7
    ... trying to understand the code of @dan1138, in the initialization part ...

    To make my code independent from any of the library code from Microchip I re-wrote the initialization code that the SYSTEMConfig(); function invokes. My PIC_Init(); function does just enough to get the PIC32MX795F512L system clock and instruction cache configured.
     
    The Microchip implementation is more complex because they try to support all version of the PIC32 in one code base. Good luck trying to sort through all that. It took me weeks to get what I have to work on just one device.
     
    That my code does not work in your hardware may have something to do with the details of your setup you have not revealed.
     
    <EDIT>
    I test my code again by building it with MPLABX v5.25 and the XC32 v2.20 compiler. It runs on my test hardware in debug and release mode. I used an ICD3 and and PICkit3 without any issues.
    post edited by dan1138 - 2019/08/16 22:25:58
    #9
    luis_e7
    New Member
    • Total Posts : 16
    • Reward points : 0
    • Joined: 2008/10/10 13:57:50
    • Location: 0
    • Status: offline
    Re: PIC32MX Works only in debug mode with pickit3 2019/08/17 08:32:28 (permalink)
    0
    Yes your're right @ds1138, it maye will take me weeks to understand this, because this part always i use to use this system library without any problem.
    Maybe I have some issues in my customized hardware, even when i took all the datasheet recomendations and follow by the ChipKit Max32 schematic that i never had this problem.
    In my hardware just connected a eeprom (in I2C5), SD card socket (in SPI1) and a RTC (in I2C5), the rest of the ports are in connectors for general pourpose and UART comunications with other devices. But for the test i am not using this. The on-chip regulator is a ON SEMICONDUCTOR 1117-3.3 with its respective tantalium capacitors, and has a 3.3 VDC output with 5.1 VDC input.
     
    Now I changed the SYS_FREQ by 40MHZ, and 64MHZ, with:
     FPLLMUL = MUL_20, FPLLIDIV = DIV_4 

    or
     FPLLMUL = MUL_16, FPLLIDIV = DIV_2 

    And the PIC run ok at power on with this settings.
    At 80MHZ only in debug mode.
    Maybe i need to check the 8MHZ crystal, decouple capacitors (33pf), in both of my PCBs that happens the same thing.
     
    post edited by luis_e7 - 2019/08/17 18:41:01
    #10
    Jump to:
    © 2019 APG vNext Commercial Version 4.5