Issues with hardware.sampler

Hi,

We are facing two issues while trying to collect samples from Triaxial analog accelerometer using hardware.sampler.

The below is the sampler configuration.

hardware.sampler.configure(pin_array, sampling_rate, sampler_buffer_array, collect_samples.bindenv(this))

  • 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:

  1. 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.

  2. 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.

We would appreciate your thoughts.

Thanks

Might have to see a bit more of your code to be able to tell. Are you calling sampler.reset()?

(Really we should have called stop() “pause” and called reset() “stop”.)

Peter

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.

@peter The following is the sampling code.

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()
}

function start_sampling() {
sampler_try_counter += 1
sampler_byte_counter = 0
sampler_overflow_flag = false
configure_sampler()
hardware.sampler.start()
}

function introduce_delay()
{
for(local a=0;a<500000;a+=1){}
}

function stop_sampling()
{
hardware.sampler.stop()
hardware.sampler.reset()

if (sampler_overflow_flag)
{
  if (sampler_try_counter < SAMPLER_TRY_LIMIT)
  {
    start_sampling()
  }
  else {
    logger.ei_server_log (verbosity.MEDIUM, "ERROR: Hardware Sampler Overflow for all 3 tries")
  }
}
power_off_accelerometer()
deallocate_sampler_buffers()

if ( server.isconnected() ) {
    resumeOnWifiConnect(1)
}

}

function resumeOnWifiConnect(reason)
{
if (sampler_overflow_flag == false)
{
multipart_upload_samples()
}
else {
resume_processing()
}
}

function collect_samples (buffer, length) {

if (length > 0)
{
  if (sampler_byte_counter < total_byte_count)
  {
    sram_write(sampler_byte_counter, buffer)
    sampler_byte_counter += length
    buffer = null
    
    if (sampler_byte_counter >= total_byte_count)
    {
      stop_sampling()
    }
  }
}
else if (length == 0 && (sampler_byte_counter < total_byte_count)) {
  sampler_overflow_flag = true
  stop_sampling()
}

}

function allocate_sampler_buffers()
{
local min_total_buffer_bytes = MIN_SAMPLES_PER_BUFFER * SAMPLER_BUFFER_COUNT * bytes_per_sample
local buffer_length = MIN_SAMPLES_PER_BUFFER * bytes_per_sample

for (local a=0; a<SAMPLER_BUFFER_COUNT; a+=1)
  sampler_buffer_array[a] = blob(buffer_length)

}

function deallocate_sampler_buffers(){
for (local a=0; a<SAMPLER_BUFFER_COUNT; a+=1)
sampler_buffer_array[a] = null
}

Hi Brandon very interesting idea about the PFM mode and capacitors starting to vibrate…

Indeed I noticed if power supply goes in to PFM there was more noise on power supply. I was able to solve the noise.