9 Replies Latest reply on May 27, 2020 1:08 AM by YuCh_3947976

    PWM

    YuCh_3947976

      Hi all,I want to set an output like below pic,the period of 100%(duty cycle) is 60 us another one(20%)  is 120 us

      but the result on oscilloscope is not what I want,how can I do?

      thanks

      IMG_2169.jpg

      IMG_2171.jpg

        • 1. Re: PWM
          MoTa_728816

          Hi,

           

          Usually PWM component generate 0 and 1 output.

          If you want to have 100% and 20% output,

          you can either use IDAC or DC bias PWM output.

           

          So I tested with CY8CKIT-044

           

          schematic

          001-schematic.JPG

          pins

          002-pins.JPG

           

          main.c

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

          #include "project.h"

           

          void init_hardware(void)

          {

              CyGlobalIntEnable; /* Enable global interrupts. */  

              PWM_Init() ;

              IDAC_Start() ;

          }

           

          void ConfigPWM(uint16_t period, uint16_t compare)

          {

              PWM_Stop() ;

              PWM_WritePeriod(period) ;

              PWM_WriteCompare(compare) ;

              PWM_WriteCounter(0) ;

              PWM_Start() ;

          }

           

          void ConfigIDC(uint8_t value)

          {

              IDAC_SetValue(value) ;

          }

           

          int main(void)

          {

              init_hardware() ;

            

              ConfigPWM(180, 60) ;

           

           

              for(;;)

              {

                  IDAC_SetValue(100) ;

                  CyDelayUs(60) ;

                  IDAC_SetValue(20) ;

                  CyDelayUs(120) ;

              }

          }

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

           

          The result oscilloscope view was

          The red signal is output of IDAC via 2k (kind of 100% and 20%)

          The yellow signal is output of PWM (100% and 0%)

          Since IDAC is controlled by FW, they are not synced.

           

          IMG_4269.JPG

           

          moto

          1 of 1 people found this helpful
          • 2. Re: PWM
            NiPi_4635631

            PWM.jpg

            180us

            180us->0.00018s

            f = 1/T =1/0.00018 = 5555,5Hz

            check the formula T = 1/f = 1/5555,5 =1,8e-4(0,00018)s

            calculate the period value for the frequency 5555,5Hz

            12 000 000/5555,5-1 = 2159

            Compare value @ 80% = (1-0.8)*(2159+1)=0,2*2160 =432

            So I tested with CY8CKIT-049-41XX

            Clock 12MHz

            36us=20%    144us=80%

            • 3. Re: PWM
              NoriakiT_91

              This is my solution for your request using CY8CKIT-044

              GS004756.png

              This project consists of two PWMs.  The PWM_FAST generates 20%/100% duty waveform. The PWM_FAST is controlled by PWM_SLOW.  When the control signal is HIGH, PWM_FAST generates 100% duty sticking at HIGH.  The configuration of PWM_FAST is as follows.

              GS004757.png

              Please set the input mode of three input signals proper.  The carrier frequency of PWM_FAST is set to 1.2MHz (24MHz/20)

              PWM_SLOW generates 60us/120us waveform with following configuration.

              GS004755.png

              Because I have no oscilloscope in home, I confirm the behavior with a handy DMM by decrease the control signal.

              GS004752.png

              GS004753.png

              Please confirm the waveform with your oscilloscope.

               

              Regards,

              Noriaki

              • 4. Re: PWM
                YuCh_3947976

                yup,I got it wrong,PWM just adjusts pulse width

                restate my questions,I want to control the time of high and low,then I adjust period and use the command(WriteCompare) to solve the problem.

                At the beginning I had plans to use IDAC,but I need a high voltage is around 3V,but the maximum  current of IDAC is 612uA,it can't output the voltage I want.

                • 5. Re: PWM
                  YuCh_3947976

                  Thanks everyone for providing many ways.

                  but why is the low output of PWM result not 0?IMG_2182.jpg

                  • 6. Re: PWM
                    MoTa_728816

                    Hi,

                     

                    May I assume that your problem is solved now?

                     

                    > At the beginning I had plans to use IDAC,

                    > but I need a high voltage is around 3V,but the maximum  current of IDAC is 612uA,it can't output the voltage I want.

                     

                    "Conceptually", if you replace 2K of my schematic to around 5K or higher, you can get 3V,

                    but driving capability is very low (as you know, 612uA).

                     

                    moto

                    • 7. Re: PWM
                      MoTa_728816

                      Hi,

                       

                      If you double click the Digital Output pin in your schematic,

                      You will see the configuration window something like below.

                      In the left-bottom corner, there is "Datasheet" button.

                      We can access the datasheet of the component from there.

                      010-pin-datasheet.JPG

                       

                      In the datasheet, VOL is stated as 0.4 ~ 0.8 MAX.

                      So we may(?) see some floating value from the ground.

                      011-datasheet.JPG

                      I know that this is not ideal, but it is the way it is.

                       

                      moto

                      • 8. Re: PWM
                        BoTa_264741

                        YuCh,

                        You can find more possible solutions in this thread

                        Ideas how to switch output voltage between V1 and V2 on TTL signal?

                         

                        Using Opamp and PWM, it is possible to hardware switch between V1 and V2. This is simplest method if adjustment of V1 and V2 is not required at the run-time.

                        /odissey1

                        mux1.png

                        • 9. Re: PWM
                          YuCh_3947976

                          thank you so much.

                          Finally, I used PWM to complete this project.