Please consider the following codes:
//Code Sample 1
void func_val(void)
{
unsigned int val;
ADCSC1 = 0x00; // sets the required channel.
while(!ADCSC1_COCO); //check for conversion complete flag.
val= ADCRL;
}
//Code sample 2
void EvalProx()
{
unsigned int proxval;
ADCSC1 = 0x02; // sets the required channel.
while(!ADCSC1_COCO); //check for conversion complete flag.
proxval = ADCRL;
}
Now both the samples are snippets from a bigger code, which compiles and works.
My question is about the concept of Analog to Digital Converters in MCU.
ADCRL
and ADCRH
are the registers in which the converted values are stored.
ADCSC
is the status control register in which I have specified two different channels to be used.
Question: The ADCRL
/ADCRH
are same for the two different setting of the ADCSC
i.e. same for both the channels. So does the value of proxval
influence the value of val
when accessed? i.e. If func_val()
is executed and then
EvalProx()
, is the value of proxval
influenced by the val? (when both the values depend on ADCRH
and ADCRL
)
I hope I am clear. Before down voting this question, I request, please take some time to tell me why you have down voted, so I can improve my question.
Datasheet of the used MCU: MC9S08DZ60
Specific Page Numbers: Chapter 10 :- Page 181,182- for ADCRH
and ADCRL
.
Best Answer
I doubt that would be the case, Usually in a case like this the compiler would read the value of ADCRL and store it a location in memory that is associated with the variable val or proxval. You can verify this by looking at the generated assembly code by the compiler. But if your worried that's I would declare val and proxval as volatile variable. If val and proxval where pointers to ADCRL then yes calling one function would affect the other but as regular variable the value from ADCRL gets actually stored to variable