Electronics > Projects, Designs, and Technical Stuff
Multiple channel PWM signal with a timer
danielks:
Is it possible to generate multiple channel PWM simultaneously using single timer interrupt on PIC ? :-\
For example using timer 0 and interrupt to generate multiple channel 50Hz PWM with different pulse width.
Or there is other better way of doing it ? :-\
Bored@Work:
--- Quote from: danielks on September 23, 2011, 04:38:08 pm ---Is it possible to generate multiple channel PWM simultaneously using single timer interrupt on PIC ? :-\
For example using timer 0 and interrupt to generate multiple channel 50Hz PWM with different pulse width.
--- End quote ---
Yes, "soft PWM" (which is the term you want to google ...) is a common technique if you need a number of simple PWM channels, and you ran out of PWM hardware.
mikeselectricstuff:
There are 2 ways to do this.
For a single channel, you can set the timer to give an interrupt after the required pulse length, then the required gap length. This has limitations at the extremes of pulse length due to how long it takes to deal with the int, but can be useful in some applications.
For multiple channels, you have to interrupt at a rate corresponding to your PWM resolution. E.g. if you want 100Hz PWM with 100 steps (=100uS/step), you set up a timer interrupt every 100uS, and update each channel's status on the interrupt.
You can get quite channel counts, but it can get tricky as channel count increases due to the need to take into account delays through the interrupt code. For up to 8 channels you can calculate all the channel bits and send them to the port as a single byte, which avoids this problem.
This technique can get quite extreme - I recently did 64 channels on an ATMEGA88 with external shift-registers for IO expansion - the interrupt code was about 2K of inline assembler!
Psi:
yeah, as you increase the number of channels and resolution you reach the limits of the micro quicker than you expect.
deephaven:
Use a small CPLD?
Navigation
[0] Message Index
[#] Next page
Go to full version