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 CCS Technical Support

12f675 rgb led pwm help?

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



Joined: 16 Aug 2007
Posts: 7

View user's profile Send private message

12f675 rgb led pwm help?
PostPosted: Sun Apr 06, 2008 4:40 am     Reply with quote

12f675 rgb led pwm help
and software?
inservi



Joined: 13 May 2007
Posts: 128

View user's profile Send private message

PostPosted: Sun Apr 06, 2008 8:06 am     Reply with quote

To your order my general! and we can also give you a few money ?
Wink
You probably make a mistake when typing your request!
You need to type that in a search field, not in this one.

dro.
_________________
in médio virtus
epv



Joined: 23 Feb 2008
Posts: 8

View user's profile Send private message

PostPosted: Wed Apr 09, 2008 1:00 pm     Reply with quote

Here is what you do.

Set up a fast 8 bit timer, and set it to interrupt on overflow. Now your interrupt routine will get called on every rollover of the timer. This is one "tick" of your pwm clock. In this routine, increment an 8 bit variable, which will wrap around to zero every 255 "ticks." (you can manually reset before that, if you want a faster loop and less resolution)

Now, declare three global variables to store the duty cycle of each of Red, Green, and Blue. In the interrupt routine, on every tick #0, you turn on the output pin assigned to each color. On every successive tick, you compare the current tick number to the duty cycle set for each color, and if it's been reached, you turn off that pin.

So, if you have R=50, G=100, and B=150, all three will be turned on at tick 0, R will turn off at tick 50 and remain off until the next tick 0. G will turn off at tick 100, etc...

Now, since changing the duty cycles mid-cycle will cause ugly glitches, you should set up four more global variables - one each for R, G, and B, which will be the "user accessible" ones you will actually assign values to in your main program, and a fourth to use as a flag to notify the interrupt routine that you've changed their values.

Then, in the interrupt routine, at every tick 0, you check to see whether the lag variable is set, and if so, assign the working R, G, and B variables from the user-accessible ones. This way, the duty cycle only changes at the beginning of the cycle, avoiding glitches.

Make sure to run the counter as fast as you can, (ie, no prescaling) and run at a high CPU frequency, or else you will get noticeable flicker.

Note that by doing it in software like this, you can do more than just 3 channels without too much penalty in terms of speed. Just turn on all your channels at the beginning of a cycle and then turn them off at the right times as the counter increments.

I bet this isn't the kind of "help and software" you were looking for, but knowing how it's actually done is probably more useful than someone handing you a hex file.
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