Flush initial zeros out of Analog Buffer DMA?

Status
Not open for further replies.

Joe459

Member
Hi guys,

I am working on a project that is very much based on the adc_dma example in the teensy ADC library, and it uses the PDB to set the frequency of sampling. The analog buffer interrupt simply sends all the data over serial where it is processed on my PC.

I notice 4 zeros at the beginning of the first buffer of acquisition, and it their existence is independent of number of averages for the adc, conversion speed, etc. It might be a bit silly and particular, but I would like to see if I can get rid of them on the teensy before sending the data to my PC. I am using a teensy 3.6.
 
?? so simply don't transmit before the first sample != 0.

Don't know how we can help without seeing your sourcecode.
 
Last edited:
?? so simply don't transmit before the first sample != 0.

Don't know how we can help without seeing your sourcecode.

Here is some source.

Code:
const int readPin_adc_0 = A15;

ADC *adc = new ADC(); 
const uint32_t initial_average_value = 2048;


DMAMEM static volatile uint16_t __attribute__((aligned(32))) dma_adc_buff1[buffer_size];
DMAMEM static volatile uint16_t __attribute__((aligned(32))) dma_adc_buff2[buffer_size];
AnalogBufferDMA abdma1(dma_adc_buff1, buffer_size, dma_adc_buff2, buffer_size);

uint16_t LUT[1024];

void setup() {

    while (!Serial && millis() < 5000) ;

    pinMode(LED_BUILTIN, OUTPUT);

    std::iota(LUT, LUT + 1023, 0);

    Serial.begin(115200);

    while (!Serial.available()) {};



    adc->adc0->setAveraging(1); 
    adc->adc0->setResolution(12); 


    abdma1.init(adc, ADC_0);
    abdma1.userData(initial_average_value); 

    adc->adc0->setConversionSpeed(ADC_CONVERSION_SPEED::VERY_HIGH_SPEED); 

    adc->adc0->setSamplingSpeed(ADC_SAMPLING_SPEED::VERY_HIGH_SPEED); 

    adc->adc0->analogRead(readPin_adc_0);
    
    adc->adc0->stopPDB();
    adc->adc0->startPDB(100000);

    adc->adc0->enableInterrupts(adc0_isr);
    

}

Code:
void loop() {

    if ( abdma1.interrupted()) {
        SendAnalogData(&abdma1, ADC_0);  
    }
}


Code:
void SendAnalogData(AnalogBufferDMA* pabdma, int8_t adc_num) {

    volatile uint16_t* pbuffer = pabdma->bufferLastISRFilled();
    
    if ((uint32_t)pbuffer >= 0x20200000u)  arm_dcache_delete((void*)pbuffer, sizeof(dma_adc_buff1));

    Serial.write((byte*) pbuffer, buffer_size_bytes);


    pabdma->clearInterrupt();

}
 
I don't really want to transmit data selectively as data chunks of the same size incoming continuously is desired for my application.
 
But you get a stream of data, not data chunks. If your application interpretes this as chunks - ok, it can :)

- insert a static bool startflag=false in SendAnalogData
- if the startflag is false: do a loop and increase your pbuffer-pointer til the end (buffer_size_bytes) or til you find a value >0. if value > 0 set startflag = true
- if you have still bytes to send and startflag is true, do your Serial.write as above.
 
Status
Not open for further replies.
Back
Top