chipKIT® Development Platform

Inspired by Arduino™

getting best speed from ADC (1 Msps?)

Created Sun, 11 Sep 2011 05:08:06 +0000 by jbeale


jbeale

Sun, 11 Sep 2011 05:08:06 +0000

Right now it looks like accessing the ADC in the usual Arduino way achieves a sample rate of 100 ksps. That is certainly better than an Arduino, but the PIC32 datasheet says the ADC can reach 1000 ksps (1 Msps). Is there any easy way to do that, eg a different library? Does sample code exist? For example, something like this (which does 100 ksps on UNO32):

// Chipkit UNO32 board A/D timing:  10 us per 10-bit ADC read

int sensorPin = 0;    // select the A/D input pin 
int sensorValue[100];  // array to store the value coming from the sensor

void setup() {
  Serial.begin(115200);
}

void loop() {
  long i;

  for (i=0;i<100;i++) {
    sensorValue[i] = analogRead(sensorPin);    
  }

  for (i=0;i<100;i++) {
    Serial.println(sensorValue[i]);
  }
 while(1) {}
}

jbeale

Sun, 11 Sep 2011 05:18:59 +0000

Ok, to follow up my own post, I see there is an example called "PIC32 1 MSPS ADC Example" posted here: http://www.microchip.com/forums/m472112.aspx

The problem is, it is for a slightly different chip, and also for a different compiler. Can anyone say how much rework would be needed for this to work on the UNO32 with MPIDE?


GeneApperson

Tue, 13 Sep 2011 00:31:22 +0000

The ADC is the same between the PIC32MX360 and the PIC32MX320, so there should be little or no difference due to the different chips. If the code was written for the Microchip C32 compiler running under the MPLAB IDE, then the chipKIT compiler should have no problem with it since it's essentially the same compiler.

Gene Apperson Digilent


jbeale

Tue, 13 Sep 2011 04:57:54 +0000

Very interesting! Just as you say, after commenting out a few lines below (probably things which are fixed in the bootloader code) /* #pragma config FPLLMUL = MUL_15, FPLLIDIV = DIV_2, FPLLODIV = DIV_1 #pragma config FPBDIV = DIV_1 #pragma config POSCMOD = XT, FNOSC = PRIPLL #pragma config FWDTEN = OFF */

the original code from that forum post, for the C32 compiler does indeed compile without errors in the MPIDE. Thanks for the tip!

...now I just need to understand the code :-)


GeneApperson

Tue, 13 Sep 2011 17:06:48 +0000

Those statements set the configuration bits. These will have no effect in a chipKIT sketch, as the boot loader doesn't reprogram the config bits, and the board runs with the config bits set when the boot loader was programmed into the board.

Gene


GeneApperson

Tue, 13 Sep 2011 17:09:35 +0000

Oh BTW:

Those config bit settings would cause the processor to run at 60Mhz with a peripheral bus clock of 60Mhz on a chpKIT board. You will probably need to change some things in the code that sets up the timing for the ADC to allow for the different bus speed. The chipKIT board runs the processor at 80Mhz with a peripheral bus speed of 80Mhz.

Gene