Hardware PWM LED

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 5.
To post in this forum you must have a registered copy of Flowcode 5 or higher.

Moderator: Benj

Post Reply
User avatar
acestu
Posts: 1720
Joined: Thu Dec 01, 2011 9:36 pm
Location: Macclesfield UK
Has thanked: 783 times
Been thanked: 223 times
Contact:

Hardware PWM LED

Post 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
Laptop Mac Book Pro i7 retina El Capitan //// Tower/Intel i7-Windows 7 64 Bit, Toshiba i5 Laptop Windows 10
Computers are like air conditioners. They work fine until you start opening windows.

medelec35
Matrix Staff
Posts: 9521
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Hardware PWM LED

Post 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
Martin

User avatar
BChappy
Posts: 15
Joined: Fri Jun 19, 2009 11:03 pm
Location: Lincoln, UK.
Has thanked: 13 times
Been thanked: 7 times
Contact:

Re: Hardware PWM LED

Post 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 286 times
All the best

Regards

Brian
Is your Project Not Working? - Help and General Advice Click here!
Flowcode v8 forum topic - Click here!

User avatar
acestu
Posts: 1720
Joined: Thu Dec 01, 2011 9:36 pm
Location: Macclesfield UK
Has thanked: 783 times
Been thanked: 223 times
Contact:

Re: Hardware PWM LED

Post 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
Laptop Mac Book Pro i7 retina El Capitan //// Tower/Intel i7-Windows 7 64 Bit, Toshiba i5 Laptop Windows 10
Computers are like air conditioners. They work fine until you start opening windows.

medelec35
Matrix Staff
Posts: 9521
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Hardware PWM LED

Post 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
Martin

dazz
Posts: 1314
Joined: Sun Jan 15, 2012 3:15 pm
Has thanked: 474 times
Been thanked: 458 times
Contact:

Re: Hardware PWM LED

Post 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
Attachments
HARDWARE_PWM_LEDtest.fcf
(11 KiB) Downloaded 288 times
To sign up to the V5 forum follow this link http://www.matrixmultimedia.com/forum_upgrades.php

User avatar
acestu
Posts: 1720
Joined: Thu Dec 01, 2011 9:36 pm
Location: Macclesfield UK
Has thanked: 783 times
Been thanked: 223 times
Contact:

Re: Hardware PWM LED

Post 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
Laptop Mac Book Pro i7 retina El Capitan //// Tower/Intel i7-Windows 7 64 Bit, Toshiba i5 Laptop Windows 10
Computers are like air conditioners. They work fine until you start opening windows.

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Hardware PWM LED

Post 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.

Post Reply