??? 07/13/06 17:28 Read: times |
#120218 - Back to basics Responding to: ???'s previous message |
Ammar Ahmed said:
I have seen the topic of pulse width modulation but unable to make a logic to reach the aim. So, forget about 'C' for now, and concentrate on understanding the principles involved. As I said before, You just need to be switching a pin on and off - the more on than off, the brighter it will be. ON +-------------+ +-- | | | OFF ---+ +-------------+ ^ ^ |<---delay1-->|<---delay2-->| Turn Turn Turn Pin Pin Pin ON OFF ON | | |<----------Period--------->| As shown, the LED is ON for the same length of time that it's off; therefore, it receives half the power that it'd get if it was permanently on; therefore, it's brightness is halved. If you increase delay1 (the ON time), while decreasing delay2 (the OFF time), the brightness will increase; If you decrease delay1 (the ON time), while increasing delay2 (the OFF time), the brightness will decrease; With PWM, it is common to keep the Period constant - but you don't have to! You could, say, keep delay1 constant (the LED is always ON for the same length of time), and just vary delay2 (increasing delay2 will decrease the brightness). Think about it. Draw the diagrams. You need to understand how it works first before you can start to code it! |