is there any limitation to declare arrays in mbed ?

06 Feb 2013

i am using the more than 15 float non arrays variable and 35 float arrays variables and each arrays having the minimum 200 elements. as we know in the m bed have 32kb RAM memory in this case it would be allowed me to declare that large no of arrays and variables ????

thank you

06 Feb 2013

Hey, It's easy to calculate as float variables on the mbed use 4 bytes,

so non array memory used is 15 * 4 = 60 bytes minimum array usage is 35 * 200 * 4 = 28,000 bytes so a total of 28,060 bytes used on floats,

so less then 32KB, but everything you do uses ram, I'm not sure how much the mbed libraries use, but you're very close to the limits, especially as you say that's the minimum array size.

06 Feb 2013

Minimum 200 elements, so if he gets more than he quickly wont have any RAM left. (His 4k he has left in best case might already be filled by his program when it runs).

Question is mainly, why do you need 30kB of float arrays? It probably wont need to be very fast, since it will take the mbed already enough time to do all the calculations to use those arrays. If there are read only arrays (for example if they are coefficients of a FIR filter), you can declare them as 'const', then they get placed in the flash memory which is more than large enough.

06 Feb 2013
===Heading1

thank you Erik And chris .

===Heading2

actually I sensed two current. and each current cycle of 0.02 sec, adc take 200 sample and then i processed on them at endingof processed it will give me pwm pulses for the induction motor. i feed that pulse to the inverter and drive the induction motor. my project name is that "Sensorless vector control of induction motor"

06 Feb 2013

However why do you need 35 arrays if you only sense two currents, and then process them?

Anyway I assume all those arrays are filled with ADC data? What I would do first is not saving them as floats, I assume you use the mbeds internal ADCs, but the same is true if you use a dedicated ADC. The mbeds ADC only returns 12 bit, using 32 bits (4 byte) to save it is a bit a waste of memory. Easiest solution is to make an (unsigned) short array, then you use only 2 bytes per ADC value, and suddenly you have half your RAM left. When you start processing them you can convert them to floats if you need that, but you shouldnt require all data as floats at the same time when processing.

You can get the raw 12-bit value using read_u16() function.

06 Feb 2013

Hi, you can see how much memory use your program in the compiler in the build section. See the image bellow for reference:

/media/uploads/spidermanpc/memoryused.jpg

Greetings

07 Feb 2013

thank you Erik and Ney

07 Feb 2013

Tejas Panchal wrote:

as we know in the m bed have 32kb RAM memory in this case it would be allowed me to declare that large no of arrays and variables

The LPC1768 used in the mbed actually has a total of 64kB of SRAM. The address range of the other 2 x 16kB blocks (AHB SRAM) is:

0x2007 C000 - 0x2007 FFFF 
0x2008 0000 - 0x2008 3FFF

This is typically used for Ethernet, USB, and DMA memory. However, if your application isn't using the extra RAM for these features then it can use it for general purpose instruction and data storage. To confirm this I have just used our Astrobe Oberon compiler to write a test program that uses two arrays with 7500 4-byte floats in each and there is still 4kB of RAM unused.

07 Feb 2013

If you want more memory (well be able to use the other 32kb) then look at this post which shows how to do just that.