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 Issues remain with array variables - syntax issues?

    Hello!

    Thanks again to all who pointed out that writing to FlashRAM has to be done in blocks and starting at addresses where the last two bits of address are 00!
    That knowledge allowed me to make my program work OK, but not in an efficient way. I could not get array variables to work for me. I ended up creating 36 separate word variables to get the job done.

    But, I realized that I had not posted anything about my array variable issues since last April. I am still wondering what I was doing wrong. Please help me better understand array variables.

    Below are some snippets of my code that are germane to the issue.

    Program background:

    My program runs on a PIC16F876A at 20 mHz

    At run time, I stuff 14-bit word sized data from a PC into upper FlashRam, then with a switch closure, I change to a routine that reads the words at those addresses and displays them bit-wise. The serial transfer of words and stuffing into FlashRAM works well and I have verified that the correct 14 bit words are correctly placed into FlashRAM.

    When I read words from FlashRAM, these words are put into 2 of my array variables for my subsequent bit-wise display.

    It helps to "conceptualize" the layout of those array variables like this:

    MAX1A[0] MAX2A[0] MAX3A[0] MAX4A[0] MAX5A[0] MAX6A[0]
    MAX1B[0] MAX2B[0] MAX3B[0] MAX4B[0] MAX5B[0] MAX6B[0]

    MAX1A[1] MAX2A[1] MAX3A[1] MAX4A[1] MAX5A[1] MAX6A[1]
    MAX1B[1] MAX2B[1] MAX3B[1] MAX4B[1] MAX5B[1] MAX6B[1]

    MAX1A[2] MAX2A[2] MAX3A[2] MAX4A[2] MAX5A[2] MAX6A[2]
    MAX1B[2] MAX2B[2] MAX3B[2] MAX4B[2] MAX5B[2] MAX6B[2]

    This comprises 12 array variables, each with 3 elements [0, 1, 2].

    After I display them (display code not shown - it works well), I move those last 6 words from the last array elements to their left adjacent array variables with a "riffle" routine that also works well (shown in my code snippets below). Then the program loops and repeats reading words from FlashRAM and displaying them until I reach a preset address in upper FlashRAM.

    What DOES NOT work is the stuffing of words into the array elements in the last column. Wrong values appear there, and the program slows to a crawl, updating about once every 30 seconds or even longer. When complied, no errors are generated.
    But when I use 36 separate word variables in place of the array elements, all works well.

    Snippets of my code that apply:

    Code:
    'snippet from my program
    'array variables declared
    MAX1A   VAR WORD[2]
    MAX1B   VAR WORD[2]
    MAX2A   VAR WORD[2]
    MAX2B   VAR WORD[2]
    MAX3A   VAR WORD[2]
    MAX3B   VAR WORD[2]
    MAX4A   VAR WORD[2]
    MAX4B   VAR WORD[2]
    MAX5A   VAR WORD[2]
    MAX5B   VAR WORD[2]
    MAX6A   VAR WORD[2]
    MAX6B   VAR WORD[2]
    
    'code loop that gets WORD values from FlashRAM and stuffs it into
    'the elements of 2 arrays
        readcode mempntr, MAX6A[0]
        mempntr = mempntr + 1
        readcode mempntr, MAX6B[0]
        mempntr = mempntr + 1
        readcode mempntr, MAX6A[1]
        mempntr = mempntr + 1
        readcode mempntr, MAX6B[1]
        mempntr = mempntr + 1    
        readcode mempntr, MAX6A[2]
        mempntr = mempntr + 1
        readcode mempntr, MAX6B[2]
        mempntr = mempntr + 1
        
    'other code that moves word values from one array element to another
    'so it can be displayed by other routines, then goes back 
    '6 more words, displays them, etc.
    
    Riffle:
      for N = 0 to 2  'move all words to the left for all 3 screens worth of WORDs
        MAX1A[N] = MAX2A[N] : MAX2A[N] = MAX3A[N] : MAX3A[N] = MAX4A[N] : MAX4A[N] = MAX5A[N] : MAX5A[N] = MAX6A[N]
        MAX1B[N] = MAX2B[N] : MAX2B[N] = MAX3B[N] : MAX3B[N] = MAX4B[N] : MAX4B[N] = MAX5B[N] : MAX5A[N] = MAX6B[N]
      next N

    There must still be something I do not understand about array usage and syntax under PICBasicPro. Please point me in the right direction with regard to array variables.

    Thank you to all who are patient with me and offer to help!
    Bob Pigford
    Newark, DE, USA

  2. #2
    Join Date
    Mar 2004
    Location
    San Antonio, Texas
    Posts
    9


    Did you find this post helpful? Yes | No

    Default

    Looking at 4.5 Arrays in the manual it looks like you need to redefining your element from word[2] to word[3]

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


    Did you find this post helpful? Yes | No

    Default Array variables and my lack of knowledge

    Quote Originally Posted by Dick M View Post
    Looking at 4.5 Arrays in the manual it looks like you need to redefining your element from word[2] to word[3]
    Thank you, Dick M. Could it be this simple?
    In the manual example in section 4.5 it reads:

    " shark VAR BYTE[10]
    fish VAR BYTE[8]
    The first array location is element 0. In the fish array defined above, the elements are numbered fish[0] to fish[7] yielding 8 elements in total."

    Gee, I had previously thought that the highest element would be #7, therefore expecting the highest number element to be used in the VAR definition. After rereading the manual (how many times did I already read the manual on this, yet I missed it), it SURE LOOKS LIKE I HAD IT ALL WRONG!!!!!

    Wow, all this struggling. How annoying it will be to find out that I declared my array VARs incorrectly. Of course, it would have been nice if the COMPILER would have reported an error, but I still feel like such a dunce. I will try it again and report back. MANY thanks, Dick M!
    Bob

    Now I must go back to PBP and try it all again!

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


    Did you find this post helpful? Yes | No

    Default PBP array are "dimensioned" differently that other BASICs

    Well, I checked my understand of dimensioning arrays in other forms of BASIC. In other BASICs,
    DIM fish(20)
    creates an array of 21 elements (0 through 20). Hence, the source of my confusion.

    In PBP:
    fish VAR WORD[20] has 20 elements (0 through 19).

    Getting smarter as I go.

    Bob

Similar Threads

  1. Bits, Bytes Words and Arrays
    By Melanie in forum FAQ - Frequently Asked Questions
    Replies: 24
    Last Post: - 14th June 2016, 07:55
  2. Minimizing code space
    By Tobias in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 30th May 2009, 07:25
  3. DS2760 Thermocouple Kit from Parallax in PicBasicPro
    By seanharmon in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 8th July 2008, 23: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, 21:01
  5. calculation problem
    By nicolelawsc in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 31st March 2006, 15: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