Skip to content

Commit 621f3a5

Browse files
committed
implement DC offset check inspired by Pull Request 107 by 3hhh
1 parent e23ea05 commit 621f3a5

File tree

2 files changed

+20
-18
lines changed

2 files changed

+20
-18
lines changed

edrumulus.cpp

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ Edrumulus::Edrumulus()
2525
error_LED_blink_time = round ( error_LED_blink_time_s * Fs );
2626
dc_offset_est_len = round ( dc_offset_est_len_s * Fs );
2727
samplerate_max_cnt = round ( samplerate_max_cnt_len_s * Fs );
28+
dc_offset_min_limit = round(ADC_MAX_RANGE / 2 - ADC_MAX_RANGE * dc_offset_max_rel_error);
29+
dc_offset_max_limit = round(ADC_MAX_RANGE / 2 + ADC_MAX_RANGE * dc_offset_max_rel_error);
2830
overload_LED_cnt = 0;
2931
error_LED_cnt = 0;
3032
status_is_overload = false;
@@ -337,7 +339,7 @@ Serial.println ( serial_print );
337339
}
338340

339341

340-
// Sampling rate check -------------------------------------------------------
342+
// Sampling rate and DC offset check -----------------------------------------
341343
// (i.e. if CPU is overloaded, the sample rate will drop which is bad)
342344
if ( samplerate_prev_micros_cnt >= samplerate_max_cnt )
343345
{
@@ -357,26 +359,23 @@ Serial.println ( serial_print );
357359
samplerate_prev_micros_cnt = 0;
358360
samplerate_prev_micros = samplerate_cur_micros;
359361

360-
/*
361-
// TEST check DC offset values
362-
String serial_print;
363-
String serial_print2;
364-
for ( int i = 0; i < number_pads; i++ )
365-
{
366-
if ( !pad[i].get_is_control() )
367-
{
368-
for ( int j = 0; j < number_inputs[i]; j++ )
362+
// DC offset check
363+
for ( int i = 0; i < number_pads; i++ )
369364
{
370-
serial_print += String ( sample_org[i][j] ) + "\t" + String ( dc_offset[i][j] ) + "\t";
371-
serial_print2 += String ( sample_org[i][j] - dc_offset[i][j] ) + "\t";
365+
if ( !pad[i].get_is_control() )
366+
{
367+
for ( int j = 0; j < number_inputs[i]; j++ )
368+
{
369+
const float& cur_dc_offset = dc_offset[i][j];
370+
//Serial.println ( cur_dc_offset ); // TEST for plotting all DC offsets
371+
if ( ( cur_dc_offset < dc_offset_min_limit ) || ( cur_dc_offset > dc_offset_max_limit ) )
372+
{
373+
status_is_error = true;
374+
}
375+
}
376+
}
372377
}
373378
}
374-
}
375-
//Serial.println ( serial_print );
376-
Serial.println ( serial_print2 );
377-
*/
378-
379-
}
380379
samplerate_prev_micros_cnt++;
381380
error_LED_cnt++;
382381
}

edrumulus.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,7 @@ const float ADC_noise_peak_velocity_scaling = 1.0f / 6.0f;
533533
const float dc_offset_est_len_s = 1.25f; // length of initial DC offset estimation in seconds
534534
const int samplerate_max_cnt_len_s = 1.25f; // time interval for sampling rate estimation in seconds
535535
const int samplerate_max_error_Hz = 200; // tolerate a sample rate deviation of 200 Hz
536+
const float dc_offset_max_rel_error = 0.25f; // DC offset limit from ADC middle position, where offset is defined relative to ADC maximum value
536537
const int cancel_time_ms = 30; // on same stand approx. 10 ms + some margin (20 ms)
537538
const float overload_LED_on_time_s = 0.25f; // minimum overload LED on time (e.g., 250 ms)
538539
const float error_LED_blink_time_s = 0.25f; // LED blink time on error (e.g., 250 ms)
@@ -576,6 +577,8 @@ const float ADC_noise_peak_velocity_scaling = 1.0f / 6.0f;
576577
int samplerate_max_cnt;
577578
int samplerate_prev_micros_cnt;
578579
unsigned long samplerate_prev_micros;
580+
int dc_offset_min_limit;
581+
int dc_offset_max_limit;
579582
Pad pad[MAX_NUM_PADS];
580583
bool peak_found[MAX_NUM_PADS];
581584
bool control_found[MAX_NUM_PADS];

0 commit comments

Comments
 (0)