PIC12F1571 ADC Value

Thread Starter

Khisraw

Joined Nov 14, 2020
56
Hi,
I am trying to read values from my ADC conversion but I get something unusual. The say Value Out of Scope. Has anyone faced the same challenge?

I used MPlab CCG and here are some of the the functions for getting the ADC value.

adc_result_t ADC1_GetConversionResult(void)
{
// Conversion finished, return the result
return ((adc_result_t)((ADRESH << 8) + ADRESL));
}

ADC1_SelectChannel(0);
ADC1_StartConversion();
ADC1_IsConversionDone();
while(ADCON0bits.GO_nDONE);
result = ADC1_GetConversionResult;

The value at the result shows as Out of Scope.

Any thoughts?
 

Ian Rogers

Joined Dec 12, 2012
1,136
LOL.. wrapper functions for bit set an bit test.. What has it come to...

Personally I steer clear of CCG, It helps to generate code but the fallout is wide...

these two
ADC1_IsConversionDone();
while(ADCON0bits.GO_nDONE);
do the same thing...

Out of scope on simulation?? Is it MPLABX that's whinging.... If the ADCFM is set one way and you are reading the other.. Possibly.. I mean setting right justify and reading left..
 

Thread Starter

Khisraw

Joined Nov 14, 2020
56
I don't get any error but I wanted to see the value of the register, but I see this using the Watch option. I actually run the code on Curiosity Board, but when I run it the simulator, I see the same values.
 

Ian Rogers

Joined Dec 12, 2012
1,136
Show your code.

That is just telling you the variable "result" isn't withing the scope of that function... When debugging other functions, you can't see the main variables... If it were global, you would see it...
 

Thread Starter

Khisraw

Joined Nov 14, 2020
56
Many thanks guys.
I found the problem. It was because I was declaring the variable "result" as a local and not a global variable.
 
Top