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 CCS Technical Support

Why PWM frequency generated with CCS not stable?

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



Joined: 30 Mar 2004
Posts: 8

View user's profile Send private message Visit poster's website

Why PWM frequency generated with CCS not stable?
PostPosted: Mon Apr 26, 2004 11:40 am     Reply with quote

I start my project with PICmicro and CCS C Compiler.I wrote my program to generate PWM signal but when I use Oscilloscope measure PWM signal the frequency not stable and period not constant why ?
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Mon Apr 26, 2004 1:09 pm     Reply with quote

Is your processor clock stable? If it is and you don't change the PWM divisor then the outpus has to be stable too.
_________________
The search for better is endless. Instead simply find very good and get the job done.
Haplo



Joined: 06 Sep 2003
Posts: 659
Location: Sydney, Australia

View user's profile Send private message

PostPosted: Mon Apr 26, 2004 5:13 pm     Reply with quote

erm...are you using the hardware PWM, or is it a software generated PWM?
Somkiat



Joined: 30 Mar 2004
Posts: 8

View user's profile Send private message Visit poster's website

PostPosted: Sun May 02, 2004 11:59 am     Reply with quote

I used hardware to genterate PWM and my clock was stable.
my PWM on OSC :


_____|'''''''''''|___|'''''''''''|___|''''|______|'''''''''''|___|'''''''''''|_______
t1 t2 t1 t2 tx t1 t2 t1 t2

Why tx<>t2 ?


and my code:

//========================
#include <16F877A.h>
#fuses XT,NOWDT,NOPROTECT,NOLVP
#use delay(clock=4000000)

void main()
{

int duty_cycle;

setup_ccp1(CCP_PWM);
setup_timer_2(T2_DIV_BY_1, 66, 1);
duty_cycle=9;
set_pwm1_duty(duty_cycle);
while(1);
}

PWM frequency = 15.15 khz ?
rwyoung



Joined: 12 Nov 2003
Posts: 563
Location: Lawrence, KS USA

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

PostPosted: Sun May 02, 2004 1:52 pm     Reply with quote

This may not explain your "runt" pulse but the argument for "set_pwm1_duty" is a 16 bit (long) integer. If you give it an 8 bit (int) then the compiler is supposed to shift the value right 2 bits.

How are you measuring the pulse width? I assume you are using an oscilloscope. Be sure it is triggering properly (example: rising edge, 2V) and that you have a good ground connection for the probe. Oscilloscopes (and especially digital ones) are very good liars if you don't pay attention... Confused

By the way, what version of compiler are you using? Once in a while, odd bugs creap into and out of the compiler so knowing what version you are using may help us diagnoze your problem.
_________________
Rob Young
The Screw-Up Fairy may just visit you but he has crashed on my couch for the last month!
Guest








PostPosted: Thu May 27, 2004 10:31 am     Reply with quote

Try


set_pwm1_duty((long int)(duty_cycle);

It's called "type casting"
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