Reading the fixed voltage reference
Posted: Mon Oct 30, 2017 9:38 pm
Hi everyone,
I have been trying to read the fixed voltage reference value on a PIC18F46K22 microcontroller. I have set the positive reference to Vdd and the negative reference to Vss.
The FVR channel is 11111 on the 18f46k22 however it would seem that I can't simply plug this number into the ADC.Read function. I therefore looked into making my own code however this doesn't seem to work since the values I read actually decrease with an increasing Vdd voltage.
Here is the function which I came up with:
My setup contains this code:
Are there any glaring issues that anyone might be able to point out to me? Any help would be much appreciated.
I have been trying to read the fixed voltage reference value on a PIC18F46K22 microcontroller. I have set the positive reference to Vdd and the negative reference to Vss.
The FVR channel is 11111 on the 18f46k22 however it would seem that I can't simply plug this number into the ADC.Read function. I therefore looked into making my own code however this doesn't seem to work since the values I read actually decrease with an increasing Vdd voltage.
Here is the function which I came up with:
Code: Select all
function GetFVR() as word
ADCON0 = %01111100 ' select the fixed voltage reference (which is channel b11111 in bits 2 - 6)
ADCON0.bits(0) = 1 ' enable adc
ADCON0.bits(1) = 1 ' start the ADC conversion sequence
While adcon0.bits(1) = 1 ' stay in this loop until conversion is complete
Wend
ADCON0.bits(0) = 0 ' disable adc
result = adresh << 8 or adresl ' store result
End Sub
Code: Select all
ADCON1 = %00000000 ' sets the positive and negative references to VDD and VSS
ADCON2 = %10100001 ' data is right justified, 8 TAD, fosc / 8