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.
PIC16F1823 ADC Vref?
-
- Posts: 217
- http://meble-kuchenne.info.pl
- Joined: Thu Dec 03, 2020 1:43 pm
- Has thanked: 6 times
- Been thanked: 7 times
-
- Matrix Staff
- Posts: 1951
- Joined: Mon Dec 07, 2020 10:06 am
- Has thanked: 510 times
- Been thanked: 697 times
Re: PIC16F1823 ADC Vref?
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.
Repeat x number of times. Read ADC, Square and add to accumulator.
Then divide by number of samples and collect the square root as a floating point number.
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
Code: Select all
SampleVar = ADC_GetAverage()
LongVar = SampleVar * SampleVar
LongCountVar = LongCountVar + LongVar
Code: Select all
LongVar = LongCountVar / x
FloatVar = sqrt(FLOAT LongVar )
Regards Ben Rowland - MatrixTSL
Flowcode Online Code Viewer (Beta) - Flowcode Product Page - Flowcode Help Wiki - My YouTube Channel
Flowcode Online Code Viewer (Beta) - Flowcode Product Page - Flowcode Help Wiki - My YouTube Channel