13 Replies Latest reply on Oct 19, 2020 12:32 AM by MoTa_728816

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

    MiGu_4743071

      Hi folks.

       

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

       

       

      The Conversion time of ADC is 2 us.

       

       

      So I generate a PWM like the Oscilloscope shows below.

      PXL_20201012_054626748.jpg

       

      And my code is

      for(uint i = 1; i <= 20; i++)
              {
                  
                  PWMadcCounts[i] = ADC_GetResult16(0);
                  PWMvolts[i] = ADC_CountsTo_Volts(0,PWMadcCounts[i]);
                  
                  CyDelayUs(2);
              }
      
      

      And put out to terminal via UART.

       

      In my imagination. It should be able to show the voltage around 4.32v at the first, then drop down to around 0v when i = 9. But it isn't.

       

      There is my project file in attachment.

       

      Is this idea impossible?

       

      Thank you for your time to read this. If it's not bothering you, having some suggest and I'll be grateful.

        • 1. Re: May I just measure the PWM pulse with SAR_ADC(CY8CKIT-044)
          MoTa_728816

          Hi,

           

          I briefly read your project.

          You configured the PWM as below.

          140 cycle of 8.4MHz = 1.666.. us < 2 us of ADC conversion time.

          And also because of this configuration, 99% of the PWM cycle the PWM output is 0.

          So, chance of ADC to detect something is very low.

          002-PWM-config.JPG

          According the the sampling theorem, if you want sample a signal of frequency Fx,

          the sampling frequency must be at least 2 x Fx.

           

          Meantime, in your get_ADC(), you are doing two additional things

          for (uint i = 1; i <= 20; i++)

          {

                      PWMadcCounts[i] = ADC_GetResult16(0);

                      PWMvolts[i] = ADC_CountsTo_Volts(0,PWMadcCounts[i]); // (1)

                      CyDelayUs(2); // (2)

          }

           

          These makes the sampling frequency even slower, I would do below to make the sampling frequency as fast as possible.

          (Or may be you need to use DMA triggered by ADC's eoc)

          uint i ;

          for (i = 1; i <= 20; i++)

          {

          ADC_IsEndConversion(ADC_WAIT_FOR_RESULT) ; // wait conversion complete    

          PWMadcCounts[i] = ADC_GetResult16(0);

          }

          for (i = 1; i <= 20; i++)

          {

          PWMvolts[i] = ADC_CountsTo_Volts(0,PWMadcCounts[i]); // (1)

          }

           

          So I modified you project as below, although it may not your intention.

           

          Schematic

          004-schematic.JPG

          PWM config

          With this the pulse width > 2us

          And the duty if about 10% so the chance of getting some data within 20 samples is high.

          005-PWM-CONFIG.JPG

          Tera Term log

          001-TeraTerm-log.JPG

           

          Please play with the period and compare value(s) of PWM to see the results.

           

          moto

          1 of 1 people found this helpful
          • 2. Re: May I just measure the PWM pulse with SAR_ADC(CY8CKIT-044)
            AlanH_86

            Nice answer.

             

            Why in the world would you want to measure the PWM using the ADC?  I couldnt think of a good reason and I would love to know what he is doing with it.

            • 3. Re: May I just measure the PWM pulse with SAR_ADC(CY8CKIT-044)
              MoTa_728816

              I would assume that final target of measurement is not the PWM in the device,

              but some external signal which has some pulse width and voltage value.

              Otherwise..., I'm in you party, too ;-P

               

              moto

              • 4. Re: May I just measure the PWM pulse with SAR_ADC(CY8CKIT-044)
                MiGu_4743071

                Hi Moto,

                 

                Thank you for your extraordinary answer. I learned a lot from it.

                 

                Actually, the purpose that I want to measure the PWM pulse is. I want to measure the transient state of a TFT via PSoC.

                TFT.jpg

                Which Vdd is 6V from power supply, Vin is PWM from PSoC, Current source is set up from PSoC IDAC(1.2 uA).

                 

                Then I want to measure the Vn. If I use the Oscilloscope. It works fine.

                Transient state.jpg

                Ch1: PWM

                Ch2: Vn

                 

                So I will try to use two channels of the ADC to measure the "PWM" and "Vn". To see the PWM goes up and the Vn rise in a mean while.

                 

                But the duration of the transient state is ~48 us(the left red circle). and ADC maybe can not convert two signal in the same time.

                 

                After reading your reply. I think I can't really measure the duration and voltage by CY8CKIT-044.

                 

                I will still try this and see what it will be.

                 

                Thank you.

                • 5. Re: May I just measure the PWM pulse with SAR_ADC(CY8CKIT-044)
                  MoTa_728816

                  Hi,

                   

                  I just double checked, the PSoC 4200M on the CY8CKIT-044 has only 1 ADC module.

                  So we can multiplex the input but can not acquire 2 input at the same time.

                   

                  But seeing your oscilloscope screen, I don' t think that you need to measure PWM,

                  but only measuring the Vn will be adequate.

                  I would use the rising edge (and/or falling edge) for the trigger of starting the measurement.

                   

                  Meantime, please note that the maximum sampling speed of the ADC is 1-Msps

                  and I'm afraid that you are close to the limit, so please be careful not to introduce

                  additional delay in the measurement loop or consider to use DMA for the maximum speed.

                  (Sorry, I'm not very familiar with DMA, but if you post a question here, you will get good answers).

                   

                  moto

                  1 of 1 people found this helpful
                  • 6. Re: May I just measure the PWM pulse with SAR_ADC(CY8CKIT-044)
                    MiGu_4743071

                    Hi Moto,

                     

                    Thanks.

                     

                    I found that there is "PSoC 4 DMA ADC EXAMPLE" in PSoC creator 4.3.

                    I'll do some study about how the DMA works.

                     

                    If there any further question, I will post another question here.

                     

                    Thank you

                    • 7. Re: May I just measure the PWM pulse with SAR_ADC(CY8CKIT-044)
                      AlanH_86

                      Yes you will need to DMA... and yes I think that you should just use the pwm to trigger the dma.

                       

                      I would observe that 2 bytes/same * 1msps = 16mbs/s so it isnt clear to me what you are going to do with the data after you get it...

                       

                      With that amount of data you will fill up the RAM really fast... and you wont be able to spit it out anywhere near the speed you want to on a UART.

                       

                      I guess I think that you need to think about what you are going to do with that much data in your system design.

                       

                      Alan

                      • 8. Re: May I just measure the PWM pulse with SAR_ADC(CY8CKIT-044)
                        BoTa_264741

                        MiGu,

                        I posted a simple oscilloscope demo project in Community section, which may be helpful for you.

                        Basic oscilloscope demo using ADC_SAR and KIT-059

                         

                        The project is based on KIT-059 PSoC5LP Prototyping board. With some effort it should be possible to port it to PSoC4.

                        /odissey1

                         

                        Figure 1. ADC in free-running mode. DMA is gated.

                        ADC_DMA_RAM_8bit_02a_A2.png

                         

                        Figure 2. Oscilloscope traces: Yellow - DUT, Cyan - PWM pulse, Fuchsia - ADC trigger pulse.

                        ADC_DMA_RAM_8bit_02a_D1.png

                         

                        Figure 3. Plotting acquired data using SerialPlot.

                        ADC_DMA_RAM_8bit_02a_E1.png

                        1 of 1 people found this helpful
                        • 9. Re: May I just measure the PWM pulse with SAR_ADC(CY8CKIT-044)
                          MiGu_4743071

                          Hi BoTa,

                           

                          OMG! Thank you!

                          Your reply are so beyond my acknowledge.

                          I need couple days to learn these.

                          Although I don't have KIT-059, but I will see what I can do with your project.

                           

                          Thanks a lot!!

                          • 10. Re: May I just measure the PWM pulse with SAR_ADC(CY8CKIT-044)
                            BoTa_264741

                            MiGu,

                            I tried to migrate PSoC5 o-scope project to PSoC4 (KIT-044) and met several issues. So far in migrated project ADC sampling frequency is lower and doesn't produce stable output as with PSoC5 (reasons yet unknown). Other hurdles to overcome is that moving data from PSoC4' ADC done not from byte to byte, but from  4-byte word to a byte. Also, unlike PSoC5, the DMA output toggles not on completion of all samples, but on each and every sample, so an extra counter needed to count the number of samples. Also, the UDB space is limited, so some of the PWM/Timer/UART functions have to be moved to a Fixed-Function blocks, which have limited functionality.

                             

                            My overall impression that porting project to PSoC4 is not worth time spent. If it is done for anything but fun, I would encourage you to buy PSoC5LP Prototyping Board, CY8CKIT-059 ($10), and save time.

                            /odissey1

                            1 of 1 people found this helpful
                            • 11. Re: May I just measure the PWM pulse with SAR_ADC(CY8CKIT-044)
                              MoTa_728816

                              Hi,

                               

                              I've been studying about DMA and I have just posted a sample below.

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

                               

                              This one seems to be sampling 2us cycle,

                              and I can not observe lag between each sampling group.

                               

                              But I'd like to implement back-to-back (aka PingPong) usage of 2 descriptors

                              and also implement a trigger mechanism.

                              So I'm afraid that my study will last longer....

                               

                              moto

                              1 of 1 people found this helpful
                              • 12. Re: May I just measure the PWM pulse with SAR_ADC(CY8CKIT-044)
                                MiGu_4743071

                                Hi Moto,

                                 

                                I'll study your project with "SerialPoltter". Thank you~

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

                                 

                                For now I realize that the original code you replied, sample rate is already around 2 us without using DMA.

                                 

                                uint i ;

                                for (i = 1; i <= 20; i++)

                                {

                                ADC_IsEndConversion(ADC_WAIT_FOR_RESULT) ; // wait conversion complete   

                                PWMadcCounts[i] = ADC_GetResult16(0);

                                }

                                for (i = 1; i <= 20; i++)

                                {

                                PWMvolts[i] = ADC_CountsTo_Volts(0,PWMadcCounts[i]); // (1)

                                }

                                 

                                I tried to crate a pwm which frequency = 1000hz, and the pulse duration is 20 us and 30 us.

                                 

                                And in my project, it can just try to find the pulse and print it out. System will freeze after print the pulse.

                                 

                                So we can have 10 or 9 datas for 20 us pulse, 15 or 14 datas for 30 us pulse.

                                 

                                as below

                                pwm 1000hz 20us result.jpgpwm 1000hz 30us result.jpg

                                 

                                Next I'll use this to measure my circuit. Let's see how it gose.

                                 

                                But using "SerialPoltter" seems to much prettier. That's my next goal. Thank you.

                                • 13. Re: May I just measure the PWM pulse with SAR_ADC(CY8CKIT-044)
                                  MoTa_728816

                                  Hi,

                                   

                                  FYI.

                                   

                                  Talking about SerialPlotter, I posted my way of using the SerialPlotter in the discussion below.

                                  How I recycle the data (aka Return of CCS811)

                                   

                                  And odissey1-san has also provided more sophisticated component as below

                                  SerialPlot: interface to real-time data charts

                                   

                                  moto