NRF54L15 adc channel does not get proper value with matter stack code

Hello Nordic team,

For the (POC), I configured ADC channel 1 and interfaced a potentiometer to pin P1.14. The ADC was set up to read the potentiometer's raw value.

/ {
	zephyr,user {
		io-channels = <&adc 1>;
	};
};


&adc {
	#address-cells = <1>;
	#size-cells = <0>;

	channel@1 {
		reg = <1>;
		zephyr,gain = "ADC_GAIN_1";
		zephyr,reference = "ADC_REF_INTERNAL";
		zephyr,acquisition-time = <ADC_ACQ_TIME_DEFAULT>;
		zephyr,input-positive = <NRF_SAADC_AIN7>; // P1.14
		zephyr,resolution = <12>;
		zephyr,oversampling = <2>; // Enable oversampling with a factor of 2
	};

};


As part of "Exercise 1 – Interfacing with ADC using Zephyr API", we configured and initialized the ADC, and invoked it within the main() function.
We also added a function call to read the ADC value, as demonstrated in the following code snippet:


//adc.cpp

int32_t readValue(void)
{
    int err;
    err = adc_read_dt(&smoke_adc, &smoke_seq);
    if (err < 0) {
        LOG_ERR("Smoke ADC read failed (%d)", err);
        return err;
    }

    LOG_INF("Smoke rawvalue : %d\n",smoke_buf);
}


To analyze the ADC readings, we considered two scenarios:

1) As shown in the code below, we called the readValue() function within the while(1) loop in main.cpp.

//main.cpp

int_main()
{
	if(smoke_init())
	{
		LOG_ERR("Smoke init failed");	
	}

	while(1)
	{
	    readValue();
		k_msleep(1000);
	}
	
	commenting StartApp function 
	
	CHIP_ERROR err = AppTask::Instance().StartApp();

	LOG_ERR("Exited with code %" CHIP_ERROR_FORMAT, err.Format());
	return err == CHIP_NO_ERROR ? EXIT_SUCCESS : EXIT_FAILURE;
}


2) The readValue() function is called every second using a timer, which is initialized through the SensorTimerHandler in the AppTask::Init() function.
This function also initializes the Matter stack.
 
CHIP_ERROR AppTask::Init()
{
	/* Initialize Matter stack */
	ReturnErrorOnFailure(Nrf::Matter::PrepareServer());

	if (!Nrf::GetBoard().Init(ButtonEventHandler)) {
		LOG_ERR("User interface initialization failed.");
		return CHIP_ERROR_INCORRECT_STATE;
	}

	k_timer_init(&mSelfTestLedTimer, &SelfTestLedTimerTimeoutCallback, nullptr);
	k_timer_init(&mSelfTestTimer, &SelfTestTimerTimeoutCallback, nullptr);

	/* Register Matter event handler that controls the connectivity status LED based on the captured Matter network
	 * state. */
	ReturnErrorOnFailure(Nrf::Matter::RegisterEventHandler(Nrf::Board::DefaultMatterEventHandler, 0));

	/* Register Smoke CO Alarm test event triggers */
#ifdef CONFIG_NCS_SAMPLE_MATTER_TEST_EVENT_TRIGGERS
	/* Register Smoke CO alarm test events handler */
	static chip::SmokeCOTestEventTriggerHandler sSmokeCoAlarmTestEventTrigger;
	ReturnErrorOnFailure(Nrf::Matter::TestEventTrigger::Instance().RegisterTestEventTriggerHandler(
		&sSmokeCoAlarmTestEventTrigger));

	/* Register test event handler to change the power source. */
	ReturnErrorOnFailure(Nrf::Matter::TestEventTrigger::Instance().RegisterTestEventTrigger(
		kPowerSourceOnEventTriggerId,
		Nrf::Matter::TestEventTrigger::EventTrigger{ 0xFFFF, PowerSourceOnEventCallback }));
	ReturnErrorOnFailure(Nrf::Matter::TestEventTrigger::Instance().RegisterTestEventTrigger(
		kPowerSourceOffEventTriggerId,
		Nrf::Matter::TestEventTrigger::EventTrigger{ 0xFFFF, PowerSourceOffEventCallback }));
#endif
    // Read ADC value using Timer
	k_timer_init(&sSensorTimer, &SensorTimerHandler, nullptr);
	k_timer_user_data_set(&sSensorTimer, this);
	SensorActivateHandler(); 
	return Nrf::Matter::StartServer();
}

CHIP_ERROR AppTask::StartApp()
{
	ReturnErrorOnFailure(Init());

	while (true) {
		Nrf::DispatchNextTask();
	}

	return CHIP_NO_ERROR;
}


Based on the two code snippets above, we examined the ADC raw data values under the following scenarios:

A) Without initializing the Matter stack, the value is read within the while(1) loop in main.cpp.
B) Initializing the Matter stack, the value is read using a timer.

  • Scenario A-1 readings:


  • Scenario B-1 readings:


  • Scenario A-2 readings:


  • Scenario B-2 readings:


    In the above, we observe readings from two scenarios, where A/B refer to the test conditions (as described earlier), and 1/2 refer to the corresponding reading numbers.

    Scenario A-1: With the potentiometer set to a specific value, the ADC reading was approximately 1111.
    Scenario B-1: Using the same potentiometer setting, the ADC reading was 4092.

    Scenario A-2: At a different potentiometer setting, the ADC reading was approximately 241.
    Scenario B-2: With the same setting, the ADC reading was around 2600.

    We can see a significant difference in the readings between the two scenarios.
    We would like to understand why the readings appear incorrect when the Matter stack is initialized.

    Looking forward to your insights.

    Thanks & Regards,

    Pratik Panchal
Parents Reply Children
No Data
Related