Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 5 of 5

Thread: Flush initial zeros out of Analog Buffer DMA?

  1. #1
    Junior Member
    Join Date
    Feb 2020
    Posts
    6

    Flush initial zeros out of Analog Buffer DMA?

    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.

  2. #2
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    7,070
    ?? so simply don't transmit before the first sample != 0.

    Don't know how we can help without seeing your sourcecode.
    Last edited by Frank B; 02-15-2020 at 10:56 AM.

  3. #3
    Junior Member
    Join Date
    Feb 2020
    Posts
    6
    Quote Originally Posted by Frank B View Post
    ?? 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();
    
    }

  4. #4
    Junior Member
    Join Date
    Feb 2020
    Posts
    6
    I don't really want to transmit data selectively as data chunks of the same size incoming continuously is desired for my application.

  5. #5
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    7,070
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •