3 Simple Ways to
Share What You Make

With Instructables you can share what you make with the world — and tap into an ever-growing community of creative experts.

PhotosPhotos

Share one or more photos of a project, recipe, or whatever you've made, quickly and easily.

Step by StepStep-By-Step

Share your step-by-step photos with text instructions of what you made so others can do it too!

VideoVideo

Share your how-to video. You'll need your embed code from a video site such as YouTube.

PWM fade

I am using micro controller in a project that has a set of functions (API) that can be used for a plethora of things.. (just up to you to program it that way) LOL

It has a PWM control... which i am trying to use to FADE in (and out eventually) a high powered LED (LUX III to be specific).. the problem I having is that at a certain point (say at 50-60%) of full brightness I see a VISUAL jump in brightness..

Im trying to get it to be smooth the whole way through to 100%

more or less the code is like:

PWM = PWM+2

which I then wait 10 mSecs and loop it again...

I have tried to put in some conditional checking to check to see if the current level of PWM is at a certain threshold..and then only loop it again after a longer delay (say 300mSecs) or something..

I tried to search.. ut Im not sure on how to get a CONSISTANTLY smooth fade...ot smooth to say 50-60%..then a visual jump in brightness and then smooth to 100%..

any ideas or links on the subject are appreciated.

Thanks

11 comments
sort by: active | newest | oldest
Jul 5, 2009. 6:24 PMhessa59 says:
Could you measure the average voltage coming out of the pwm pin some how ie true rms voltmeter or capacitor and regular voltmeter. This will tell you if the voltage coming out of the the pwm is changing in a linear fashion. If you are generating a smoothly ramping voltage then you will have to investigate the LED characteristics. LEDs like all diodes have a "knee voltage" that is they start to conduct dramatically after a certain voltage. Check LED characteristic curves. If you combine this with possible non linearities in human vision I think it is almost certain that you will need some kind of look up table solution. Store a range of empirically determined values in an array and use a loop to feed them to the pwm statement.
Jul 3, 2009. 3:59 AMmathews says:
You may be more successful controlling to PWM yourself with outputs and delays. What else is the micro controller doing? If the program runs in a large loop regularly, you could add in an extra function to control PWM.
Jul 3, 2009. 6:20 AMmathews says:
Looking at the pin-out image of the ORION, the PWM pins are multi-purpose, each able to be an output. If you are unable to do what you want with the PWM function of the chip, don't use it. Write your own function to handle the on/off time of the output. With this you cold either pre-define the on/off times within a lookup table, or find an equation which will define the on/off time. The second will be harder to implement, but it will be much smaller.
Jul 3, 2009. 4:35 PMmathews says:
Generic PWM Solution

for(mark=0; mark++; mark == 100){ //Start for loop
space = 100 - mark; //Calculate the off time
out(0) = 1; //Turn on the output(0)
wait(mark); //Stay on for mark-time
out(0) = 0; //Turn off the output(0)
wait(space); //Stay off for the space-time
} //End for loop

This will increase from off to on at a rate of one brightness level per 0.1seconds. To make it change from on to off, invert the for statement.

i.e. for(mark = 100; mark--; mark == 0){
Jul 3, 2009. 8:50 AMPKM says:
I found that most of the high levels of LED PWM look about the same to me, a 50% duty cycle looks a lot brighter than "half brightness". I made a more continuous-looking PWM on my arduino by using a square-root function (ie rather than fading between 0-255 increasing by 1 each time, I used 0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225, 255). This appears more linear to human eyes but a bit jumpier because there are only 17 values. I'm not quite sure I get your problem- while fading you say it appears to suddenly get brighter at one point? Try slowing down the fade so that it takes 5-10 seconds and watch to see if it still happens. If so, check your code to make sure it's not skipping any values, a linear PWM shouldn't do this.
Jul 3, 2009. 11:30 AMgmoon says:
I'm not familiar with your APL, but could this be a integer range / rollover error?

There's no conditional to check if the PWM variable =< 0, so an integer would just roll over. I.E., if byte A=0, A-1 yields a value of 255.

Pro

Get More Out of Instructables

Already have an Account?

close

All Steps Viewing
View all steps of an Instructable on the same page when you're a Pro Member.

Upgrade to Pro today!