This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

strange behavior with unsigned long variables

I'm using the cygnal F124 chip. now my program is 33K in size and my ram memory isa bout 7.2K. I use the uart0 to print some information and one LCD, last week my unsigned long variable changed without writting in them.. I use this variables as counters these counters are updated every one second but after 3 o4 seconds this variables change from 200 to 156234324 or another big number!!!!!

I want to know what is the problem here.. these variables are globla! and I only updated by 2 or 3 functions

Another thing is can someone tell me how to optimize the code using the keil compiler. I want to know which pragma function should I have to use to get better performance and dont have this kind of errors

Parents
  • HERE IS MY FUNCTION
    This function call to get_xpacket function which updated the counters, and the view_falg variable is updated by interrupt every 2 seconds. this function print in a LCD the counters, when I run the program..
    it runs fine after 2 minutes the counters are strange! the lcd print strange values.
    maybe something is overwritting them but How can I know it because they work fine for a moment and then I stop the program and the values are very rare.
    I attach my interrupt isr using the pca too.


    void tester()
    {
    unsigned char idata a,st1,conter,sfin,i;
    //unsigned int pp;

    conter=0;
    sfin=1;
    errores=0;
    colls=0;
    MII_ERROR=0;
    PHY=0;
    MPA=0;
    CR1=0;
    FAE=0;
    FO=0;
    RP=0;
    okpak=0;
    length1=0;
    length2=0;
    length3=0;
    length4=0;
    viewflag=0;
    xcount=0;
    xpaquetes=0;
    xbytes=0;
    xcount2=100;
    key_opt=10;


    cls();
    SFRPAGE = UART0_PAGE;
    printf("%c[s",esc);
    SFRPAGE = CONFIG_PAGE;
    get_xpacket();
    detectar_tecla();

    if (uart_buf == 0x1B)
    {
    sfin=0;
    uart_buf=0;
    }

    if (key_opt==10 && viewflag==1)
    {
    sprintf(lcd_line1,"Num.Paquetes: %6ld",xpaquetes);
    sprintf(lcd_line2,"Num.Bytes : %6ld",xbytes);
    sprintf(lcd_line3,"Paquetes OK : %6ld",okpak);
    sprintf(lcd_line4,"Errores : %6ld",errores);
    line1;
    for (i=0;i<20;++i)
    lcd_send_byte(1,lcd_line1[i]);
    line2;
    for (i=0;i<20;++i)
    lcd_send_byte(1,lcd_line2[i]);
    line3;
    for (i=0;i<20;++i)
    lcd_send_byte(1,lcd_line3[i]);
    line4;
    for (i=0;i<20;++i)
    lcd_send_byte(1,lcd_line4[i]);
    viewflag=0;
    //lcd_pantalla

    }


    void PCA0_ISR (void) interrupt 9
    {

    PCA0L = 0x00;
    PCA0H = 0x00;
    if (CCF0)
    {
    CCF0=0;
    }

    xcount=xcount+1;
    if (xcount>=xcount2)
    {
    xcount=0;
    viewflag=1;
    }


    }

Reply
  • HERE IS MY FUNCTION
    This function call to get_xpacket function which updated the counters, and the view_falg variable is updated by interrupt every 2 seconds. this function print in a LCD the counters, when I run the program..
    it runs fine after 2 minutes the counters are strange! the lcd print strange values.
    maybe something is overwritting them but How can I know it because they work fine for a moment and then I stop the program and the values are very rare.
    I attach my interrupt isr using the pca too.


    void tester()
    {
    unsigned char idata a,st1,conter,sfin,i;
    //unsigned int pp;

    conter=0;
    sfin=1;
    errores=0;
    colls=0;
    MII_ERROR=0;
    PHY=0;
    MPA=0;
    CR1=0;
    FAE=0;
    FO=0;
    RP=0;
    okpak=0;
    length1=0;
    length2=0;
    length3=0;
    length4=0;
    viewflag=0;
    xcount=0;
    xpaquetes=0;
    xbytes=0;
    xcount2=100;
    key_opt=10;


    cls();
    SFRPAGE = UART0_PAGE;
    printf("%c[s",esc);
    SFRPAGE = CONFIG_PAGE;
    get_xpacket();
    detectar_tecla();

    if (uart_buf == 0x1B)
    {
    sfin=0;
    uart_buf=0;
    }

    if (key_opt==10 && viewflag==1)
    {
    sprintf(lcd_line1,"Num.Paquetes: %6ld",xpaquetes);
    sprintf(lcd_line2,"Num.Bytes : %6ld",xbytes);
    sprintf(lcd_line3,"Paquetes OK : %6ld",okpak);
    sprintf(lcd_line4,"Errores : %6ld",errores);
    line1;
    for (i=0;i<20;++i)
    lcd_send_byte(1,lcd_line1[i]);
    line2;
    for (i=0;i<20;++i)
    lcd_send_byte(1,lcd_line2[i]);
    line3;
    for (i=0;i<20;++i)
    lcd_send_byte(1,lcd_line3[i]);
    line4;
    for (i=0;i<20;++i)
    lcd_send_byte(1,lcd_line4[i]);
    viewflag=0;
    //lcd_pantalla

    }


    void PCA0_ISR (void) interrupt 9
    {

    PCA0L = 0x00;
    PCA0H = 0x00;
    if (CCF0)
    {
    CCF0=0;
    }

    xcount=xcount+1;
    if (xcount>=xcount2)
    {
    xcount=0;
    viewflag=1;
    }


    }

Children
No data