Hi,
I'm using a PIC18F87k22 microcontroller and I'm stuck with the Read_as_string ADC component.
I should have measurements between 0 to 5V, instead I have 0 to 20V, which is 4 times grater than expected.
It seems that the conversion factor is using a 10-bit ADC resolution (max adc code = 1023) which is 4 times lower than the embedded 12-bit resolution ADC (max adc code = 4095).
If I try the Read_as_Int ADC component I get correct values from 0 to 4095.
Is there a way to specify the ADC resolution, or is it automatically set with the microcontroller reference?
Thank you,
12-bit adc resolution PIC18F87k22
Moderator: Benj
-
- Matrix Staff
- Posts: 9521
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
Re: 12-bit adc resolution PIC18F87k22
Hi etillol
Have you tried adjusting Vref Voltage within ADC components Ext Properties?
Just right click on the pot that's on the control panel and select Ext Properties.
Just a suggestion so may or may not work?
Martin
Have you tried adjusting Vref Voltage within ADC components Ext Properties?
Just right click on the pot that's on the control panel and select Ext Properties.
Just a suggestion so may or may not work?
Martin
Martin
-
- Posts: 8
- Joined: Tue Feb 12, 2013 3:31 pm
- Location: Carpentras, France
- Has thanked: 2 times
- Been thanked: 3 times
Re: 12-bit adc resolution PIC18F87k22
I double check that, just in case: I confirm Vref is set to 500 x 10mV.
But I took a look at the code of the ReadAsVoltage() function:
The conversion factor is 0.000976 which is 1V/1024, and if the adc is 12-bit resolution, we should probably have 1V/4096 = 0.000244.
Am I wrong?
But I took a look at the code of the ReadAsVoltage() function:
Code: Select all
float FCD_ADC0_ReadAsVoltage()
{
int iSample;
float fSample, fVoltage, fVperDiv;
#define MX_ADC_VREF_V 500
iSample = FCD_ADC0_ReadAsInt(); //Read as 10-bit Integer
fVoltage = float32_from_int32(MX_ADC_VREF_V); //Convert reference voltage count to floating point (0 - 500 x 10mV)
fVoltage = float32_mul(fVoltage, 0.01); //Convert reference voltage count to actual voltage (0 - 5)
fVperDiv = float32_mul(fVoltage, 0.000976); //Convert actual voltage to voltage per division (VRef / 1024)
fSample = float32_from_int32(iSample); //Convert to floating point variable
fVoltage = float32_mul(fSample, fVperDiv); //Calculate floating point voltage
#undef MX_ADC_VREF_V
return (fVoltage);
}
Am I wrong?
- Enamul
- Posts: 1772
- Joined: Mon Mar 05, 2012 11:34 pm
- Location: Nottingham, UK
- Has thanked: 271 times
- Been thanked: 814 times
Re: 12-bit adc resolution PIC18F87k22
Yes. You are right. In the above code it should be 0.000244 instead of 0.000976