Jump to content
  • 0

MX7 ADC not reading correctly


bwc0840

Question

Working with the MX7 Pro board and having problems with the ADC inputs.  For the background, I am using AN2, AN3, and AN4 to sense external voltages.  When placing 3vdc on any of the three analog inputs and reading the values via the ReadADC10(offset) command, the max value returned is 73.  I am using the internal Vref which should return a value around 1000 +/-.  Changed AN4 to AN6 in case I had blown the input and am seeing the same results.  The same program works correctly on the older MX4 version.  Thanks in advance for the assistance.

Link to comment
Share on other sites

5 answers to this question

Recommended Posts

Certainly.  Below is the section of code that is used to pull the values for the three inputs.  The calling routine passes 100 into numofsamples.   When applying 0-3vdc on any of the three channels (JA-1, JA-2, or JA-3), the count displayed via a 4x80 LCD screen varies from 0-73 instead of 0-1023.   Also, when attempting to look at the variables in debug mode, nothing is displayed.  Added the ICESEL command per the website instructions.  No errors found when compiling the code.  At this point, providing a picture of the setup is not possible.  I have attempted using an external power supply as well as using the debug power supply jumper settings.  Results are consistent regardless of the power source. 

 

#pragma config POSCMOD=HS, FNOSC=PRIPLL
#pragma config FPLLIDIV=DIV_2, FPLLMUL=MUL_20, FPLLODIV=DIV_1
#pragma config FPBDIV=DIV_1, FWDTEN=OFF, CP=OFF, BWP=ON
#pragma config WDTPS = PS1
#pragma config DEBUG = ON

#pragma config ICESEL = ICS_PGx1  //added 12-2017 for using the license debugger on the MX7

 

Parameters used to set up the ADC

 #define PARAM1 ADC_MODULE_ON | ADC_FORMAT_INTG | ADC_CLK_AUTO | ADC_AUTO_SAMPLING_ON
 #define PARAM2 ADC_VREF_AVDD_AVSS | ADC_OFFSET_CAL_DISABLE | ADC_SCAN_ON | ADC_SAMPLES_PER_INT_3 | ADC_ALT_BUF_ON | ADC_ALT_INPUT_OFF
 #define PARAM3 ADC_CONV_CLK_INTERNAL_RC | ADC_SAMPLE_TIME_15  
 #define PARAM4 ENABLE_AN2_ANA | ENABLE_AN3_ANA | ENABLE_AN4_ANA
 #define PARAM5  SKIP_SCAN_AN0  | SKIP_SCAN_AN1 | SKIP_SCAN_AN5 | SKIP_SCAN_AN6 | SKIP_SCAN_AN7 | SKIP_SCAN_AN8 |\
                  SKIP_SCAN_AN9  | SKIP_SCAN_AN10 | SKIP_SCAN_AN11|\
                  SKIP_SCAN_AN12 | SKIP_SCAN_AN13 | SKIP_SCAN_AN14 | SKIP_SCAN_AN15

OpenADC10(PARAM1, PARAM2, PARAM3, PARAM4, PARAM5);

EnableADC10();    // Enable the ADC

Reading the ADC

void adcRead(int numofsamples)
{
  int offset, countstart;
  cnt = 0;
  ch1 = 0;
  ch2 =0;
  ch3 = 0;
  samplecounts = 0;
  countstart = _CP0_GET_COUNT();
  char abc[16];
  while (cnt < numofsamples)
      {
         ClearWDT();
         while (!mAD1GetIntFlag());    // Wait for the ADC to be ready
         offset = 8 * ((~ReadActiveBufferADC10() & 0x01)); 
         samplecounts++;
         //RB2 - JA-01 = ch1 analog input
         //RB3 - JA-02 = ch2 analog input
         //RB4 - JA-03 = ch3 analog input
         ch1 = ReadADC10(offset);  // read ADC for channel 1
         ch2  = ReadADC10(offset+1);  // read channel 2      
         ch3  = ReadADC10(offset+2);  // read channel 3

        LCDgoto (3,1);
        sprintf(abc,"AN3 = %4D",ch3);
        LCDout(abc);
         mAD1ClearIntFlag();           // Clear the interrupt flag
         cnt = (_CP0_GET_COUNT() - countstart);
         //samplecounts++;
       }
}

 

Link to comment
Share on other sites

Hi @bwc0840,

I'm not certain why the code you had works nicely for the MX4 but not the MX7, but it looks like according to these two links (here and here on page 314) you may need to use the SetChanADC10 function to set the voltage references. It looks like more documentation on the pic32-library is stored locally on your machine. Mine is under C:\Program Files (x86)\Microchip\xc32\v1.43\docs\pic32-lib-help\Microchip PIC32MX Peripheral Library

Let me know what you get.

Thanks,
JColvin

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...