Squirrels have fuzzy tails.
0 Members and 1 Guest are viewing this topic.
I still think the hardware PWM is the way to go. You do have to use all three timers, but once set up, you only have to set the pulse-width setting and forget about it until you need to change it. Changing each one is just a single variable change, and 6 of those would easily fit between UART readings.
On for 1mSOff for 20mSRepeat
On for 1uSOff for 20uSRepeat
Thank you mbateman . Hardware PWM looks like the way to go.But I also would like to understand how I would do it software-wise. I mean lets say I didn't have the ATmega168 and I was stuck with a chip that has one UART but no PWM. Would the following codeCode: [Select]On for 1mSOff for 20mSRepeat give the same voltage as this Code: [Select]On for 1uSOff for 20uSRepeat
In the case of the LED, it will just flicker between on and off creating the illusion of dimming. There will be some inherent delay in the time it takes for it to turn on and off, so you may have to expirament with your base frequency to find what works best
I guess I would need a standard delay between PWM , any ideas on how to calculate what that delay should be?
Each step would be 1/256, so to get 50% brightness, you would set OCRxx to 128.
Perceived intensity = 2.5 log (Real Intensity)
PWM is not setting a voltage, it is setting a duty cycle. If you are thinking of average voltage, then, yes, the average is .125V. But that is not what is happening. It is getting Vcc for 2.5% of the time. During that time, it is lit. The other 97.5% of the time it is off. If your base freqency is too slow, you will actually see it turn on and off. But if you set the base frequency high enough, your eyes/brain interpret it as a dim LED.
Perceived intensity is not linear. see http://en.wikipedia.org/wiki/Weber-Fechner_lawand http://en.wikipedia.org/wiki/Apparent_magnitudeSo you may need a logarithmic look up table. The last article would suggest that:Perceived intensity = 2.5 log (Real Intensity)Which would go towards explaining the result that Admin 'perceives'
Oh I see now , But how can I set it up for red, blue ,green. It should be a unique equation for each color , shouldn't it?