5 Replies Latest reply on Jun 23, 2014 12:24 PM by DaKn_263916

    PWM with 50Khz



      i need to create a PWM-Signal with 50 KHz to control a LED that expects a PWM-Signal with 50 KHz and TTL=5V.




      I´ve set the System Clock to 24 MHz and use the following Dividers VC1=6, VC2= 4, VC3=20 to create the 50KHz.


      Can I use an 8bit PWM-Module or do i need to use an 16bit PWM-Module? What value do i have to put in as "Period" ? I used 50000 on a 16 Bit Module, but i guess thats wrong.




      So far i´ve written the following Code:




      int i = 0;
          M8C_EnableGInt ;                            // Turn on interrupts
            SleepTimer_SetInterval(SleepTimer_1_HZ);   // Set interrupt to a
          for (i=0; i<=65535; i++)
              //SleepTimer_SyncWait(2, SleepTimer_WAIT_RELOAD);
          for (i=65535; i>=0; i--)
              //SleepTimer_SyncWait(2, SleepTimer_WAIT_RELOAD);




       But the LED that i need to dimm shows no Reaction, the LED on the Eval-Board flickers in different Brightnesses, but not at 50 KHz, i can see it with my bare eye.


      hopefully you get the problem i am describing,




      Greetings from Germany, Patrick

        • 1. Re: PWM with 50Khz

          When using a 16-bit PWM you need a frequency of 50 kHz. That means your PWM input frequency divided by the PWM-period+1 must give 50,000. so when using 24MHz your period value must be 479.




          To dim the LED you should set the pulsewidth to something between 0 (zero) and your period value (479) to have it dimmet 0 to 100%.




          Happy coding



          • 2. Re: PWM with 50Khz

            Not sure if this is appplicable but there is a LED dimming module,


            SSDM, under LED Dimming in the module catalog.




            Has the advantage of reduced clock noise.




            Regards, Dana,

            • 3. Re: PWM with 50Khz

              I´ve set the System Clock to 24 MHz and use the following Dividers VC1=6, VC2= 4, VC3=20 to create the 50KHz.




              If you want the led to switch at a 50 Khz period, duty cycle changed to control its


              brightness, then use a 8 bit, and its clock would be 256 X 50 Khz, period set to 255,


              and change the compare value over a range of 0 - 255.




              The PWM relationships from datasheet (FCLOCK is the clock you feed to PWM) -


              TOUT = (PeriodValue+1)/FCLOCK


              FOUT = FCLOCK/(PeriodValue+1)




              If you are just doing dimming 50 Khz probably unnecessarily fast, something like


              100 Hz to 1 Khz typical. If you used clock of 50 Khz to 8 bit PW, VC3, set PWM


              period to 249, then you would get LED switching freq of 200 Hz..




              Regards, Dana.

              • 4. Re: PWM with 50Khz

                Thank you for your help, now that I see how the period-value is calculated, things are much clearer.


                I know that 50KHz is a lot for just dimming a LED, but thats what is written in the specifications for the LED-Drivers im using, so I hope this works out.




                Greetings, Patrick

                • 5. Re: PWM with 50Khz

                  Keep in mind, if you can use it, the SSDM approach minimizes EMI.




                  Regards, Dana.