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

Need help for pwm

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



Joined: 09 Mar 2007
Posts: 6

View user's profile Send private message

Need help for pwm
PostPosted: Fri Mar 09, 2007 3:43 am     Reply with quote

I write the following program to generate pwm and there is no output 0n rc2/ccp1 pin ,any body help me.

#include <16F877A.h>
#fuses HS
#fuses NOWDT
#fuses NOPROTECT
#fuses NOLVP
#fuses NODEBUG
#fuses NOPUT
#fuses NOBROWNOUT
#use delay(clock=20000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)
#use fast_io(A)
#use fast_io(B)
#use fast_io(C)
#use fast_io(D)
#pragma zero_ram
#define motora PIN_B7
void main(void)
{

set_tris_c(0b00000000);

setup_timer_2(T2_DIV_BY_16,255,1);
setup_ccp1(CCP_PWM);
set_pwm1_duty(1023);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);

// TODO: USER CODE!!

}
Ttelmah
Guest







PostPosted: Fri Mar 09, 2007 4:54 am     Reply with quote

Two things:
Unless you add:

while (TRUE);

at the end of your code, the processor will go to sleep, and no output at all will occur.

Second, you need a lower duty cycle, to see any pulse.
Set_pwm1_duty(512L);

will give a square wave, which will be easier to see. The 'L', is not necessary with 512 (since it is above 255), but ensures that the code 'sees' a 'long', no matter what value is given, and treats the number as such.

Best Wishes
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