Page 1 of 1

PIC16F1823 ADC Vref?

Posted: Tue Feb 16, 2021 6:23 am
by seokgi
Hi.
I am programming using PIC16F1823. I want to get a value using ADC.

If Vref is set to VDD 5V, the value is read. However, even if you set Vref to FVR and change it by 10mV, the value comes in as 1023. How to set the reference voltage?

And how do I read the current as RMS value?

Thank you.

Re: PIC16F1823 ADC Vref?

Posted: Tue Feb 16, 2021 11:49 am
by BenR
Hello,

Instead of calling the RawAverage function try instead the GetAverage function. This will do additional things like configuring the ADC channel. Also num samples of 1000 is a bit excessive, maybe try say 10 instead :)

RMS requires you to square each ADC reading, add them together into an accumulator, divide by the number of samples and then do a square root on the result.

Code: Select all

LongCountVar  = 0
Repeat x number of times. Read ADC, Square and add to accumulator.

Code: Select all

SampleVar  = ADC_GetAverage()
LongVar = SampleVar * SampleVar
LongCountVar = LongCountVar + LongVar 
Then divide by number of samples and collect the square root as a floating point number.

Code: Select all

LongVar = LongCountVar / x
FloatVar = sqrt(FLOAT LongVar )