PIC16F1823 ADC Vref?

For general Flowcode discussion that does not belong in the other sections.
Post Reply
seokgi
Posts: 217
http://meble-kuchenne.info.pl
Joined: Thu Dec 03, 2020 1:43 pm
Has thanked: 6 times
Been thanked: 7 times

PIC16F1823 ADC Vref?

Post 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.
Attachments
Current_Mesurment.fcfx
(20.38 KiB) Downloaded 331 times

BenR
Matrix Staff
Posts: 1951
Joined: Mon Dec 07, 2020 10:06 am
Has thanked: 510 times
Been thanked: 697 times

Re: PIC16F1823 ADC Vref?

Post 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 )

Post Reply