WRITECODE stores wrong 14-bit word values in FlashMEM


Closed Thread
Results 1 to 19 of 19

Hybrid View

  1. #1
    Join Date
    Jan 2009
    Location
    Delaware
    Posts
    19


    Did you find this post helpful? Yes | No

    Default Found the problem - ARRAY variables!

    Hello all!

    Following Darrel Taylor's excellent instructions, I was careful to WRITECODE to 4 word (complete) blocks starting at $1800 (or any other address where the two LSBs are 0's). I still saw wrong stored values. Every 6th address (and a few others) had an error ... VERY strange behavior.

    I had been using 12 WORD sized array variables of 3 elements each, stuffing the last 2 variables of each array into memory (WRITECODE). Suspecting that array variables were the culprits, I changed to 36 individual WORD variables along with all the repetitive code required. NOW IT WORKS!

    The PBP manual (pg 25) says clearly that "The compiler will assure that arrays, as well as simple variables, will fit in memory before successfully compiling."

    My code is about 4100 WORDs in size. It compiled just fine, albiet showing three notes at the bottom of the screen that code page boundaries were being crossed. I had assumed that since the code compiled just fine, that the 3 warnings pertained to the overall size of my code. BUT, perhaps those were warnings that arrays would not work.

    BUT why did it still compile OK? Did the PBP compiler let me down?

    Makes me wary of using array variables. I need to learn more about this in the future!

    Thanks again to all for your help!
    Bob Pigford
    Newark, Delaware

  2. #2
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Great! Glad it helped.
    Quote Originally Posted by BobPigford
    Makes me wary of using array variables.
    Nothing to worry about there. Arrays work perfectly with PBP.
    And yes, PBP makes sure the arrays will fit in a BANK of RAM.

    The crossing boundary warnings refer to the FLASH memory used by the program. The same area of memory that you are WRITECODEing to.
    Arrays can not cause that warning.

    Array indexes always start at 0.
    So if you have a word array of 3 elements, the index goes from 0 to 2.
    It's easy to forget and try to use 1 - 3, but 3 would be outside of the array, probably a RAM location used by another variable.

    PBP does not do any "Range Checking". It's up to you to stay within the bounds of the array.

    Just about any good program will use arrays in some form or another.
    So yup, time to learn ... then play ... then learn more ...
    <br>
    DT

  3. #3
    Join Date
    Jan 2009
    Location
    Miami, Florida USA
    Posts
    704


    Did you find this post helpful? Yes | No

    Default

    Darrel,
    From reading other posts and other documentation (if I understood them correctly) when using arrays in a pic16fxxx and if the program crosses the memory boundary then that would be looking for trouble. In other words, if you are using arrays all over the place in your program, then your program has to fit in one memory block which is ussually not the case. Otherwise, the program won't work properly.
    I personally like arrays. They make your program looks neat and more profesional, but also my programs are usually bigger than 2K.

    Any comments on this?

    Robert

  4. #4
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    NO! Not true at all.

    The size of your program has NO effect on arrays.
    Arrays are in RAM, the program is in FLASH.

    You may be thinking of the problems that can happen with the BRANCH command if the code is larger than 2K. In which case you need to use BRANCHL.
    DT

  5. #5
    Join Date
    Jan 2009
    Location
    Delaware
    Posts
    19


    Did you find this post helpful? Yes | No

    Smile Well, I was careful about arrays, perhaps I missed something.

    Darrel, et al,

    I understand going out of bounds of a dimensioned array, and that arrays start at 0. I believe that my use of array variables was correct, but I will go back and look again. Perhaps I missed something.

    I am glad to hear that PBP did not let me down, per se, as array variables are held in RAM and arrays crossing any page boundaries are handled by PBP.

    So, I guess I will have to go back and bang out the code with array variables again. It may be a while, but I will report back.

    Thanks to all for your help!
    Bob Pigford
    Newark, DE, USA

  6. #6
    Join Date
    Jan 2009
    Location
    Delaware
    Posts
    19


    Did you find this post helpful? Yes | No

    Cool Oops - I "misspoke" about arrays and boundaries

    Quote Originally Posted by BobPigford View Post
    I am glad to hear that PBP did not let me down, per se, as array variables are held in RAM and arrays crossing any page boundaries are handled by PBP.
    Oops. I should not have talked about arrays crossing any boundaries since Darrel reminded me that they are in RAM. Sorry.

    Bob

  7. #7
    Join Date
    Jan 2009
    Location
    Miami, Florida USA
    Posts
    704


    Did you find this post helpful? Yes | No

    Default

    Darrel,
    I think my confusion comes from the PicBasic Pro Manual, section 4.5, "Arrays".
    "Arrays must fit entirely within one RAM bank on 12-bit, 14-bit or pic17cxxx devices."

    Yeap, I know the program is not stored in RAM. But, what are the implications of this limit to one RAM bank for arrays? Would it be only the limited number of elements in an array?

    Robert

Similar Threads

  1. Bits, Bytes Words and Arrays
    By Melanie in forum FAQ - Frequently Asked Questions
    Replies: 24
    Last Post: - 14th June 2016, 08:55
  2. Minimizing code space
    By Tobias in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 30th May 2009, 08:25
  3. DS2760 Thermocouple Kit from Parallax in PicBasicPro
    By seanharmon in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 9th July 2008, 00:19
  4. pic to pic ir link versus wired link : help please anyone
    By xnihilo in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 30th May 2008, 22:01
  5. calculation problem
    By nicolelawsc in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 31st March 2006, 16:23

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts