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

Simple PWM problem ! Any ideas ?

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



Joined: 16 Sep 2008
Posts: 51

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

Simple PWM problem ! Any ideas ?
PostPosted: Sat Jan 17, 2009 1:27 am     Reply with quote

Hello everybody !

I have a problem with a simple PWM setup.
I'm trying to generate a 38 KHz pwm pulse, using a PIC18f452 @ 4 MHz (CCS C compiler version 4.057).
However, when i measure the pulse with PICKIT 2 logic analizer, the output doesn't correspond to 38 KHz.
Here is the output from pickit analizer :
http://rapidshare.com/files/184712495/test1.bmp.html

And here is the code of my simple application:
Code:

#include <18F452.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=4000000)

 
void main()
 {
 setup_ccp1(CCP_PWM);
 setup_timer_2(T2_DIV_BY_1, 25, 1);
 set_pwm1_duty(13);
 while(1);
  }


I've placed the capacitors as near to the crystal as possible, as it is specified in the datasheet of the pic. The values of the capacitors are correct.

What could be the problem ??

Thank you all !!
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Jan 17, 2009 1:40 pm     Reply with quote

Create a simple program to toggle a pin at about 38 KHz. Use your
PicKit2 logic analyzer to see if it can read the correct frequency of the
signal on pin B0. (Or use a different pin if your hardware requires it).
Example:
Code:

// 38 KHz has a period of about 26 us. 
// Each half-cycle is about 13 us.

while(1)
  {
   output_high(PIN_B0);
   delay_us(13);
   output_low(PIN_B0);
   delay_us(13);
  }

This will tell you if your logic analyzer is working (or is configured)
correctly.
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