|
|
|
|
EE Design > In Technical
Title: Pulse-Width-Modulation using PIC Microcontrollers Author: Vincent Wong Date: 29th March 2005 PWM is a method by varying the duty-cycle of a square waveform while maintaining it's period. By varying the dutycycle, we can see that the on-time(mark) and the off time(space) also varies proportionaly. So, the average output voltage varies as the dutycycle of the waveform varies. This method is usefull to vary the voltage applied to a load e.g. an LED. Let us take a look at the waveforms below. ![]() ![]() ![]() The period is fixed to about 1ms or 1KHz. Observe the noise generated across the waveform. An LED connected to the PWM output pin gives half brightness for 50% dutycycle output followed by full brightness and least brightness as shown in the figures above. A timer is used to vary the dutycycle of the waveform. It is fixed to 1KHz. The timer value is reloaded in the main program. When the timer times out, it will clear the output pin to logic 0 and returns to main program. In the main program, the timer is turned off initially before reloding the timer register with a new value. Then the ouput pin is set to logic 1 before turning it on and enable timer interrupt. A delay if 1ms is given before the program loops back to the start of main program. This is to maintain a fixed period of 1ms. |