Adc Sampling running out of memory?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Adc Sampling running out of memory?

763 Views
curiosul
Contributor III

Hello!

I am trying to make a basic filter for ADC measurements. The idea is provide the average of previous 1000 samples as an output. To store the samples I have used a circular buffer with 1000 elements. When a new element is added the last element is removed; this way I always have stored last 1000 ADC samples so I can easily get the average.

The problems is that I will have to store samples for multiple ADC channnels. For 10 ADc channels would be 10 * 1000 samples/channel = 10k samples stored in memory at any moment of time.

I have made my program and it works only when I initialize buffers with only 10 samples (or less) per channel. When I use a bigger number of samples the program is just failing to start. I suspect that I am running out of memory.

Initial memory configuration was:

HEAP_SIZE  = DEFINED(__heap_size__)  ? __heap_size__  : 0x00000100;
STACK_SIZE = DEFINED(__stack_size__) ? __stack_size__ : 0x00000100;

/* Specify the memory areas */
MEMORY
{
  m_interrupts          (RX)  : ORIGIN = 0x00000000, LENGTH = 0x00000100
  m_flash_config        (RX)  : ORIGIN = 0x00000400, LENGTH = 0x00000010
  m_text                (RX)  : ORIGIN = 0x00000410, LENGTH = 0x0000FBF0
  m_data                (RW)  : ORIGIN = 0x1FFFFC00, LENGTH = 0x00010000

}

And I have tried to change into something like this:

HEAP_SIZE  = DEFINED(__heap_size__)  ? __heap_size__  : 0x0000FFFF;
STACK_SIZE = DEFINED(__stack_size__) ? __stack_size__ : 0x00000200;

/* Specify the memory areas */
MEMORY
{
  m_interrupts          (RX)  : ORIGIN = 0x00000000, LENGTH = 0x00000100
  m_flash_config        (RX)  : ORIGIN = 0x00000400, LENGTH = 0x00000010
  m_text                (RX)  : ORIGIN = 0x00000410, LENGTH = 0x0000FBF0
  m_data                (RW)  : ORIGIN = 0x1FFFFC00, LENGTH = 0x0001FFFF

But with this configuration it won't work even with 10 samples/channel.

And the thing is that the project is also using functions like printf() which requires a pretty high amount of memory.

The question is: How do I increase memory to it's maximum limits?

Microcontroller used: Kinetis SKEAZN642

I have also attached the project in case it helps.

0 Kudos
1 Reply

633 Views
mjbcswitzerland
Specialist V

Hi Alex

The KEA64 has maximum 4k SRAM so I think that you will need to use something like an IIR low pass filter (requiring only a couple of bytes of storage per channel) to do the averaging rather than long buffers in RAM (which would avoid you needing to solve the RAM setup too).

Regards

Mark

0 Kudos