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

bad structure declaration?

i'm trying to create an array of structures but when i make more than a handful my robot doesn't work.

so in main.h i have

typedef struct SPid
{
  int dState;      	 // Last position input
  int iState;      	 // Integrator state
  int iMax, iMin;    // Maximum and minimum allowable integrator state
  int desired_value; // the desired value the PID should converge upon


  float 	iGain,    	// integral gain
        	pGain,    	// proportional gain
         	dGain;     	// derivative gain
}SPid;

extern SPid vel_Gains[];

and then in main.c
#include "MAIN.H"
struct SPid vel_Gains[5];

it barely works for vel_Gains[2], (printf looks glitchy but readable) and then vel_Gains[1] works for sure...

i'm using the small memory model btw...

is there a size limitation on global variables?

thanks,
fred

  • There's not a size limit on globals, so much as a size limit on the internal RAM of an 8051. (128 bytes).

    In the "small" data model, any variables without an explicit memory type qualifier are assumed to go into the "data" space, which is the internal RAM. Your struct is about 22 bytes, so five of them is 110 bytes, and you're almost out of room.

    Try declaring them "xdata". Or just change to the large memory model.

    A number of programmers recommend explicit memory qualifers for all declarations, rather than relying on the memory model to get things right. If you ever switch memory models, having explicit declarations for everything will continue to work. Without them, you'll be hunting down problem locations in your code where you let a variable default.

  • thanks for your reply,

    i added

    struct SPider xhuge vel_Gains;
    

    and it didn't work... i don't think my compiler has xdata....

    do i need to modify my START167.A66 file to tell it where the ram is? (i believe i set the RAM location in keil)

  • could someone explain what this means?

    "If you want the data to reside in xdata, then you'll need to be sure your startup code executes the code in INIT.A51 to actually copy the initializer values from ROM to the xdata RAM. "

  • If you have reasons to believe that you have run out of memory check build time warnings and errors, linker generated memory map. Linker will fail with an error message if it runs out of memory.
    There could be plenty of reasons why a program doesn't work as expected. With the problem description you have provided it looks unlikely it has anything to do with memory limits.

    - mike

  • could someone explain what this means?

    Variables live in RAM, so they can vary. RAM does not retain its values when you turn the power off. If you initialize global variables with constants in C:

    char myArray[] = { 1, 2, 3};

    the (RAM) variable myArray has to begin with the constants 1, 2, and 3. But those constants have to be stored in some sort of ROM, rather than RAM, to survive loss of power. That is, they are stored somewhere, in ROM, in addition to the actual variable myArray. Before main() executes, some piece of code has to copy any such constant initializers from ROM to the proper locations in RAM. This job is done in the Keil toolchain by the INIT.A51 code.

    You may not need this particular feature, so use of INIT.A51 is optional. If you do not link it into your code, but use static initializers anyway, your variables will not be initialized the way you think they will.


    Have you read this thread:

    http://www.keil.com/forum/docs/thread4241.asp

    And the app note it mentions?

  • hello,

    it seems like what i posted should just work... i switched to a large memory model and reconfigured everything in DAVE... (basically a fresh start with large memory model)

    it still doesn't work... when i add other modules like timers and lcd interface... all of a sudden things don't work... and only work when i remove the structure data structure...

    is there something wrong with my compiler (keil 4.xx and my board? the phytec c167?)

    note: no one from last semester was able to use structs on this board as well... maybe there is something we all don't know about... like how to configure the 64k of RAM we have... or something or another)
    cheers,
    fred

  • Your description of the problem is too vague. It's like "Something isn't working. What could it be?" The answer to this is it could be anything. You'll have to be more specific in order to get more meaningful answers. You'll have to experiment to narrow down the number of possibilites. By experimenting I mean not just adding or removing modules, that's still not specific enough.

    - mike