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
Posted: Wed Oct 10, 2007 8:37 am
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
Posted: Wed Oct 10, 2007 8:55 am
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().
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