Teensy 3.6 ADC PDB interrupt

Status
Not open for further replies.
Hi everyone, thanks for taking time reading this post :) much appreciated. (also forgive me if this is not 100% right forum section)

I am currently doing project for logging noise in metro station (which does not have access to GPS) hence I will be using accelerometer for localisation (not the best way to measure distance travelled but I have the data from the metro hence can just map - reasonable for my application). So basically I need to log 40ksps audio data and 3 channels accelerometer with 500sps each (more than enough). The data will be taken for max 2 hours.

Anyway, I have been going thru PDB interrupt using pedvide's ADC. Attached below is my current code:
Code:
#include "ADC.h"
#include "SdFat.h"

const int ledPin = LED_BUILTIN;

const int readAudio = A9; //ADC0
const int period0 = 25; //40ksps

const int readX = A17; //ADC1
const int readY = A18; //ADC1
const int readZ = A19; //ADC1
const int period1 = 2000; //500sps

const int SD_CS_PIN = BUILTIN_SDCARD;

ADC *adc = new ADC();


void setup() {
  // put your setup code here, to run once:
  pinMode(ledPin, OUTPUT);
  pinMode(readAudio, INPUT);
  pinMode(readX, INPUT);
  pinMode(readY, INPUT);
  pinMode(readZ, INPUT);

  Serial.begin(9600);
  delay(1000);
  
  Serial.println("Setting up ADC");
  adc_setup();
  Serial.println("Done setup");

  adc->adc0->stopPDB();
  adc->adc1->stopPDB();

  uint16_t temp = adc->adc0->startSingleRead(readAudio);
  Serial.println(temp);
  adc->enableInterrupts(ADC_0);
  adc->adc0->startPDB(period0);

  temp = adc->adc1->startSingleRead(readX);
  Serial.println(temp);
  adc->enableInterrupts(ADC_1);
  adc->adc1->startPDB(period1);
}

void adc_setup() {
  // ADC0 //
  adc->setAveraging(1);
  adc->setResolution(12);
  adc->setConversionSpeed(ADC_CONVERSION_SPEED::VERY_HIGH_SPEED);
  adc->setSamplingSpeed(ADC_SAMPLING_SPEED::VERY_HIGH_SPEED);

  // ADC1 //
  adc->setAveraging(1, ADC_1);
  adc->setResolution(12, ADC_1);
  adc->setConversionSpeed(ADC_CONVERSION_SPEED::VERY_HIGH_SPEED, ADC_1);
  adc->setSamplingSpeed(ADC_CONVERSION_SPEED::VERY_HIGH_SPEED, ADC_1);
}

void loop() {
  // put your main code here, to run repeatedly:
}


void adc0_isr(){
  adc->adc0->readSingle();
}
void adc1_isr(){
  adc->adc1->readSingle();
}

void pdb_isr(void) {
  PDB0_SC &=~PDB_SC_PDBIF; // clear interrupt
}

The code is still very early as you can see and nothing much. I acknowledge that I need a buffer (or maybe two ?) to log the data. As you can see, adc0 has different sampling speed with adc1 which is a bit troublesome (atleast for me). As for that, I have some questions to proceed with this.

  1. Can someone explain the pdb_isr function/interrupt ? Is the interrupt is meant for me to do the logging data there ? How is it run ?
  2. What kind of buffer is reasonable ? Note that the data will be taken for 2 hours, hence I would not like to have overrruns. Also, how the buffer should be, given that I have two different sets of sampling speed.
  3. Any idea on the structure of the logging data ? For example, there will be block with only sound measurement but not for accelerometer (due to different sampling speed). Should the data for accelerometer is zero when data is not fetched ? Or just have two different files (but this will compromise the speed to open/close files ?)
  4. I have seen sdfat code that allocate the files first before writing which claimed to be faster. How it works ? Does it basically provide zeros matrices inside the file and then fill it up ? If so, how to implement this ?

There are some sample codes; lowlatencylogger, microSoundRecorder. But honestly, some of the stuff I cant really comprehend especially on buffers. Any sample code or help would be so much appreciated.

Sorry for any inconvenience, hence thank you so much for taking time to read/reply this. Have a great day :)
 
Status
Not open for further replies.
Back
Top