Setting up the AtoD Sampling
Look up the following in the device datasheet:
Tad = ADC Clock period ADC Clock Period
Sample Time
Conversion Time (value not needed to setup but this tells you how long it will take to convert)
ADCS – ADC Conversion Clock Select bits
ADC_CONV_CLK_#Tcy
This value sets Tad:
Tpb (Peripheral bus speed) x Value Used = Tad
SAMC – Auto-Sample Time bits
ADC_SAMPLE_TIME_# (A/D Auto Sample Time x Tad)
This value sets the sample time
Example – PIC32MX120F032B
Tad = ADC Clock period ADC Clock Period = 65nS min
Conversion Time = 12Tad typ
Sample Time = 1Tad min
With a 40MHz osc and 40MHz peripheral bus these values would provide the required times:
ADC_CONV_CLK_3 provides Tad = 75nS
ADC_SAMPLE_TIME_3 provides 3Tad so more than the 1Tad minimum but enuring our input impedance etc doesn't affect the sampling capacitor being fully charged each time.