Keil Logo

when I use big arrays, i get problem...

Next Thread | Thread List | Previous Thread Start a Thread | Settings

Details Message
Read-Only
Author
Mustafa Koyuncu
Posted
7-Apr-2011 08:34 GMT
Toolset
C51
New! when I use big arrays, i get problem...

Hi,

I am using AT89C51rd2. When I use big arrays like abc[270] and def[274] in my code, nothing works correct. But i use abc[40] and def[40], every thing is ok.

when abc[270] and def[274] declared, keil generates:

Program Size: data=109.1 xdata=1159 code=12696

when abc[40] and def[40] declared, keil generates:

Program Size: data=109.1 xdata=695 code=12461

In options, "use on-chip xram" is checked. I tried to set AUXR resiter in firmware like XRS0=0,XRS1=0,XRS2=1 to select "software selectable" xram size as 1792. Nothing is work....

What can be the problem???

Thanks...

Read-Only
Author
Andrew Neil
Posted
7-Apr-2011 08:38 GMT
Toolset
C51
New! RE: nothing works correct

That's next to meaningless!

You need to describe precisely what things you are trying to do, what results you were expecting, what results you actually got, and what thought & debugging you have applied in trying to resolve the issue.

Read-Only
Author
Mustafa Koyuncu
Posted
7-Apr-2011 09:11 GMT
Toolset
C51
New! RE: nothing works correct

First problem,
I am driving an IC and if the IC is setup correctly, my system's total current consumption should 0.17 A. But with big arrays it is 0.7 A. So this means IC is not setuped correctly by MCU.

Second problem,
No uart commands works when big arrays defined...

even when the big arrays defined but "not used" (Sources\main.c(717): warning C280: 'abc': unreferenced local variable), I got these problems... (array defination: abc[275])

I tought many people get this type problems, so I think they understand the situation well...

By the way, thank you for "meaningless".

Read-Only
Author
Andrew Neil
Posted
7-Apr-2011 09:59 GMT
Toolset
C51
New! Still too little to go on

Remember that nobody on this forum knows anything about your, or your project, or your hardware, or your software other than what you clearly and explicitly state in your posts.

If you can't find the problem when you have the code and the hardware right there in front of you, how do you expect anyone to do so without seeing or knowing anything about the hardware & software?

"So this means IC is not setuped correctly by MCU"

That's good - you've made a first step!

Now you need to investigate further to find why it's not getting set up correctly.

Again, with no access to your hardware or your software, nobody else can do this for you.

You haven't even said what IC it is, or how you set it up.

"No uart commands works"

Sorry, that's meaningless again!

You're back to, "My car doesn't work - what's wrong with it?"

What are these "UART commands"?
What are they supposed to do?
What do they actually do?
What thinking & debugging have you done in an attempt to account for the difference?

"I tought many people get this type problems"

But we don't know exactly what type of problems you are having!

There's an almost infinite number of things that could cause stuff to "not work".

Again, think about "My car doesn't work - what's wrong with it?"; how many different things can you think of that would make a car "not work" - there must be hundreds!

"I think they understand the situation well"

Only if you explain it well!

You have identified that the presence/absence of "big arrrays" seems to affect this - so you need to investigate what, exactly, is different.

Have you tried this in the Simulator?

Here are some debugging tips & techniques:

http://www.8052.com/faqs/120313

http://www.techonlineindia.com/article/09-09-23/Developing_a_good_bedside_manner.aspx

Read-Only
Author
tan bukhari
Posted
7-Apr-2011 11:53 GMT
Toolset
C51
New! RE: nothing works correct

hey mustafa.

my project had a simelar problem in start. i have been coding for nearly 5 months and have lots of many experience and write very complicated code {it needs comments !!!!!} but not even i can answer your question. you have more memory ?????

tan.

Read-Only
Author
erik malund
Posted
7-Apr-2011 13:51 GMT
Toolset
C51
New! RE: when I use big arrays, i get problem...

I am using AT89C51rd2. When I use big arrays like abc[270] and def[274] in my code, nothing works correct. But i use abc[40] and def[40], every thing is ok.

when abc[270] and def[274] declared, keil generates:

Program Size: data=109.1 xdata=1159 code=12696

if I recall the RD2 has 756 bytes of XDATA check the datasheet

Erik

Read-Only
Author
Mustafa Koyuncu
Posted
8-Apr-2011 12:10 GMT
Toolset
C51
New! RE: when I use big arrays, i get problem...

I think its not an application specific issue, because when I define a variable which is not used in code and when it exceed 768 byte xram, it starts to make problem. It look like a memory allocation problem, and indirect addressing does not work good for exceeding 768bytes.

In the At89C51Rd2's datasheet, it says, xram set 768 bytes at reset but it is software configurable up to 1792 bytes. So i tried to set AUXR resigter as XRS0=0, XRS1=0, XRS2=1 but it did not work...

Am I wrong? I am expecting a way to solve this problem...

Thanks for replies...

Read-Only
Author
erik malund
Posted
8-Apr-2011 13:53 GMT
Toolset
C51
New! RE: when I use big arrays, i get problem...

when I define a variable which is not used in code
why do you "define a variable which is not used in code"

and when it exceed 768 byte xram, it starts to make problem.
how do you see that "it starts to make problem" also see below

It look like a memory allocation problem, and indirect addressing does not work good for exceeding 768bytes.
it does not matter if addressing is indirect or not, if the memory is there

So i tried to set AUXR resigter as XRS0=0, XRS1=0, XRS2=1 but it did not work...
where in the code, hopefully in startup.a51. also what is the XDATA size set to

Am I wrong? I am expecting a way to solve this problem...
expecting??

Erik

Read-Only
Author
Mustafa Koyuncu
Posted
8-Apr-2011 14:08 GMT
Toolset
C51
New! RE: when I use big arrays, i get problem...

-why do you "define a variable which is not used in code"-
to test if does it make a problem.

-how do you see that "it starts to make problem" also see below-
For example, xdata=900, it make small problems. Uart commands answers back but not true.
For xdata=1159, nothing works, no answer...

-it does not matter if addressing is indirect or not, if the memory is there-
it was just a opinion.. ;)

-where in the code, hopefully in startup.a51. also what is the XDATA size set to-
at the beginning of the main. i did not know that startup code make this.

So...?

Read-Only
Author
erik malund
Posted
8-Apr-2011 14:40 GMT
Toolset
C51
New! RE: when I use big arrays, i get problem...

-how do you see that "it starts to make problem" also see below-
For example, xdata=900, it make small problems. Uart commands answers back but not true.
For xdata=1159, nothing works, no answer...

that is rather arbitrary that "something falls apart when I'm doing something else" is about the most worthless diganostic there is
make a piece of code that writes and reads back from, say address 500, then address 1000

i did not know that startup code make this.

So...?

make it do it

I would not be surprised if selecting RD2 automatically set it for 756 bytes

just a note

make a renamed copy of startup.a51 and include it in your project

Erik

Read-Only
Author
Mustafa Koyuncu
Posted
11-Apr-2011 06:40 GMT
Toolset
C51
New! RE: when I use big arrays, i get problem...

Finally problem is solved.. :)))

Firstly I had change just XDATA lenght, but it did not work. Then I tried to add some assembly code at the beginning of the place which XDATA space cleared in startup.a51. Then is OK...

Thanks for all replies.....

Read-Only
Author
Mustafa Koyuncu
Posted
11-Apr-2011 06:44 GMT
Toolset
C51
New! RE: when I use big arrays, i get problem...

Here is the code that I added:

This code set AUXR to 1792 bytes XRAM....

XDATALEN        EQU     1792

IF XDATALEN <> 0

                mov a,8EH
                setb acc.4
                clr acc.2
                clr acc.3
                mov 8EH,a

                MOV     DPTR,#XDATASTART
                MOV     R7,#LOW (XDATALEN)
  IF (LOW (XDATALEN)) <> 0
                MOV     R6,#(HIGH (XDATALEN)) +1
  ELSE
                MOV     R6,#HIGH (XDATALEN)
  ENDIF
                CLR     A
XDATALOOP:      MOVX    @DPTR,A
                INC     DPTR
                DJNZ    R7,XDATALOOP
                DJNZ    R6,XDATALOOP
ENDIF
Read-Only
Author
Andrew Neil
Posted
11-Apr-2011 07:33 GMT
Toolset
C51
New! RE: This code set AUXR to 1792 bytes XRAM

Well done, and thanks for sharing the solution - too many people never bother to do that.

:-(

In your very first post, you said,

"I tried to set AUXR resiter in firmware like XRS0=0,XRS1=0,XRS2=1 to select 'software selectable' xram size as 1792. Nothing is work...."

So what was the difference between what you tried then (that didn't work), and what you have done now (that does work)?

Read-Only
Author
Mustafa Koyuncu
Posted
11-Apr-2011 08:50 GMT
Toolset
C51
New! RE: This code set AUXR to 1792 bytes XRAM

before, I wrote the code to set AUXR in (beginning of) main (as C code), and it did not work...
but then I made it in startup and it is ok...

Read-Only
Author
Andrew Neil
Posted
11-Apr-2011 09:05 GMT
Toolset
C51
New! RE: I wrote the code to set AUXR in (beginning of) main (as C code),

Do you now understand why that's a bad idea?

It would also be a goos idea to comment your additions to the startup file - both to remind yourself why it's there, and what it does...

Read-Only
Author
Mustafa Koyuncu
Posted
11-Apr-2011 09:25 GMT
Toolset
C51
New! RE: I wrote the code to set AUXR in (beginning of) main (as C code),

I do not understand what was the bad idea?

Read-Only
Author
Per Westermark
Posted
11-Apr-2011 09:39 GMT
Toolset
C51
New! RE: I wrote the code to set AUXR in (beginning of) main (as C code),

Would it make a difference if you configure this setting before or after the startup code initializes all variables stored in this memory region?

Read-Only
Author
Andrew Neil
Posted
11-Apr-2011 10:15 GMT
Toolset
C51
New! RE: I wrote the code to set AUXR in (beginning of) main (as C code),

Look at the code you posted:

XDATALEN        EQU     1792

IF XDATALEN <> 0

                mov a,8EH
                setb acc.4
                clr acc.2
                clr acc.3
                mov 8EH,a

                MOV     DPTR,#XDATASTART
                MOV     R7,#LOW (XDATALEN)
  IF (LOW (XDATALEN)) <> 0
                MOV     R6,#(HIGH (XDATALEN)) +1
  ELSE
                MOV     R6,#HIGH (XDATALEN)
  ENDIF
                CLR     A
XDATALOOP:      MOVX    @DPTR,A
                INC     DPTR
                DJNZ    R7,XDATALOOP
                DJNZ    R6,XDATALOOP
ENDIF

XDATALEN is set to a valuse of 1792 - if you don't correctly configure the chip (via AUXR), what will happen in that loop which tries to access 1792 bytes of XDATA...?

And that isn't the only thing!

All of the rest of the startup code will be assuming that 1792 bytes of XRAM are available and will be trying to access them...

Read-Only
Author
erik malund
Posted
11-Apr-2011 15:04 GMT
Toolset
C51
New! an editorial

Many are afraid of touching startup.a51 however in some cases it is MANDATORY.
when the OP followed my suggestion (set AUXR in startup) everything worked.
thus
ANYTHING related to xdata configuration (e.g. SILabs) MUST be done at the beginning of startup
if you have an external XDATA memory, you may need to configure the clock at the beginning of startup.
if you have a crossbar (SILabs, some ARMs, ,,,) you need to configure it at the beginning of startup.

Generally:
anything that relates to XDATA access MUST be done at the beginning of startup
this can be memory configuration, memory timing, crossbar, ....

HAVE NO FEAR modifying startup is quite simple. DO NOT call a C routine, C is not "ready"

Erik

Read-Only
Author
Andrew Neil
Posted
11-Apr-2011 17:08 GMT
Toolset
C51
New! RE: Many are afraid of touching startup.a51

I wonder if they are actually afraid, or if they just don't think about it and/or don't realise that it's there?

http://www.keil.com/support/man/docs/c51/c51_ap_customfiles.htm

Read-Only
Author
erik malund
Posted
11-Apr-2011 17:36 GMT
Toolset
C51
New! afraid? realize?

I guess it's more like an automatic "place all initialization at top of main" which, for some NON-51 compilers (e.g. visual C) may be totally relevant.

There are some 'typical' 'mistakes' 99% of PC coders make when they try to be '51 programmers.

Erik

PS I have found "place all initialization at top of main" not to work for IAR/STM32 cortex so it's not just the '51. OK this is a Keil forum, but I work with the tools my customer gives me. Sone the issue is in the ST provided code I believe that the same holds true for Keil ARM

Next Thread | Thread List | Previous Thread Start a Thread | Settings

  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.