3 Replies Latest reply on May 12, 2015 3:39 PM by user_1377889

    DMA fails to capture results from an ADC?

    jakub.sanak

      I have a DMA setup to capture 4095 8-bit samples from an ADC and then send it via UART to my PC. All of this is done in one procedure :

         
       void pulseAndReg() { // uint16 PulseSampleNo = SAMPLES_IN_BUFFER; ADC_Mag_StartConvert(); pulseEndFlag = 0;
          
          // transmit the pulse    
          WaveDelayProducer_setGlobalEnable(1);
          CyDelayUs(PULSE_LENGTH_US);
          WaveDelayProducer_setGlobalEnable(0);
          
          // start collecting data
          isr_PulseEnd_Enable();
          CyDmaChEnable(DMA_1_Chan, 1);
          // wait for end of collection
          while(!pulseEndFlag)
          {
              //block until collection finished
          }
          
          isr_PulseEnd_Disable();
          UART_PC_PutArray(samplesBuffer8, SAMPLES_IN_BUFFER);
          CyDmaChDisable(DMA_1_Chan);
          ADC_Mag_StopConvert();

      }
         

      Before the procedure runs a bunch of stuff is being initialized before main():

         

      #define SAMPLES_IN_BUFFER (uint16)(0x0FFF)
         
      #define PULSE_LENGTH_US 300u

      /* Variable declarations for DMA_1 */
      /* Move these variable declarations to the top of the function */
      uint8 DMA_1_Chan;
      uint8 DMA_1_TD[1];

          /* DMA Configuration for DMA_1 */
      #define DMA_1_BYTES_PER_BURST 1
      #define DMA_1_REQUEST_PER_BURST 1
      #define DMA_1_SRC_BASE (CYDEV_PERIPH_BASE)
      #define DMA_1_DST_BASE (CYDEV_SRAM_BASE)

         


      uint8 samplesBuffer8[SAMPLES_IN_BUFFER] = {0};

         

      and in main():

         

      ADC_Mag_Start();
          UART_PC_Start();
         
          DMA_1_Chan = DMA_1_DmaInitialize(DMA_1_BYTES_PER_BURST, DMA_1_REQUEST_PER_BURST,
         HI16(DMA_1_SRC_BASE), HI16(DMA_1_DST_BASE));
          DMA_1_TD[0] = CyDmaTdAllocate();
          CyDmaTdSetConfiguration(DMA_1_TD[0], SAMPLES_IN_BUFFER, DMA_1_TD[0], DMA_1__TD_TERMOUT_EN | TD_INC_DST_ADR);
          CyDmaTdSetAddress(DMA_1_TD[0], LO16((uint32)ADC_Mag_DEC_SAMP_PTR), LO16((uint32)samplesBuffer8));
          CyDmaChSetInitialTd(DMA_1_Chan, DMA_1_TD[0]);

         


          CyGlobalIntEnable;  /* Uncomment this line to enable global interrupts. */
          isr_PulseEnd_Start();
          isr_PulseEnd_Disable();

         

       

         

      My problem is, all that seems to be inhabitting the samplesBuffer8 after the procedure is run is a bunch of ones, nothing else. I've been trying to debug this problem for ages now and I can't seem to figure out the reason why the program behaves this way. Any ideas anyone?