Low Memory Warning: What's the best way to initialize an array?

gui93: I'm acquiring AC voltage data. So I need a whole period in order to calculate things like RMS value and maximum value.

So, what I've been doing is:

Record N samples -> Use a function to break down the samples into complete periods -> Analyse

You are scanning very very quickly your 100 or 1000 samples. Are you measuring something that varies that quickly? 50Hz or 60Hz is pretty slow moving compared to your scan rate for standard AC. Do you really need that many samples to be correct?

J-M-L:
You are scanning very very quickly your 100 or 1000 samples. Are you measuring something that varies that quickly? 50Hz or 60Hz is pretty slow moving compared to your scan rate for standard AC. Do you really need that many samples to be correct?

Sorry, in the code I forgot to write ‘delay(Ts)’ inside the ‘if(i<N)’ brackets. I’m using Ts=1 (millisecond), which translates to a sampling frequency of 1kHz.

Later on, I’ll have to use a frequency of 8kHz, but I have no idea how to do that on Arduino :stuck_out_tongue: How do you usually set your sampling frequency?

gui93: I'm acquiring AC voltage data. So I need a whole period in order to calculate things like RMS value and maximum value.

So, what I've been doing is:

Record N samples -> Use a function to break down the samples into complete periods -> Analyse

Both RMS value and maximum value can be calculated sequentially, without storage.

I'm acquiring AC voltage data. So I need a whole period in order to calculate things like RMS value and maximum value.

So, what I've been doing is:

Record N samples -> Use a function to break down the samples into complete periods -> Analyse

Well, there's your problem. :)

aarg: Both RMS value and maximum value can be calculated sequentially, without storage.

Like aarg says, no storage required. Example Here..

Basically, it waits for a zero crossing, then it starts integrating (summing) for two crossings (one full cycle). Then it divides the sums by the number of samples and voilà! You only need RAM for a couple of summing variables.

Many embedded problems can be solved this way.

Cheers, /dev

gui93: And the advantage of doing that is that integers take a smaller space than floats?

Yes, and integer calculations are a lot faster because they can mostly be done in hardware.