Page 1 of 1

Hardware PWM LED

Posted: Wed May 15, 2013 7:06 pm
by acestu
HI,

I have just tried to put this chart together logically without looking at examples, basically all I want to do is alter the brightness of an LED via a pot, now I have enabled PWM1 and I can change the duty cycle via the pot, then connected an LED to the ccp1 pin, but the LED does not light, I have checked that the PWM is the right output, so what am I not doing ?


HARDWARE_PWM_LED.fcf
(8.5 KiB) Downloaded 263 times
Thanks
Acestu

Re: Hardware PWM LED

Posted: Wed May 15, 2013 8:47 pm
by medelec35
1st I would place the PWM before the loop and not within the loop.
Then I would use a delay of say 100ms between ADC and PWM macros.

The PWM frequency is set at 19.KHz are you sure it needs to be that high?
1- 5KHz for example should be fine for your LED

Martin

Re: Hardware PWM LED

Posted: Wed May 15, 2013 8:51 pm
by BChappy
Hi Acestu,

I have moved PWM Enable out of the loop, this only needs to be called once.
As long as the PWM is enabled the port will be set correctly (no C Code). Not sure about the PWM / LED component simulation working!
I've not used the '877 for a long time but it should work on hardware.
I've attached a modified program.
HARDWARE_PWM_LED_2_.fcf
(9 KiB) Downloaded 287 times
All the best

Regards

Brian

Re: Hardware PWM LED

Posted: Wed May 15, 2013 9:45 pm
by acestu
Hi,

Thanks Martin and Bchappy, is the only way to change the frequency Martin to change the crystal ?,
also I take it Bchappy that this is not going to simulate anyway ?

Thanks
Acestu

Re: Hardware PWM LED

Posted: Wed May 15, 2013 10:23 pm
by medelec35
acestu wrote:is the only way to change the frequency Martin to change the crystal ?,
Acestu
No its very simple to change the frequency.
Right click PWM component thats on the control panel and select ext properties.
Change Prescaler divide to adjust course frequency.
Change the Period register to adjust finer frequency.

Martin

Re: Hardware PWM LED

Posted: Wed May 15, 2013 10:39 pm
by dazz
Hi Stu
you can change the frequency by changing the period register and prescaler divide, or by using your adc made a quick change to your chart added 2 adc channels to change the frequency just to show a quick way to change it

Regards
Dazz

Re: Hardware PWM LED

Posted: Wed May 15, 2013 10:51 pm
by acestu
Hi,

Thanks for the info guys, I understand the PWM better now, I take it that the LED does not simulate then, the only reason I ask is that the RGB LED does simulate fine.

Cheers
Acestu

Re: Hardware PWM LED

Posted: Thu May 16, 2013 10:46 am
by Benj
Hello,

Hardware PWM doesn't really simulate as it would hammer the system due to the high frequency output toggling. You can generate software based PWM using a timer interrupt and a counter, this should at least try and simulate though will probably flicker more then change brightness.