ADC Settings

FRC

Does your uC have a FRC to use as the clock source? Nice and simple if it does.

FVR

Does your uC have a FVR to use as the reference voltage? Useful if you want an accurate reference, but not useful it you want your analog readings referenced to the uC power rail of course.

You need to add it as a separate peripheral and select its multiplier to give the reference voltage you want

Using in your code

NOTE: May be “ADC_” or “ADC1_” depending on PIC device

#include "mcc_generated_files/adc.h"

//INITIALISE
	//Start AtoD Conversion
	ADC_SelectChannel(channel_AN1);
	ADC_StartConversion();


//PROCESS ATOD
	uint16_t atod_result = 0;

	//----- CHECK FOR ANALOG CONVERSION COMPLETE -----
	//Exit if last conversion is not complete
	if (ADC_IsConversionDone())
	{
		//Get result of last conversion
		atod_result = (uint16_t)ADC_GetConversionResult();

		//Start next measurement
		ADC_SelectChannel(channel_AN1);
		ADC_StartConversion();
	}

An example function to handle AtoD measurements

See PIC18 page

USEFUL?
We benefit hugely from resources on the web so we decided we should try and give back some of our knowledge and resources to the community by opening up many of our company’s internal notes and libraries through mini sites like this. We hope you find the site helpful.
Please feel free to comment if you can add help to this page or point out issues and solutions you have found, but please note that we do not provide support on this site. If you need help with a problem please use one of the many online forums.

Comments

Your email address will not be published. Required fields are marked *