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

RGB LED control

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



Joined: 27 Feb 2011
Posts: 4
Location: chennai

View user's profile Send private message

RGB LED control
PostPosted: Sun Feb 27, 2011 8:17 am     Reply with quote

hai.. Very Happy

I am doing the project of multiple colors generate using RGB LED with soft color changing. Right now I only have PIC16F877A controller. It have only 2 PWM. I need 3 PWM How to I generate? Please help me.

M.Senthilkumar
Gabriel



Joined: 03 Aug 2009
Posts: 1067
Location: Panama

View user's profile Send private message

PostPosted: Mon Feb 28, 2011 8:55 am     Reply with quote

I did this exact same thing with a 16F84A about a 3 years ago.
It can be done without any hardware pwm.

You can generate a pwm signal with counters
based on that signal you can produce 2 more that are offset by 120 degrees....

I failed to backup the code and my pc crashed (died).... so I can't give it to you and I didn't try to recode it.

But it can be done easily and its pretty short code...
_________________
CCS PCM 5.078 & CCS PCH 5.093
ezflyr



Joined: 25 Oct 2010
Posts: 1019
Location: Tewksbury, MA

View user's profile Send private message

PostPosted: Mon Feb 28, 2011 10:53 am     Reply with quote

Hi,

Another possibility is to use an LED module that has a built in PWM controller, like the ShiftBrite. I recently did a project using these modules and found them very easy to work with. They can be 'cascaded', and you only need to send them digital data corresponding to color and intensity to make them work.

John
Gabriel



Joined: 03 Aug 2009
Posts: 1067
Location: Panama

View user's profile Send private message

PostPosted: Mon Feb 28, 2011 1:16 pm     Reply with quote

There are also some LEDs that have an integrated controller.
They look like an ordinary LED but constantly cycle through all color paterns....

You only need to feed it power and GND.

The software solution I mentioned is pretty simple... I think all it took was a 2 nested loops and a few counter variables...give it a try. You might learn something...

g
_________________
CCS PCM 5.078 & CCS PCH 5.093
Gabriel



Joined: 03 Aug 2009
Posts: 1067
Location: Panama

View user's profile Send private message

PostPosted: Mon Feb 28, 2011 2:04 pm     Reply with quote

Code:

int setduty=0;      //defines duty cycle
bool direction=0;   //direction of duty cycle

while(1)
{

freq=0;         //frequency period counter
counter1=0;      //duty cycle counter
output_high(PIN1);   //set pin X high

   while(freq<255)   //frequency is fixed to 255 loop cycles.
   {
      if(counter1>=setduty1) //when the desired duty cycle ends, drive pin low.
      {
      output_low(PIN1);   //On time has expired, drive pin low
      }

   freq++;      //controls the frequency period
   counter++;   //controls the pin ON state
   }

if(direction==0);   //count up till 255
setduty++;
if(direction==1);   //count down till 255
setduty--;

if(setduty>=255)   // if maximum duty cycle is reached, change directions.
direction!=direction;

}


I have not tested the above.... think of it more as pseudo code...
I wrote it in wordpad at the office..... it "should" fade a LED from off to full bright and then back to off (continuously).

You can use this as a base... incorporating 2 more pwm I/O should not be that difficult from here....

I recommend you try this out and get one LED fading on and off first.


I do not guarantee this code to work but you should get the idea...

By adding 2 more lines you could drive another pin in the exact opposite direction of the first one... when you turn "PIN1" on turn "PIN2" off....
then you will have 2 pwm 180 degrees off... in other words one LED getting brighter while the other is proportionally fading.
_________________
CCS PCM 5.078 & CCS PCH 5.093
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