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

???? Multiple PWM , How to set to different frequenies ???

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



Joined: 02 Oct 2003
Posts: 2

View user's profile Send private message Send e-mail

???? Multiple PWM , How to set to different frequenies ???
PostPosted: Fri Oct 17, 2003 12:53 pm     Reply with quote

Is there a way set ccp1 and ccp2 (PWM) to diffent frequencies ?

Timer_2 seems to adjust both.

thanks


[email protected]
fpgeh



Joined: 07 Sep 2003
Posts: 19
Location: Vancouver, BC

View user's profile Send private message

PostPosted: Fri Oct 17, 2003 1:19 pm     Reply with quote

I'm sure you can do a search to find many ways of performing PWM using a timer. Here's a code snipit anyways that uses timer1. It's not as transparent as the PWM peripherals, but it runs automatically without using many resources.




#define TIMER1_OVERFLOW_CNT 65535

static BOOLEAN pinState;

// These need to be initialized
static int16 cyclesPerPeriod; // must be < TIMER1_OVERFLOW_CNT
static int16 cyclesHigh; // must be < cyclesPerPeriod


#INT_TIMER1
timer1_isr() {
// toggle output and reload timer
pinState = !pinState;
if (pinState) {
output_high(PIN_XX);
set_timer1(TIMER1_OVERFLOW_CNT - cyclesHigh);
}
else {
output_low(PIN_XX);
set_timer1(TIMER1_OVERFLOW_CNT - (cyclesPerPeriod -cyclesHigh));
}

}
Mark30504



Joined: 02 Oct 2003
Posts: 2

View user's profile Send private message Send e-mail

thanks
PostPosted: Fri Oct 17, 2003 1:47 pm     Reply with quote

Hello Thanks

I am trying to use the built in PWM fuctions of ccp1 and ccp2

but I would like to run them at different frequencies.

thanks
fpgeh



Joined: 07 Sep 2003
Posts: 19
Location: Vancouver, BC

View user's profile Send private message

PostPosted: Fri Oct 17, 2003 1:50 pm     Reply with quote

Yes, I understood your question. Unfortunately, as far as I know only CCP1 is capable of generating PWM outputs. Look at the datasheet. I was just giving an example of using a different resource to generate the 2nd PWM output.
Roger Courtney



Joined: 15 Oct 2003
Posts: 3
Location: Cleveland, Ohio

View user's profile Send private message

Re: thanks
PostPosted: Fri Oct 17, 2003 2:12 pm     Reply with quote

Mark30504 wrote:
Hello Thanks

I am trying to use the built in PWM fuctions of ccp1 and ccp2

but I would like to run them at different frequencies.

thanks


According to the datasheet, when using CCP1 and CCP2 as PWM's, "The PWMs will have the same frequency and update rate (TMR2 interrupt)" It appears you can give them different duty cycles, however.
_________________
rnc
Neutone



Joined: 08 Sep 2003
Posts: 839
Location: Houston

View user's profile Send private message

Re: thanks
PostPosted: Fri Oct 17, 2003 2:38 pm     Reply with quote

Mark30504 wrote:
Hello Thanks

I am trying to use the built in PWM fuctions of ccp1 and ccp2

but I would like to run them at different frequencies.

thanks


You can get different frequencies on the pic18 series. This is done by settign the PWM modules to seperate timers 2 and 4.

Code:
    setup_timer_2 (T2_DIV_BY_1,0x20,4);
   setup_timer_4 (T4_DIV_BY_16,0xFF,1);
   setup_ccp1(CCP_PWM);
   setup_ccp4(CCP_PWM);
   SET_PWM4_DUTY (240);
   SET_PWM1_DUTY (16);
   bit_set(*0xFB1,6);
   bit_clear(*0xFB1,3);
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Fri Oct 17, 2003 2:44 pm     Reply with quote

You can use the Compare modules to toggle the output pins. With a little thought and careful programming, you can output 2 different PWM frequencies that are "psuedo" hardware controlled. The output is controlled by hardware but you manually load the on off times. Is the frequency a multiple of the other? What frequencies are you wanting and duty cycle? Does the duty cycle change? This method is easier to do on the 18F's since you can use timer 1 & 3 to control the CCP module.
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