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

PWM Newbie

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



Joined: 14 Mar 2007
Posts: 12

View user's profile Send private message ICQ Number

PWM Newbie
PostPosted: Fri Mar 16, 2007 7:11 pm     Reply with quote

Hello,

I am trying to start learning PWM techniques using 18F452.

The first simple task is to generate a fixed duty cycle- square wave using CCP1 pin of my PIC.

I simply use the following code:
( I am sorry if my question is very simple...)
Code:
#include <18F452.h>
#device adc=8

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES HS                       //High speed Osc (> 4mhz)
#FUSES NOPROTECT                //Code not protected from reading
#FUSES BROWNOUT                 //Reset when brownout detected
#FUSES PUT                      //Power Up Timer
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O


#use delay(clock=10000000)



void main()
{
  while(1)
  { set_tris_c(0);
   setup_ccp1(CCP_PWM);
   set_PWM1_DUTY(10);
   setup_timer_2(T2_DIV_BY_1,0,1);
  }
 
 }


There are several unclear points for me here.
1. This code simply produces a DC offset and there is no variation in this voltage.

2. I just see a square wave-form in the beginning and it converges to a DC offset. If I will "manually" configure PWM, what's the point of all these functions?

Please tell me my obvious mistakes.

Thanks in advance

sokrates
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Mar 16, 2007 8:19 pm     Reply with quote

See the PWM demo program in this post:
http://www.ccsinfo.com/forum/viewtopic.php?t=17729&start=1
sokrates



Joined: 14 Mar 2007
Posts: 12

View user's profile Send private message ICQ Number

checked the data-sheet
PostPosted: Fri Mar 16, 2007 8:44 pm     Reply with quote

Thanks PCM Programmer Team.

I checked the Data sheet and completely understood how this works.

I didn't set the PR register in my initial code that's why I could never clear CCP output pin resulting in an always high output.

However, I now have another problem.

I want to use PWM output to control a servo motor and the minimum frequency ( about ~ 600 Hz ) in my case is just too high.

I think I can use "post scaling" but data sheet does not have a comprehensive description about it.

Can you guys help me ?

Thanks!
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Mar 16, 2007 8:59 pm     Reply with quote

Quote:
Thanks PCM Programmer Team.

I'm not a team. I'm one user of the CCS PCM compiler.
I don't work for CCS.

See this thread about the PWM postscaler. It doesn't affect PWM frequency.
http://www.ccsinfo.com/forum/viewtopic.php?t=29846&highlight=postscaler+pwm


See my post in this thread. It has a formula to calculate the PWM
frequency. You should be able to do a frequency close to 600 Hz.
http://www.ccsinfo.com/forum/viewtopic.php?t=17993
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