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

PWM

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



Joined: 07 Sep 2007
Posts: 3

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

PWM
PostPosted: Wed Oct 10, 2007 6:07 am     Reply with quote

hi...

how to gentrate the PWM frequency 0.1Hz to 300Hz with variable DUTYCYCLES..

i am using PIC16F877A .. osc freq 20MHz..CCP1(for PWM output pin).
tom_hanks



Joined: 04 Apr 2007
Posts: 20

View user's profile Send private message

PostPosted: Wed Oct 10, 2007 8:37 am     Reply with quote

void pwmTask(unsigned int pulse_width,unsigned int period)
{
unsigned int time_on = pulse_width;
unsigned int time_off = period - pulse_width;
while(1)
{
pwm_output = 1; //pwm_output = signal connected to FET
sleep(time_on);
pwm_output = 0;
sleep(time_off);
}
}
Code:
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Oct 10, 2007 8:55 am     Reply with quote

The sleep() function doesn't mean 'pause' or 'wait' in CCS.
It puts the PIC into power-down mode. From the manual:
Quote:

Syntax: sleep(mode)
Parameters: None
Returns: Undefined
Function: Issues a SLEEP instruction. Details are device
dependent. However, in general the part will enter low power
mode and halt program execution until woken by specific external
events. Depending on the cause of the wake up execution may
continue after the sleep instruction. The compiler inserts a sleep()
after the last statement in main().
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