|
|
View previous topic :: View next topic |
Author |
Message |
whung.john Guest
|
software pwm width set question |
Posted: Fri Jul 13, 2007 10:55 am |
|
|
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
|
|
Posted: Fri Jul 13, 2007 1:18 pm |
|
|
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 |
Posted: Fri Jul 13, 2007 10:57 pm |
|
|
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 . |
|
|
|
|
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
|