![]() |
|||||||||||||||||
![]() |
|
Custom Search
Readers
comments
|
|||||||||||||||
Interrupt Generated PWMThis page shows you how you can create an interrupt generated PWM signal using internal timer peripherals.PWM is Pulse Width Modulation : for more pwm pic notes click here.
There are two methods both using timers: 1.Using one timer. 2.Using two timers First MethodThe first method uses a timer to time the resolution periods of the PWM so if you needed a PWM signal with 20 distinct states (representing the duty cycle) then 1/20% duty cycle would have the time period measured by the timer.This method uses lots of processing power and produces a fairly poor PWM signal - but if you only have one timer available it does work. Performance is not good but the performance you need depends on the application e.g. for a light dimmer - this method works as well as any other. Note: For this interrupt generated pwm method the maximum frequency of the PWM is low and you can not increase it too much as the timer period becomes too small and the processor begins to spend all its time processing the interrupt. Click here for a source code example of the single timer: interrupt generated pwm. Second methodThe second method is more useful as it does not place such a load on the processor but it does use up two timer resources.The basic idea is to time the PWM period by using the first timer to measure clock cycles for this period and then generate an interrupt. When this interrupt fires the output is set high (start of the PWM signal). At this point the second timer is setup (to define the duty cycle of the PWM signal) and then its interrupt enabled. when the second interrupt fires the output is set low. This generates the PWM signal with minimal processor loading. Click here for a source code example of the double timer: interrupt generated pwm. |
|||||||||||||||||
|
|
|||||||||||||||||
|
|||||||||||||||||