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

software pwm width set question

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
whung.john
Guest







software pwm width set question
PostPosted: Fri Jul 13, 2007 10:55 am     Reply with quote

hi:
today i read custom form content follow as :
but i dont understand width value ,how to culcuate.
please help me to solve,thanks u.

#include <16F877>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 4000000)

#define PWM_PIN PIN_B1

#define LOOPCNT 39

int8 width;

//-------------------------------
#INT_RTCC
void tick_interrupt(void);

//====================================
main()
{
width = 10;

setup_counters(RTCC_INTERNAL, RTCC_DIV_1);
enable_interrupts(INT_RTCC);
enable_interrupts(GLOBAL);

while(1);
}

//====================================
#INT_RTCC
void tick_interrupt(void)
{
static int8 loop = LOOPCNT;
static int8 pulse;

if(--loop == 0)
{
loop = LOOPCNT;
pulse = width;
}

if(pulse)
{
output_high(PWM_PIN);
pulse--;
}
else
{
output_low(PWM_PIN);
}

}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Jul 13, 2007 1:18 pm     Reply with quote

The width value can be from 0 to LOOPCNT. This corresponds to 0%
and 100% duty cycle. In the example below, the width = 0 for 0% duty
cycle and the width = 39 for 100% duty cycle.
Code:

#include <16F877.H>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 4000000)

#define PWM_PIN  PIN_B0

#define LOOPCNT 39

int8 width;

//-------------------------------
#INT_RTCC
void tick_interrupt(void);

//====================================
main()
{
width = 0;

setup_counters(RTCC_INTERNAL, RTCC_DIV_1);
enable_interrupts(INT_RTCC);
enable_interrupts(GLOBAL);

// Step through all values for width, from 0 to 39.
// This will slowly increase the duty cycle from 0 to 100%,
// by doing one step every 100 ms.
while(1)
  {
   for(width = 0; width <= LOOPCNT; width++)
       delay_ms(100);
  }
 
}

//====================================
#INT_RTCC
void tick_interrupt(void)
{
static int8 loop = LOOPCNT;
static int8 pulse;

if(--loop == 0)
  {
   loop = LOOPCNT;
   pulse = width;
  }

if(pulse)
  {
   output_high(PWM_PIN);
   pulse--;
  }
else
  {
   output_low(PWM_PIN);
  }

}
 
whung.john
Guest







max frequency
PostPosted: Fri Jul 13, 2007 10:57 pm     Reply with quote

thanks u very much for programmer:
but if ithink use software pwm make a frequency.
how much (MAX frequency AND min frequency) can make from software pwm RTCC OR TIMER1 OR timer2.
can u teach me how to culcuate? thanks u .
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