12-bit adc resolution PIC18F87k22

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 4.
To post in this forum you must have a registered copy of Flowcode 4 or higher. To sign up for this forum topic please use the "Online Resources" link in the Flowcode Help Menu.

Moderator: Benj

Post Reply
etillol
Posts: 8
Joined: Tue Feb 12, 2013 3:31 pm
Location: Carpentras, France
Has thanked: 2 times
Been thanked: 3 times

12-bit adc resolution PIC18F87k22

Post by etillol »

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,

medelec35
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

Post by medelec35 »

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
Martin

etillol
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

Post by etillol »

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:

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

}
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?

etillol
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

Post by etillol »

Maybe this 12-bit resolution factor is corrected in Flowcode v5?

User avatar
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

Post by Enamul »

Yes. You are right. In the above code it should be 0.000244 instead of 0.000976
Enamul
University of Nottingham
enamul4mm@gmail.com

Post Reply