pin_array has three pins associated with x, y, z axis.
sampling_rate is 10kHz
sampler_buffer_array has 4 buffers of each with size 6144 bytes.
Upon each call back from hardware.sampler, the buffer data gets inserted to SRAM.
The issues we are facing are:
Memory leak: Even after sampling, the memory utilized by buffers(buffer_count * buffer_size) is not freed. Tried assigning ‘sampler_buffer_array’ to ‘null’ but no luck.
Even without a overflow, waveform constructed from collected data has discrepancies(unexpected peaks) at the regular intervals of buffer size.
E.g. say each sample takes 6 bytes, discrepancies are seen at each integral multiple of 1024.
Because of these issues, we are getting out of memory exceptions once in a while due to issue_1, and quality of vibration signal is not good due to issue_2.
Here’s a fun little theory (which I don’t think is actually the issue but is interesting)…
I assume you are using a switching power supply to power the imp and that it has a low PFM power mode (most low I_q supplies do these days).
So during sampling the power consumption drops down low enough that the supply goes to PFM mode. When the imp needs to do a buffer swap the power consumption spikes and the psu tries to switch from PFM to PWM to keep up.
This creates all kind of electrical noise which your analog sensors may pick up, but it can cause the caps on your board to vibrate due to the piezoelectric effect (commonly called singing). This causes a mechanical coupling through the PCB to your accelerometer so the noise you are picking up is an actual vibration, it’s just caused by your PCB rather than what you are measuring.
My guess is that this is more likely electrical noise, but I found this idea interesting.
function start_sampler() {
//disconnecting wifi to stop interfering with analog accel voltage
server.disconnect()
introduce_delay() // wait for the supply to stabilize
allocate_sampler_buffers()
start_sampling()
}