Jump to content
43oh

Big array in memory


Recommended Posts

     I'm using a Tiva C series TM4C123G and I need to write 2 arrays of about 30000 places each, and this can't be done on the RAM memory so I was wondering if I could use the Flash memory instead. Is there a better way to solve this problem? And does anybody have a piece of code showing how to assign a array to the flash memory?

     On the same matter, I will need to ADC sample between 10khz and 15Khz, is there enough time to write to the flash memory? My clock is set to 80Mhz.

 

 

Link to post
Share on other sites

I never realy tried but in the TivaWare there's sometigh to handle flash. It's number 13 in the Peripheral library guide.

Careful to not erase your code.The flash is divided into blocks of 1Kb so it is possible to use it for data storage without compromising the code.

 

Here it is the guide for the peripheral library 

SW-TM4C-DRL-UG-2.1.0.12573.pdf

Link to post
Share on other sites

Hi,

2x30000 places of what? if shorts means ~120k, if longs, ~240k, so a small place left for program itself. And this is only if the array is declared as constant, no modifiable; flash cannot replace RAM in usual operations. A better alternative is TM4C129x, which has 256K RAM, could be placed there.

Or use the EPI peripheral with some external dynamic RAM (up to 512M).

L

Link to post
Share on other sites

Hi,

A better alternative is TM4C129x, which has 256K RAM, could be placed there.

Or use the EPI peripheral with some external dynamic RAM (up to 512M).

L

 

Tiva Connected Launchpad (TM4C129x) seems like might be simplest if you want to stick with Tiva.

 

Other options could consider - if memory serves there are STM32 micros with like 1 MB of RAM.

 

You could use an external static RAM connected to the Tiva C (might take a fair number of pins).

 

 

 

I'm trying to store shorts, actually the values I read on the ADC i'm trying to store in array so when I finish my readings I can write back to RAM memory and work with those arrays separately. Can I replace the RAM with flash memory in this case? 

 

Once you have them stored in flash - why not just use them from there?  The access is a little slower, but you couldn't fit one whole array in memory anyway.

 

You might also want to look at the TM4C datasheet for the processor - chapter 8 on memory.

(For instance they note that program execution from flash is held off while a flash write is in progress - so any part of your program that you want to run during flash writes would need to be put in RAM.)

 

The TM4C datasheets are a bit lacking when it comes to timing information for memory.  So while I would expect that you have time sufficient to write your values to flash, you might want to just do a quick test program and see how long flash writes take.  (Then post results back here to help the next person.)

 

Assume you have already considered the possibilities of data compression?

Link to post
Share on other sites

Yes, I could use the array from the flash memory, my problem is not accessing it but writing it on flash. What I'm trying to do is create an interrupt and inside the interrupt I sample at 10~15Khz store in the memory, and when I leave the interrupt I have as much time as needed to process these data. I believe I could move my program to the RAM memory to do the writing on the flash memory. I want to try it but I just have no idea how to write an array in flash, I've seen examples of variables being written but not arrays. I'm starting with microcontrollers, I've never done anything with texas boards.

Link to post
Share on other sites

What I'm trying to do is create an interrupt and inside the interrupt I sample at 10~15Khz store in the memory, and when I leave the interrupt I have as much time as needed to process these data.

Not quite sure what you intend here - you could certainly have an interrupt firing at 10 to 15 Khz to sample the ADC. (Interrupt routines are typically short as possible - wouldn't want to gather all 30000 elements.) The interrupt could just save samples in a RAM buffer. Once it had assembled enough samples they could be written to flash. (Since can only write flash in 32 bit words.)

 

I believe I could move my program to the RAM memory to do the writing on the flash memory. I want to try it but I just have no idea how to write an array in flash, I've seen examples of variables being written but not arrays. I'm starting with microcontrollers, I've never done anything with texas boards.

If you look at the Flash API, it lets you write one 32 bit word at a time. So package up 4 shorts into a 32 bit word, write it, then do the next one, etc.

Link to post
Share on other sites

Hi,

I am not advising for writing into flash although this seems possible. The main problem here is the lifetime of flash - in such application the number of lifetime writing cycles will be exceeded very soon, maybe less than several month. One may arguing the fact "it will work so after", but some secondary effects may come into play: with increasing number of writings, also increases the writing time of a single word, so calculations based of such time will fail soon. Not to speak about erasing the sectors which is more longer than a "normal" writing (and also increases with time)- to avoid that a ping-pong scheme wold be needed to implement.

 

But un-revealed here is why such big number of samples to be taken at once? usual filtering takes tens to make sharp, near-ideal filters. Speech? there are already some routines in Tiva. Other?

 

L

Link to post
Share on other sites

Thanks for the ideas, my goal is to sample the voltage and current of a system every 30s but when I sample I need a high amout of samples thus 30k samples during 3 seconds I would have a sampling frequency of 10Khz. I will keep in mind this problem with flash memory I may have to rethink my strategy. If you guys have any ideas please let me know.

Link to post
Share on other sites

You need the values to make averages? The ADC of the TM4c123 can do by hardware 64 samples average.

So istead of 30k samples you can do only about 468 values. Since the ADC is 12 bits you can use 16bits variable to save the values. so it's 2 bytes per value. 2*468=936bytes. How about that? :P

Then just average those 468 values. 

Link to post
Share on other sites

Hi,

@karatesever: can you specify if the voltage/current are from power line or some other places into your project? I think at this stage (not knowing enough your goals, may be wrong) you are overrating your goals - generally to measure effective voltage/current you need a restricted number of  samples per period - and you compute then the effective value (true RMS). And you may acquire a new set in the mean time. 

 

@LRA, hardware sampling in Tiva is only for DC; for AC is meaningless - for DC only lower the noise (by square root of number of samples). For AC: if the signal is sinusoidal the average value is 0 (well, centred on a DC value in unipolar ADC present on most microcontrollers...).

 

L

Link to post
Share on other sites

The voltage and current are from power line, so it is AC and I can't average the values. I'm interested in power consumption as well as power quality, that's why I'm looking for a high resolution sampling so I can get a good amount of harmonics. I'm considering buying the TM4C129 which has more RAM memory because I don't know if I can work this problem out.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...