Hello, I am trying to record the analog signal by using NRF52832.
The problem is, when I record the signal only with one channel, the signal looks very fine, up to a 2kHz sampling rate.
However, if I just added another channel to the code, I lost much data, even from the 100Hz sampling rate.

Is there any reason for this situation?
I will upload a code that I think is relevant to the recording and sending of a signal.
<code>
static int AIN_INX = 0;
#define AIN_1 0 // P0.03/AIN 1
#define AIN_3 2 // P0.04/AIN 2 for Input value
#define PAD_1_MASK (1UL << AIN_1)
#define PAD_2_MASK (1UL << AIN_3)
#define PAD_ID_0 0
#define PAD_ID_1 1
#define UART_TX_BUF_SIZE 512 /**< UART TX buffer size. */
#define UART_RX_BUF_SIZE 1 /**< UART RX buffer size. */
volatile uint32_t threshold_value_pad1 = 3000;
volatile uint32_t threshold_value_pad2 = 3000;
#define ADC_TIMER_TICKS_TIMEOUT APP_TIMER_TICKS(1) // decide sampling rate
#define HRS_BUFFER_LEN 150
uint16_t InputVal1_buf[HRS_BUFFER_LEN];
uint16_t InputVal2_buf[HRS_BUFFER_LEN];
static void heart_rate_meas_timeout_handler(void * p_context)
{
ret_code_t err_code;
UNUSED_PARAMETER(p_context);
if (AIN_INX == 0){
err_code = ble_hrs_heart_rate_measurement_send(&m_hrs, InputVal2_buf);
array_initialize(InputVal2_buf);
buf1 = 0;
}
else{
err_code = ble_hrs_heart_rate_measurement_send(&m_hrs, InputVal1_buf);
array_initialize(InputVal1_buf);
buf0 = 0;
}
if ((err_code != NRF_SUCCESS) &&
(err_code != NRF_ERROR_INVALID_STATE) &&
(err_code != NRF_ERROR_RESOURCES) &&
(err_code != BLE_ERROR_GATTS_SYS_ATTR_MISSING)
)
{
APP_ERROR_HANDLER(err_code);
}
else;
tmp = 0;
btmpChk = true;
}
void csense_handler(nrf_drv_csense_evt_t * p_event_struct)
{
switch (p_event_struct->analog_channel)
{
case AIN_1:
if(buf_chk == false){
input_Val = (int32_t)p_event_struct->read_value + VOLTAGE_OFFSET;
if(input_Val <= 0){
input_Val = 0;
}
else if(input_Val >= read_val_max){
input_Val = read_val_max;
}
buf_chk = true;
}
case AIN_3:
if(buf_chk == true){
input_Val = (int32_t)p_event_struct->read_value + VOLTAGE_OFFSET;
if(input_Val <= 0){
input_Val = 0;
}
else if(input_Val >= read_val_max){
input_Val = read_val_max;
}
buf_chk = true;
}
default:
break;
}
if (AIN_INX == 0){
if ((buf0 < HRS_BUFFER_LEN) && (buf0 >= 0)){
InputVal1_buf[buf0] = (int16_t)input_Val*255/read_val_max ;
if(InputVal1_buf[buf0] >= 255) InputVal1_buf[buf0] = 255;
buf0++;
}
else{
InputVal2_buf[buf1] = (int16_t)input_Val*255/read_val_max ;
if(InputVal2_buf[buf1] >= 255) InputVal2_buf[buf1] = 255;
buf1++;
buf0 = 0;
AIN_INX = 1;
}
}
else if (AIN_INX == 1){
if ((buf1 < HRS_BUFFER_LEN) && (buf1 >= 0)){
InputVal2_buf[buf1] = (int16_t)input_Val*255/read_val_max ;
if(InputVal2_buf[buf1] >= 255) InputVal2_buf[buf1] = 255;
buf1++;
}
else{
InputVal1_buf[buf0] = (int16_t)input_Val*255/read_val_max ;
if(InputVal1_buf[buf0] >= 255) InputVal1_buf[buf0] = 255;
buf0++;
buf1 = 0;
AIN_INX = 0;
}
}
else;
}
void csense_initialize(void)
{
ret_code_t err_code;
nrf_drv_csense_config_t csense_config = { 0 };
#if USE_COMP == 0
csense_config.output_pin = OUTPUT_PIN;
#endif
NRF_LOG_INFO("csense_initialize.\r\n");
err_code = nrf_drv_csense_init(&csense_config, csense_handler);
APP_ERROR_CHECK(err_code);
nrf_drv_csense_channels_enable(PAD_1_MASK | PAD_2_MASK);
}
int main(void)
{
NRF_CLOCK->TASKS_HFCLKSTART = 1;
while(NRF_CLOCK->EVENTS_HFCLKSTARTED == 0)
;
bool erase_bonds = false;
log_init();
timers_init();
ble_stack_init();
gap_params_init();
gatt_init();
advertising_init();
conn_params_init();
peer_manager_init();
application_timers_start();
services_init();
sensor_simulator_init();
NRF_LOG_INFO("Heart Rate Sensor example started.\r\n");
advertising_start(erase_bonds);
csense_initialize();
SEGGER_RTT_WriteString(0,"Hello World from SEGGER!\r\n");
pwm_init();
// Enter main loop.
while (1)
{
{
pwm_update_duty_cycle(50);
}
if (NRF_LOG_PROCESS() == false)
{
power_manage();
NRF_LOG_FLUSH();
__WFI();
}
}
}
even worse is
#define ADC_TIMER_TICKS_TIMEOUT APP_TIMER_TICKS(10)
This is the line where I determine the sampling rate.
(ex,
APP_TIMER_TICKS(10) = 100Hz sampling rate
APP_TIMER_TICKS(100) = 10Hz sampling rate
)
But the problem is it seems it doesn't work the same for both channels.

I thought I record both signal at 100Hz sampling rate (#define ADC_TIMER_TICKS_TIMEOUT APP_TIMER_TICKS(10))
However, one channel has been recorded at a 200 Hz sampling rate, while another has been recorded at a 100 Hz sampling rate.
It would be sincerely appreciated if someone could help me with this.
Please let me know if you need any further code of mine to fix this situation,
Thank you very much