ADC adc_pdb xample does not compile

Status
Not open for further replies.

DrM

Well-known member
Compiling the ADC pdb example, produces the following error messags

adc_pdb: In function 'void loop()':
adc_pdb:87: error: 'class ADC_Module' has no member named 'getPDBFrequency'
Serial.println(adc->adc0->getPDBFrequency());
^
adc_pdb:95: error: 'class ADC' has no member named 'resetError'
adc->resetError();
^
'class ADC_Module' has no member named 'getPDBFrequency'

I am using the current versions of the aduino IDE and ADC library.
 
That lib is included with TD 1.42 - complete verbose console output would show where the ADC lib is coming from.

Looks to be on my system … line #82 as counted here in the ino
 
Hmm. good call. I have Teensy 1.41. Maybe that explains also why I don't see output from adc1_isr().

How do I update the TD?
 
Okay new problem. The pdb_isr never runs.

I modified it as follows

void adc0_isr() {
buf[nbuf++] = (uint16_t)adc->readSingle(ADC_0);
if (nbuf >= BUFLEN-1) {
//adc->disableInterrupts(ADC_0);
adc->adc0->stopPDB();
}
adc->adc0->readSingle();
//digitalWriteFast(LED_BUILTIN, !digitalReadFast(LED_BUILTIN) );
}

void adc1_isr() {
buf2[nbuf2++] = (uint16_t)adc->readSingle(ADC_1);
if (nbuf2 >= BUFLEN-1) {
//adc->disableInterrupts(ADC_1);
adc->adc1->stopPDB();
}
adc->adc1->readSingle();
//digitalWriteFast(LED_BUILTIN, !digitalReadFast(LED_BUILTIN) );
}

void pdb_isr(void) {
PDB0_SC &=~PDB_SC_PDBIF; // clear interrupt
//digitalWriteFast(LED_BUILTIN, !digitalReadFast(LED_BUILTIN) );

pdbknt++;
}

and in the main loop, I added a statement to the 'p' command to print the counters. BUFLEN is 1024. At the end of 1024 cycles, we have

Frequency: 1000
knts adc0 1024 adc1 1023 pdb 0

Note that the second adc does not finish the last input cycle, and the pdb counter was never incremented.
 
Here is the complete program. This is the example from the ADC library, with mods as described above. The aberrant behaviour is described after the code.

Code:
#include <ADC_Module.h>
#include <ADC.h>
#include <RingBuffer.h>
#include <RingBufferDMA.h>

/* Example for triggering the ADC with PDB
*   Valid for Teensy 3.0 and 3.1, not LC
*/


#include <ADC.h>

const int readPin = A9; // ADC0
const int readPin2 = A2; // ADC1

ADC *adc = new ADC(); // adc object;

void setup() {

    pinMode(LED_BUILTIN, OUTPUT);
    pinMode(readPin, INPUT);
    pinMode(readPin2, INPUT);

    Serial.begin(9600);

    Serial.println("Begin setup");

    ///// ADC0 ////
    adc->setAveraging(1); // set number of averages
    adc->setResolution(8); // set bits of resolution
    adc->setConversionSpeed(ADC_CONVERSION_SPEED::VERY_HIGH_SPEED); // change the conversion speed
    adc->setSamplingSpeed(ADC_SAMPLING_SPEED::VERY_HIGH_SPEED); // change the sampling speed

    ////// ADC1 /////
    #if ADC_NUM_ADCS>1
    adc->setAveraging(1, ADC_1); // set number of averages
    adc->setResolution(8, ADC_1); // set bits of resolution
    adc->setConversionSpeed(ADC_CONVERSION_SPEED::VERY_HIGH_SPEED, ADC_1); // change the conversion speed
    adc->setSamplingSpeed(ADC_SAMPLING_SPEED::VERY_HIGH_SPEED, ADC_1); // change the sampling speed
    #endif

    Serial.println("End setup");

}

#define BUFLEN 1024

int buf[BUFLEN] = { 0 };
int nbuf = 0;

int buf2[BUFLEN] = { 0 };
int nbuf2 = 0;

int pdbknt = 0;

char c=0;
int value;
int value2;

void loop() {

    if (Serial.available()) {
        c = Serial.read();
        if(c=='v') { // value
            Serial.print("Value ADC0: ");
            value = (uint16_t)adc->readSingle(ADC_0); // the unsigned is necessary for 16 bits, otherwise values larger than 3.3/2 V are negative!
            Serial.println(value*3.3/adc->getMaxValue(ADC_0), DEC);
            #if ADC_NUM_ADCS>1
            Serial.print("Value ADC1: ");
            value2 = (uint16_t)adc->readSingle(ADC_1); // the unsigned is necessary for 16 bits, otherwise values larger than 3.3/2 V are negative!
            Serial.println(value2*3.3/adc->getMaxValue(ADC_1), DEC);
            #endif
        } else if(c=='s') { // start pdb, before pressing enter write the frequency in Hz
            uint32_t freq = Serial.parseInt();
            if (freq == 0) {
                Serial.println("Stop pdb.");
                adc->adc0->stopPDB();
                adc->adc1->stopPDB();
            }
            else {
                Serial.print("Start pdb with frequency ");
                Serial.print(freq);
                Serial.println(" Hz.");
                pdbknt = 0;
                adc->adc0->stopPDB();
                adc->adc0->startSingleRead(readPin); // call this to setup everything before the pdb starts, differential is also possible
                adc->enableInterrupts(ADC_0);
                adc->adc0->startPDB(freq); //frequency in Hz
                #if ADC_NUM_ADCS>1
                adc->adc1->stopPDB();
                adc->adc1->startSingleRead(readPin2); // call this to setup everything before the pdb starts
                adc->enableInterrupts(ADC_1);
                adc->adc1->startPDB(freq); //frequency in Hz
                #endif
            }
        } else if(c=='p') { // pbd stats
            Serial.print("Frequency: ");
            Serial.println(adc->adc0->getPDBFrequency());
            Serial.print("knts adc0 " );
            Serial.print( nbuf );
            Serial.print(" adc1 " );
            Serial.print( nbuf2 );
            Serial.print(" pdb " );
            Serial.println( pdbknt );
        }

    }


    // Print errors, if any.
    adc->printError();
    adc->resetError();

    //digitalWriteFast(LED_BUILTIN, !digitalReadFast(LED_BUILTIN));

    delay(10);
}


// Make sure to call readSingle() to clear the interrupt.
void adc0_isr() {
        buf[nbuf++] = adc->adc0->readSingle();
        if (nbuf >= BUFLEN-1) {
          //adc->disableInterrupts(ADC_0);
          adc->adc0->stopPDB();
        }
        //digitalWriteFast(LED_BUILTIN, !digitalReadFast(LED_BUILTIN) );
}

#if ADC_NUM_ADCS>1
void adc1_isr() {
        buf2[nbuf2++] = adc->adc1->readSingle();
        if (nbuf2 >= BUFLEN-1) {
          //adc->disableInterrupts(ADC_1);
          adc->adc1->stopPDB();
        }
        //digitalWriteFast(LED_BUILTIN, !digitalReadFast(LED_BUILTIN) );
}
#endif

// pdb interrupt is enabled in case you need it.
void pdb_isr(void) {
        pdbknt++;
        
        PDB0_SC &=~PDB_SC_PDBIF; // clear interrupt
        //digitalWriteFast(LED_BUILTIN, !digitalReadFast(LED_BUILTIN) );
        
}

After entering the command 's1000', the output is

Frequency: 1000
knts adc0 1024 adc1 1023 pdb 0

As above, the second adc does not finish the last input cycle, and the pdb counter was never incremented.
 
Last edited:
Status
Not open for further replies.
Back
Top