• AVR Freaks

Hot!Working with Large Arrays in MPLAB XC8

Page: 12 > Showing page 1 of 2
Author
66pvoarvp
Starting Member
  • Total Posts : 42
  • Reward points : 0
  • Joined: 2016/12/05 18:29:36
  • Location: 0
  • Status: offline
2020/06/25 03:15:38 (permalink)
0

Working with Large Arrays in MPLAB XC8

Hi all,
We are working with data packet transmitter with PIC18F27K42 device.
We are using Latest MPLABX and XC8 compiler.
 
When buffer larger than 256 bytes long is created, we getting error message, attached to this post.
Used simple
"char array99[300];"
to create buffer array.
 
we searched in net, now feel that it is due to bank concept used in the device.
We don't know whether our opinion is correct or not.
 
Suggest us a method to solve this issue.
 
Thanks & regards,

Attached Image(s)

#1

21 Replies Related Threads

    mbrowning
    USNA79
    • Total Posts : 1791
    • Reward points : 0
    • Joined: 2005/03/16 14:32:56
    • Location: Melbourne, FL
    • Status: online
    Re: Working with Large Arrays in MPLAB XC8 2020/06/25 03:28:23 (permalink)
    +3 (3)
    I’ve used static arrays much larger than 300 bytes with no problem on k42’s.

    Is this an auto array? You probably can’t create such large elements on the compiled stack.
    #2
    Coman
    Junior Member
    • Total Posts : 29
    • Reward points : 0
    • Joined: 2016/11/06 14:56:29
    • Location: 0
    • Status: offline
    Re: Working with Large Arrays in MPLAB XC8 2020/06/25 03:28:51 (permalink)
    -3 (3)
    I think you cannot use 
    array[256 + n] because the databanks are 256 bytes long.
     
    You can use (type) *array++ 
    pointer to memory and pointer math to express an array over multiple databanks.
    #3
    1and0
    Access is Denied
    • Total Posts : 10999
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: Working with Large Arrays in MPLAB XC8 2020/06/25 03:33:27 (permalink)
    +2 (2)
    mbrowning
    Is this an auto array? You probably can’t create such large elements on the compiled stack.

    +1.
     
    Make the array static or global.
    #4
    66pvoarvp
    Starting Member
    • Total Posts : 42
    • Reward points : 0
    • Joined: 2016/12/05 18:29:36
    • Location: 0
    • Status: offline
    Re: Working with Large Arrays in MPLAB XC8 2020/06/25 03:33:54 (permalink)
    0
    mbrowning
    I’ve used static arrays much larger than 300 bytes with no problem on k42’s.

    Is this an auto array? You probably can’t create such large elements on the compiled stack.

    the code is exactly as i gave in original post, it is "char array99[300];" and nothing else.
    i got compile time error.
     
    can we use static array, as we construct data packet in one function and pass it to transmitter function?
    Regards,
    #5
    1and0
    Access is Denied
    • Total Posts : 10999
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: Working with Large Arrays in MPLAB XC8 2020/06/25 03:35:54 (permalink)
    +1 (1)
    66pvoarvp
    the code is exactly as i gave in original post, it is "char array99[300];" and nothing else.
    i got compile time error.
     
    can we use static array, as we construct data packet in one function and pass it to transmitter function?

    Our posts got crossed. Read my previous post.
     
    #6
    66pvoarvp
    Starting Member
    • Total Posts : 42
    • Reward points : 0
    • Joined: 2016/12/05 18:29:36
    • Location: 0
    • Status: offline
    Re: Working with Large Arrays in MPLAB XC8 2020/06/25 03:36:01 (permalink)
    0
    Coman
    I think you cannot use 
    array[256 + n] because the databanks are 256 bytes long.
     
    You can use (type) *array++ 
    pointer to memory and pointer math to express an array over multiple databanks.




    got it, we will try it and post the result back here.
     
    Thanks & regards,
    #7
    1and0
    Access is Denied
    • Total Posts : 10999
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: Working with Large Arrays in MPLAB XC8 2020/06/25 03:38:38 (permalink)
    0
    66pvoarvp
    Coman
    I think you cannot use 
    array[256 + n] because the databanks are 256 bytes long.
     
    You can use (type) *array++ 
    pointer to memory and pointer math to express an array over multiple databanks.




    got it, we will try it and post the result back here.

    Did you miss my posts ???
     
    #8
    66pvoarvp
    Starting Member
    • Total Posts : 42
    • Reward points : 0
    • Joined: 2016/12/05 18:29:36
    • Location: 0
    • Status: offline
    Re: Working with Large Arrays in MPLAB XC8 2020/06/25 03:38:58 (permalink)
    0
    1and0
    mbrowning
    Is this an auto array? You probably can’t create such large elements on the compiled stack.

    +1.
     
    Make the array static or global.


    In the rush to solve it, i am not sure, but i remember that we declared it as a global variable also.
    And got the same error.
     
    Thanks & regards,
    #9
    mbrowning
    USNA79
    • Total Posts : 1791
    • Reward points : 0
    • Joined: 2005/03/16 14:32:56
    • Location: Melbourne, FL
    • Status: online
    Re: Working with Large Arrays in MPLAB XC8 2020/06/25 03:39:32 (permalink)
    +2 (2)
    the code is exactly as i gave in original post, it is "char array99[300];" and nothing else.i got compile time error. can we use static array, as we construct data packet in one function and pass it to transmitter function?Regards,

    The line of code by itself tells us nothing. If declared inside a function then it is auto and that’s likely your problem.
    #10
    66pvoarvp
    Starting Member
    • Total Posts : 42
    • Reward points : 0
    • Joined: 2016/12/05 18:29:36
    • Location: 0
    • Status: offline
    Re: Working with Large Arrays in MPLAB XC8 2020/06/25 03:42:17 (permalink)
    0
    1and0
    mbrowning
    Is this an auto array? You probably can’t create such large elements on the compiled stack.

    +1.
     
    Make the array static or global.


    yes, as you told. It is not giving any error message.
    After testing the overall operation, I would post the result.
     
    Thanks & regards.
    #11
    Coman
    Junior Member
    • Total Posts : 29
    • Reward points : 0
    • Joined: 2016/11/06 14:56:29
    • Location: 0
    • Status: offline
    Re: Working with Large Arrays in MPLAB XC8 2020/06/25 03:45:41 (permalink)
    -2 (2)
    another thing that can come to my mind is the linker file
     
    for example
     
    ACCESSBANK NAME=accessram START=0x0 END=0x5F
    DATABANK NAME=gpr0 START=0x60 END=0xFF
    DATABANK NAME=gpr1 START=0x100 END=0x330
    DATABANK NAME=gpr2 START=0x331 END=0x34F
    DATABANK NAME=gpr3 START=0x350 END=0x3FF
    DATABANK NAME=usb4 START=0x400 END=0x4FF PROTECTED
    DATABANK NAME=usb5 START=0x500 END=0x5FF PROTECTED
    DATABANK NAME=usb6 START=0x600 END=0x6FF PROTECTED
    DATABANK NAME=usb7 START=0x700 END=0x7FF PROTECTED
    ACCESSBANK NAME=accesssfr START=0xF60 END=0xFFF PROTECTED
    SECTION NAME=CONFIG ROM=config
    STACK SIZE=0x50 RAM=gpr3
    SECTION NAME=USB_VARS RAM=usb4
     
    #pragma udata gpr1=0x100
    BYTE HUGE_ARRAY[500];
     
    this way i can fit the 500 byte array in gpr1, that spans over multiple databanks...
    #12
    1and0
    Access is Denied
    • Total Posts : 10999
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: Working with Large Arrays in MPLAB XC8 2020/06/25 03:51:03 (permalink)
    +1 (1)
    Coman
    another thing that can come to my mind is the linker file
     
    for example
     
    ACCESSBANK NAME=accessram START=0x0 END=0x5F
    DATABANK NAME=gpr0 START=0x60 END=0xFF
    DATABANK NAME=gpr1 START=0x100 END=0x330
    DATABANK NAME=gpr2 START=0x331 END=0x34F
    DATABANK NAME=gpr3 START=0x350 END=0x3FF
    DATABANK NAME=usb4 START=0x400 END=0x4FF PROTECTED
    DATABANK NAME=usb5 START=0x500 END=0x5FF PROTECTED
    DATABANK NAME=usb6 START=0x600 END=0x6FF PROTECTED
    DATABANK NAME=usb7 START=0x700 END=0x7FF PROTECTED
    ACCESSBANK NAME=accesssfr START=0xF60 END=0xFFF PROTECTED
    SECTION NAME=CONFIG ROM=config
    STACK SIZE=0x50 RAM=gpr3
    SECTION NAME=USB_VARS RAM=usb4
     
    #pragma udata gpr1=0x100
    BYTE HUGE_ARRAY[500];
     
    this way i can fit the 500 byte array in gpr1, that spans over multiple databanks...


    That is NOT the linker file for the 18F27K42. Besides, it's for MPASM, not XC8.
    #13
    66pvoarvp
    Starting Member
    • Total Posts : 42
    • Reward points : 0
    • Joined: 2016/12/05 18:29:36
    • Location: 0
    • Status: offline
    Re: Working with Large Arrays in MPLAB XC8 2020/06/25 03:54:04 (permalink)
    0
    Coman
    another thing that can come to my mind is the linker file
     
    for example
     
    ACCESSBANK NAME=accessram START=0x0 END=0x5F
    DATABANK NAME=gpr0 START=0x60 END=0xFF
    DATABANK NAME=gpr1 START=0x100 END=0x330
    DATABANK NAME=gpr2 START=0x331 END=0x34F
    DATABANK NAME=gpr3 START=0x350 END=0x3FF
    DATABANK NAME=usb4 START=0x400 END=0x4FF PROTECTED
    DATABANK NAME=usb5 START=0x500 END=0x5FF PROTECTED
    DATABANK NAME=usb6 START=0x600 END=0x6FF PROTECTED
    DATABANK NAME=usb7 START=0x700 END=0x7FF PROTECTED
    ACCESSBANK NAME=accesssfr START=0xF60 END=0xFFF PROTECTED
    SECTION NAME=CONFIG ROM=config
    STACK SIZE=0x50 RAM=gpr3
    SECTION NAME=USB_VARS RAM=usb4
     
    #pragma udata gpr1=0x100
    BYTE HUGE_ARRAY[500];
     
    this way i can fit the 500 byte array in gpr1, that spans over multiple databanks...




    Thanks for the advice.
    we tried it.
    As pointed by 1and0 , there is no .gld file for 18F27K42 device and we gave up that method.
     
    Thanks & regards,
    #14
    ric
    Super Member
    • Total Posts : 28009
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: Working with Large Arrays in MPLAB XC8 2020/06/25 04:57:10 (permalink)
    +3 (3)
    As 1and0 has been trying to tell you, the compiler can do it easily, and you don't need to fiddle with linker files (which XC8 doesn't use).
    You just have to make sure the variable is global or static, NOT an auto variable.
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #15
    crosland
    Super Member
    • Total Posts : 2017
    • Reward points : 0
    • Joined: 2005/05/10 10:55:05
    • Location: Warks, UK
    • Status: offline
    Re: Working with Large Arrays in MPLAB XC8 2020/06/25 08:25:05 (permalink)
    +3 (3)
    Never in the field of PIC programming has so much crap been generated by so few posters.
    #16
    66pvoarvp
    Starting Member
    • Total Posts : 42
    • Reward points : 0
    • Joined: 2016/12/05 18:29:36
    • Location: 0
    • Status: offline
    Re: Working with Large Arrays in MPLAB XC8 2020/06/26 00:06:25 (permalink)
    0
    ric
    As 1and0 has been trying to tell you, the compiler can do it easily, and you don't need to fiddle with linker files (which XC8 doesn't use).
    You just have to make sure the variable is global or static, NOT an auto variable.
     


    Thanks for your word.
     
    You have overlooked, that the device number PIC18F27K42 was clearly mentioned in very first post itself.
    We have made it Global, and adding other pieces of code.
     
    Thank you.
    #17
    66pvoarvp
    Starting Member
    • Total Posts : 42
    • Reward points : 0
    • Joined: 2016/12/05 18:29:36
    • Location: 0
    • Status: offline
    Re: Working with Large Arrays in MPLAB XC8 2020/06/26 00:08:06 (permalink)
    +1 (1)
    didn't get you.
    #18
    66pvoarvp
    Starting Member
    • Total Posts : 42
    • Reward points : 0
    • Joined: 2016/12/05 18:29:36
    • Location: 0
    • Status: offline
    Re: Working with Large Arrays in MPLAB XC8 2020/06/26 00:10:48 (permalink)
    0
    mbrowning
    I’ve used static arrays much larger than 300 bytes with no problem on k42’s.

    Is this an auto array? You probably can’t create such large elements on the compiled stack.

    Using Global / static array as advised by you and other members.
    Testing the code part.
    regards.
    #19
    ric
    Super Member
    • Total Posts : 28009
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: Working with Large Arrays in MPLAB XC8 2020/06/26 00:42:08 (permalink)
    0 (2)
    66pvoarvp
    You have overlooked, that the device number PIC18F27K42 was clearly mentioned in very first post itself.

    Are you commenting on the text in my signature, which is at the foot of every one of my posts on this forum?
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #20
    Page: 12 > Showing page 1 of 2
    Jump to:
    © 2020 APG vNext Commercial Version 4.5