CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Need help for Software PWM (lots of channels)

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
ELCouz



Joined: 18 Jul 2007
Posts: 427
Location: Montreal,Quebec

View user's profile Send private message

Need help for Software PWM (lots of channels)
PostPosted: Sat Dec 27, 2014 12:53 pm     Reply with quote

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
_________________
Regards,
Laurent

-----------
Here's my first visual theme for the CCS C Compiler. Enjoy!
ELCouz



Joined: 18 Jul 2007
Posts: 427
Location: Montreal,Quebec

View user's profile Send private message

PostPosted: Sat Dec 27, 2014 1:31 pm     Reply with quote

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!
temtronic



Joined: 01 Jul 2010
Posts: 9122
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sat Dec 27, 2014 1:56 pm     Reply with quote

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
ELCouz



Joined: 18 Jul 2007
Posts: 427
Location: Montreal,Quebec

View user's profile Send private message

PostPosted: Sat Dec 27, 2014 2:12 pm     Reply with quote

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)


_________________
Regards,
Laurent

-----------
Here's my first visual theme for the CCS C Compiler. Enjoy!
jgschmidt



Joined: 03 Dec 2008
Posts: 184
Location: Gresham, OR USA

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Sat Dec 27, 2014 6:36 pm     Reply with quote

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
ELCouz



Joined: 18 Jul 2007
Posts: 427
Location: Montreal,Quebec

View user's profile Send private message

PostPosted: Sat Dec 27, 2014 10:51 pm     Reply with quote

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!
dyeatman



Joined: 06 Sep 2003
Posts: 1912
Location: Norman, OK

View user's profile Send private message

PostPosted: Sun Dec 28, 2014 5:22 am     Reply with quote

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!!!!
ELCouz



Joined: 18 Jul 2007
Posts: 427
Location: Montreal,Quebec

View user's profile Send private message

PostPosted: Sun Dec 28, 2014 10:13 am     Reply with quote

dyeatman wrote:
Here is a cheaper board based alternative that i have used several times;
http://www.adafruit.com/products/815
Quote:


Thanks...

First I wanted to buy this but I need High current...

So the board I've purchased is up to 30v and 1A (transistor are on the board)

_________________
Regards,
Laurent

-----------
Here's my first visual theme for the CCS C Compiler. Enjoy!
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group