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.

  1. 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.
  2. 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’)

Using PLIB
// Include all channels in scan
PLIB_ADC_InputScanMaskAdd(MY_ADC_INSTANCE, ADC_INPUT_SCAN_ALL);
// Internal Counter triggers conversion
PLIB_ADC_ConversionTriggerSourceSelect(MY_ADC_INSTANCE, ADC_CONVERSION_TRIGGER_INTERNAL_COUNT);
// Sample Time = 31TAD and TAD = 2TCY
PLIB_ADC_SampleAcquisitionTimeSet(MY_ADC_INSTANCE, 30);
PLIB_ADC_ConversionClockSet(MY_ADC_INSTANCE, 80000000, 20000000);
// Set the interrupt every 16 samples
PLIB_ADC_SamplesPerInterruptSelect(MY_ADC_INSTANCE, ADC_16SAMPLES_PER_INTERRUPT);
// Enable scanning of channels
PLIB_ADC_MuxAInputScanEnable(MY_ADC_INSTANCE);
// Enable the ADC
PLIB_ADC_Enable(MY_ADC_INSTANCE);


0 Comments

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.