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

How to generate pwm signal on the pin c5 ?

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



Joined: 05 Jan 2013
Posts: 22

View user's profile Send private message

How to generate pwm signal on the pin c5 ?
PostPosted: Sun Jan 06, 2013 12:58 pm     Reply with quote

I want to generate pwm signal on the pin C5 but I can't. Crying or Very sad
Please help me.
Code:

#include <16F72.h>
#fuses HS,NOWDT,NOPROTECT
#use delay(clock=14000000)

void main(){

int data;

delay_ms(50);
setup_timer_2(T2_DIV_BY_1,254,1);
setup_ccp1(ccp_pwm);

while(1){
   data=data+5;
   if(data==255){data=0;}
   delay_ms(50);
   set_pwm1_duty(data);
  }
}


Version: 4.128
temtronic



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

View user's profile Send private message

PostPosted: Sun Jan 06, 2013 1:52 pm     Reply with quote

hmmm..according to my PIC16F72 datasheet, the CCP1 pin is RC2 NOT RC5....
mahdifahime



Joined: 05 Jan 2013
Posts: 22

View user's profile Send private message

PostPosted: Sun Jan 06, 2013 2:11 pm     Reply with quote

I understand that the CCP1 pin is RC2 but I want to use RC5 instead of RC2
temtronic



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

View user's profile Send private message

PostPosted: Sun Jan 06, 2013 2:42 pm     Reply with quote

In that case ,you'll have to write your own PWM code.
Details you'll have to work out are frequency (Hz...KHz), resolution(# of bits) and range (0%-100% PWM).

I'm pretty sure CCS does supply an example in the 'examples' folder of the compiler.

Simplest software PWM doesn't use an ISR which means nothing else can be done. Using an ISR allows for 'multitasking'. Choice is yours.

hth
jay
mahdifahime



Joined: 05 Jan 2013
Posts: 22

View user's profile Send private message

PostPosted: Sun Jan 06, 2013 3:03 pm     Reply with quote

But i saw that generate pwm on portb or portc or porta. How to generate!!!!!??????
Even in language basic can generate pwm on port sightly
Ttelmah



Joined: 11 Mar 2010
Posts: 19388

View user's profile Send private message

PostPosted: Sun Jan 06, 2013 3:27 pm     Reply with quote

You cannot, on this chip.
Many of the later chips with things like the ECCP module, support 'pulse steering', allowing you to route the CCP signal to specific other pins, but the 16F72, _only_ supports one hardware PWM output, on pin C2.
As others have said, you can (at a much lower frequency) perform software PWM on any pin. There is an example for servo control in the code library, but all will involve a lot of processor time.
You have read something incorrect, or incorrectly.

Best Wishes
mahdifahime



Joined: 05 Jan 2013
Posts: 22

View user's profile Send private message

PostPosted: Sun Jan 06, 2013 11:14 pm     Reply with quote

It mean I can't do it?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Jan 06, 2013 11:34 pm     Reply with quote

Use software PWM on pin C5. Example:
http://www.ccsinfo.com/forum/viewtopic.php?t=37807&start=3
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