PWM with 50Khz

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

Hi,

   

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;
   
    PWM16_WritePeriod(50000);
    PWM16_WritePulseWidth(0);
    PWM16_DisableInt();
    PWM16_Start();
   
 
    M8C_EnableGInt ;                            // Turn on interrupts
      SleepTimer_Start();
      SleepTimer_SetInterval(SleepTimer_1_HZ);   // Set interrupt to a
       SleepTimer_EnableInt();
   
   
   
    while(1){
    for (i=0; i<=65535; i++)
    {
   
       
        //SleepTimer_SyncWait(2, SleepTimer_WAIT_RELOAD);
       
        PWM16_WritePulseWidth(i);
        PWM16_Start();
       
        LCD_PrHexInt(i);
   
   
   
    }
    for (i=65535; i>=0; i--)
    {
        //SleepTimer_SyncWait(2, SleepTimer_WAIT_RELOAD);
   
        PWM16_WritePulseWidth(i);
   
        LCD_PrHexInt(i);
   
    }
    }

   

 

   

 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

0 Likes
5 Replies
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

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

   

Bob

0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

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,

0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

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.

0 Likes
Anonymous
Not applicable

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

0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

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

   

 

   

Regards, Dana.

0 Likes