• AVR Freaks

Hot!Variables and Watches windows

Author
szlovak
Starting Member
  • Total Posts : 76
  • Reward points : 0
  • Joined: 2005/02/10 13:40:28
  • Location: Łódź, Poland
  • Status: offline
2019/04/19 13:45:31 (permalink)
0

Variables and Watches windows

Hello
 
I'm using Pickit3 for debugging C program and I'm confused about watching some variables. I use XC8, on pic18f25k50, latest MplabX. I can't find any useful info nowhere on internet why some variables show up , some don't. I've been adding some nop instructions , that helps debugger to stop at certain places in code, but when I add breakpoints at my variables, breakpoints are broken, it didn't help them. And if they are not broken, it does improves nothing. There is about 120 variables to choose from, but as you might guess, these are not these ones that I need. Debugger even finds many variables from other c files in that project, but it can't find in main.c. Is there any way to use it? Do I have to refresh project somehow?

Greetings
Adam Kozarzewski
#1

6 Replies Related Threads

    NKurzman
    A Guy on the Net
    • Total Posts : 17494
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: online
    Re: Variables and Watches windows 2019/04/19 14:45:02 (permalink)
    0
    Your problems more likely with the optimizer
    It may decide to merge variables together or never assigned them around location because it doesn’t need to to generate a code to match your expressions.
    You can force the compiler to give the variable on location. Make the variable global or static or volatile which sometimes a combination of all of these
    Return the variable to its original definition after you have finished the debugging. Otherwise the code will be less efficient and possibly use more memory.
    #2
    qhb
    Superb Member
    • Total Posts : 9998
    • Reward points : 0
    • Joined: 2016/06/05 14:55:32
    • Location: One step ahead...
    • Status: offline
    Re: Variables and Watches windows 2019/04/19 22:47:17 (permalink)
    0
    As NKurzman mentioned, they are probably getting optimised away, but we can only guess as you did not show any of your code.
     

    Nearly there...
    #3
    szlovak
    Starting Member
    • Total Posts : 76
    • Reward points : 0
    • Joined: 2005/02/10 13:40:28
    • Location: Łódź, Poland
    • Status: offline
    Re: Variables and Watches windows 2019/04/21 06:27:12 (permalink)
    0
    This is part of my code. I want to see MSB, LSB , wynik values. For me it's mystery why it doesn't show up.


    unsigned char MSB, LSB;
    unsigned char COMMAND_CONFIG = (SENSOR_CMD_ACK_DISABLE | SENSOR_CMD_IT_1_2T | SENSOR_CMD_SD_DISABLE | SENSOR_CMD_RESERVED);
    static unsigned long  wynik;


    int main(void) {
        ACTCONbits.ACTEN = 1;
        TRISCbits.TRISC0 = 0;
        TRISAbits.TRISA0 = 1;
        TRISBbits.TRISB0 = 1;
        TRISBbits.TRISB1 = 1;
        ANSELBbits.ANSB0 = 0;
        ANSELBbits.ANSB1 = 0;
        WPUBbits.WPUB0 = 0;
        WPUBbits.WPUB1 = 0;
        OSCCONbits.IRCF2 = 1;
        OSCCONbits.IRCF1 = 1;
        OSCCONbits.IRCF0 = 1;
        led = 1;
        __delay_ms(500);
        led = 0;
        __delay_ms(500);
        led = 1;
        __delay_ms(500);
        led = 0;
       I2C_Init(100000);

       // I2C_Start();
      //  I2C_Write(SENSOR_ADDR_ARA | 1);
      //  LSB = I2C_Read();
      //      I2C_Stop();
        I2C_Start();
        asm("nop");
        I2C_Write(SENSOR_DEFAULT_ADDRESS);
        asm("nop");
         while (I2C_Slave_Ack());
        I2C_Write(COMMAND_CONFIG);
        // while (I2C_Slave_Ack());
        I2C_Stop();

        while (1) {
            __delay_ms(65);
            I2C_Start();
            I2C_Write(SENSOR_CMD_READ_MSB | 1);
            asm("nop");
            MSB = I2C_Read();
            asm("nop");
            asm("nop");
            I2C_Stop();
            I2C_Start();
            I2C_Write(SENSOR_CMD_READ_LSB | 1);
            LSB = I2C_Read();
            asm("nop");
            asm("nop");
            I2C_Stop();

            wynik=MSB*256+LSB;
            asm("nop");
            asm("nop");
        }





     

    Or  better please show an example how to see a value returned from function. For me it's "borked" how mplab is doing this
    post edited by szlovak - 2019/04/21 06:39:34

    Greetings
    Adam Kozarzewski
    #4
    NKurzman
    A Guy on the Net
    • Total Posts : 17494
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: online
    Re: Variables and Watches windows 2019/04/21 09:10:37 (permalink)
    +1 (1)
    volatile unsigned char MSB, LSB;

    There are predefined macros fo Nop
    NOP() or Nop() depending on the compiler.

    It is not borked. It is how compilers work.
    You want them to optimize.
    #5
    szlovak
    Starting Member
    • Total Posts : 76
    • Reward points : 0
    • Joined: 2005/02/10 13:40:28
    • Location: Łódź, Poland
    • Status: offline
    Re: Variables and Watches windows 2019/04/21 10:49:57 (permalink)
    0
    Thanks, it has worked, finally.

    Greetings
    Adam Kozarzewski
    #6
    qhb
    Superb Member
    • Total Posts : 9998
    • Reward points : 0
    • Joined: 2016/06/05 14:55:32
    • Location: One step ahead...
    • Status: offline
    Re: Variables and Watches windows 2019/04/21 13:39:39 (permalink)
    0
    If you had actually used those variables in something that had an effect on the output of your program, you would not have needed the "volatile" qualifiers.
    When your program is finished, you can remove them.
     
    As NKurzman mentioned, if you just rely on inspecting never-used values in a debugger's watch window, then the compiler's optimiser is going to be fighting with you.
     
     

    Nearly there...
    #7
    Jump to:
    © 2019 APG vNext Commercial Version 4.5