So in essence, we want to influence a main value by a large value at first, then less and less, or start small and go bigger. The way we increase the value we add/remove from our main number, and how we let it inlfuence it creates a non-linear curb that, when translated to brightness in a led, may or may not look linear to our naked eye. Even my sister at age 12 understands it when put like this. You don't need a table either. To get a more advanced shape one adds more variables to the mix. If you have A that increases slowly, but starts at a high level, and B that increases exponentially but start at 0, and do C(n)=C(n-1)+A-B, you can get a lot of interesting curves. Adding move variables or adjusting their curves will give even more. If you need a simple curb with a typical logarithmic-type fade in/out a tiny function can do the trick. But, a table will be faster and only use program-memory instead of RAM... KreAture ----- Original Message ----- From: "William Chops Westfield" To: Sent: Thursday, February 13, 2003 6:10 PM Subject: Re: [PIC]: Non linear PWM of LEDs > Actually, Josh, this is basic high school math. Unless you actually > are a high school student and haven't gotten to logarithms and > exponentials yet, you have no business trying to be an engineer. > > You can get through high school math, with good grades, without gaining > much of an understanding about how logarithms get applied to the real > world. More people tend to forget their basic calculus, "required" in > college but never really used. I know that the last time I looked at my > college physics text, there were an awful lot of symbols that I don't > remember how to work with (gradients and laplacians and ... stuff.) > > One need not be "trying to be an engineer" to want to play with PICs and > pretty colored LEDs. If an artist (for example) gets led into technical > issues in their search for an effect, that's OK. If they end up > understanding that there's method and science behind the scenes, that's > good (IMO), and if they end up actually digging in and relearning their > "high-school-level math", that's quite excellent. > > Historically, this has been more common in analog electronics and music, > I think. But I don't think that us "REAL Engineers" ought to be too upset > at having to explain things every once in a while. It can be better than > being asked to IMPLEMENT an effect at a level we don't understand either. > > So... > > We're trying to get preceived linear (smooth) brightness changes in a LED > by matching the (supposedly) logarithmic response of the human eye/etc. > > A "logarithmic series" is one where the next value in the series is > calculated by multiplying the previous value by a constant. > > S0 = A > S1 = S0 * C = A * C > S2 = S1 * C = A * C * C > S3 = S2 * C = A * C * C * C > : > Sn = A * C^N > > So if S0 = 1, and Sn = 255, for instance, we know that A = 1, and 255 = > C^n, where N is the number of steps in the series. To solve for C, take > the Nth root of both sides C = root(255, N) An Nth root is equivilent to > raising to the power 1/N (this is derived from logarithm theory), and this > is the "m" factor that Olin's program calculates, more or less: > m = max_out^(1.0/max_in - 1) > m = 255^(1/254) > > BillW > > -- > http://www.piclist.com hint: The PICList is archived three different > ways. See http://www.piclist.com/#archives for details. > -- http://www.piclist.com hint: The PICList is archived three different ways. See http://www.piclist.com/#archives for details.