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

Generating pwm

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



Joined: 16 Mar 2009
Posts: 29

View user's profile Send private message

Generating pwm
PostPosted: Thu Aug 05, 2010 6:56 am     Reply with quote

Hi all

I have a pic16f877a and I need to generate a pwm with frequency 153600 and duty 50%.

I have
Code:

#use delay(clock=20000000)


I know I have to set timer2 and pwm1_duty. but I cannot find correct values.

for example I have tried
Code:

setup_timer_2(T2_DIV_BY_1, 31, 1);
set_pwm1_duty(66);

but it doesn't work


someone can help me?


thanks
Ttelmah



Joined: 11 Mar 2010
Posts: 19338

View user's profile Send private message

PostPosted: Thu Aug 05, 2010 7:22 am     Reply with quote

Change the set_pwm_duty line, to:

set_pwm_duty(64L);

You need the 'L' to tell the compiler to treat the constant value as a 'long' integer. Look at the manual entry for the pwm_duty function to see why this is needed.

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