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

software pwm

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



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Jun 02, 2011 2:35 pm     Reply with quote

I modified his code a little bit and it works better now. Here is the revised program:

Code:

#include <18F4520.h>
#fuses HS,NOWDT,PUT,BROWNOUT,NOLVP
#use delay(clock=20M)

#define PRELOAD (65536 - 180)

#define RED    PIN_D0
#define GREEN  PIN_D1
#define BLUE   PIN_D2

int red_duty;
int green_duty;
int blue_duty;
int Intcount;


#int_timer1
void timer1_isr()
{
set_timer1(PRELOAD + get_timer1()); 

// Interrupt marker for viewing on oscilloscope.
//output_high(PIN_D7); 
//delay_us(1);
//output_low(PIN_D7);
   
if(Intcount == 255)
  {
   Intcount = 0;
   if(red_duty) output_high(RED);
   if(green_duty) output_high(GREEN);
   if(blue_duty) output_high(BLUE);   
  }   
   
if(Intcount == red_duty)
  {
   output_low(RED);
  }   

if(Intcount == green_duty)
  {
   output_low(GREEN);
  }   
 
if(Intcount == blue_duty)
  {
   output_low(BLUE);
  }   

Intcount++;
}


//=========================================
void main()
{

// Initialize interrupt counter and output pins.
Intcount = 0;
output_low(RED);
output_low(GREEN);
output_low(BLUE);

red_duty = 0;
green_duty = 1;
blue_duty = 2;

//red_duty = 253;
//green_duty = 254;
//blue_duty = 255;

setup_timer_1(T1_INTERNAL | T1_DIV_BY_1);
enable_interrupts(INT_TIMER1);
enable_interrupts(GLOBAL);


while(1);
}


 
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