Memory Problem in PIC18F46K22

Discussion in 'General Electronics Chat' started by Nebulas_PSP, Aug 22, 2014.

  1. Nebulas_PSP

    Thread Starter New Member

    Aug 22, 2014
    5
    0
    Hi All,

    I am using controller 18F46K22 for one of my application under development.
    The following are the problem that i am facing when i use this controller:
    1. The frequency of Errors/Bugs which i am getting during the working of it, is not stable.
    2. After some time interval variables are giving garbage values.

    When i reported this problem to the vendor of the same controller, they responded with me saying, this controller may have memory leakage problem and they are under the research of the solution.

    I will be very happy if you share your experience with me to sort out this issue, and please help me out as soon as possible guys :confused:

    Regards,

    Parashuram Patil,
    Nebulas Kolhapur.
     
  2. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,395
    1,607
  3. joeyd999

    AAC Fanatic!

    Jun 6, 2011
    2,693
    2,762
    These are programming errors...not errors related to the silicon itself.

    Debug your code.
     
  4. tshuck

    Well-Known Member

    Oct 18, 2012
    3,531
    675
    +1

    I have used that microcontroller quite a bit and never had any problems.

    Post your code, it is rare that the problem lies in silicon.
     
  5. Nebulas_PSP

    Thread Starter New Member

    Aug 22, 2014
    5
    0
    Thank you so much for your reply tshuck and joeyd999,

    Its not programming error, i have checked it with Hardware debugger, and if it is programming error or the problem with logic, the error should be same at all the time right??
    but its not :(

    and another thing, after some time interval some random variables are assigned with garbage values, what might be the problem??
     
  6. Nebulas_PSP

    Thread Starter New Member

    Aug 22, 2014
    5
    0
    Hi tshuck,

    just now i got updated information from the vendor of PIC18F46K22 that, this controller has memory leakage problem.

    Might be the lot which we got :(
     
  7. tshuck

    Well-Known Member

    Oct 18, 2012
    3,531
    675
    What do you mean by memory leakage? Most often, this refers to a programming practice of not releasing allocated memor. Do you mean to say that the flash memory is corrupted?

    Not necessarily.
     
  8. Nebulas_PSP

    Thread Starter New Member

    Aug 22, 2014
    5
    0
    I mean to say, RAM variable values are getting changed randomly than what i set in the program.
    Eg. Consider the follwing program code
    if (SHOWDispWhat==1) SHOWDispWhat =2;
    else if (SHOWDispWhat==2) SHOWDispWhat =3;
    else if (SHOWDispWhat==3) SHOWDispWhat =4;
    else if (SHOWDispWhat==4) SHOWDispWhat =5;
    else if (SHOWDispWhat==5) SHOWDispWhat =6;
    else if (SHOWDispWhat==6) SHOWDispWhat =7;
    else if (SHOWDispWhat==7) SHOWDispWhat =8;
    else if (SHOWDispWhat==8) SHOWDispWhat =9;
    else if (SHOWDispWhat==9) SHOWDispWhat =10;
    else if (SHOWDispWhat==10) SHOWDispWhat =11;
    else if (SHOWDispWhat==11) SHOWDispWhat =12;
    else if (SHOWDispWhat==12) SHOWDispWhat =13;
    else if (SHOWDispWhat==13) SHOWDispWhat =1;

    but when i display this variable "SHOWDispWhat" on LCD, after some time the value in this variable shows other than 1 to 13, whic is never assigned in the above code. like 182, 43, 50 etc.
     
  9. joeyd999

    AAC Fanatic!

    Jun 6, 2011
    2,693
    2,762
    WTH is a "memory leakage problem" WRT hardware?

    "Memory leakage" usually means deallocated memory is not freed, and only pertains to high-level languages like C.

    The 46K22 uses the same memory structure of all PICs (at least those that are fabbed with the same process). If that particular part "loses" its memory, I'd expect Microchip would have a serious problem with their fab -- resulting in *lots* of parts having the same problem.

    This doesn't pass the smell test, regardless of what the "vendor" says. Is the vendor Microchip themselves? If so, please provide a link to the errata. I'd really like to see it as my business depends upon Microchip's quality.

    EDIT: FYI, Microchip uses "static" memory, as opposed to "dynamic". Static memory doesn't "leak", in the strict sense of the word.

    EDIT 2: Are you working in a location with a high incidence of gamma rays? If so, you've got more problems than just "memory leakage"!
     
  10. joeyd999

    AAC Fanatic!

    Jun 6, 2011
    2,693
    2,762
    More often than not, this error can be produced in at least the following possible ways:

    1. An interrupt is firing between the setting of the variable and its display, causing a change in the variable;
    2. You are not banking correctly, causing memory writes to modify locations different than expected;
    3. You've got some code running off in an unexpected direction, causing corruption of some memory locations.
     
    Eric007 likes this.
  11. joeyd999

    AAC Fanatic!

    Jun 6, 2011
    2,693
    2,762
    Further, the Program Counter, as well as all other control registers, use the same kind of memory. If the problem is as you say, I am surprised anything is working at all, much less just giving wrong answers.
     
  12. tshuck

    Well-Known Member

    Oct 18, 2012
    3,531
    675
    Is SHOWDispWhat ever initialized? If not, you can't expect it to behave properly.

    I didn't see anything in the errata related to memory (and I wouldn't expect to). A code snippet doesn't really help as we can't see what you are doing with SHOWDispWhat.

    Also, please put code in the code tags ([ code] [/ code] - without the spaces), add this makes it easier to read your code.
     
    Last edited: Aug 25, 2014
  13. joeyd999

    AAC Fanatic!

    Jun 6, 2011
    2,693
    2,762
    Code ( (Unknown Language)):
    1. if (SHOWDispWhat==1) SHOWDispWhat =2;
    2. else if (SHOWDispWhat==2) SHOWDispWhat =3;
    3. else if (SHOWDispWhat==3) SHOWDispWhat =4;
    4. else if (SHOWDispWhat==4) SHOWDispWhat =5;
    5. else if (SHOWDispWhat==5) SHOWDispWhat =6;
    6. else if (SHOWDispWhat==6) SHOWDispWhat =7;
    7. else if (SHOWDispWhat==7) SHOWDispWhat =8;
    8. else if (SHOWDispWhat==8) SHOWDispWhat =9;
    9. else if (SHOWDispWhat==9) SHOWDispWhat =10;
    10. else if (SHOWDispWhat==10) SHOWDispWhat =11;
    11. else if (SHOWDispWhat==11) SHOWDispWhat =12;
    12. else if (SHOWDispWhat==12) SHOWDispWhat =13;
    13. else if (SHOWDispWhat==13) SHOWDispWhat =1;
    14.  
    Oh, and while we're at it, perhaps some better code construction would be helpful:

    Code ( (Unknown Language)):
    1.  
    2. SHOWDispWhat = (SHOWDispWhat == 13) ? 1 : SHOWDispWhat+1;
    3.  
    or, if you can start at 0 instead of one, it's even easier:

    Code ( (Unknown Language)):
    1.  
    2. SHOWDispWhat = (SHOWDispWhat+1)%13;
    3.  
    This will count from 0 to 12 (instead of 1 to 13).
     
    Last edited: Aug 22, 2014
    Eric007 likes this.
  14. BobTPH

    Active Member

    Jun 5, 2013
    787
    114
    Despite your objections, I would give 10:1 odds that the problem is a programming error. Memory corruption type errors are common when using low-level languages, like assembler or C. And a compiler bug is still more likely than a problem with the hardware memory.

    Bob
     
  15. joeyd999

    AAC Fanatic!

    Jun 6, 2011
    2,693
    2,762
    Wow. C is a low-level language now?

    Good to know. I don't feel so bad for using .asm anymore.
     
    Eric007 likes this.
  16. alfacliff

    Well-Known Member

    Dec 13, 2013
    2,449
    428
    I have run into programming problems where the programmer failed to alloow for undocumented commands. in other words, a combination of inputs that was not programmed for did things strangely. you have to keep track of what memory is used and clear it when it is not used. some try to ureuse memory in the same program, using a byte for temproary storeage of several variables, without clearing it after use.
     
  17. alfacliff

    Well-Known Member

    Dec 13, 2013
    2,449
    428
    if anyone tried to tell me the problem was "memory leakage" I would ask them where it dripped to.
     
  18. joeyd999

    AAC Fanatic!

    Jun 6, 2011
    2,693
    2,762
    The circular file register on the floor next to my desk?
     
  19. RichardO

    Well-Known Member

    May 4, 2013
    1,238
    385
    It is also good practice to clear your data memory at reset time. This makes any variables that are not uninitialized in your code a known value -- even if it is not the right one. It also makes it easier to see when the contents of a memory location is not what you think it should be.
     
  20. Eric007

    Senior Member

    Aug 5, 2011
    1,044
    33
    For your info, C is a *high* level language.
     
Loading...