| Details | Message |
|---|
Read-Only Author Fran H Posted 18-Jun-2009 16:22 GMT Toolset C51 |  large (>8k) array in xdata, program running incorrectly Fran H Hi guys, I tried to construct a waveform with more than 6000 points. the program is like: arg.h . . int xdata wave[6000] . . main(){ . . for...{ wave[i]=i*10; . } . it passed the compiling and linking. it showed that xdata=12131. but when i ran the program, it's actually showing a messed up waveform. it only works correctly when i reduced the size of the wave[] to 4000, which makes xdata=8131. i m using version 7.2, and the xram on the board is 128k. i think it's something missing in the program but couldnt figure it out yet since i m just a beginner of mcu programing in c. any suggestion? i really appreciate it. |
|
Read-Only Author Per Westermark Posted 18-Jun-2009 16:27 GMT Toolset C51 |  RE: large (>8k) array in xdata, program running incorrectly Per Westermark i=5999 -> 10*i = 59990. Max integer size is 32767. See any problem? |
|
Read-Only Author Fran H Posted 18-Jun-2009 16:40 GMT Toolset C51 |  RE: large (>8k) array in xdata, program running incorrectly Fran H Thank you! but that was a bad example, because even I changed it to: unsigned int xdata wave[6000] main(){ . wave[i]=10; . . I still have the same problem if the size is more than 4000. is there anything to do with the 8k issue i just read http://www.keil.com/support/docs/2177.htm ? |
|
Read-Only Author Andy Neil Posted 18-Jun-2009 16:57 GMT Toolset C51 |  Does it work correctly in the simulator? Andy Neil If it does, that suggests that there's an issue with your hardware; If it doesn't, then there's something more fundamental... |
|
Read-Only Author Hans-Bernhard Broeker Posted 18-Jun-2009 22:21 GMT Toolset C51 |  RE: large (>8k) array in xdata, program running incorrectly Hans-Bernhard Broeker is there anything to do with the 8k issue i just read No. That's quite a different issue. For starters, your array is not an initialized variable. |
|
Read-Only Author Andy Neil Posted 18-Jun-2009 16:59 GMT Toolset C51 |  RE: the xram on the board is 128k Andy Neil A standard 8051 cannot directly address 128K - so this must mean that you have some kind of banking arrangement? Are you certain that your banking is working correctly - and that it doesn't have any issues related to 8K boundaries...? |
|
Read-Only Author Fran H Posted 18-Jun-2009 19:42 GMT Toolset C51 |  RE: the xram on the board is 128k Fran H thanks for the advice. i dont have a simulator. and i dont think it's the banking problem either. I changed the compile option to fixed the variables order. It actually allow the program doing what it's supposed to do with the wave[] as large as 32000, except any point higher than index 4000, goes back to the value of index 0, which makes me think it might be related to that '8k' problem. |
|
Read-Only Author Andy Neil Posted 18-Jun-2009 23:40 GMT Toolset C51 |  RE: i dont have a simulator Andy Neil Of course you do - uVision has a built-in simulator! |
|
Read-Only Author erik malund Posted 19-Jun-2009 00:27 GMT Toolset C51 |  as usual i have to guess since ... erik malund ... you, like many others, did not see a reason to tell us which uC you are using. I guess you are using a SILabs or NXP (or other) with 8k internal XRAM and have not modified (a local copy of) startup.a51 to enable access to your external XRAM. Erik |
|
Read-Only Author Andy Neil Posted 19-Jun-2009 00:54 GMT Toolset C51 |  RE: i dont think it's the banking problem Andy Neil On what basis? |
|
Read-Only Author Andy Neil Posted 19-Jun-2009 00:58 GMT Toolset C51 |  RE: think it might be related to that '8k' problem Andy Neil But that is specifically related to initialised arrays, and it would produce a compiler error - neither of which applies in your case! |
|
Read-Only Author Fran H Posted 19-Jun-2009 02:04 GMT Toolset C51 |  RE: think it might be related to that '8k' problem Fran H ok, i appreciate all you guys' advice, i m using the silab f120. since i just began working on mcu, let me work on it a bit more and see what i find out. |
|
Read-Only Author Dejan Durdenic Posted 19-Jun-2009 09:15 GMT Toolset C51 |  RE: think it might be related to that '8k' problem Dejan Durdenic Are you sure you have enabled external XRAM? By default on F120 only internal 8K of XRAM is enabled. That can explain the odd behaviour of your program. To use external XRAM, you should propperly initialize EMI interface and the crossbar... regards Dejan |
|
Read-Only Author Fran H Posted 19-Jun-2009 14:53 GMT Toolset C51 |  RE: think it might be related to that '8k' problem Fran H Thank you Dejan, I might be mistaken the xram with the 128k on-chip programmable flash memory. what i need to use is actually this banked 128k. suppose that i have enabled it, how should i put the large array in it instead of the 8k ram? I guess it should not be xdata anymore or i configure something in the ide. right? |
|
Read-Only Author erik malund Posted 19-Jun-2009 14:42 GMT Toolset C51 |  BINGO erik malund i m using the silab f120 my guess was correct, had you stated your processor in your first post you would be running by now. DO NOT set the "memory model SFRs" in main(), you MUST set them in startup.a51. mov SFRPAGE,# mov EMI0CF,# mov EMI0TC,# the datasheet will tell you the values that match your app Erik |
|
Read-Only Author Fran H Posted 19-Jun-2009 16:43 GMT Toolset C51 |  RE: BINGO Fran H Thank you Erik. now correct me if i m wrong. in order to enable the 128 k flash memory as xram beyond that internal 8k+256 ram, i need to configure the SFRs of external data memory interface, and the banking(PSbank, PSCTL). and let the compiler arrange the array location in it. |
|
Read-Only Author erik malund Posted 19-Jun-2009 18:27 GMT Toolset C51 |  you do not need banking erik malund for >8k, just set it up for 64k not banked. If I have misunderstood your posts and you DO need more than 64k, then there is a SILabs appnote how to do it (it is NOT done the "keil way" but works with Keil). Banking will slow down XDATA access dramatically Erik |
|
Read-Only Author Fran H Posted 19-Jun-2009 20:44 GMT Toolset C51 |  RE: you do not need banking Fran H ok. i read the flash memory part of the datasheet. it's for code and non-volatile data storage. does it mean that i can only put the codes there? i am not sure if i can use it as xram for xdata. if set up the memory >8k, say up to 64k, in EMI0CF, so all the memory beyond 8k is from the flash memory, or i actually need some memory chip? |
|
Read-Only Author erik malund Posted 19-Jun-2009 21:07 GMT Toolset C51 |  do you play "air guitar"? erik malund YOU NEED TO READ "THE BIBLE" (not just for this) the '51 is a harvard architecture ok. i read the flash memory part of the datasheet. it's for code and non-volatile data storage. does it mean that i can only put the codes there? i am not sure if i can use it as xram for xdata. It is for code only (and possibly some constants) if set up the memory >8k, say up to 64k, in EMI0CF, so all the memory beyond 8k is from the flash memory, or i actually need some memory chip do you play "air guitar"? then, possibly you can figure out how to use "air memory" :) YES, for more than 8k data memory you need an external RAM Erik here are the links to "the bible" Chapter 1 - 80C51 Family Architecture: http://www.nxp.com/acrobat_download/various/80C51_FAM_ARCH_1.pdf Chapter 2 - 80C51 Family Programmer's Guide and Instruction Set: http://www.nxp.com/acrobat_download/various/80C51_FAM_PROG_GUIDE_1.pdf Chapter 3 - 80C51 Family Hardware Description: http://www.nxp.com/acrobat_download/various/80C51_FAM_HARDWARE_1.pdf |
|
Read-Only Author erik malund Posted 20-Jun-2009 14:23 GMT Toolset C51 |  OH, I forgot erik malund you can have anything in flash (code) memory that you do not change. Thus if you have an array of constants using the 'code' keyword will place it in flash. Erik |
|
Read-Only Author one milimerer Posted 20-Jun-2009 15:12 GMT Toolset C51 |  RE: OH, I forgot one milimerer Thanks for the answer. |
|
Read-Only Author Fran H Posted 20-Jun-2009 18:03 GMT Toolset C51 |  RE: OH, I forgot Fran H Thanks Erik, I read the doc from those links, it's a great resource. I finally figured out these things. |
|