View previous topic :: View next topic |
Author |
Message |
Somkiat
Joined: 30 Mar 2004 Posts: 8
|
Why PWM frequency generated with CCS not stable? |
Posted: Mon Apr 26, 2004 11:40 am |
|
|
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
|
|
Posted: Mon Apr 26, 2004 1:09 pm |
|
|
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
|
|
Posted: Mon Apr 26, 2004 5:13 pm |
|
|
erm...are you using the hardware PWM, or is it a software generated PWM? |
|
|
Somkiat
Joined: 30 Mar 2004 Posts: 8
|
|
Posted: Sun May 02, 2004 11:59 am |
|
|
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
|
|
Posted: Sun May 02, 2004 1:52 pm |
|
|
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...
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
|
|
Posted: Thu May 27, 2004 10:31 am |
|
|
Try
set_pwm1_duty((long int)(duty_cycle);
It's called "type casting" |
|
|
|