Multiple channel PWM signal with a timer  - Page 1
Forum section: electronics / projects

author: danielks
author_rank: Contributor
timestamp: September 23, 2011, 04:38:08 pm
content: 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 ?

author: Bored@Work
author_rank: Super Contributor
timestamp: September 23, 2011, 08:22:23 pm
content: Quote from: danielks on September 23, 2011, 04:38:08 pmYes, "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.

author: mikeselectricstuff
author_rank: Super Contributor
timestamp: September 25, 2011, 08:47:53 pm
content: 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!

author: Psi
author_rank: Super Contributor
timestamp: September 25, 2011, 11:22:57 pm
content: yeah, as you increase the number of channels and resolution you reach the limits of the micro quicker than you expect.

author: deephaven
author_rank: Frequent Contributor
timestamp: September 26, 2011, 11:53:56 am
content: Use a small CPLD?

author: mikeselectricstuff
author_rank: Super Contributor
timestamp: September 26, 2011, 12:17:37 pm
content: Quote from: deephaven on September 26, 2011, 11:53:56 amThe problem is you can quickly run out of registers to hold each PWM value with CPLDs. If you want lots of channels, look at chips like the TLC5941 LED driver, which gives you sixteen 12-bit PWMs.

author: deephaven
author_rank: Frequent Contributor
timestamp: September 27, 2011, 11:17:51 am
content: Quote from: mikeselectricstuff on September 26, 2011, 12:17:37 pmAn Altera EPM570 gives you 570 registers which should be enough.

author: mikeselectricstuff
author_rank: Super Contributor
timestamp: September 27, 2011, 11:37:00 am
content: Quote from: deephaven on September 27, 2011, 11:17:51 amI wouldn't call a >£10 CPLD small. CPLDs tend to get expensive over about 72 cells - an FPGA would be a lot cheaper than this part, and you then have plenty of RAM to store PWM values.

author: deephaven
author_rank: Frequent Contributor
timestamp: September 27, 2011, 12:30:51 pm
content: Quote from: mikeselectricstuff on September 27, 2011, 11:37:00 amYou're right, £10.82 one off from Farnell, but don't all FPGAs need an external config eprom which would bump the cost up?

author: McMonster
author_rank: Frequent Contributor
timestamp: September 27, 2011, 04:44:10 pm
content: Quote from: deephaven on September 27, 2011, 12:30:51 pmSome of the smaller ones have it built in.