View previous topic :: View next topic |
Author |
Message |
mahdifahime
Joined: 05 Jan 2013 Posts: 22
|
How to generate pwm signal on the pin c5 ? |
Posted: Sun Jan 06, 2013 12:58 pm |
|
|
I want to generate pwm signal on the pin C5 but I can't.
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: 9226 Location: Greensville,Ontario
|
|
Posted: Sun Jan 06, 2013 1:52 pm |
|
|
hmmm..according to my PIC16F72 datasheet, the CCP1 pin is RC2 NOT RC5.... |
|
|
mahdifahime
Joined: 05 Jan 2013 Posts: 22
|
|
Posted: Sun Jan 06, 2013 2:11 pm |
|
|
I understand that the CCP1 pin is RC2 but I want to use RC5 instead of RC2 |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9226 Location: Greensville,Ontario
|
|
Posted: Sun Jan 06, 2013 2:42 pm |
|
|
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
|
|
Posted: Sun Jan 06, 2013 3:03 pm |
|
|
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: 19510
|
|
Posted: Sun Jan 06, 2013 3:27 pm |
|
|
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
|
|
Posted: Sun Jan 06, 2013 11:14 pm |
|
|
It mean I can't do it? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
|