In my project I need to read a voltage value from a potentiometer and so I need to use an ADC. I'm using Arduino Due and I'm programming in Atmel Studio 6.2.
I'm new in using the ADC, so I was looking at the ADC example inside Atmel Studio to understand how does it work. Before looking at the example I also read the datasheet to try to figure out how the ADC works. I need to use a software trigger for the ADC, because I need to read the ADC value only when necessary in the program, in the example there is also this case, but I still have some doubts.
What I don't understand is, when does the ADC handler is called with a software trigger? Is it called as soon as the "ADC_start" function is used?
In attachment there is the code of the program, but the parts that are of my interest I think that are the following:
If I understood in the right way when ADC_start is called in the main, the ADC starts the conversion and the ADC handler is called, here if the conversion is ready, checking drdy, the latest value is stored in ul_temp and the for cycle starts. The first time only the value in the channel 1 of the ADC is stored in g_adc_sample_data.us_value, due to the if statement in the for cycle. In the end g_adc_sample_data.us_done has a value of 1. The program goes back to the main, if the user does not enter any keys, the program goes to the for cycle in the end of the main, that cannot be entered because g_adc_sample_data.us_done ==1 not 2 (ADC_DONE_MASK == 2, I think). So what i think is that when the main goes back to the ADC_start the handler is called again and the value of the ADC channel 15 is stored in the second element of the array g_adc_sample_data.us_value and g_adc_sample_data.us_done = 2. So then in the main it is possible to access the for, g_adc_sample_data.us_done == 2 and print the data on the screen. Is it correct? Because I thought that when the trigger is called (ADC_start) the conversion starts from the beginning not from the second value, so this step it's not clear to me.
Sorry for the long question and if I wrote something wrong, if somebody can help me it could be great.
Thank you in advance.