Help

For C and ASSEMBLY users to post questions and code snippets for programming in C and ASSEMBLY. And for any other C or ASM course related questions.

Moderators: Benj, Mods

Post Reply
allenf
Posts: 9
Joined: Thu Jul 14, 2011 5:56 pm
Contact:

Help

Post by allenf »

Ive got a demo copy of flowcode 4 to see if its what I need but I`m still having trouble.
What I want to do is ramp the brightness of an LED up from 10% to about 80% then bring it to 100% then back to 80% then ramp it down to 10% then loop continuosly.
Any one got any ideas on how to do this ( I know I need to use a 16f27 / 28 /28a PIC with the pwm but all I can get it to do is either flash on or off not "pulse" )

Cheers
Allen

User avatar
JohnCrow
Valued Contributor
Valued Contributor
Posts: 1367
Joined: Wed Sep 19, 2007 1:21 pm
Location: Lincolnshire
Has thanked: 364 times
Been thanked: 716 times
Contact:

Re: Help

Post by JohnCrow »

Hi Allen

As you have stated, the best way to make an led brighness fade up & down is to use PWM. This is one of the items that is not available in the free version.
You will need to register the pro version to get this. (Not sure if PWM is in the home version.)

There are plenty of sample flowcharts on the forum, just do a search for "LED Fading" or "PWM LED Brighness"
You will be able to load the flowchart but not compile them.
LED Brightness is not something that can be simulated.

Sorry to be a bit vague
1 in 10 people understand binary, the other one doesn't !

allenf
Posts: 9
Joined: Thu Jul 14, 2011 5:56 pm
Contact:

Re: Help

Post by allenf »

Ok thanks for that

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

Re: Help

Post by medelec35 »

This should help you:
http://www.matrixmultimedia.com/mmforum ... 891#p22891
Its dimming LED using bit bang method.
You would be able to use Demo to compile bit bang method since it does not rely on the PWM component.
I have created the flowchart so if variable = 50 then LED is at 50% brightness etc.

Martin
Martin

allenf
Posts: 9
Joined: Thu Jul 14, 2011 5:56 pm
Contact:

Re: Help

Post by allenf »

Thanks for that Martin.
I`ve finally got that sample running and read through ther post time after time,
Im still just not getting how to actually FADE an led searches dont come up with anything i can understand
I`m basically looking for an automatic potentiometer for the led where it just keeps turning itself up and down ( if that makes sense)
it must be possible if a PIC can run a washing machine (which I cant) then its got to be able to turn up and down the brightness of a single led surely



I just dont get this stuff bring back black and white tv`s and slide rulers the world was an easier place

allen

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

Re: Help

Post by medelec35 »

If you switch an LED on and off fast enough (say over 80 times a second or 80Hz) it will look like is is permanently on. It looks like its on solid because of persistence of vision.
The square wave on period is called the Mark.
The off period is called the space.
The brightness of the LED is determined by the ratio of ON time of square wave compared with OFF time. The duty is ON time /ON time +OFF time.

So if square wave is on for the same length of time it is off then the duty is 50% so the LED will look like it's at half brightness.

Worked example:
Time = 1/frequency
1/80Hz = 12.5ms
If the LED is on for 3ms and off for 9.5ms (then back on for 3ms and off for 9.5ms indefinitely)
then the duty is 3/(3+9.5)*100 = 0.24*100 = 24%
So the LED will be at 24% of its full brightness or nearly 1/4 of its full brightness.
Note the on + off should add up in total to the square wave period. ie. 3 + 9.5 = 12.5 ms
This makes sense since LED is off for a longer time period then it's on. So on average should look dimmer.

Does this help?

Martin
Martin

User avatar
Steve
Matrix Staff
Posts: 3421
Joined: Tue Jan 03, 2006 3:59 pm
Has thanked: 114 times
Been thanked: 422 times
Contact:

Re: Help

Post by Steve »

One tiny note to add to Martin's great explanation is that the actual brightness of the LED is not necessarily directly proportional to the mark:space ratio. With some LEDs, you might find that the brightness you perceive is the same at 100% and 50% and the dimming of the LED only happens at lower ratios.

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

Re: Help

Post by medelec35 »

Thanks Steve,
I do agree with you, but was trying to keep explanation as simple as I could. But never the less is a valid point, and in hindsight I should have mentioned that.
@Allen. What version of Flowcode do you have?
Reason for asking is if I created a flowchart with V4, you will not be able to load flowchart with V3.
Martin

Post Reply