PLIB ADC with PIC32 ‘EC’ Family
This week I fix my ADC driver, which I done it incorrectly previously.
PIC32MZ come with 2 different Family namely the ‘EC’ family and ‘EF ‘ family. The main difference for both of them would be ‘EC’ only capable of 10bit ADC conversion while ‘EF’ can up to 12bit ADC. For my particular project I will be using ‘EC’ family. ‘EF’ stands for floating point unit, therefore this particular family version is capable of having advance analog feature.
After some reading and experiment to build my ‘EC’ ADC code, I realize Harmony do not support ‘EC’ version of ADC driver. Normally, if you run an ADC harmony example project ‘adc_pot’ the configuration for the examples is always ‘EF’ family. Studying the MHC configuration anybody would taught/assume that the same applies to all PIC32MZ family, however its totally different.
As long as one is using ‘EC’ family during MHC configuration, the ADC driver will not be supported. Thus it comes down to 2 option to write or configured an ADC for ‘EC’ family.
- Continue with MHC configuration, but make changes in ‘port’ setting, based on Harmony Help library, it stated that PIC32 pin’s can be configured using MHC to user defined peripheral eg: to SPI, ADC and etc. However, when I tried to implement ADC initialization with MHC ‘port’, MHC could not generate the correct ADC code.
- So it comes down to the second option, using PLIB to write the initialization code. Keeping in mind the way to write ADC for PIC32MZ ‘EC’ family should be similar to PIC32MX family, because both are 10bit ADC conversion and PLIB library is the same for both PIC32 MX and MZ (the same goes to ‘EC’ and ‘EF’)
// Include all channels in scan
// Internal Counter triggers conversion
// Sample Time = 31TAD and TAD = 2TCY
PLIB_ADC_ConversionClockSet(MY_ADC_INSTANCE, 80000000, 20000000);
// Set the interrupt every 16 samples
// Enable scanning of channels
// Enable the ADC