8 Replies Latest reply on Oct 23, 2020 1:42 AM by MoTa_728816

    A study of simple oscilloscope using ADC and DMA (CY8CKIT-044) version 1

    MoTa_728816

      Hi,

       

      Before I posted a similar sample

      A Simple Oscilloscope (CY8CKIT-044) using SerialPlotter

       

      But in a discussion below, very fast sampling was required.

      May I just measure the PWM pulse with SAR_ADC(CY8CKIT-044)

       

      As I was not familiar with DMA, I have been studying it for a while now.

      This sample is the first (somewhat) working version of my simple oscilloscope using ADC and DMA.

      It is supposed to be sampling 2us each.

       

      It seems to be working OK, but I want to implement the following 2 functionalities.

      Probably in the later versions.

      (1) Utilize 2 descriptors to prevent time lag. (But I can not detect it, even with current version using only 1 descriptor, which wonders me.)

      (2) Implement a trigger to stop the signal at certain phase. (But I'd like to challenge this after (1))

       

      SerialPoltter Screen

      001-Serial_Plot.JPG

      schematic

      002-Schematic.JPG

      pins

      003-Pins.JPG

       

      main.c

      Note: as usual I cheated by using my tty_utils.[ch] to make uart hanling easier,

      but it's not the main topic of this sample anyway.

      ====================

      #include "project.h"

      #include "stdio.h"

      #include "tty_utils.h"

       

      #define RESULT_BUF_SIZE 1024

      #define SAMPLING_CYCLE 2 /* us */

      #define CLOCK_FREQ_MHZ 12

       

      uint16_t result_buf[RESULT_BUF_SIZE] ;

      int  num_result = RESULT_BUF_SIZE ;

       

      volatile int measured_flag = 0 ;

       

      CY_ISR(meaure_done_isr)

      {

          measured_flag = 1 ;

      }

       

      void init_hardware(void)

      {

          uint32_t dma_dsc ;

         

          CyGlobalIntEnable; /* Enable global interrupts. */   

          tty_init() ;

         

          isr_1_ClearPending() ;

          isr_1_StartEx(meaure_done_isr) ;

       

          Counter_WritePeriod(num_result) ;

          Counter_WriteCounter(0) ;

          Counter_Start() ;

          ADC_Start() ;

          DMA_Start((void *)ADC_SAR_CHAN0_RESULT_PTR, result_buf) ;

          dma_dsc = DMA_GetNextDescriptor() ;

          DMA_SetNumDataElements(dma_dsc, num_result) ;

       

          Timer_Init() ;

          Timer_WritePeriod(SAMPLING_CYCLE * CLOCK_FREQ_MHZ) ;

          Timer_WriteCounter(0) ;

      }

       

      void clear_buf(void)

      {

          int i = 0 ;

          for (i = 0 ; i < RESULT_BUF_SIZE ; i++ ) {

              result_buf[i] = 0 ;

          }

      }

       

      void dump_buf(void)

      {

          int i = 0 ;

          for (i = 0 ; i < num_result ; i++ ) {

              snprintf(str, STR_BUF_LEN, "%d\n\r", result_buf[i]) ;

              print(str) ;

          }

      }

       

      int main(void)

      {

          int count = 0 ;

         

          init_hardware() ;

         

          splash("ADC-DMA Test") ;

         

          Timer_Start() ;

       

          for(;;)

          {

              if (measured_flag) {

                  measured_flag = 0 ;

                  dump_buf() ;

                  Counter_WriteCounter(0) ;

                  Timer_WriteCounter(0) ;

                  Timer_Start() ;

              }

          }

      }

      ====================

       

      moto