View previous topic :: View next topic |
Author |
Message |
ELCouz
Joined: 18 Jul 2007 Posts: 427 Location: Montreal,Quebec
|
Need help for Software PWM (lots of channels) |
Posted: Sat Dec 27, 2014 12:53 pm |
|
|
Hi,
I've been using the PWM snippet from n-squared for years
Code: |
#use fast_io(d)
#use fast_io(b)
#use fast_io(a)
int8 byte_ix,pattern[100][3];
int8 pattern_index;
#int_timer2 high
void timer2_isr(void) // 6.6mS interrupt for 150Hz
{
output_d(pattern[pattern_index][0]);
output_b(pattern[pattern_index][1]);
output_a(pattern[pattern_index][2]);
if (++pattern_index >= 100)
pattern_index = 0;
}
void set_pwm_pattern(int8 channel, int8 duty_cycle)
{
int8 byte_ix, mask, index;
mask = 1 << (channel & 7);
byte_ix = channel >> 3;
for (index = 0; index < duty_cycle; index++)
pattern[index][byte_ix] |= mask;
mask ^= 0xFF;
while (index < 100)
pattern[index++][byte_ix] &= mask;
}
|
and i'm wondering how to modify it to work with a full integer range?
Now it's 0 to 100 for pwm duty range
I would like to bring it to 0-255 duty range.
I'm trying to understand this snippet but it's advanced stuff ![Smile](images/smiles/icon_smile.gif) _________________ Regards,
Laurent
-----------
Here's my first visual theme for the CCS C Compiler. Enjoy! |
|
![](templates/subSilver/images/spacer.gif) |
ELCouz
Joined: 18 Jul 2007 Posts: 427 Location: Montreal,Quebec
|
|
Posted: Sat Dec 27, 2014 1:31 pm |
|
|
I think I get it...
It's impossible to have a range that wide (255) because it would reduce the frequency of the pwm....
It's sad that no pic are available with many hardware pwm channels (more than 8). _________________ Regards,
Laurent
-----------
Here's my first visual theme for the CCS C Compiler. Enjoy! |
|
![](templates/subSilver/images/spacer.gif) |
temtronic
Joined: 01 Jul 2010 Posts: 9174 Location: Greensville,Ontario
|
|
Posted: Sat Dec 27, 2014 1:56 pm |
|
|
Have to ask what are you trying to control? LEDs, RC servos,??? What else does the PIC have to do ?
You can get a 16F84 to run 12 LEDs, a 46K22 24 LEDs ,using SW PWM ,depending on what else is going on.
These days you can buy 'rgb Pixels for about 50cents each, running off the SPI bus. These also several 16 bit PWM 'drivers' though I just use a small PIC,cheaper and simpler for me.
hth
jay |
|
![](templates/subSilver/images/spacer.gif) |
ELCouz
Joined: 18 Jul 2007 Posts: 427 Location: Montreal,Quebec
|
|
Posted: Sat Dec 27, 2014 2:12 pm |
|
|
temtronic wrote: | Have to ask what are you trying to control? LEDs, RC servos,??? What else does the PIC have to do ?
You can get a 16F84 to run 12 LEDs, a 46K22 24 LEDs ,using SW PWM ,depending on what else is going on.
These days you can buy 'rgb Pixels for about 50cents each, running off the SPI bus. These also several 16 bit PWM 'drivers' though I just use a small PIC,cheaper and simpler for me.
hth
jay |
I was driving 2x RGBW led strips with ULN2067B (1.5A each channel)
I found a best solution ... I could drive 16 channels with a 12-bit res. with a PIC12 using i2c!!
Using this board (chip is PCA9685)
![](http://msn.elcouz.net/$KGrHqEOKowFIt9KRSuMBSOBlIQNdQ~~60_12.JPG) _________________ Regards,
Laurent
-----------
Here's my first visual theme for the CCS C Compiler. Enjoy! |
|
![](templates/subSilver/images/spacer.gif) |
jgschmidt
Joined: 03 Dec 2008 Posts: 184 Location: Gresham, OR USA
|
|
Posted: Sat Dec 27, 2014 6:36 pm |
|
|
Take a look at the WS2803 chip... I use this to control up to 18 individual LEDS, each pulsing on and off at different speeds. You have 256 PWM levels for each output. You can also control 6 RGB LEDs. All you need is SPI OUT and SPI clock. You can also daisy-chain the chips.
You can find these on eBay for about $2 in DIP and SOIC versions. (Watch out - the pinouts are different!) There are other chips like these available, like the TI TLC5943 and variants but I found the WS2803 the easiest and most versatile for my needs. They can handle up to 30V.
email me if you need code snippets and hints on use. _________________ Jürgen
www.jgscraft.com |
|
![](templates/subSilver/images/spacer.gif) |
ELCouz
Joined: 18 Jul 2007 Posts: 427 Location: Montreal,Quebec
|
|
Posted: Sat Dec 27, 2014 10:51 pm |
|
|
jgschmidt wrote: | Take a look at the WS2803 chip... I use this to control up to 18 individual LEDS, each pulsing on and off at different speeds. You have 256 PWM levels for each output. You can also control 6 RGB LEDs. All you need is SPI OUT and SPI clock. You can also daisy-chain the chips.
You can find these on eBay for about $2 in DIP and SOIC versions. (Watch out - the pinouts are different!) There are other chips like these available, like the TI TLC5943 and variants but I found the WS2803 the easiest and most versatile for my needs. They can handle up to 30V.
email me if you need code snippets and hints on use. |
Thanks for your reply!
I dislike the TLC5943... require a precise clock signal and must be refreshed all the time... _________________ Regards,
Laurent
-----------
Here's my first visual theme for the CCS C Compiler. Enjoy! |
|
![](templates/subSilver/images/spacer.gif) |
dyeatman
Joined: 06 Sep 2003 Posts: 1924 Location: Norman, OK
|
|
Posted: Sun Dec 28, 2014 5:22 am |
|
|
Here is a cheaper board based alternative that i have used several times;
http://www.adafruit.com/products/815 _________________ Google and Forum Search are some of your best tools!!!! |
|
![](templates/subSilver/images/spacer.gif) |
ELCouz
Joined: 18 Jul 2007 Posts: 427 Location: Montreal,Quebec
|
|
![](templates/subSilver/images/spacer.gif) |
|