- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Labels:
-
PSoC 1
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Keep in mind, if you can use it, the SSDM approach minimizes EMI.
Regards, Dana.