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

can open a large array as 1024bytes for CY7C68013 ?

since my topic use CY7C68013+AD7934+EEPROM as directly convert an analog signal to digital and send back to PC, but for the sampling rate of 10kHz, i want to have a buffer for me to save those data...and i have tried a lot of ways for opening a large array in KeilC...
but most of the time it's not access...
can someone else tell me how to create it...
and i would wonder ask... can i allocate it @ fx2reg.h? and how to finish it up?

one of my unsuccess way...

CODE:

#pragma NOIV
#include "fx2.h"
#include "fx2regs.h"
#include "fx2sdly.h"            // SYNCDELAY macro

extern BOOL GotSUD;             // Received setup data flag
extern BOOL Sleep;
extern BOOL Rwuen;
extern BOOL Selfpwr;

BYTE Configuration;             // Current configuration
BYTE AlternateSetting;          // Alternate settings

#define VR_NAKALL_ON    0xD0
#define VR_NAKALL_OFF   0xD1

#define WB     IOD_0
#define CS     IOD_1
#define RD     IOD_2
#define WR     IOD_3
#define CONVST IOD_4
#define BUSY   IOD_5

#define ALLOCATE_EXTERN
#define START_MEM01             0x1e00
#define LENGTH_MEM01    0x200
BYTE xdata *AD0DATA[]= START_MEM01; 

void ad0(void);
void TD_Init(void)             // Called once at startup
{
.
.
.
}
void ad0(void)
{
.
.
.
        AD0DATA[count] = IOA;
        AD0DATA[count+1]= (IOB & 0x0f);
}
void T0int(void)                        //----timer 0 int----//
{
    CS=1;
    WR=1;
CONVST=1;
    OEA=0xff;
    OEB=0xff;
    TL0=0x0c;
    TH0=0xfe;
    if (count < 1023)
       count+=2;
    else
    {
        count=0;
        TR0=0;
    }
     ad0();
}
void TD_Poll(void)
{
        unsigned int i=0,j=0,loop=0;

    if(!(EP01STAT & 0x02))          //PC TO USB
    {
     if(EP1OUTBUF[0]==0x05)  // Continous sampling and Sent to PC //
                {
        freq=(EP1OUTBUF[2]<<8)+EP1OUTBUF[1];
        cycle=(EP1OUTBUF[4]<<8)+EP1OUTBUF[3];
            SYNCDELAY;
        EP1OUTBC=0x05;          // 5bytes data already be read
        SYNCDELAY;
        flag=1;
        count=0;
            TMOD=0x01;
           TL0=0x0c;
           TH0=0xfe;
        TR0=1;                  ET0=1;
        SYNCDELAY;
        times=0;
        while( times < cycle )
        {
           if(!(EP2468STAT & bmEP6FULL))                       {
           j=0;
             for(i=0;i<64;i++)
              {                                         EP6FIFOBUF[j]=AD0DATA[j];
                EP6FIFOBUF[j+1]=AD0DATA[j+1];
             j+=2;
             }
        EP6BCH = 0x00;
         SYNCDELAY;
                EP6BCL = 0x80; // arm EP6IN
         SYNCDELAY;
        }
}

Parents
  • since i didn't programming 8051 for a long time(and i use C to implement 8051 before)...
    can u give me some of the datasheet for reviewing that?

    i know differernent address spaces as well,but i didn;t know how to create an array as large as 2048bytes../
    i have tried to directly wrote as

     unsigned int AD0DATA[2048];
    


    in this way, i can just create an array as large as AD0DATA[30]...
    it's not sufficient for my usage...
    for storage 2~3kbytes data
    OR

    add statement in fx2reg.h and my.c
    @fx2reg.h

    #define ALLOCATE_EXTERN
    EXTERN xdata volatile BYTE AD0DATA[2048]  _AT_ 0x17FF;
    
    


    @my.c directly use AD0DATA as an array

    OR
    just like the post, to make a pointer's array to allocate that...

    can u give me some suggestion,thx!!!

Reply
  • since i didn't programming 8051 for a long time(and i use C to implement 8051 before)...
    can u give me some of the datasheet for reviewing that?

    i know differernent address spaces as well,but i didn;t know how to create an array as large as 2048bytes../
    i have tried to directly wrote as

     unsigned int AD0DATA[2048];
    


    in this way, i can just create an array as large as AD0DATA[30]...
    it's not sufficient for my usage...
    for storage 2~3kbytes data
    OR

    add statement in fx2reg.h and my.c
    @fx2reg.h

    #define ALLOCATE_EXTERN
    EXTERN xdata volatile BYTE AD0DATA[2048]  _AT_ 0x17FF;
    
    


    @my.c directly use AD0DATA as an array

    OR
    just like the post, to make a pointer's array to allocate that...

    can u give me some suggestion,thx!!!

Children
  • I think you have found the bug in the IDE that they don't fix.

    The easy workaround is to select to the large model.

  •  unsigned int AD0DATA[2048];
    

    And what problem(s) did you encounter when you did that?

  • No evidence has been given that suggests any bug anywhere!

    There isn't even enough information to know what problem(s) the OP is actually having!

    :-(

  • the compiler error due to "the data segment is too large"
    it's just give me this message about

     unsigned int AD0DATA[2048];
    


    can i send my code to u to easy regonized what my problem is?

  • I think you have found the bug in the IDE that they don't fix.
    i don't understand what it means....can u give me somemore information?
    The easy workaround is to select to the large model
    large model????what's that...

  • Having an array of 2048 int variables would require 4096 bytes of RAM. Not telling what memory section to use and trying to locate a 4096 byte array into the DATA memory region does give very known problems. You did find these problems.

    First step is to consider if you really know what size of array to use. You sometimes talks about 1024 bytes. Sometimes about 2048 bytes. Sometimes about 1024 ints. And in this case you have an example of 2048 ints.

    Then you have to figure out the difference between having an array of integers, a pointer to the array, or an array of a large number of pointers. Do think about the meaning of:

    BYTE xdata *AD0DATA[]= START_MEM01;
    

    When you have finally figured out what size of array that you need (and if it should be an array of bytes, an array of integers or an array of pointers to integers), you will have to read through the documentation for your chip. Do you have that amount of RAM? Where in the chip is it? Is it really in DATA? How large is your XDATA? Is your XDATA large enough in case you put special requirements about start address in XDATA?

  • what size and what type of array that you need (and if it should be an array of bytes, an array of integers or an array of pointers to integers)
    em... i need a 2048 array of bytes for me to save data

    you will have to read through the documentation for your chip.
    i try hard to find it out...

    Do you have that amount of RAM? Where in the chip is it?
    it's enough for me,after compiling my program w/o that array, it only spend 4kbytes, so i would guest that it's enough for a 2048-bytes array. it can allocate @0x0000~0x1FFF.

    Is it really in DATA? How large is your XDATA?
    this part...i am not sure what is the difference between DATA and XDATA...

    Is your XDATA large enough in case you put special requirements about start address in XDATA?
    for the address, i try to allocate it @0x17FF(since my array is 2048bytes and the address are limited @0x1FFF)
    but it's doesn't work....

  • So 2048 bytes is 0x0800. That would mean that you can start the array at 0x1800, since it will then span 0x1800..0x1fff which is 0x0800 entries. No need to place it one byte early, unless you for some reason wants an extra byte after the array.

    But you are talking about:

    unsigned int AD0DATA[2048];
    

    That is not a 2kB array. It is 2048 entries of the type int, and the int data type is two bytes large, so the array is 4kB large. I'm not sure how you will manage to fit 4kB of data in the last 2kB+1 bytes of your RAM.

    By the way - exactly why do you feel that you need to place the array at an absolute position? Do you have a problem with letting the linker use the next available address, as long as you have remembered to specify exactly which memory region to use?

    Another thing. You claim that your program requires 4kB without the array. I have to believe that you mean 4kB of RAM, and not 4kB of flash. But if you have 8kB of XDATA, and you potentially allocate around 4kB of it for other things, you may not have 4kB left - so your 2048 entry large array of int may still not fit.

  • i have a silly question...how to define where is my array started?
    if i just writing

    BYTE xdata AD0DATA[2048];
    


    i can just create an array...but i didn't know where did it start...
    and i just test by directly wrote as

    BYTE xdata AD0DATA[2048];
    


    compile is ok,but when i used it to saved my data and send back to PC...the BULK transfer can't be completed...

    By the way - exactly why do you feel that you need to place the array at an absolute position? Do you have a problem with letting the linker use the next available address, as long as you have remembered to specify exactly which memory region to use?
    actually...i don't know what region did my program saved in the RAM of CY7C68013...but i think that, in each reset, the program are read from the EEPROM(24LC64), it should be read from 0x0000, so, it would be better to allocate the array to the absolute position.

    Another thing. You claim that your program requires 4kB without the array. I have to believe that you mean 4kB of RAM, and not 4kB of flash. But if you have 8kB of XDATA, and you potentially allocate around 4kB of it for other things, you may not have 4kB left - so your 2048 entry large array of int may still not fit.
    the size that I claim is based on the information from the KeilC compiler, which wroten "3944bytes written".

  • "but i didn't know where did it start..."
    Why do you need to know where it start. From inside the application, the name of the array represents the start address of the array. It is only if an external application needs to use some form of interface to perform absolute reads/writes into the memory space of the processor (for example a chip programmer) that the outside world need to care about the exact start address. If using a debugger, then the debug information will contain the required information to tell the debugger about the address of all accessible symbols in the program.

    "actually...i don't know what region did my program saved in the RAM of CY7C68013...but i think that, in each reset, the program are read from the EEPROM(24LC64), it should be read from 0x0000, so, it would be better to allocate the array to the absolute position."

    Your program? Are you running a program from RAM? I haven't looked at the datasheet of your specific processor, but most 8051 chips can't run any programs from RAM. Some of them can - with special programming - map XDATA memory to overlap a CODE memory address range, allowing self-modifying code or downloading code blocks from serial EEPROM or a serial link and run in RAM. For a processor that does not allow XDATA to be mapped into CODE space, the 8051 architecture will not allow a program to be run from RAM - the processor has multiple memory regions, and instruction processing can only be performed from the memory region known as CODE.

  • my program is read from EEPROM to the USB chip(CY7C68013) through I2C, which is download to the internal RAM of 8051 inside CY7C68013.

    BYTE xdata AD0DATA[2048];
    void TD_Init(void)             // Called once at startup
    {
            CKCON=0x00;
            IT0=0; //
            EX0=0; //EX0=1 INT1 enable
            EA=1;
            CS=1;
            WR=1;
            RD=1;
            CONVST=1;
            for (ii=0;ii<2048;ii++)
            {
                    EP2FIFOBUF[ii]=0;
                    EP6FIFOBUF[ii]=0;
                 AD0DATA[ii]=0;
            }
       AUTOPTRSETUP |= 0x01;         // enable dual autopointer feature
       Rwuen = TRUE;                 // Enable remote-wakeup
    }
    


    as i add the AD0DATA[ii]=0; in my program...it's showed me the USB device cannot be detected= =+
    so...it means that...the array that i create have failed...
    but y??

  • EP2FIFOBUF[ii]=0;
    EP6FIFOBUF[ii]=0;
    AD0DATA[ii]=0;
    

    Now, you have three different 2048 element long arrays. Where are the other arrays located, and of what data type?

    But none of the code explains why you need to have your array at a specific location.

    "so...it means that...the array that i create have failed...
    but y??"

    How can you deduce that your array have failed. Exactly how can an array fail?

    But you can have an almost infinite number of problems. Do you have valid contents in the EEPROM? Is your I2C code working. Is the USB code correct? The list can go on almost indefinitely. You just have to split your problem into smaller pieces, and verify them one by one.

  • i know differernent address spaces as well,but i didn;t know how to create an array as large as 2048bytes../
    i have tried to directly wrote as

    unsigned int AD0DATA[2048];

    that is NOT 2048 bytes, it is 4096 bytes

    Erik

  • i am now using
    BYTE xdata AD0DATA[2048];
    thx

  • actually, for not adding AD0DATA[ii]=0;into the loop
    everything is OK!!!
    and the EP2FIFOBUF and EP6FIFOBUF has a space for FIFO transfer, which is internally allocate there...
    that cmd is not a problem then.