Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reading ADC data during deep-sleep from ULP-RISCV (IDFGH-9700) #11040

Closed
3 tasks done
Walid-Adel opened this issue Mar 22, 2023 · 6 comments
Closed
3 tasks done

Reading ADC data during deep-sleep from ULP-RISCV (IDFGH-9700) #11040

Walid-Adel opened this issue Mar 22, 2023 · 6 comments
Assignees
Labels
Resolution: Done Issue is done internally Status: Done Issue is done internally

Comments

@Walid-Adel
Copy link

Walid-Adel commented Mar 22, 2023

Answers checklist.

  • I have read the documentation ESP-IDF Programming Guide and the issue is not addressed there.
  • I have updated my IDF branch (master or release) to the latest version and checked that the issue is present there.
  • I have searched the issue tracker for a similar issue and not found a similar issue.

General issue report

@sudeep-mohanty
I'm using ESP32-S2
I'm trying to read ADC data from ULP-RISCV :

  • i created an infinite loop in the ULP main function as following:
int main(void)
{
	for(;;)
	{
		if(once)
		{
			raw_adc_data = ulp_riscv_adc_read_channel(ADC_UNIT_1, ADC_CHANNEL_1);
			once = 0;
		}
		if(is_sleep)
		{
		    if(cycle_count == 1000)
		    {
		    	server_time++;
		    	cycle_count = 0;
                        raw_adc_data2 = ulp_riscv_adc_read_channel(ADC_UNIT_1, ADC_CHANNEL_1);
		        if((raw_adc_data2 < 150))
		        {
		        	ulp_riscv_wakeup_main_processor();
		        	is_sleep = 0;
		        }
		    }
		   cycle_count++;
		}
		ulp_riscv_delay_cycles(ULP_RISCV_CYCLES_PER_MS);
	}

	return 0;
}

-----> in this method i was able to read adc data from ulp but in active state (not in deep sleep) and it was reading correct values. but when going to deep sleep it always read 8191.
by the way, if i want to read adc data during active state (not deep sleep) then i just set the variable once to 1 and ulp will execute its if block. And also if i want to execute the ulp during deep-sleep then i just set the variable is_sleep to 1 and ulp will execute its if block.

In short, if i want to read adc data during active state then:

  1. Inside the main CPU, i do the following: ulp_once = 1
  2. Inside the ULP, it will execute the following if block directly:
if(once)
{
	raw_adc_data = ulp_riscv_adc_read_channel(ADC_UNIT_1, ADC_CHANNEL_1);
	once = 0;
}

And if i want to read adc data during deep-sleep then:

  1. Inside the main CPU, i do the following: ulp_is_sleep = 1 and then call enter the deep-sleep mode
  2. Inside the ULP, it will execute the following if block directly:
    if(is_sleep)
    	{
    	    if(cycle_count == 1000)
    	    {
    	    	server_time++;
    	    	cycle_count = 0;
                        raw_adc_data2 = ulp_riscv_adc_read_channel(ADC_UNIT_1, ADC_CHANNEL_1);
    	        if((raw_adc_data2 < 150))
    	        {
    	        	ulp_riscv_wakeup_main_processor();
    	        	is_sleep = 0;
    	        }
    	    }
    	   cycle_count++;
    	}
    	ulp_riscv_delay_cycles(ULP_RISCV_CYCLES_PER_MS);
    }
    

===> but again it was reading fine during active state (when executing the if block of variable once). But on the other hand, it always reading 8191 during deep-sleep (when executing the if block of variable is_sleep)
so, how can i solve it so that it reads correct adc data during deep sleep ?

@espressif-bot espressif-bot added the Status: Opened Issue is new label Mar 22, 2023
@github-actions github-actions bot changed the title Reading ADC data during deep-sleep from ULP-RISCV Reading ADC data during deep-sleep from ULP-RISCV (IDFGH-9700) Mar 22, 2023
@ESP-Marius
Copy link
Collaborator

Hi,

There is an in-progress issue internally for a known problem with S2 ULP ADC in deep sleep related to some power configurations (it gives the wrong results when reading). I'll remind them that we still have users asking for support with this...

@espressif-bot espressif-bot added Status: Selected for Development Issue is selected for development and removed Status: Opened Issue is new labels Mar 29, 2023
@Walid-Adel
Copy link
Author

Walid-Adel commented Mar 31, 2023

@ESP-Marius Thanks for your response
So, is there any way in which i can read ADC data from ULP without having wrong results ?

@Walid-Adel
Copy link
Author

Walid-Adel commented Apr 7, 2023

@ESP-Marius I tried the code with ESP32S3 chip and now it's working fine and it's more stable than S2 board.
it seems like the ULP is working better with S3 board.
Do you have any suggestion for using/reading from ulp_adc using S2 board ?

@ESP-Marius
Copy link
Collaborator

ESP-Marius commented Apr 10, 2023

@Walid-Adel Yes, S3 supports using the ADC from the ULP RISCV.

Sorry, currently I dont have any suggestion for using it with the S2, but I'll keep pushing for a fix for it.

@espressif-bot espressif-bot added Status: Reviewing Issue is being reviewed Resolution: NA Issue resolution is unavailable Status: Done Issue is done internally Resolution: Done Issue is done internally and removed Status: Selected for Development Issue is selected for development Status: Reviewing Issue is being reviewed Resolution: NA Issue resolution is unavailable labels Apr 11, 2023
espressif-bot pushed a commit that referenced this issue May 5, 2023
ADC can now be used from the ULP-RISCV on S2 after the RTC power parameters were
fixed in a624d8d

Closes #11052
Closes #11040
espressif-bot pushed a commit that referenced this issue Jun 14, 2023
ADC can now be used from the ULP-RISCV on S2 after the RTC power parameters were
fixed in a624d8d

Closes #11052
Closes #11040
@mickeyl
Copy link
Contributor

mickeyl commented Jan 2, 2024

@ESP-Marius I reckon this is raw voltage. Is there any way to tap into the calibration curves when the main cores are sleeping or any other way to take the calibration into account?

@ESP-Marius
Copy link
Collaborator

Currently there is no convenient way of accessing these calibration curves (they are stored in internal RAM, which gets powered down). But I think it should be possible to do some updates to the adc calibration API to allow it be allocated to RTC RAM, as well as make the convert API callable from the ULP.

I'll make an internal ticket for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Resolution: Done Issue is done internally Status: Done Issue is done internally
Projects
None yet
Development

No branches or pull requests

4 participants